@import './../theme/vars.scss';

$radio-prefix-cls: #{$vender-prefix}-radio2;
$radio-group-prefix-cls: #{$radio-prefix-cls}-group;
$radio-inner-prefix-cls: #{$radio-prefix-cls}-inner;
$radio-duration: 0.3s;

.#{$radio-group-prefix-cls} {
  display: inline-block;
  font-size: $font-size-base;
}

// 一般状态
.#{$radio-prefix-cls}-wrapper {
  position: relative;
  display: inline-block;
  margin-right: 8px;
  font-size: $font-size-base;
  white-space: nowrap;
  cursor: pointer;
}

.#{$radio-prefix-cls} {
  position: relative;
  display: inline-block;
  line-height: 1;
  white-space: nowrap;
  vertical-align: text-bottom;
  cursor: pointer;
  outline: none;

  .#{$radio-prefix-cls}-wrapper:hover:not(.#{$radio-prefix-cls}-wrapper-disabled) &,
  &:hover:not(.#{$radio-prefix-cls}-disabled),
  &-focused {
    .#{$radio-inner-prefix-cls} {
      border-color: $primary-color;
    }
  }

  &-checked::after {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: 1px solid $primary-color;
    border-radius: 50%;
    content: '';
    visibility: hidden;
  }

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

  &-inner {
    position: relative;
    top: 0;
    left: 0;
    display: block;
    width: 16px;
    height: 16px;
    background-color: white;
    border: 1px solid $border-color-base;
    border-radius: 16px;
    transition: all $radio-duration;

    &::after {
      position: absolute;
      top: 3px;
      left: 3px;
      display: table;
      width: 8px;
      height: 8px;
      background-color: $primary-color;
      border-top: 0;
      border-left: 0;
      border-radius: $border-radius-base;
      content: ' ';
      opacity: 0;
      transform: scale(0);
      transition: all $radio-duration $ease-in-out-circ;
    }
  }

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

.#{$radio-prefix-cls}-vertical {
  display: block;
  margin-right: 0;

  & + .#{$radio-prefix-cls}-vertical {
    margin-top: 8px;
  }
}

// 选中状态
.#{$radio-prefix-cls}-checked {
  .#{$radio-inner-prefix-cls} {
    border-color: $primary-color;

    &::after {
      opacity: 1;
      transform: scale(1);
      transition: all $radio-duration $ease-in-out-circ;
    }
  }
}

.#{$radio-prefix-cls}-disabled {
  .#{$radio-inner-prefix-cls} {
    background-color: $radio-disable-bg;
    border-color: $border-color-base;

    &::after {
      background-color: #ccc;
    }
  }

  .#{$radio-prefix-cls}-input {
    cursor: not-allowed;
  }

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

span.#{$radio-prefix-cls} + * {
  padding: 0 8px;
}

.#{$radio-prefix-cls}-button-wrapper {
  position: relative;
  display: inline-block;
  height: $radio-height;
  padding: 0 16px;
  margin: 0;
  line-height: $radio-height - 2;
  color: black;
  cursor: pointer;
  background: white;
  border: $border-width-base $border-style-base $border-color-base;
  border-left: 0;
  transition: all 0.3s ease;

  a {
    color: white;
  }

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

  .#{$radio-group-prefix-cls}-lg & {
    height: $radio-height-lg;
    line-height: $radio-height-lg - 2px;
  }

  .#{$radio-group-prefix-cls}-sm & {
    height: $radio-height-sm;
    padding: 0 12px;
    line-height: $radio-height-sm - 2;

    &:first-child {
      border-radius: $border-radius-sm 0 0 $border-radius-sm;
    }

    &:last-child {
      border-radius: 0 $border-radius-sm $border-radius-sm 0;
    }
  }

  &:not(:first-child) {
    &::before {
      position: absolute;
      top: 0;
      left: -1px;
      display: block;
      width: 1px;
      height: 100%;
      background-color: $border-color-base;
      content: '';
    }
  }

  &:first-child {
    border-left: $border-width-base $border-style-base $border-color-base;
    border-radius: $border-radius-base 0 0 $border-radius-base;
  }

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

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

  &:hover,
  &-focused {
    position: relative;
    color: $primary-color;
  }

  .#{$radio-prefix-cls}-inner,
  input[type='checkbox'],
  input[type='radio'] {
    width: 0;
    height: 0;
    opacity: 0;
  }

  &-checked {
    z-index: 1;
    color: $primary-color;
    background: white;
    border-color: $primary-color;
    box-shadow: -1px 0 0 0 $primary-color;

    &::before {
      background-color: $primary-color;
      opacity: 0.1;
    }

    &:first-child {
      border-color: $primary-color;
      box-shadow: none;
    }

    &:hover {
      color: $primary-5;
      border-color: $primary-5;
      box-shadow: -1px 0 0 0 $primary-5;
    }

    &:active {
      color: $primary-7;
      border-color: $primary-7;
      box-shadow: -1px 0 0 0 $primary-7;
    }
  }

  &-disabled {
    color: $disabled-color;
    cursor: not-allowed;
    background-color: $radio-disable-bg;
    border-color: $border-color-base;

    &:first-child,
    &:hover {
      color: $disabled-color;
      background-color: $radio-disable-bg;
      border-color: $border-color-base;
    }

    &:first-child {
      border-left-color: $border-color-base;
    }
  }

  &-disabled#{&}-checked {
    color: white;
    background-color: #e6e6e6;
    border-color: $border-color-base;
    box-shadow: none;
  }
}
