@use "../mixins/function.scss" as *;
@use "../mixins/mixins.scss" as *;

@include b(checkbox) {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  user-select: none;
  position: relative;
  margin: 0;
  padding: 0;
  @include m(has-label) {
    gap: 8px;
  }

  @include e(inner) {
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    margin: 0;
    opacity: 0;
    cursor: inherit;
    z-index: 1;
  }

  @include e(icon) {
    width: 14px;
    height: 14px;
    border: 1px solid getCssVar("color", "fill-3");
    border-radius: 2px;
    background-color: getCssVar("color", "bg-3");
    position: relative;
    z-index: 0;
    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),
      outline 0.25s cubic-bezier(0.71, -0.46, 0.29, 1.46);

    // 选中状态的对勾
    &::after {
      box-sizing: content-box;
      content: "";
      border: 1px solid transparent;
      border-left: 0;
      border-top: 0;
      height: 7px;
      left: 50%;
      position: absolute;
      top: 50%;
      transform: translate(-45%, -60%) rotate(45deg) scaleY(0);
      width: 3px;
      transition: transform 0.15s ease-in 0.05s;
      transform-origin: center;
    }

    // 半选状态的横线
    &::before {
      content: "";
      position: absolute;
      display: none;
      background-color: #fff;
      height: 2px;
      transform: scale(0.5);
      left: 0;
      right: 0;
      top: 5px;
    }
  }

  @include e(label) {
    font-size: 14px;
    color: getCssVar("color", "text-1");
    cursor: inherit;
    pointer-events: auto;
    padding: 2px 0;
    white-space: nowrap;
  }

  @include when(checked) {
    @include be(checkbox, icon) {
      background-color: getCssVar("color", "primary-6");
      border-color: getCssVar("color", "primary-6");

      &::after {
        display: block;
        transform: translate(-45%, -60%) rotate(45deg) scaleY(1);
        border-color: #fff;
      }

      &::before {
        display: none;
      }
    }
  }

  @include when(indeterminate) {
    @include be(checkbox, icon) {
      background-color: getCssVar("color", "primary-6");
      border-color: getCssVar("color", "primary-6");

      &::after {
        display: none;
      }

      &::before {
        display: block;
      }
    }
  }

  @include when(disabled) {
    cursor: not-allowed;

    @include be(checkbox, icon) {
      border-color: getCssVar("color", "fill-3");
      background-color: getCssVar("color", "bg-3");

      &::after {
        border-color: getCssVar("color", "text-3");
      }

      &::before {
        background-color: getCssVar("color", "text-3");
      }
    }

    @include be(checkbox, label) {
      color: getCssVar("color", "text-3");
      cursor: not-allowed;
    }
  }
}

@include b(checkbox-group) {
  display: inline-flex;
  gap: 12px;
  @include when(vertical) {
    flex-direction: column;
  }
}
