@use 'sass:map';

@use 'mixins/mixins' as *;
@use 'mixins/utils' as *;
@use 'mixins/var' as *;
@use 'mixins/button' as *;
@use 'common/var' as *;

$radio-font-size: () !default;
$radio-font-size: map.merge($button-font-size, $radio-font-size);

@include b(radio) {
  @include set-component-css-var('radio', $radio);
}

@include b(radio) {
  color: getCssVar('radio-text-color');
  font-weight: getCssVar('radio-font-weight');
  position: relative;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
  outline: none;
  font-size: getCssVar('font-size', 'base');
  user-select: none;
  margin-right: 30px;
  height: map.get($radio-height, 'default');

  @each $size in $sizes {
    &.#{$namespace}-radio--#{$size} {
      height: map.get($radio-height, $size);
    }
  }

  @include when(bordered) {
    padding: 0 map.get($checkbox-bordered-padding-right, 'default')-$border-width 0 map.get($checkbox-bordered-padding-left, 'default')-$border-width;

    border-radius: getCssVar('border-radius-small');
    border: getCssVar('border');
    box-sizing: border-box;

    &.is-checked {
      border-color: getCssVar('color-primary');
    }

    &.is-disabled {
      cursor: not-allowed;
      border-color: getCssVar('color-neutral-light-4');
    }

    @each $size in $sizes {
      &.#{$namespace}-radio--#{$size} {
        padding: 0 map.get($checkbox-bordered-padding-right, $size)-$border-width 0 map.get($checkbox-bordered-padding-left, $size)-$border-width;
        border-radius: getCssVar('border-radius-small');

        .#{$namespace}-radio__label {
          font-size: map.get($button-font-size, $size);
        }

        .#{$namespace}-radio__inner {
          height: map.get($radio-bordered-input-height, $size);
          width: map.get($radio-bordered-input-width, $size);
        }
      }
    }
  }

  &:last-child {
    margin-right: 0;
  }

  @include e(input) {
    white-space: nowrap;
    cursor: pointer;
    outline: none;
    display: inline-flex;
    position: relative;
    vertical-align: middle;

    @include when(disabled) {
      .#{$namespace}-radio__inner {
        background-color: map.get($radio-disabled, 'input-fill');
        border-color: map.get($radio-disabled, 'input-border-color');
        cursor: not-allowed;
        box-shadow: inset 0 0 0 2px #fff;

        &::after {
          cursor: not-allowed;
          background-color: map.get($radio-disabled, 'icon-color');
        }

        & + .#{$namespace}-radio__label {
          cursor: not-allowed;
        }
      }
      &.is-checked {
        .#{$namespace}-radio__inner {
          background-color: map.get($radio-disabled, 'checked-input-fill');
          border-color: map.get($radio-disabled, 'checked-input-border-color');

          &::after {
            border-color: map.get($radio-disabled, 'checked-icon-color');
            background-color: getCssVar('color-white');
          }
        }
      }
      & + span.#{$namespace}-radio__label {
        color: getCssVar('text-color', 'placeholder');
        cursor: not-allowed;
      }
    }

    @include when(checked) {
      .#{$namespace}-radio__inner {
        border: 1.5px solid map.get($radio-checked, 'icon-color');

        &::after {
          transform: rotate(45deg) scaleY(1);
          border-color: getCssVar('color-success');
        }
      }

      & + .#{$namespace}-radio__label {
        color: map.get($radio-checked, 'text-color');
      }
    }

    @include when(focus) {
      .#{$namespace}-radio__inner {
        border-color: getCssVar('radio-input-border-color-hover');
      }
    }
  }
  @include e(inner) {
    border: getCssVar('radio-input-border');
    border-radius: getCssVar('radio-input-border-radius');
    // width: getCssVar('radio-input-width');
    // height: getCssVar('radio-input-height');
    width: map.get($radio-bordered-input-height, 'default');
    height: map.get($radio-bordered-input-height, 'default');
    background-color: getCssVar('radio-input-bg-color');
    position: relative;
    cursor: pointer;
    display: inline-block;
    box-sizing: border-box;
    z-index: getCssVar('index-normal');
    transition:
      border-color 0.25s cubic-bezier(0.71, -0.46, 0.29, 1.46),
      background-color 0.25s cubic-bezier(0.71, -0.46, 0.29, 1.46),
      outline 0.25s cubic-bezier(0.71, -0.46, 0.29, 1.46);

    display: flex;
    align-items: center;
    justify-content: center;

    &:hover {
      border-color: getCssVar('radio-input-border-color-hover');
    }

    &::after {
      box-sizing: content-box;
      content: '';
      border: 1.5px solid transparent;
      border-left: 0;
      border-top: 0;
      height: 7px;
      left: 4px;
      // position: absolute;
      top: 1px;
      transform: rotate(45deg) scaleY(0);
      width: 3px;
      transition: transform 0.15s ease-in 0.05s;
      transform-origin: center;
      margin-left: -0.5px;
      margin-top: -2px;
    }
  }

  @include e(original) {
    opacity: 0;
    outline: none;
    position: absolute;
    z-index: -1;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    margin: 0;

    &:focus-visible {
      & + .#{$namespace}-radio__inner {
        outline: 2px solid getCssVar('radio-input-border-color-hover');
        outline-offset: 1px;
        border-radius: getCssVar('radio-input-border-radius');
      }
    }
  }

  &:focus:not(:focus-visible):not(.is-focus):not(:active):not(.is-disabled) {
    /*获得焦点时 样式提醒*/
    .#{$namespace}-radio__inner {
      box-shadow: 0 0 2px 2px getCssVar('radio-input-border-color-hover');
    }
  }

  @include e(label) {
    font-size: getCssVar('radio-font-size');
    padding-left: 8px;
  }

  @each $size in $sizes {
    &.#{$namespace}-radio--#{$size} {
      @include e(label) {
        font-size: map.get($radio-font-size, $size);
      }
      @include e(inner) {
        width: map.get($radio-bordered-input-height, $size);
        height: map.get($radio-bordered-input-height, $size);

        &::after {
          @extend %#{$size}-radio;
        }
      }
    }
  }
}
%large-radio,
%default-radio {
  width: 3px;
  height: 7px;
  left: 4px;
}

%medium-radio {
  width: 2px;
  height: 6px;
  left: 4px;
}

%small-radio,
%mini-radio {
  width: 2px;
  height: 4px;
  left: 3px;
}
