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

@include b(checkbox) {
  color: $--checkbox-font-color;
  font-size: 0;
  position: relative;
  cursor: pointer;
  display: inline-block;
  white-space: nowrap;
  user-select: none;
  vertical-align: top;
  &:hover {
    .el-checkbox__inner {
      border-color: $--checkbox-input-border-color-hover;
    }
  }
  // 点击
  &:focus,
  &:active {
    .el-checkbox__inner {
      box-shadow: 0px 0px 0px 2px rgba(211, 229, 255, 1);
    }
  }
  @include when(bordered) {
    padding: $--checkbox-bordered-padding;
    border-radius: $--checkbox-input-border-radius;
    border: $--border-base;
    box-sizing: border-box;
    line-height: 16px;

    &:hover {
      .el-checkbox__inner {
        border-color: $--checkbox-bordered-border-color-checked;
      }
    }

    &.is-checked {
      border-color: $--checkbox-bordered-border-color-checked;

      &:hover {
        .el-checkbox__inner {
          border-color: $--checkbox-bordered-border-color-checked;
        }
      }
    }

    &.is-disabled {
      border-color: $--checkbox-bordered-border-color-disabled;
      cursor: not-allowed;
      .el-checkbox__inner {
        border-color: $--checkbox-bordered-border-color-disabled;
      }
    }

    & + .el-checkbox.is-bordered {
      margin-left: 10px;
    }

    &.el-checkbox--small {
      padding: $--checkbox-bordered-small-padding;

      .el-checkbox__label {
        font-size: $--checkbox-bordered-small-font-size;
      }

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

          &::after {
            margin: -2px 0 0 -2px;
          }
        }
        &.is-checked {
          .el-checkbox__inner {
            &::after {
              transform: rotate(45deg) scaleY(1);
            }
          }
        }
      }
    }
  }
  @include e(input) {
    white-space: nowrap;
    cursor: pointer;
    outline: none;
    display: inline-block;
    position: relative;
    vertical-align: middle;

    // 禁用
    @include when(disabled) {
      // 非选中状态禁用
      .el-checkbox__inner {
        background-color: $--checkbox-input-bg-color-disabled;
        border-color: $--checkbox-input-border-color-disabled;
        cursor: not-allowed;

        &::after {
          display: none;
        }

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

      // 选中状态下的禁用样式
      &.is-checked {
        .el-checkbox__inner {
          background-color: $--checkbox-input-bg-color-disabled;
          border: $--checkbox-input-border-size $--checkbox-input-border-color-disabled;

          &::after {
            display: block;
            cursor: not-allowed;
            color: $--checkbox-input-check-color-disabled;
            border-color: $--checkbox-input-check-color-disabled;
          }
        }
      }

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

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

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

    // 已选中
    @include when(checked) {
      // 带对号的输入框
      .el-checkbox__inner {
        border-color: transparent;
        background-color: $--checkbox-input-bg-color-checked;

        &::after {
          transform: scale(1);
        }
        &::after {
          display: block;
          color: $--checkbox-input-check-color;
          transform: rotate(45deg) scaleY(1);
        }
      }
    }

    // 半选横线样式
    @include when(indeterminate) {
      .el-checkbox__inner {
        background-color: $--checkbox-input-indeterminate-bg-color;
        border-color: $--checkbox-input-indeterminate-border-color;

        &::before {
          content: "";
          position: absolute;
          display: block;
          background-color: $--checkbox-input-indeterminate-color;
          height: 2px;
          width: 8px;
          top: 6px;
          left: 3px;
        }
      }
    }
  }
  // checkbox选框
  @include e(inner) {
    display: block;
    position: relative;
    border: $--checkbox-input-border-size $--checkbox-input-border-color;
    border-radius: $--checkbox-input-border-radius;
    box-sizing: border-box;
    width: $--checkbox-size;
    height: $--checkbox-size;
    background-color: $--checkbox-input-bg-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);
    

    // 后面的对号
    &::after {
      box-sizing: content-box;
      content: "";
      border: 2px solid #fff;
      border-left: 0;
      border-top: 0;
      height: 8px;
      left: 5px;
      position: absolute;
      top: 1px;
      transform: rotate(45deg) scaleY(0);
      width: 3px;
      transition: transform .15s ease-in .05s;
      transform-origin: center;
    }
  }

  @include e(original) {
    opacity: 0;
    outline: none;
    position: absolute;
    margin: 0;
    width: 0;
    height: 0;
    left: 0;
    top: 0;
    z-index: -1;
  }

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

  & + .el-checkbox {
    margin-left: 10px;
  }
}

