@import '../../style/themes/index';
@import '../../style/mixins/index';

@yee-radio-prefix-cls: ~'@{yee-prefix}-radio';
@yee-radio-group-prefix-cls: ~'@{yee-radio-prefix-cls}-group';
@yee-radio-inner-prefix-cls: ~'@{yee-radio-prefix-cls}-inner';
@yee-radio-duration: 0.3s;
@yee-radio-focus-shadow: 0 0 0 3px fade(@yee-radio-dot-color, 8%);
@yee-radio-button-focus-shadow: @yee-radio-focus-shadow;

.@{yee-radio-group-prefix-cls} {
  .yee-reset-component;

  display: inline-block;
}

// 一般状态
// .@{yee-radio-prefix-cls}-wrapper {
//   .yee-reset-component;

//   position: relative;
//   display: inline-block;
//   margin-right: 8px;
//   white-space: nowrap;
//   cursor: pointer;
// }

.@{yee-radio-prefix-cls} {
  .yee-reset-component;

  position: relative;
  display: inline-block;
  line-height: 1;
  white-space: nowrap;
  vertical-align: sub;
  outline: none;
  cursor: pointer;

  .@{yee-radio-prefix-cls}-wrapper:hover &,
  &:hover .@{yee-radio-inner-prefix-cls},
  &-input:focus + .@{yee-radio-inner-prefix-cls} {
    border-color: @yee-radio-dot-color;
  }

  &-input:focus + .@{yee-radio-inner-prefix-cls} {
    box-shadow: @yee-radio-focus-shadow;
  }

  &-checked::after {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: 1px solid @yee-radio-dot-color;
    border-radius: 50%;
    visibility: hidden;
    animation: antRadioEffect 0.36s ease-in-out;
    animation-fill-mode: both;
    content: '';
  }

  &:hover::after,
  .@{yee-radio-prefix-cls}-wrapper:hover &::after {
    visibility: visible;
  }

  &-inner {
    &::after {
      @yee-radio-dot-size: @yee-radio-size - 8px;

      position: absolute;
      top: (@yee-radio-size - @yee-radio-dot-size) / 2 - 1px;
      left: (@yee-radio-size - @yee-radio-dot-size) / 2 - 1px;
      display: table;
      width: @yee-radio-dot-size;
      height: @yee-radio-dot-size;
      background-color: @yee-radio-dot-color;
      border-top: 0;
      border-left: 0;
      border-radius: @yee-radio-dot-size;
      transform: scale(0);
      opacity: 0;
      transition: all @yee-radio-duration @yee-ease-in-out-circ;
      content: ' ';
    }

    position: relative;
    top: 0;
    left: 0;
    display: block;
    width: @yee-radio-size;
    height: @yee-radio-size;
    background-color: @yee-radio-button-bg;
    border-color: @yee-border-color-base;
    border-style: solid;
    border-width: 1px;
    border-radius: 100px;
    transition: all @yee-radio-duration;
  }

  &-input {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 1;
    cursor: pointer;
    opacity: 0;
  }
}

// 选中状态
.@{yee-radio-prefix-cls}-checked {
  .@{yee-radio-inner-prefix-cls} {
    border-color: @yee-radio-dot-color;
    &::after {
      transform: scale(1);
      opacity: 1;
      transition: all @yee-radio-duration @yee-ease-in-out-circ;
    }
  }
}

.@{yee-radio-prefix-cls}-disabled {
  .@{yee-radio-inner-prefix-cls} {
    background-color: @yee-input-disabled-bg;
    border-color: @yee-border-color-base !important;
    cursor: not-allowed;
    &::after {
      background-color: fade(@yee-black, 20%);
    }
  }

  .@{yee-radio-prefix-cls}-input {
    cursor: not-allowed;
  }

  & + span {
    color: @yee-disabled-color;
    cursor: not-allowed;
  }
}

span.@{yee-radio-prefix-cls} + * {
  padding-right: 8px;
  padding-left: 8px;
}

