/*
 * @package   panopticon
 * @copyright Copyright (c)2023-2025 Nicholas K. Dionysopoulos / Akeeba Ltd
 * @license   https://www.gnu.org/licenses/agpl-3.0.txt GNU Affero General Public License, version 3 or later
 */

/**
 * We had to override this file because it included a few hardcoded colours and made assumptions that the SCSS variables
 * contain colour values which it then tried to tint. This made it a pain to make it work with the Dark Mode. Using CSS
 * variables has made it far easier to make display consistent.
 */

/* ===============================
=            Choices            =
=============================== */

@use "sass:color";

$choices-button-offset: .5em !default;
$choices-button-dimension: .5em !default;

.choices {
  position: relative;
  overflow: hidden;
  //margin-bottom: $choices-guttering;
  //font-size: $choices-font-size-lg;

  &:focus {
    outline: none;
  }

  &:last-child {
    margin-bottom: 0;
  }

  &.is-open {
    overflow: visible;
  }

  &.is-disabled {
    .choices__inner,
    .choices__input {
      background-color: var(--bs-secondary-bg);
      cursor: not-allowed;
      user-select: none;
    }
    .choices__item {
      cursor: not-allowed;
    }
  }

  [hidden] {
    display: none !important;
  }
}

.choices[data-type*='select-one'] {
  cursor: pointer;
  .choices__inner {
    padding-bottom: 7.5px;
  }
  .choices__input {
    display: block;
    width: 100%;
    padding: 10px;
    border-bottom: 1px solid var(--bs-border-color);
    background-color: #fff;
    margin: 0;
  }
  .choices__button {
    background-image: $choices-icon-cross-inverse;
    padding: 0;
    background-size: 8px;
    position: absolute;
    top: 50%;
    right: 0;
    margin-top: -10px;
    margin-right: 25px;
    height: 20px;
    width: 20px;
    border-radius: 10em;
    opacity: 0.25;

    &:hover,
    &:focus {
      opacity: 1;
    }

    &:focus {
      box-shadow: 0 0 0 2px var(--bs-primary);
    }
  }
  .choices__item[data-value=''] .choices__button {
    display: none;
  }

  &::after {
    content: "";
    height: 0;
    width: 0;
    border-style: solid;
    border-color: var(--bs-body-color) transparent transparent transparent;
    border-width: 5px;
    position: absolute;
    right: 11.5px;
    top: 50%;
    margin-top: -2.5px;
    pointer-events: none;
  }

  &.is-open::after {
    border-color: transparent transparent var(--bs-body-color) transparent;
    margin-top: -7.5px;
  }

  &[dir="rtl"] {
    &::after {
      left: 11.5px;
      right: auto;
    }
    .choices__button {
      right: auto;
      left: 0;
      margin-left: 25px;
      margin-right: 0;
    }
  }
}

.choices[data-type*='select-multiple'],
.choices[data-type*='text'] {
  .choices__inner {
    cursor: text;
  }
  .choices__button {
    position: relative;
    display: inline-block;
    margin-top: 0;
    margin-right: -$choices-button-offset * 0.5;
    margin-bottom: 0;
    margin-left: $choices-button-offset;
    padding-left: $choices-button-offset * 2;
    border-left: 1px solid var(--bs-primary-border-subtle);
    background-image: $choices-icon-cross;
    background-size: $choices-button-dimension;
    width: $choices-button-dimension;
    line-height: 1;
    opacity: 0.75;
    border-radius: 0;

    &:hover,
    &:focus {
      opacity: 1;
    }
  }
}

.choices__inner {
  display: inline-block;
  vertical-align: top;
  width: 100%;
  background-color: var(--bs-body-bg);
  padding: 7.5px 7.5px 3.75px;
  border: 1px solid var(--bs-border-color);
  border-radius: var(--bs-border-radius);
  min-height: 44px;
  overflow: hidden;

  .is-focused &,
  .is-open & {
    border-color: var(--bs-light-border-subtle);
  }

  .is-open & {
    border-radius: .25em .25em 0 0;
  }

  .is-flipped.is-open & {
    border-radius: 0 0 .25em .25em;
  }
}

.choices__list {
  margin: 0;
  padding-left: 0;
  list-style: none;

  &[aria-expanded] {
    @extend %choices-dropdown;
  }
}

