/*
 * @Author: 焦质晔
 * @Date: 2020-02-28 22:13:07
 * @Last Modified by: 焦质晔
 * @Last Modified time: 2024-11-05 19:05:36
 */
@use '../../style/src/themes' as *;
@use '../../style/src/mixins/reset' as *;
@use './variable' as *;

$prefix: '#{$qm-prefix}-checkbox';

.#{$prefix}-wrapper {
  @include reset-component();
  display: inline-block;
  cursor: pointer;

  &:hover:not(&-disabled) {
    .#{$prefix}-inner {
      border-color: $v-primary-color;
    }
  }

  .#{$prefix} {
    display: inline-block;
    position: relative;
    top: -0.09em;
    width: 16px;
    height: 16px;
    line-height: 1;
    white-space: nowrap;
    vertical-align: middle;
    outline: none;
    cursor: pointer;

    &-inner {
      display: inline-block;
      position: relative;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      border: 1px solid $border-color-base;
      border-radius: $v-border-radius;
      border-collapse: separate;
      background-color: #fff;
      transition: all 0.3s ease;
      box-sizing: border-box;
      &::after {
        content: ' ';
        display: table;
        position: absolute;
        top: 42%;
        left: 2px;
        width: 4px;
        height: 9px;
        border: 2px solid #fff;
        border-top: 0;
        border-left: 0;
        opacity: 0;
        transform: rotate(45deg) scale(0) translate(-50%, -50%);
        transition: all 0.1s cubic-bezier(0.71, -0.46, 0.88, 0.6), opacity 0.1s;
      }
    }

    &-input {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      margin: 0;
      z-index: 1;
      opacity: 0;
      cursor: pointer;
    }

    // &-focus {
    //   box-shadow: 0 0 0 2px rgba($v-primary-color, 0.15);
    // }

    &-disabled {
      cursor: not-allowed;
      .#{$prefix}-input {
        cursor: not-allowed !important;
      }
    }
  }

  // 选中状态
  .#{$prefix}-checked {
    &::after {
      content: ' ';
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      border: 1px solid $v-primary-color;
      border-radius: $v-border-radius;
      animation: antCheckboxEffect 0.36s ease-in-out;
      animation-fill-mode: both;
      box-sizing: border-box;
    }

    .#{$prefix}-inner {
      border-color: $v-primary-color;
      background-color: $v-primary-color;
      &::after {
        transform: rotate(45deg) scale(1) translate(-50%, -50%);
        opacity: 1;
        transition: all 0.2s cubic-bezier(0.12, 0.4, 0.29, 1.46) 0.1s;
      }
    }
  }

  // 半选状态
  .#{$prefix}-indeterminate {
    .#{$prefix}-inner {
      border-color: $border-color-base !important;
      background-color: #fff !important;

      &::after {
        content: ' ';
        top: 50%;
        left: 50%;
        width: 8px;
        height: 8px;
        border: 0;
        background-color: $v-primary-color;
        transform: translate(-50%, -50%) scale(1);
        transition: none;
        opacity: 1;
      }
    }

    &.#{$prefix}-disabled {
      .#{$prefix}-inner {
        background-color: $background-color-light;
        &::after {
          background-color: $v-font-disabled-color;
        }
      }
    }
  }

  // 禁用状态
  .#{$prefix}-disabled {
    cursor: not-allowed;

    &::after {
      animation-name: none;
      display: none;
    }

    .#{$prefix}-inner {
      border-color: $border-color-base !important;
      background-color: $background-color-light !important;
      &::after {
        animation-name: none;
        border-color: $v-font-disabled-color;
      }
    }

    & + span {
      color: $v-font-disabled-color;
    }
  }

  .#{$prefix}-text {
    margin-left: 6px;
  }
}

@keyframes antCheckboxEffect {
  0% {
    transform: scale(1);
    opacity: 0.5;
  }
  100% {
    transform: scale(1.6);
    opacity: 0;
  }
}
