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

$checkbox: 'cp-ui-checkbox';

.#{$checkbox} {
  font-size: $font-size-normal;
  font-variant: tabular-nums;
  line-height: $line-height-normal;
  color: rgba(0, 0, 0, 0.65);
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  list-style: none;
  cursor: pointer;
  display: inline-block;

  &:hover {
    .#{$checkbox}-select-inner {
      border-color: $color-brand-normal;
    }
  }

  &-select {
    font-size: $font-size-normal;
    font-variant: tabular-nums;
    color: rgba(0, 0, 0, 0.65);
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    list-style: none;
    white-space: nowrap;
    cursor: pointer;
    outline: none;
    display: inline-block;
    line-height: 1;
    position: relative;
    vertical-align: middle;
    top: -0.09em;

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

    &-inner {
      position: relative;
      top: 0;
      left: 0;
      display: block;
      width: 16px;
      height: 16px;
      border: 1px solid #d9d9d9;
      border-radius: 2px;
      background-color: #fff;
      -webkit-transition: all 0.3s;
      transition: all 0.3s;
      border-collapse: separate;

      &::after {
        -webkit-transform: rotate(45deg) scale(0);
        -ms-transform: rotate(45deg) scale(0);
        transform: rotate(45deg) scale(0);
        position: absolute;
        left: 4.57142857px;
        top: 1.14285714px;
        display: table;
        width: 5.71428571px;
        height: 9.14285714px;
        border: 2px solid #fff;
        border-top: 0;
        border-left: 0;
        content: ' ';
        -webkit-transition: 0.1s cubic-bezier(0.71, -0.46, 0.88, 0.6), opacity 0.1s;
        transition: 0.1s cubic-bezier(0.71, -0.46, 0.88, 0.6), opacity 0.1s;
        opacity: 0;
      }
    }
  }

  &-label {
    padding: 0 8px;
  }

  &-checked {
    .#{$checkbox}-select-inner {
      background-color: $color-brand-normal;
      border-color: $color-brand-normal;

      &::after {
        -webkit-transform: rotate(45deg) scale(1);
        -ms-transform: rotate(45deg) scale(1);
        transform: rotate(45deg) scale(1);
        position: absolute;
        display: table;
        border: 2px solid #fff;
        border-top: 0;
        border-left: 0;
        content: ' ';
        -webkit-transition: all 0.2s cubic-bezier(0.12, 0.4, 0.29, 1.46) 0.1s;
        transition: all 0.2s cubic-bezier(0.12, 0.4, 0.29, 1.46) 0.1s;
        opacity: 1;
      }
    }

    .#{$checkbox}-select {
      &::after {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        border-radius: 2px;
        border: 1px solid $color-brand-normal;
        content: '';
        -webkit-animation: antCheckboxEffect 0.36s ease-in-out;
        animation: antCheckboxEffect 0.36s ease-in-out;
        -webkit-animation-fill-mode: both;
        animation-fill-mode: both;
        visibility: hidden;
      }
    }
  }

  &-indeterminate {
    .#{$checkbox}-select-inner {
      background-color: #fff;
      border-color: #d9d9d9;

      &::after {
        content: ' ';
        -webkit-transform: translate(-50%, -50%) scale(1);
        -ms-transform: translate(-50%, -50%) scale(1);
        transform: translate(-50%, -50%) scale(1);
        border: 0;
        left: 50%;
        top: 50%;
        width: 8px;
        height: 8px;
        background-color: $color-brand-normal;
        opacity: 1;
      }
    }
  }

  &-disabled {
    .#{$checkbox}-select {
      cursor: not-allowed;
    }

    .#{$checkbox}-select-inner {
      border-color: #d9d9d9 !important;
      background-color: #f5f5f5;

      &::after {
        -webkit-animation-name: none;
        animation-name: none;
        border-color: #f5f5f5;
        border-collapse: separate;
      }
    }

    &.#{$checkbox}-checked {
      .#{$checkbox}-select-inner {
        &::after {
          -webkit-animation-name: none;
          animation-name: none;
          border-color: rgba(0, 0, 0, 0.25);
        }
      }
    }
  }

  input[type='checkbox'][disabled] {
    cursor: not-allowed;
  }
}