@import './../theme/vars.scss';

$prefixCls: crisp;
// checkbox
$checkboxPrefixCls: #{$prefixCls}-checkbox;
$checkboxInnerPrefixCls: #{$checkboxPrefixCls}-inner;

/* 一般状态 */
.#{$checkboxPrefixCls} {
  position: relative;
  display: inline-block;
  line-height: 1;
  white-space: nowrap;
  vertical-align: middle;
  cursor: pointer;
  outline: none;

  &:hover .#{$checkboxInnerPrefixCls},
  &-input:focus + .#{$checkboxInnerPrefixCls} {
    border-color: $main-color;
  }

  &-inner {
    position: relative;
    top: 0;
    left: 0;
    display: inline-block;
    width: 14px;
    height: 14px;
    background-color: white;
    border-color: #d9d9d9;
    border-style: solid;
    border-width: 1px;
    border-radius: 3px;
    transition: border-color 0.3s cubic-bezier(0.68, -0.55, 0.27, 1.55), background-color 0.3s cubic-bezier(0.68, -0.55, 0.27, 1.55);

    &::after {
      position: absolute;
      top: 1px;
      left: 4px;
      display: table;
      width: 5px;
      height: 8px;
      border: 2px solid white;
      border-top: 0;
      border-left: 0;
      content: ' ';
      transform: rotate(45deg);
      animation-duration: 0.3s;
      animation-name: crispuiCheckboxOut;
      animation-timing-function: cubic-bezier(0.68, -0.55, 0.27, 1.55);
    }
  }

  &-input {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 9999;
    cursor: pointer;
    opacity: 0;
  }

  // 半选状态
  &-indeterminate {
    .#{$checkboxPrefixCls}-inner {
      background-color: white;
      border-color: $main-color;

      &::after {
        position: absolute;
        top: 50%;
        left: 50%;
        width: 8px;
        height: 8px;
        background: $main-color;
        border: 0;
        content: '';
        transform: translate(-50%, -50%);
      }
    }
  }

  /* 选中状态 */
  &-checked {
    &:hover {
      .#{$checkboxInnerPrefixCls} {
        border-color: $main-color;
      }
    }

    .#{$checkboxInnerPrefixCls} {
      background-color: $main-color;
      border-color: $main-color;

      &::after {
        position: absolute;
        top: 1px;
        left: 4px;
        display: table;
        width: 5px;
        height: 8px;
        border: 2px solid white;
        border-top: 0;
        border-left: 0;
        content: ' ';
        transform: rotate(45deg);
        animation-duration: 0.3s;
        animation-name: crispuiCheckboxOut;
        animation-timing-function: cubic-bezier(0.68, -0.55, 0.27, 1.55);
      }
    }
  }

  &-disabled {
    cursor: not-allowed;

    &.#{$checkboxPrefixCls}-checked {
      &:hover {
        .#{$checkboxInnerPrefixCls} {
          border-color: #d9d9d9;
        }
      }

      .#{$checkboxInnerPrefixCls} {
        background-color: #f3f3f3;
        border-color: #d9d9d9;

        &::after {
          border-color: #ccc;
          animation-name: none;
        }
      }
    }

    &:hover {
      .#{$checkboxInnerPrefixCls} {
        border-color: #d9d9d9;
      }
    }

    .#{$checkboxInnerPrefixCls} {
      background-color: #f3f3f3;
      border-color: #d9d9d9;

      &::after {
        border-color: #f3f3f3;
        animation-name: none;
      }
    }

    .#{$checkboxPrefixCls}-input {
      cursor: not-allowed;
    }
  }
}

@keyframes crispuiCheckboxIn {
  0% {
    opacity: 0;
    transform-origin: 50% 50%;
    transform: scale(0, 0) rotate(45deg);
  }

  100% {
    opacity: 1;
    transform-origin: 50% 50%;
    transform: scale(1, 1) rotate(45deg);
  }
}

@keyframes crispuiCheckboxOut {
  0% {
    opacity: 1;
  }

  100% {
    opacity: 0;
  }
}

// input
.#{$prefixCls}-input {
  position: relative;
  display: inline-block;
  width: 100%;
  height: 32px;
  padding: 4px 11px;
  margin: 0;
  font-family: $font-family-all;
  font-size: 12px;
  font-variant: tabular-nums;
  line-height: 1.5;
  color: rgba(0, 0, 0, 0.65);
  list-style: none;
  background-color: white;
  border: 1px solid #d9d9d9;
  border-radius: 4px;
  box-sizing: border-box;
  transition: all 0.3s;

  &::-moz-placeholder,
  &::-ms-input-placeholder,
  &::-webkit-input-placeholder {
    color: #bfbfbf;
    opacity: 1;
  }

  &:hover {
    border-color: $main-color;
    border-right-width: 1px;
  }

  &:focus {
    border-color: $main-color;
    border-right-width: 1px;
    outline: 0;
    box-shadow: 0 0 0 2px rgba($primary-color, 0.2);
  }

  &-disabled {
    color: rgba(0, 0, 0, 0.25);
    cursor: not-allowed;
    background-color: whitesmoke;
    opacity: 1;

    &:hover {
      border-color: #e2e2e2;
      border-right-width: 1px;
    }
  }

  &-lg {
    height: 40px;
    padding: 6px 11px;
    font-size: 14px;
  }

  &-sm {
    height: 24px;
    padding: 1px 7px;
  }

  &-affix-wrapper {
    position: relative;
    display: inline-block;
    width: 100%;
    padding: 0;
    margin: 0;
    font-family: $font-family-all;
    font-size: 12px;
    font-variant: tabular-nums;
    line-height: 1.5;
    color: rgba(0, 0, 0, 0.65);
    list-style: none;
    box-sizing: border-box;

    &:hover .#{$prefixCls}-input:not(.#{$prefixCls}-input-disabled) {
      border-color: $main-color;
      border-right-width: 1px;
    }

    .#{$prefixCls}-input-prefix,
    .#{$prefixCls}-input-suffix {
      position: absolute;
      top: 50%;
      line-height: 0;
      color: rgba(0, 0, 0, 0.65);
      transform: translateY(-50%);

      :not(i) {
        line-height: 1.5;
      }
    }

    .#{$prefixCls}-input {
      position: static;
      min-height: 100%;

      &-prefix {
        left: 12px;
      }

      &-suffix {
        right: 12px;
      }

      &:not(:first-child) {
        padding-left: 30px;
      }

      &:not(:last-child) {
        padding-right: 30px;
      }
    }
  }
}