.@{yee-radio-prefix-cls}-button-wrapper {
  position: relative;
  display: inline-block;
  height: @yee-btn-height-base;
  margin: 0;
  padding: 0 @yee-padding-md - 1px;
  color: @yee-radio-button-color;
  line-height: @yee-btn-height-base - 2px;
  background: @yee-radio-button-bg;
  border: @yee-border-width-base @yee-border-style-base @yee-border-color-base;
  // strange align fix for chrome but works
  // https://gw.alipayobjects.com/zos/rmsportal/VFTfKXJuogBAXcvfAUWJ.gif
  border-top-width: @yee-border-width-base + 0.02px;
  border-left: 0;
  cursor: pointer;
  transition:
    color 0.3s,
    background 0.3s,
    border-color 0.3s,
    box-shadow 0.3s;

  a {
    color: @yee-radio-button-color;
  }

  > .@{yee-radio-prefix-cls}-button {
    display: block;
    width: 0;
    height: 0;
    margin-left: 0;
  }

  .@{yee-radio-group-prefix-cls}-large & {
    height: @yee-input-height-lg;
    font-size: @yee-font-size-lg;
    line-height: @yee-input-height-lg - 2px;
  }

  .@{yee-radio-group-prefix-cls}-small & {
    height: @yee-input-height-sm;
    padding: 0 @yee-control-padding-horizontal-sm - 1px;
    line-height: @yee-input-height-sm - 2px;
  }

  &:not(:first-child) {
    &::before {
      position: absolute;
      top: @yee-border-width-base * -1;
      left: -1px;
      display: block;
      box-sizing: content-box;
      width: 1px;
      height: 100%;
      padding: @yee-border-width-base 0;
      background-color: @yee-border-color-base;
      transition: background-color 0.3s;
      content: '';
    }
  }
  &:first-child {
    border-left: @yee-border-width-base @yee-border-style-base @yee-border-color-base;
    border-radius: @yee-border-radius-base 0 0 @yee-border-radius-base;
  }

  &:last-child {
    border-radius: 0 @yee-border-radius-base @yee-border-radius-base 0;
  }

  &:first-child:last-child {
    border-radius: @yee-border-radius-base;
  }

  &:hover {
    position: relative;
    color: @yee-radio-dot-color;
  }

  &:focus-within {
    box-shadow: @yee-radio-button-focus-shadow;
  }

  .@{yee-radio-prefix-cls}-inner,
  input[type='checkbox'],
  input[type='radio'] {
    width: 0;
    height: 0;
    opacity: 0;
    pointer-events: none;
  }

  &-checked:not(&-disabled) {
    z-index: 1;
    color: @yee-radio-dot-color;
    background: @yee-radio-button-checked-bg;
    border-color: @yee-radio-dot-color;

    &::before {
      background-color: @yee-radio-dot-color;
    }

    &:first-child {
      border-color: @yee-radio-dot-color;
    }

    &:hover {
      color: @yee-radio-button-hover-color;
      border-color: @yee-radio-button-hover-color;
      &::before {
        background-color: @yee-radio-button-hover-color;
      }
    }

    &:active {
      color: @yee-radio-button-active-color;
      border-color: @yee-radio-button-active-color;
      &::before {
        background-color: @yee-radio-button-active-color;
      }
    }

    &:focus-within {
      box-shadow: @yee-radio-button-focus-shadow;
    }
  }

  .@{yee-radio-group-prefix-cls}-solid &-checked:not(&-disabled) {
    color: @yee-component-background;
    background: @yee-radio-dot-color;
    border-color: @yee-radio-dot-color;
    &:hover {
      color: @yee-component-background;
      background: @yee-radio-button-hover-color;
      border-color: @yee-radio-button-hover-color;
    }
    &:active {
      color: @yee-component-background;
      background: @yee-radio-button-active-color;
      border-color: @yee-radio-button-active-color;
    }
    &:focus-within {
      box-shadow: @yee-radio-button-focus-shadow;
    }
  }

  &-disabled {
    color: @yee-disabled-color;
    background-color: @yee-input-disabled-bg;
    border-color: @yee-border-color-base;
    cursor: not-allowed;

    &:first-child,
    &:hover {
      color: @yee-disabled-color;
      background-color: @yee-input-disabled-bg;
      border-color: @yee-border-color-base;
    }
    &:first-child {
      border-left-color: @yee-border-color-base;
    }
  }

  &-disabled&-checked {
    color: @yee-text-color-inverse;
    background-color: tint(@yee-black, 90%);
    border-color: @yee-border-color-base;
    box-shadow: none;
  }
}

@keyframes antRadioEffect {
  0% {
    transform: scale(1);
    opacity: 0.5;
  }
  100% {
    transform: scale(1.6);
    opacity: 0;
  }
}

// Firefox hack
@supports (-moz-appearance: meterbar) and (background-blend-mode: difference, normal) {
  .@{yee-radio-prefix-cls} {
    vertical-align: text-bottom;
  }
}
