@import 'common/var';
@import 'mixins/mixins';
@import 'mixins/_button';
@import 'mixins/utils';

@include b(checkbox) {
  color: $--checkbox-font-color;
  font-weight: $--checkbox-font-weight;
  font-size: $--checkbox-font-size;
  position: relative;
  line-height: inherit;
  cursor: pointer;
  display: inline-block;
  vertical-align: bottom;
  white-space: nowrap;
  user-select: none;
  margin-right: 20px;

  @include when(bordered) {
    padding: $--checkbox-bordered-padding;
    border-radius: $--checkbox-border-radius;
    border: $--checkbox-input-border;
    box-sizing: border-box;
    height: $--checkbox-bordered-height;
    line-height: 1;
    vertical-align: bottom;

    &.is-checked {
      border-color: $--color-primary;
    }

    &.is-disabled {
      border-color: $--border-color-base;
      cursor: not-allowed;
    }
  }

  @include e(input) {
    white-space: nowrap;
    cursor: pointer;
    outline: none;
    display: inline-block;
    line-height: 1;
    position: relative;
    vertical-align: middle;

    @include when(disabled) {
      .el-checkbox__inner {
        background-color: $--checkbox-disabled-input-fill;
        border-color: $--checkbox-disabled-border-color;
        cursor: not-allowed;

        &::after {
          cursor: not-allowed;
          border-color: $--checkbox-disabled-icon-color;
        }

        & + .el-checkbox__label {
          cursor: not-allowed;
        }
      }

      &.is-checked {
        .el-checkbox__inner {
          background-color: $--checkbox-disabled-checked-input-fill;
          border-color: $--checkbox-disabled-checked-input-border-color;

          &::after {
            border-color: $--checkbox-disabled-checked-icon-color;
          }
        }
      }

      &.is-indeterminate {
        .el-checkbox__inner {
          background-color: $--checkbox-disabled-checked-input-fill;
          border-color: $--checkbox-disabled-checked-input-border-color;

          &::before {
            background-color: $--checkbox-disabled-checked-icon-color;
            border-color: $--checkbox-disabled-checked-icon-color;
          }
        }
      }

      & + span.el-checkbox__label {
        color: $--disabled-color-base;
        cursor: not-allowed;
      }
    }

    @include when(checked) {
      .el-checkbox__inner {
        background-color: $--checkbox-checked-input-border-color;
        border-color: $--checkbox-checked-input-border-color;

        &::after {
          transform: rotate(45deg) scaleY(1);
          border-color: $--checkbox-background-color;
        }
      }

      // & + .el-checkbox__label {
      //   color: $--checkbox-checked-font-color;
      // }
    }
    @include when(focus) {
      /*focus时 视觉上区分*/
      .el-checkbox__inner {
        border-color: $--checkbox-input-border-color-hover;
      }
    }
    @include when(indeterminate) {
      .el-checkbox__inner {
        background-color: $--checkbox-checked-input-border-color;
        border-color: $--checkbox-checked-input-border-color;

        &::before {
          content: '';
          position: absolute;
          display: block;
          background-color: $--checkbox-background-color;
          height: 4px;
          transform: scale(0.6);
          left: 0;
          right: 0;
          top: 4px;
        }

        &::after {
          display: none;
        }
      }
    }
  }
  @include e(inner) {
    display: inline-block;
    position: relative;
    border: $--checkbox-input-border;
    border-color: $--checkbox-border-color;
    border-radius: $--checkbox-border-radius;
    box-sizing: border-box;
    width: $--checkbox-input-width;
    height: $--checkbox-input-height;
    background-color: $--checkbox-background-color;
    z-index: $--index-normal;
    transition: border-color 0.25s cubic-bezier(0.71, -0.46, 0.29, 1.46),
      background-color 0.25s cubic-bezier(0.71, -0.46, 0.29, 1.46);

    &:hover {
      border-color: $--checkbox-input-border-color-hover;
    }

    &::after {
      box-sizing: content-box;
      content: '';
      border: 2px solid $--checkbox-checked-icon-color;
      border-left: 0;
      border-top: 0;
      height: 8px;
      left: 4px;
      position: absolute;
      top: 0;
      transform: rotate(45deg) scaleY(0);
      width: 3px;
      transition: transform 0.15s ease-in 0.05s;
      transform-origin: center;
    }
  }

  @include m(medium) {
    &.is-bordered {
      padding: $--checkbox-bordered-medium-padding;
      border-radius: $--button-medium-border-radius;
      height: $--checkbox-bordered-medium-height;
      // line-height: $--checkbox-bordered-medium-height;
    }
    .el-checkbox__label {
      line-height: 17px;
      font-size: $--button-medium-font-size;
    }

    .el-checkbox__inner {
      height: $--checkbox-bordered-medium-input-height;
      width: $--checkbox-bordered-medium-input-width;
    }
  }

  @include m(small) {
    &.is-bordered {
      padding: $--checkbox-bordered-small-padding;
      border-radius: $--button-small-border-radius;
      height: $--checkbox-bordered-small-height;
      line-height: $--checkbox-bordered-small-height;
    }

    .el-checkbox__label {
      line-height: 15px;
      font-size: $--button-small-font-size;
    }

    .el-checkbox__inner {
      height: $--checkbox-bordered-small-input-height;
      width: $--checkbox-bordered-small-input-width;

      &::after {
        height: 6px;
        width: 2px;
        left: 3px;
      }
    }

    .is-indeterminate {
      .el-checkbox__inner {
        &::before {
          top: 3px;
        }
      }
    }
  }

  @include m(mini) {
    &.is-bordered {
      padding: $--checkbox-bordered-mini-padding;
      border-radius: $--button-mini-border-radius;
      height: $--checkbox-bordered-mini-height;
      line-height: $--checkbox-bordered-mini-height;
    }

    .el-checkbox__label {
      line-height: 12px;
      font-size: $--button-mini-font-size;
    }

    .el-checkbox__inner {
      height: $--checkbox-bordered-mini-input-height;
      width: $--checkbox-bordered-mini-input-width;
      &::after {
        height: 6px;
        width: 2px;
        left: 3px;
      }
    }

    .is-indeterminate {
      .el-checkbox__inner {
        &::before {
          top: 3px;
        }
      }
    }
  }

  @include e(original) {
    opacity: 0;
    outline: none;
    position: absolute;
    margin: 0;
    width: 0;
    height: 0;
    z-index: -1;
    &:focus-visible {
      & + .el-checkbox__inner {
        outline-offset: 1px;
        outline: 1px solid $--color-primary;
      }
    }
  }

  @include e(label) {
    display: inline-block;
    padding-left: 5px;
    line-height: 19px;
    font-size: $--checkbox-font-size;
  }

  &:last-of-type {
    margin-right: 0;
  }
}
@include b(checkbox-group) {
  font-size: 0;
  display: inline-block;
  vertical-align: bottom;
}
