@import "../../style/index";
@import "../../style/mixins/index";

@radio-prefix-cls: ~"@{ant-prefix}-radio";
@radio-group-prefix-cls: ~"@{radio-prefix-cls}-group";
@radio-inner-prefix-cls: ~"@{radio-prefix-cls}-inner";
@radio-duration: 0.3s;
@radio-focus-shadow: 0 0 0 3px @slider-handle-color-focus-shadow;
@radio-button-focus-shadow: @radio-focus-shadow;

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

  display: inline-block;
  font-size: 0;

  .@{ant-prefix}-badge-count {
    z-index: 1;
  }

  > .@{ant-prefix}-badge:not(:first-child)
    > .@{radio-prefix-cls}-button-wrapper {
    border-left: none;
  }

  &&-large {
    .@{radio-prefix-cls}-button-wrapper {
      padding: 0 @radio-button-padding-horizontal-lg;
    }
  }

  &&-small {
    .@{radio-prefix-cls}-button-wrapper {
      padding: 0 @radio-button-padding-horizontal-sm;
    }
  }
}

// 一般状态
.@{radio-prefix-cls}-wrapper {
  .reset-component();
  position: relative;
  display: inline-flex;
  align-items: baseline;
  cursor: pointer;
  color: @text-color-primary;

  &:not(:last-child) {
    margin-right: @radio-wrapper-margin-right;
  }

  &-disabled {
    cursor: not-allowed;
  }

  &::after {
    display: inline-block;
    width: 0;
    overflow: hidden;
    content: "\a0";
  }

  &&-in-form-item {
    input[type="radio"] {
      width: 14px;
      height: 14px;
    }
  }
}

.@{radio-prefix-cls} {
  .reset-component();

  position: relative;
  top: @radio-top;
  display: inline-block;
  outline: none;
  cursor: pointer;

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

    &-inner {
      background-color: @radio-hover-bg;
    }
  }

  &-input:focus + .@{radio-inner-prefix-cls} {
    background-color: @radio-active-bg;
  }

  &-inner {
    background-color: @component-background;

    &::after {
      position: absolute;
      top: 50%;
      left: 50%;
      display: block;
      width: @radio-size;
      height: @radio-size;
      margin-top: -(@radio-size / 2);
      margin-left: -(@radio-size / 2);
      background-color: @component-background;
      border-top: 0;
      border-left: 0;
      border-radius: @radio-size;
      transform: scale(0);
      opacity: 0;
      transition: all @radio-duration @ease-in-out-circ;
      content: " ";
    }

    position: relative;
    top: 0;
    left: 0;
    display: block;
    width: @radio-size;
    height: @radio-size;
    border-color: @radio-border-color;
    border-style: solid;
    border-width: @radio-border-width;
    border-radius: 50%;
    transition: all @radio-duration;
  }

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

  &&-disabled {
    .@{radio-inner-prefix-cls} {
      border-color: @radio-disabled-border-color;
      background-color: @radio-disabled-bg !important;
    }
  }

  &&-disabled&-checked {
    .@{radio-inner-prefix-cls} {
      border-color: @primary-3;
      background-color: @primary-3 !important;

      &::after {
        background-color: @component-background;
      }
    }
  }
}

// 选中状态
.@{radio-prefix-cls}-checked {
  .@{radio-inner-prefix-cls} {
    border-color: @radio-dot-color;
    background-color: @radio-checked-bg !important;

    &::after {
      transform: scale((unit(@radio-dot-size) / unit(@radio-size)));
      opacity: 1;
      transition: all @radio-duration @ease-in-out-circ;
    }
  }
}

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

  .@{radio-inner-prefix-cls} {
    background-color: @input-disabled-bg;
    cursor: not-allowed;

    &::after {
      background-color: @radio-dot-disabled-color;
    }
  }

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

  & + span {
    color: @text-color-primary;
    cursor: not-allowed;
  }
}

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

.@{radio-prefix-cls}-button-wrapper {
  position: relative;
  display: inline-block;
  height: @btn-height-base;
  margin: 0;
  padding: 0 @radio-button-padding-horizontal;
  color: @text-color;
  font-size: @font-size-sm;
  line-height: @btn-height-base;
  background: @radio-button-bg;
  border: none;
  cursor: pointer;
  transition: color 0.3s, background 0.3s, border-color 0.3s, box-shadow 0.3s;

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

  span:last-child {
    font-weight: 500;
  }

  &:hover {
    > .@{radio-prefix-cls}-button:not(.@{radio-prefix-cls}-button-checked):not(.@{radio-prefix-cls}-button-disabled) {
      z-index: 1;
      background-color: @radio-button-bg;
    }
  }

  &:active {
    > .@{radio-prefix-cls}-button:not(.@{radio-prefix-cls}-button-checked):not(.@{radio-prefix-cls}-button-disabled) {
      z-index: 1;
      background-color: @color-neutral-line;
    }
  }

  > .@{radio-prefix-cls}-button {
    position: absolute;
    top: 4px;
    left: 2px;
    z-index: -1;
    width: calc(100% - 4px);
    height: @radio-button-size;
    background-color: @component-background;
    border-radius: @border-radius-base;
  }

  .@{radio-group-prefix-cls}-large & {
    height: @radio-button-wrapper-height-lg;
    font-size: @font-size-base;
    line-height: @radio-button-wrapper-height-lg;

    > .@{radio-prefix-cls}-button {
      height: @radio-button-size-lg;
    }
  }

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

    > .@{radio-prefix-cls}-button {
      //width: calc(100% - 4px);
      height: @radio-button-size-sm;
    }
  }

  &:first-child {
    border-radius: @border-radius-base 0 0 @border-radius-base;

    > .@{radio-prefix-cls}-button {
      left: 4px;
      width: calc(100% - 6px);
    }

    span:last-child {
      margin-left: 2px;
    }
  }

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

    > .@{radio-prefix-cls}-button {
      width: calc(100% - 6px);
    }

    span:last-child {
      margin-left: -2px;
    }
  }

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

  &:hover {
    position: relative;
  }

  .@{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: @radio-dot-color;
    background: @radio-button-checked-bg;
    border-color: @radio-dot-color;

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

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

    &:hover {
      color: @radio-button-hover-color;
      border-color: @radio-button-hover-color;

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

    &:active {
      color: @radio-button-active-color;
      border-color: @radio-button-active-color;

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

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

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

  &-disabled&-checked {
    z-index: 1;
    background-color: @radio-disabled-button-checked-bg;

    > span:last-child {
      color: @primary-3;
    }
  }
}

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

  100% {
    transform: scale(1.6);
    opacity: 0;
  }
}

@import "./rtl";
