@import "./variables/_variables.scss";

.comboboxWrapper {
  position: relative;
  display: flex !important;
  align-items: center;
  justify-content: center;

  .combobox {
    border: 0;
    outline: 0;
    width: 100%;
    padding-left: 0;
    padding-right: 0;
    padding-top: 0;
    padding-bottom: 0;
    border-radius: $base-gap;
    text-overflow: ellipsis;
  }

  .combobox:focus {
    border: $bsr-black-90;
  }

  .combobox[data-focus-visible] {
    outline: $bsr-black-90;
  }

  input {
    height: 100%;
    text-overflow: ellipsis;
  }

  input:focus {
    border: $bsr-black-90;
  }

  button {
    height: 100%;
    //width: $input-button-width;
    border-radius: 0.125rem;
    padding: 0px !important;
    background-color: transparent !important;

    &.comboboxCancel {
      svg {
        width: 1.25rem;
        height: 100%;
        color: $bsr-grey-100;
        stroke-width: 1.25pt;
      }
      &:focus {
        background-color: transparent !important;
      }
    }

    &:active {
      box-shadow: none !important;
    }
  }

  // BMSK-AddresdField
  &.focused,
  &:focus,
  &:focus-within {
    box-shadow: $bsr-shadow-default !important;
    background-color: $white;
  }

  &.dark {
    background-color: $bsr-light-brown-100;
  }
}

.comboboxCancel {
  width: fit-content;
  background-color: transparent !important;
  svg {
    width: 1.25rem;
    height: 100%;
    color: $bsr-grey-100;
    stroke-width: 1.25pt;
  }
}

.comboboxPopoverWrapper {
  // popover darf kein outline haben
  background: $bsr-white-100;

  :focus-visible {
    outline: 0;
    border: 0;
  }

  .popover {
    position: absolute;
    top: -3px;
    left: 0;
    z-index: 1000;
    display: block;
    max-width: none;
    box-shadow: $bsr-shadow-default;
    border-radius: $border-radius;
  }

  div[role="listbox"] {
    overflow-x: hidden;
    background: $bsr-white-100;
    border-top-left-radius: 0;
    border-top-right-radius: 0;
    border-top: none;
    padding-inline: 0;
    padding-block: 4px;
    transform: translateY(0.6rem);

    div[role="option"] {
      font-weight: $fontweight-normal;
      white-space: normal;

      &:active,
      &:hover {
        color: $bsr-black-90 !important;
      }

      &[aria-selected="true"],
      &[aria-selected="true"].selected {
        box-shadow: 0 0 0 2px #fff, 0 0 0 4px $primary;
        border-color: $primary;
        outline: 0;

        &:active,
        &:hover {
          color: $white;
        }
      }

      &[aria-selected="true"].selected {
        background-color: $bsr-black-30 !important;
        color: $bsr-black-90;
      }
      &.selected {
        box-shadow: none;
        background-color: $bsr-black-30 !important;
        color: $bsr-black-90;
      }
    }
  }
}

.rowDark {
  .comboboxWrapper {
    .comboboxArrow,
    .comboboxCancel {
      background-color: transparent;
    }
  }
}

.disabled {
  pointer-events: none;
  background-color: $bsr-grey-100;
}

// MultiSelectField
.multiSelectField {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 45px;
  padding: ($base-gap) ($base-gap * 2);
  gap: $base-gap;
  background-color: $bsr-white-100;
  border: $bsr-border-width-s solid $bsr-grey-100;
  border-radius: $border-radius-sm;
  font-family: "TradeGothicNext", "TradeGothicNextSR", sans-serif;
  font-size: $inputField-font-size;
  line-height: $inputField-line-height;
  color: $bsr-black-90;
  cursor: text;

  &:focus-within {
    border-color: $bsr-black-90;
    outline: $bsr-border-width-m solid $bsr-black-90;
  }

  &.error {
    border-color: transparent;
    outline: $bsr-border-width-l solid $bsr-border-color-error;
  }

  &.read-only,
  &.disabled {
    background-color: $bsr-black-10;
    color: $bsr-black-60;
    cursor: not-allowed;
  }

  &.dark {
    background-color: $bsr-light-brown-100;
    color: $bsr-white-100;
  }

  .multiSelectField__row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    flex: 1 1 auto;
    gap: $base-gap;
    min-width: 0;
  }

  .multiSelectField__tag {
    display: inline-flex;
    align-items: center;
    gap: $base-gap;
    margin: 0;
    padding: 0 ($base-gap * 2);
    min-height: calc(45px - #{$base-gap * 4});
    background-color: $bsr-white-100;
    color: $bsr-black-90;
    border: $bsr-border-width-s solid $bsr-grey-100;
    border-radius: $border-radius-lg * 2;
    font-family: inherit;
    font-size: inherit;
    line-height: 1.2;
    cursor: pointer;

    &:hover,
    &:focus-visible {
      background-color: $bsr-black-10;
    }

    &:focus-visible {
      outline: $bsr-border-width-m solid $bsr-black-90;
      outline-offset: 1px;
    }

    &:disabled {
      cursor: default;
      color: $bsr-black-40;
      border-color: $bsr-black-40;
      background-color: transparent;
    }

    .multiSelectField__tagRemove {
      font-weight: 600;
      font-size: 0.8em;
      color: $bsr-grey-100;
    }
  }

  // input rendered by ariakit Combobox – neutralize global form input styles
  input[role="combobox"] {
    flex: 1 1 80px;
    min-width: 80px;
    width: auto;
    margin: 0;
    padding: 0 $base-gap;
    background: transparent;
    border: 0;
    outline: 0;
    color: inherit;
    font: inherit;
    line-height: inherit;
    box-shadow: none;

    &:focus,
    &:focus-visible,
    &:active {
      border: 0;
      outline: 0;
      box-shadow: none;
    }
  }

  .multiSelectField__cancel {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    min-height: 0;
    padding: 0;
    margin: 0;
    background: transparent;
    border: 0;
    color: $bsr-grey-100;
    cursor: pointer;

    &::before {
      content: "✕";
      font-size: 0.9em;
      line-height: 1;
    }

    &:hover,
    &:focus-visible {
      color: $bsr-black-90;
    }

    svg {
      display: none;
    }
  }
}

.multiSelectFieldPopover {
  z-index: 1000;
  display: flex;
  flex-direction: column;
  max-height: min(var(--popover-available-height, 320px), 320px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: $base-gap;
  background-color: $bsr-white-100;
  border: $bsr-border-width-s solid $bsr-grey-100;
  border-radius: $border-radius-sm;
  box-shadow: $bsr-shadow-default;
  font-family: "TradeGothicNext", "TradeGothicNextSR", sans-serif;
  font-size: $inputField-font-size;
  line-height: $inputField-line-height;
  color: $bsr-black-90;

  div[role="option"] {
    padding: ($base-gap * 2) ($base-gap * 3);
    border-radius: $border-radius-sm;
    cursor: pointer;
    white-space: normal;

    &:hover,
    &[data-active-item] {
      background-color: $bsr-black-10;
    }

    &[aria-selected="true"] {
      background-color: $bsr-grey-100;
      color: $bsr-white-100;
    }
  }
}

.pagination {
  button[role="combobox"] {
    height: fit-content;
  }
}