// 多选按钮组合样式  button 部分引用button的样式
@include b(checkbox-button) {
  position: relative;
  display: inline-block;
  background-color: $--checkbox-button-bg-default;
  @include e(inner) {
    display: inline-block;
    line-height: 1;
    font-weight: $--checkbox-font-weight;
    white-space: nowrap;
    vertical-align: middle;
    cursor: pointer;
    background: $--button-default-fill;
    border: $--checkbox-botton-border-base;       // PreValue: $--border-base
    border-left: 0;
    color: $--color-text-secondary;   // PreValue: $--button-default-color
    -webkit-appearance: none;
    text-align: center;
    box-sizing: border-box;
    outline: none;
    margin: 0;
    position: relative;
    transition: $--all-transition;
    @include utils-user-select(none);

    @include button-size($--button-padding-vertical, $--button-padding-horizontal, $--button-font-size, 0);

    // 按钮样式的多选组合hover
    &:hover {
      border-color: $--checkbox-default-theme-color;
      color: $--checkbox-input-border-color-hover;
      box-shadow: -1px 0 0 0 $--checkbox-default-theme-color;
    }

    & [class*="el-icon-"] {
      line-height: 0.9;

      & + span {
        margin-left: 5px;
      }
    }
  }

  @include e(original) {
    opacity: 0;
    outline: none;
    position: absolute;
    margin: 0;
    z-index: -1;
  }

  // 选中情况下的样式变化
  &.is-checked {
    // 按钮样式的多选组合
    & .el-checkbox-button__inner {
      color: $--checkbox-button-color-checked;
      background-color: $--checkbox-button-bg-color-checked;
      border-color: $--checkbox-button-border-color-checked;
      box-shadow: $--checkbox-button-box-shadow;
    }
    &:first-child .el-checkbox-button__inner {
      border-left-color: $--checkbox-button-border-color-checked;
    }
  }

  &.is-disabled {
    // 引用 button 样式
    & .el-checkbox-button__inner {
      color: $--button-default-disabled-color;
      cursor: not-allowed;
      background-image: none;
      background-color: $--button-disabled-bg-color;
      border-color: $--border-color-gray-light;  // PreValue: $--button-default-disabled-color
      box-shadow: none;
    }
    &:first-child .el-checkbox-button__inner {
      border-left-color: $--border-color-gray-light;  // PreValue: $--button-default-disabled-color
    }
  }

  &:first-child {
    .el-checkbox-button__inner {
      border-left: $--checkbox-botton-border-base;    // $--border-base
      border-radius: $--checkbox-input-border-radius 0 0 $--checkbox-input-border-radius;
      box-shadow: none !important;
      &:hover{
        border-left-color: $--checkbox-default-theme-color;
      }
    }
  }

  &.is-focus {
    & .el-checkbox-button__inner {
      //border-color: $--checkbox-button-border-color-checked;
    }
  }

  &:last-child {
    .el-checkbox-button__inner {
      border-radius: 0 $--checkbox-input-border-radius $--checkbox-input-border-radius 0;
    }
  }
  // 小尺寸button
  @include m(small) {
    .el-checkbox-button__inner {
      @include button-size(
        $--button-small-padding-vertical,
        $--button-small-padding-horizontal,
        $--button-small-font-size,
        0
      );
    }
  }
}

@include b(checkbox-group) {
  font-size: 0;
}