.choices__list--single {
  display: inline-block;
  padding: 4px 16px 4px 4px;
  width: 100%;

  [dir="rtl"] & {
    padding-right: 4px;
    padding-left: 16px;
  }
  .choices__item {
    width: 100%;
  }
}

.choices__list--multiple {
  display: inline;
  .choices__item {
    display: inline-block;
    vertical-align: middle;
    border-radius: .5em;
    padding: 4px 10px;
    font-size: var(--bs-badge-font-size);
    font-weight: 500;
    margin-right: 3.75px;
    margin-bottom: 3.75px;
    background-color: var(--bs-primary);
    border: 1px solid var(--bs-primary-border-subtle);
    color: #fff;
    word-break: break-all;
    box-sizing: border-box;

    &[data-deletable] {
      padding-right: 5px;
    }

    [dir="rtl"] & {
      margin-right: 0;
      margin-left: 3.75px;
    }

    &.is-highlighted {
      background-color: var(--bs-primary-bg-subtle);
      border: 1px solid var(--bs-primary);
    }

    .is-disabled & {
      background-color: var(--bs-btn-disabled-bg);
      border: 1px solid var(--bs-secondary);
    }
  }
}

%choices-dropdown {
  visibility: hidden;
  z-index: 100;
  position: absolute;
  width: 100%;
  background-color: var(--bs-body-bg);
  border: 1px solid var(--bs-border-color);
  top: 100%;
  margin-top: -1px;
  border-bottom-left-radius: .5em;
  border-bottom-right-radius: .5em;
  overflow: hidden;
  word-break: break-all;
  will-change: visibility;

  &.is-active {
    visibility: visible;
  }

  .is-open & {
    border-color: var(--bs-light);
  }

  .is-flipped & {
    top: auto;
    bottom: 100%;
    margin-top: 0;
    margin-bottom: -1px;
    border-radius: 0.25rem 0.25rem 0 0;
  }
  .choices__list {
    position: relative;
    max-height: 300px;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    will-change: scroll-position;
  }
  .choices__item {
    position: relative;
    padding: 10px;

    [dir="rtl"] & {
      text-align: right;
    }
  }
  .choices__item--selectable {
    @media (min-width: 640px) {
      padding-right: 100px;

      &::after {
        content: attr(data-select-text);
        font-size: var(--bs-badge-font-size);
        opacity: 0;
        position: absolute;
        right: 10px;
        top: 50%;
        transform: translateY(-50%);
      }

      [dir="rtl"] & {
        text-align: right;
        padding-left: 100px;
        padding-right: 10px;

        &::after {
          right: auto;
          left: 10px;
        }
      }
    }

    &.is-highlighted {
      background-color: var(--bs-tertiary-bg);

      &::after {
        opacity: 0.5;
      }
    }
  }
}

.choices__list--dropdown {
  @extend %choices-dropdown;
}

.choices__item {
  cursor: default;
}

.choices__item--selectable {
  cursor: pointer;
}

.choices__item--disabled {
  cursor: not-allowed;
  user-select: none;
  opacity: 0.5;
}

.choices__heading {
  font-weight: 600;
  font-size: var(--bs-badge-font-size);
  padding: 10px;
  border-bottom: 1px solid var(--bs-border-color);
  color: color.adjust(#333, $lightness: 30%);
}

.choices__button {
  text-indent: -9999px;
  appearance: none;
  border: 0;
  background-color: transparent;
  background-repeat: no-repeat;
  background-position: center;
  cursor: pointer;

  &:focus {
    outline: none;
  }
}

.choices__input {
  display: inline-block;
  vertical-align: baseline;
  background-color: var(--bs-body-bg);
  margin-bottom: 5px;
  border: 0;
  border-radius: 0;
  max-width: 100%;
  padding: 4px 0 4px 2px;

  &:focus {
    outline: 0;
  }

  &::-webkit-search-decoration,
  &::-webkit-search-cancel-button,
  &::-webkit-search-results-button,
  &::-webkit-search-results-decoration {
    display: none;
  }

  &::-ms-clear,
  &::-ms-reveal {
    display: none;
    width: 0;
    height: 0;
  }

  [dir="rtl"] & {
    padding-right: 2px;
    padding-left: 0;
  }
}

.choices__placeholder {
  opacity: 0.5;
}

/* =====  End of Choices  ====== */