@use "variables";

$defaultHeight: 16px;
$defaultWidth: 16px;
$lgHeight: 24px;
$lgWidth: 24px;

%radio-label-before {
  flex-direction: row-reverse;
  justify-content: space-between;

  .fwe-radio-label-content {
    margin-left: 0px;
    margin-right: 8px;
  }
}

%radio-label-below {
  flex-direction: column;

  .fwe-radio-label-content {
    margin: 8px 0px 0px 0px;
  }
}

.fwe-radio-group {
  &.fwe-radio-lg {
    label.fwe-radio {
      .fwe-radio-checkmark {
        height: $lgHeight;
        width: $lgWidth;

        &::after {
          border-width: 8px;
        }
      }

      .fwe-radio-label-content {
        line-height: 32px;
      }
    }
  }

  &.fwe-radio-label-before {
    label.fwe-radio {
      @extend %radio-label-before;
    }
  }

  &.fwe-radio-label-below {
    label.fwe-radio {
      @extend %radio-label-below;
    }
  }
}

label.fwe-radio {
  cursor: pointer;
  display: flex;
  align-items: center;
  vertical-align: middle;
  -webkit-user-select: none;
  user-select: none;

  .fwe-radio-checkmark {
    position: relative;
    height: $defaultHeight;
    width: $defaultWidth;
    box-sizing: border-box;
    display: inline-block;

    &::before {
      content: "";
      position: absolute;
      top: 0;
      left: 0;
      box-sizing: border-box;
      width: 100%;
      height: 100%;
      border-width: 1px;
      border-style: solid;
      border-radius: 50%;
      border-color: variables.$control-border;
      background-color: variables.$white;
    }

    &::after {
      content: "";
      position: absolute;
      top: 0;
      left: 0;
      box-sizing: border-box;
      width: 100%;
      height: 100%;
      transform: scale(0, 0);
      border-width: 5px;
      border-style: solid;
      border-radius: 50%;
      border-color: variables.$white;
      background-color: variables.$white;
      transition: none;
    }
  }

  &.fwe-radio-lg {
    .fwe-radio-checkmark {
      height: $lgHeight;
      width: $lgWidth;

      &::after {
        border-width: 8px;
      }
    }

    .fwe-radio-label-content {
      line-height: 32px;
    }
  }

  .fwe-radio-label-content {
    line-height: 24px;
    margin-left: 8px;
  }

  &.fwe-radio-label-before {
    @extend %radio-label-before;
  }

  &.fwe-radio-label-below {
    @extend %radio-label-below;
  }

  input[type="radio"] {
    position: absolute;
    opacity: 0;
    cursor: pointer;

    &:hover:not(:disabled) ~ .fwe-radio-checkmark::before {
      background-color: variables.$control;
    }

    &:hover:user-invalid ~ .fwe-radio-checkmark::before {
      background-color: variables.$white;
    }

    &:hover:checked:not(:disabled) ~ .fwe-radio-checkmark::after {
      border-color: variables.$hero-hover;
    }

    &:active ~ .fwe-radio-checkmark::before {
      border-color: variables.$control-hover;
      background-color: variables.$white;
    }

    &:checked ~ .fwe-radio-checkmark::before {
      border-color: variables.$border;
      background-color: variables.$hero;
    }

    &:checked ~ .fwe-radio-checkmark::after {
      border-color: variables.$hero;
      transition: transform ease-out 0.15s;
      transform: scale(1, 1);
    }

    &:disabled ~ .fwe-radio-checkmark::before {
      background-color: variables.$control-disabled;
      border-color: variables.$control-disabled;
      cursor: not-allowed;
    }

    &:disabled ~ .fwe-radio-checkmark::after {
      background-color: variables.$white;
      border-color: variables.$control-disabled;
      cursor: not-allowed;
    }

    &:disabled {
      cursor: not-allowed;
    }

    &:disabled ~ .fwe-radio-label-content {
      color: variables.$text-disabled;
      cursor: not-allowed;
    }

    &:user-invalid ~ .fwe-radio-checkmark::before {
      border-color: variables.$red;
    }
  }
}
