@import '../style/core/animation';
@import '../style/theme/color';
@import '../style/theme/corner';
@import '../style/core/font';

.devui-checkbox {
  position: relative;
  display: flex;
  display: -ms-flexbox;
  align-items: center;
  -ms-flex-align: center;
  height: 100%;
  margin: 0;

  .devui-checkbox-tick {
    position: absolute;

    .devui-tick {
      stroke: $devui-light-text;
      stroke-dasharray: 13 13;
      stroke-dashoffset: 13;
      opacity: 0;
      transform: scale(0);
      transform-origin: 50% 50%;
      transition:
        stroke-dashoffset $devui-animation-duration-base $devui-animation-ease-in-out,
        opacity $devui-animation-duration-base $devui-animation-ease-in-out,
        transform $devui-animation-duration-base $devui-animation-ease-in-out;
    }
  }

  &.active:not(.halfchecked) .devui-tick {
    opacity: 1;
    stroke-dashoffset: 0;
    transform: scale(1);
    transition: stroke-dashoffset $devui-animation-duration-slow $devui-animation-ease-in, opacity $devui-animation-duration-base $devui-animation-ease-in-out;
  }

  &.active,
  &.halfchecked {
    &:not(.disabled) .devui-checkbox-material:not(.custom-color) {
      border-color: $devui-brand;
    }
  }

  &.active:not(.disabled) {
    .devui-checkbox-material {
      background-size: 100% 100%;
      transition: border-color $devui-animation-duration-base $devui-animation-ease-in-out;
    }
  }

  &.unchecked:not(.disabled) {
    .devui-checkbox-material:not(.custom-color) {
      background-size: 0% 0%;
      transition: background-size $devui-animation-duration-base $devui-animation-ease-in-out, border-color $devui-animation-duration-base $devui-animation-ease-in-out;
    }

    &:hover .devui-checkbox-material:not(.custom-color) {
      border-color: $devui-brand;
    }
  }

  &.unchecked:not(.disabled) {
    .devui-checkbox-material.custom-color {
      background-size: 0% 0%;
      transition: border-color $devui-animation-duration-base $devui-animation-ease-in-out;
    }
  }

  &.halfchecked {
    .devui-checkbox-material:not(.custom-color) {
      background-color: $devui-brand;

      & > .devui-checkbox-halfchecked-bg {
        opacity: 1;
        transform: scale(0.4288);
        transition: transform $devui-animation-duration-base $devui-animation-ease-in-out;
        background-color: $devui-light-text;
      }
    }
  }

  &.halfchecked {
    .devui-checkbox-material.custom-color {
      & > .devui-checkbox-halfchecked-bg {
        opacity: 1;
        transform: scale(0.4288);
        transition: transform $devui-animation-duration-base $devui-animation-ease-in-out;
        background-color: $devui-light-text;
      }
    }
  }

  .devui-checkbox-material {
    text-align: initial;
    height: 14px;
    width: 14px;
    position: relative;
    user-select: none;
    border: 1px solid $devui-line;
    border-radius: $devui-border-radius;
    background: linear-gradient($devui-brand, $devui-brand) no-repeat center/0%;
    margin-right: 8px;
    vertical-align: text-bottom;

    &.devui-checkbox-default-background {
      background-color: $devui-base-bg;
    }

    &.devui-checkbox-no-label {
      margin-right: 0;
    }

    & > .devui-checkbox-halfchecked-bg {
      display: inline-block;
      position: absolute;
      content: '';
      background-color: $devui-light-text;
      top: 0;
      left: 0;
      height: 100%;
      width: 100%;
      transform: scale(1);
      opacity: 0;
    }

    & > svg {
      width: 14px;
      height: 14px;
    }
  }

  &:not(.disabled).halfchecked {
    .devui-checkbox-material:not(.custom-color) {
      &:focus,
      &:active,
      &:hover {
        background-color: $devui-brand;
      }

      // 激活状态深色
      &:active,
      &:focus,
      &:hover:active,
      &:hover:focus {
        background-color: $devui-brand-active;
      }
    }
  }

  &-input {
    opacity: 0;
    position: absolute;
    margin: 0;
    z-index: -1;
    width: 0;
    height: 0;
    overflow: hidden;
    left: 0;
    pointer-events: none;
  }

  & label {
    position: relative;
    font-size: $devui-font-size;
    font-weight: normal;
    height: 16px;
    line-height: 16px;
    cursor: pointer;
    color: $devui-text;
    margin: 0;
    display: block;
    flex: 1;

    & > span {
      display: inline-block;
      box-sizing: content-box;
      vertical-align: top;
    }
  }

  // 禁用状态透明色
  &.disabled {
    label {
      cursor: not-allowed;
      color: $devui-disabled-text;
    }

    .devui-checkbox-material {
      border-color: $devui-icon-fill-active-disabled;
      background-color: $devui-icon-fill-active-disabled;
    }

    &.unchecked {
      .devui-checkbox-material {
        border-color: $devui-disabled-line;
        background-color: $devui-disabled-bg;
      }
    }

    &.halfchecked {
      .devui-checkbox-material {
        background-color: $devui-icon-fill-active-disabled;
      }
    }

    &.active {
      svg polygon {
        fill: $devui-light-text;
      }
    }
  }
}

::ng-deep :root .devui-glow-style .devui-checkbox {
  .devui-checkbox-glow-box {
    position: absolute;
    width: 16px;
    height: 16px;

    .devui-checkbox-glow-bg {
      display: block;
      width: 16px;
      height: 16px;
      user-select: none;
      border-radius: $devui-border-radius;
      box-shadow: none;
      transition: box-shadow $devui-animation-duration-slow $devui-animation-ease-in-out-smooth;
    }
  }

  &:not(.disabled):hover .devui-checkbox-glow-bg {
    box-shadow: 0 0 0 6px $devui-range-item-hover-bg;
  }
}

.devui-no-animation {
  transition: none !important;
}
