@use 'sass:map';

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

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

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

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

  @include when(bordered) {
    padding: map.get($radio-bordered-padding, 'default');
    border-radius: var(--el-border-radius-base);
    border: var(--el-border-base);
    box-sizing: border-box;

    &:hover .#{$namespace}-radio__inner {
      border-color: var(--el-radio-checked-input-border-color);
    }

    &.is-checked {
      border-color: var(--el-color-primary);
    }

    &.is-disabled {
      cursor: not-allowed;
      border-color: var(--el-border-color-light);
    }

    & + .#{$namespace}-radio.is-bordered {
      margin-left: 10px;
    }

    @each $size in (medium, small) {
      &.#{$namespace}-radio--#{$size} {
        padding: map.get($radio-bordered-padding, $size);
        border-radius: var(--el-border-radius-base);

        .#{$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;

        &::after {
          cursor: not-allowed;
          border-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');
          }
        }
      }
      & + span.#{$namespace}-radio__label {
        color: var(--el-text-color-placeholder);
        cursor: not-allowed;
      }
    }

    @include when(checked) {
      .#{$namespace}-radio__inner {
        border-color: map.get($radio-checked, 'input-border-color');
        background: map.get($radio-checked, 'input-background-color');

        &::after {
          transform: rotate(45deg) scaleY(1);
        }
      }

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

    @include when(focus) {
      .#{$namespace}-radio__inner {
        border-color: var(--el-radio-input-border-color-hover);
      }
    }
  }
  @include e(inner) {
    border: var(--el-radio-input-border);
    border-radius: var(--el-radio-input-border-radius);
    width: var(--el-radio-input-width);
    height: var(--el-radio-input-height);
    background-color: var(--el-radio-input-bg-color);
    position: relative;
    cursor: pointer;
    display: inline-block;
    box-sizing: border-box;

    &:hover {
      border-color: var(--el-radio-input-border-color-hover);
    }

    &::after {
      box-sizing: content-box;
      content: '';
      border: 1px solid map.get($radio-checked, 'icon-color');
      border-left: 0;
      border-top: 0;
      height: 6px;
      left: 4px;
      position: absolute;
      top: 2px;
      transform: rotate(45deg) scaleY(0);
      width: 3px;
      transition: transform 0.15s ease-in 0.05s;
      transform-origin: center;
    }
  }

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

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

  @include e(label) {
    font-size: var(--el-radio-font-size);
    padding-left: 10px;
  }
}
