@import '../../common/style/tdesign/index.scss';


@mixin transparentBgImage () {
  background-image: linear-gradient(45deg, #c5c5c5 25%, transparent 0, transparent 75%, #c5c5c5 0, #c5c5c5),
    linear-gradient(45deg, #c5c5c5 25%, transparent 0, transparent 75%, #c5c5c5 0, #c5c5c5);
  background-size: 6px 6px;
  background-position: 0 0, 3px 3px;
}


$color-picker-panel-width: var(--press-color-picker-panel-width, 375px);
$color-picker-panel-padding: 16px;
$color-picker-panel-radius: 6px;
$color-picker-saturation-height: 144px;
$color-picker-saturation-radius: 6px;
$color-picker-saturation-thumb-size: 24px;
$color-picker-margin: 12px;
$color-picker-slider-height: 8px;
$color-picker-slider-wrapper-radius: calc($color-picker-slider-height / 2);
$color-picker-slider-wrapper-padding: 0 9px;
$color-picker-slider-thumb-size: 24px;
$color-picker-slider-thumb-padding: 3px;
$color-picker-input-format-margin-left: 24px;
$color-picker-swatches-title-font: 16px;
$color-picker-gradient-preview-width: 28px;
$color-picker-gradient-preview-height: 28px;
$color-picker-gradient-preview-radius: 3px;
$color-picker-swatch-width: 24px;
$color-picker-swatch-height: 24px;
$color-picker-swatch-padding: 0;
$color-picker-swatch-border-radius: 3px;
$color-picker-thumbs-shadow: $shadow-1;
$color-picker-border-radius-circle: 50%;
$color-picker-format-background-color: var(--press-color-picker-format-background-color, $gray-color-1);

$color-picker: 'press-color-picker';

.#{$color-picker} {
  &__panel {
    padding: 0;
    width: $color-picker-panel-width;
    background: #fff;
    border-top-left-radius: 12px;
    border-top-right-radius: 12px;
    user-select: none;
  }

  &__body {
    padding: $color-picker-panel-padding;
    padding-bottom: 28px;
  }

  &__thumb {
    position: absolute;
    z-index: 1;
    outline: none;
    width: $color-picker-slider-thumb-size;
    height: $color-picker-slider-thumb-size;

    border-radius: $color-picker-border-radius-circle;
    box-shadow: $color-picker-thumbs-shadow;
    color: $text-color-brand;
    box-sizing: border-box;

    &::before,
    &::after {
      content: '';
      position: absolute;
      border-radius: $color-picker-border-radius-circle;
      box-sizing: border-box;
      display: block;
      border: 1px solid #dcdcdc;
    }

    &::before {
      left: 0;
      top: 0;
      width: 100%;
      height: 100%;
      background-color: #fff;
    }

    &::after {
      left: 3px;
      top: 3px;
      width: calc(100% - 6px);
      height: calc(100% - 6px);
      padding: $color-picker-slider-thumb-padding;
      background: currentcolor;
    }
  }

  &__saturation {
    height: $color-picker-saturation-height;
    border-radius: $color-picker-saturation-radius;
    position: relative;
    overflow: hidden;
    background: transparent;

    &::before,
    &::after {
      content: '';
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
    }

    &::before {
      /* stylelint-disable-next-line color-no-hex */
      background: linear-gradient(90deg, #fff, transparent);
    }

    &::after {
      /* stylelint-disable-next-line color-no-hex */
      background: linear-gradient(0deg, #000, transparent);
    }

    .#{$color-picker}__thumb {
      width: $color-picker-saturation-thumb-size;
      height: $color-picker-saturation-thumb-size;
      border-radius: $color-picker-border-radius-circle;
      transform: translate(-50%, -50%);
    }
  }

  &__slider-wrapper {
    border-radius: $color-picker-slider-wrapper-radius;
    padding: $color-picker-slider-wrapper-padding;
    position: relative;

    &--hue-type {
      /* stylelint-disable-next-line color-named */
      background: linear-gradient(90deg, red, #ff0 17%, #0f0 33%, #0ff 50%, #00f 67%, #f0f 83%, red);
      margin: 8px 0;
    }

    &--alpha-type {
      background: $text-color-anti;
      margin: 20px 0 8px 0;

      @include transparentBgImage();

      .#{$color-picker}__rail {
        background: linear-gradient(to right, transparent, currentcolor);
      }
    }
  }

  &__slider-padding {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: $color-picker-slider-height;
    border-radius: $color-picker-slider-wrapper-radius;
  }

  &__slider {
    height: $color-picker-slider-height;
    position: relative;
    border-radius: $color-picker-slider-wrapper-radius;
    cursor: pointer;
    color: transparent;
    outline: none;
    z-index: 1;

    .#{$color-picker}__thumb {
      transform: translate(-50%, -50%);
      top: 50%;
    }

    .#{$color-picker}__rail {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      overflow: hidden;
      border-radius: inherit;
    }
  }

  &__sliders-wrapper {
    display: flex;
    align-items: center;
    margin: 16px 0 20px;
  }

  &__sliders {
    width: 100%;
  }

  &__sliders-preview {
    flex-shrink: 0;
    margin-left: $color-picker-margin;
    width: $color-picker-gradient-preview-width;
    height: $color-picker-gradient-preview-height;
    border-radius: $color-picker-gradient-preview-radius;
    overflow: hidden;
    background: $text-color-anti;

    @include transparentBgImage();
  }

  &__sliders-preview-inner {
    display: block;
    width: 100%;
    height: 100%;
  }

  &__format {
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: rgba(0, 0, 0, .4);
    font-size: 14px;
    text-align: center;
    line-height: 28px;
    height: 28px;
    margin: 20px 0 28px 0;
  }

  &__format-item {
    background: $color-picker-format-background-color;

    &--first {
      flex-shrink: 0;
      width: 68px;
      border: 1px solid #dcdcdc;
      border-radius: 6px;
      margin-right: 24px;
      margin-right: 12px;
    }

    &--second {
      flex: 1;
    }
  }

  &__format-inputs {
    display: flex;
    align-items: center;
    justify-content: space-around;
  }

  &__format-input {
    flex: 1;
    width: 0;
    margin-left: -1px;

    border: 1px solid #dcdcdc;
    border-radius: 6px;

    &:not(:first-child):not(:last-child) {
      border-radius: 0;
    }

    &:first-child:not(:last-child) {
      border-top-right-radius: 0;
      border-bottom-right-radius: 0;
    }

    &:last-child:not(:first-child) {
      border-top-left-radius: 0;
      border-bottom-left-radius: 0;
    }

    &--fixed {
      flex-shrink: 0;
      flex-grow: 0;
      flex-basis: 66.50px;
    }
  }

  &__swatches-wrap {
    position: relative;
  }

  &__swatches {
    + .#{$color-picker}__swatches {
      margin-top: $color-picker-margin;
    }
  }

  &__swatches-title {
    font: $color-picker-swatches-title-font;
    padding: 0;
    color: rgba(0, 0, 0, .9);
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 24px;
    line-height: 24px;
  }

  &__swatches-items {
    margin-top: 12px;
    width: 100%;
    list-style: none;
    display: flex;

    overflow-x: auto;
    overflow-y: auto;

    &::-webkit-scrollbar {
      display: none;
      width: 0;
      height: 0;
      color: transparent;
    }
  }

  &__swatches-item {
    display: flex;
    width: $color-picker-swatch-width;
    height: $color-picker-swatch-height;
    border-radius: 3px;
    padding: $color-picker-swatch-padding;
    overflow: hidden;

    cursor: pointer;

    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    transform-origin: center;
    transition: all $anim-duration-base $anim-time-fn-easing;
    box-sizing: border-box;

    flex-shrink: 0;
    margin-right: 12px;
    border-radius: $color-picker-swatch-border-radius;

    &::after {
      content: '';
      width: 100%;
      height: 100%;
      position: absolute;
      left: 0;
      top: 0;
      opacity: 0;
      background: rgba(0, 0, 0, .2);
    }

    &:active {
      &::after {
        opacity: 1;
      }
    }
  }

  &__swatches-inner {
    width: 100%;
    height: 100%;
    display: block;
    border-radius: $color-picker-swatch-border-radius;
    position: relative;
  }
}

