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

.yeeCheckboxFn(@yee-checkbox-prefix-cls: ~'@{yee-prefix}-checkbox') {
  @yee-checkbox-inner-prefix-cls: ~'@{yee-checkbox-prefix-cls}-inner';
  // 一般状态
  .@{yee-checkbox-prefix-cls} {
    .yee-reset-component;

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

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

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

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

    &-inner {
      position: relative;
      top: 0;
      left: 0;
      display: block;
      width: @yee-checkbox-size;
      height: @yee-checkbox-size;
      background-color: @yee-checkbox-check-color;
      border: @yee-checkbox-border-width @yee-border-style-base @yee-border-color-base;
      border-radius: @yee-border-radius-sm;
      // Fix IE checked style
      // https://github.com/ant-design/ant-design/issues/12597
      border-collapse: separate;
      transition: all 0.3s;

      &::after {
        @yee-check-width: (@yee-checkbox-size / 14) * 5px;
        @yee-check-height: (@yee-checkbox-size / 14) * 8px;

        position: absolute;
        top: 50%;
        left: 22%;
        display: table;
        width: @yee-check-width;
        height: @yee-check-height;
        border: 2px solid @yee-checkbox-check-color;
        border-top: 0;
        border-left: 0;
        transform: rotate(45deg) scale(0) translate(-50%, -50%);
        opacity: 0;
        transition:
          all 0.1s @yee-ease-in-back,
          opacity 0.1s;
        content: ' ';
      }
    }

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

  // 选中状态
  .@{yee-checkbox-prefix-cls}-checked .@{yee-checkbox-inner-prefix-cls}::after {
    position: absolute;
    display: table;
    border: 2px solid @yee-checkbox-check-color;
    border-top: 0;
    border-left: 0;
    transform: rotate(45deg) scale(1) translate(-50%, -50%);
    opacity: 1;
    transition: all 0.2s @yee-ease-out-back 0.1s;
    content: ' ';
  }

  .@{yee-checkbox-prefix-cls}-checked {
    .@{yee-checkbox-inner-prefix-cls} {
      background-color: @yee-checkbox-color;
      border-color: @yee-checkbox-color;
    }
  }

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

    &.@{yee-checkbox-prefix-cls}-checked {
      .@{yee-checkbox-inner-prefix-cls}::after {
        border-color: @yee-disabled-color;
        animation-name: none;
      }
    }

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

    .@{yee-checkbox-inner-prefix-cls} {
      background-color: @yee-input-disabled-bg;
      border-color: @yee-border-color-base !important;
      &::after {
        border-color: @yee-input-disabled-bg;
        border-collapse: separate;
        animation-name: none;
      }
    }

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

    // Not show highlight border of checkbox when disabled
    &:hover::after,
    .@{yee-checkbox-prefix-cls}-wrapper:hover &::after {
      visibility: hidden;
    }
  }

  .@{yee-checkbox-prefix-cls}-wrapper {
    .yee-reset-component;

    display: inline-block;
    line-height: unset;
    cursor: pointer;
    &.@{yee-checkbox-prefix-cls}-wrapper-disabled {
      cursor: not-allowed;
    }
    & + & {
      margin-left: 8px;
    }
  }

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

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

    display: inline-block;
    &-item {
      display: inline-block;
      margin-right: 8px;
      &:last-child {
        margin-right: 0;
      }
    }
    &-item + &-item {
      margin-left: 0;
    }
  }

  // 半选状态
  .@{yee-checkbox-prefix-cls}-indeterminate {
    .@{yee-checkbox-inner-prefix-cls} {
      background-color: @yee-component-background;
      border-color: @yee-border-color-base;
    }
    .@{yee-checkbox-inner-prefix-cls}::after {
      @indeterminate-width: @yee-checkbox-size - 8px;
      @indeterminate-height: @yee-checkbox-size - 8px;

      top: 50%;
      left: 50%;
      width: @indeterminate-width;
      height: @indeterminate-height;
      background-color: @yee-checkbox-color;
      border: 0;
      transform: translate(-50%, -50%) scale(1);
      opacity: 1;
      content: ' ';
    }

    &.@{yee-checkbox-prefix-cls}-disabled .@{yee-checkbox-inner-prefix-cls}::after {
      background-color: @yee-disabled-color;
      border-color: @yee-disabled-color;
    }
  }
}

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