// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
//
// Copyright (c) KALEIDOS INC

@import "refactor/common-refactor.scss";

.custom-select {
  --border-color: var(--menu-background-color);
  --bg-color: var(--menu-background-color);
  --icon-color: var(--icon-foreground);
  --text-color: var(--menu-foreground-color);
  @extend .new-scrollbar;
  @include bodySmallTypography;
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  height: $s-32;
  width: 100%;
  margin: 0;
  padding: $s-8;
  border-radius: $br-8;
  background-color: var(--bg-color);
  border: $s-1 solid var(--border-color);
  color: var(--text-color);
  cursor: pointer;

  &.icon {
    grid-template-columns: auto 1fr auto;
  }

  &:hover {
    --bg-color: var(--menu-background-color-hover);
    --border-color: var(--menu-background-color);
    --icon-color: var(--menu-foreground-color-hover);
  }

  &:focus {
    --bg-color: var(--menu-background-color-focus);
    --border-color: var(--menu-background-focus);
  }
}

.disabled {
  --bg-color: var(--menu-background-color-disabled);
  --border-color: var(--menu-border-color-disabled);
  --icon-color: var(--menu-foreground-color-disabled);
  --text-color: var(--menu-foreground-color-disabled);
  pointer-events: none;
  cursor: default;
}

.dropdown-button {
  @include flexCenter;
  svg {
    @extend .button-icon-small;
    transform: rotate(90deg);
    stroke: var(--icon-color);
  }
}

.current-icon {
  @include flexCenter;
  width: $s-24;
  padding-right: $s-4;
  svg {
    @extend .button-icon-small;
    stroke: var(--icon-foreground);
  }
}

.custom-select-dropdown {
  @extend .dropdown-wrapper;
  .separator {
    margin: 0;
    height: $s-12;
    border-block-start: $s-1 solid var(--dropdown-separator-color);
  }
}

.custom-select-dropdown[data-direction="up"] {
  bottom: $s-32;
  top: auto;
}

.checked-element {
  @extend .dropdown-element-base;
  .icon {
    @include flexCenter;
    height: $s-24;
    width: $s-24;
    padding-right: $s-4;
    svg {
      @extend .button-icon;
      stroke: var(--icon-foreground);
    }
  }

  .label {
    flex-grow: 1;
    width: 100%;
  }

  .check-icon {
    @include flexCenter;
    svg {
      @extend .button-icon-small;
      visibility: hidden;
      stroke: var(--icon-foreground);
    }
  }

  &.is-selected {
    color: var(--menu-foreground-color);
    .check-icon svg {
      stroke: var(--menu-foreground-color);
      visibility: visible;
    }
  }
  &.disabled {
    display: none;
  }
}

.current-label {
  @include textEllipsis;
}
