@use "../mixins/function.scss" as *;
@use "../mixins/mixins.scss" as *;
@use "../common/var.scss" as *;

@include b(color-picker) {
  @each $size in $size-list {
    @include m(#{$size}) {
      @include be(color-picker, trigger) {
        height: getCssVar("size", #{$size});
        line-height: getCssVar("size", #{$size});
        padding: 4px;
        border-radius: getCssVar("radius", #{$size});
      }
      @include be(color-picker, preview) {
        height: calc(getCssVar("size", #{$size}) - 8px);
        width: calc(getCssVar("size", #{$size}) - 8px);
        border-radius: getCssVar("radius", #{$size});
      }
    }
  }
  @include e(trigger) {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background-color: getCssVar("color", "fill-2");
    user-select: none;
    cursor: pointer;
    &:hover {
      background-color: getCssVar("color", "fill-2");
    }
    &:active {
      background-color: getCssVar("color", "fill-3");
    }
    @include when(disabled) {
      cursor: not-allowed;
      &:hover {
        background-color: getCssVar("color", "fill-2");
      }
      @include be(color-picker, value) {
        color: getCssVar("color", "text-3");
      }
    }
  }
  @include e(preview) {
    box-sizing: border-box;
  }
  @include e(value) {
    color: getCssVar("color", "text-1");
  }
  @include e(wrapper) {
    width: 280px;
    border-radius: getCssVar("radius", "medium");
    box-shadow: getCssVar("shadow", "1");
    border: 1px solid getCssVar("color", "fill-3");
    background-color: getCssVar("color", "bg-3");
    padding: 8px;
  }
  @include e(content) {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }
  @include e(panel) {
    position: relative;
    width: 100%;
    height: 180px;
    border-radius: getCssVar("radius", "medium");
    overflow: hidden;
    cursor: pointer;
  }
  @include e(panel-bg) {
    position: absolute;
    inset: 0;
    &::after {
      content: "";
      position: absolute;
      inset: 0;
      background: linear-gradient(to top, #000, transparent);
    }
  }
  @include e(panel-thumb) {
    position: absolute;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 2px solid getCssVar("color", "fill-3");
    transform: translate(-50%, -50%);
    box-shadow: getCssVar("shadow", "3");
    pointer-events: none;
  }
  @include e(control) {
    display: flex;
    align-items: center;
    gap: 12px;
    height: 36px;
  }
  @include e(control-item) {
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    gap: 12px;
    flex: 1;
    height: 100%;
    padding: 4px 8px;
  }
  @include e(control-wrapper) {
    position: relative;
  }
  @include e(control-track) {
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    height: 8px;
    border-radius: getCssVar("radius", "medium");
    overflow: hidden;
    cursor: pointer;
  }
  @include e(control-thumb) {
    position: absolute;
    top: 50%;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: getCssVar("color", "bg-2");
    border: 1px solid getCssVar("color", "fill-3");
    transform: translate(-50%, -50%);
    cursor: pointer;
    z-index: 10;
    &:active {
      cursor: pointer;
    }
    &::before {
      display: block;
      width: 100%;
      height: 100%;
      background: getCssVar("color", "bg-2");
      border-radius: 50%;
      content: "";
    }
    &::after {
      position: absolute;
      top: 50%;
      left: 50%;
      width: 8px;
      height: 8px;
      background: currentColor;
      border-radius: 50%;
      transform: translate(-50%, -50%);
      content: "";
    }
  }
  @include e(control-hue) {
    width: 100%;
    height: 100%;
    background: linear-gradient(to right, red, yellow, lime, cyan, blue, magenta, red);
  }
  @include e(control-alpha) {
    width: 100%;
    height: 100%;
    background-image:
      linear-gradient(45deg, #ddd 25%, transparent 25%),
      linear-gradient(-45deg, #ddd 25%, transparent 25%),
      linear-gradient(45deg, transparent 75%, #ddd 75%),
      linear-gradient(-45deg, transparent 75%, #ddd 75%);
    background-size: 8px 8px;
    &::after {
      content: "";
      position: absolute;
      inset: 0;
      background: linear-gradient(to right, transparent, currentColor);
    }
  }
  @include e(control-preview) {
    width: 36px;
    height: 36px;
    border-radius: getCssVar("radius", "medium");
    overflow: hidden;
    background-image:
      linear-gradient(45deg, #ddd 25%, transparent 25%),
      linear-gradient(-45deg, #ddd 25%, transparent 25%),
      linear-gradient(45deg, transparent 75%, #ddd 75%),
      linear-gradient(-45deg, transparent 75%, #ddd 75%);
    background-size: 8px 8px;
  }
  @include e(control-preview-color) {
    width: 100%;
    height: 100%;
  }
  @include e(input) {
    display: flex;
    gap: 8px;
  }
  @include e(input-hex) {
    flex: 1;
  }
  @include e(input-rgb) {
    flex: 1;
    display: flex;
    gap: 8px;
  }
  @include e(presets) {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }
  @include e(presets-title) {
    font-size: 14px;
    color: getCssVar("color", "text-1");
  }
  @include e(presets-list) {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    gap: 6px;
  }
  @include e(presets-item) {
    aspect-ratio: 1;
    border-radius: getCssVar("radius", "medium");
    cursor: pointer;
  }
}
