/* 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/. */

:host {
  --select-border: var(--button-border);
  --select-border-radius: var(--button-border-radius);
  --select-border-color-hover: var(--button-border-color-hover);
  --select-border-color-disabled: var(--button-border-color-disabled);
  --select-background-color: var(--button-background-color);
  --select-background-color-hover: var(--button-background-color-hover);
  --select-background-color-disabled: var(--button-background-color-disabled);
  --select-opacity-disabled: var(--button-opacity-disabled);
  --select-margin-block: var(--input-margin-block-adjust);
  --select-margin-inline: var(--input-margin-inline-start-adjust) var(--space-small);
  --select-min-height: var(--button-min-height);
  --select-font-size: var(--button-font-size);
  --select-font-weight: var(--button-font-weight);
  --select-option-font-weight: var(--font-weight);
  --select-text-color: var(--button-text-color);
  --select-text-color-hover: var(--button-text-color-hover);
  --select-text-color-disabled: var(--button-text-color-disabled);
  --select-option-text-color: var(--text-color);
  --select-icon-fill: var(--button-icon-fill);
}

.select-wrapper {
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  border: var(--select-border);
  border-radius: var(--select-border-radius);
  background-color: var(--select-background-color);
  color: var(--select-text-color);
  margin-block: var(--select-margin-block);
  margin-inline: var(--select-margin-inline);
  min-width: var(--select-min-width);
  max-width: var(--select-max-width);
  -moz-context-properties: fill;
  fill: var(--select-icon-fill);

  &:has(select:hover),
  &:has(select:open) {
    border-color: var(--select-border-color-hover);
    background-color: var(--select-background-color-hover);
    color: var(--select-text-color-hover);
  }

  &:has(select:disabled) {
    border-color: var(--select-border-color-disabled);
    background-color: var(--select-background-color-disabled);
    color: var(--select-text-color-disabled);
    opacity: var(--select-opacity-disabled);
  }

  &:has(select:focus-visible) {
    outline: var(--focus-outline);
    outline-offset: var(--focus-outline-offset);
  }
}

select {
  border: none;
  border-radius: var(--select-border-radius);
  padding-block: var(--space-xsmall);
  padding-inline: var(--space-large) var(--space-xxlarge);
  margin: 0;
  min-height: var(--select-min-height);
  width: 100%;
  font-size: var(--select-font-size);
  font-weight: var(--select-font-weight);
  appearance: none;
  color: inherit;
  background-color: transparent;

  &:focus-visible {
    outline: none;
    outline-offset: unset;
  }

  & option {
    font-weight: var(--select-option-font-weight);
    color: var(--select-option-text-color);
  }
}

.select-option-icon,
.select-chevron-icon {
  position: absolute;
  width: var(--icon-size);
  height: var(--icon-size);
  pointer-events: none;
}

.select-option-icon {
  inset-inline-start: var(--space-large);
  opacity: 0;
  transform: scale(0);
  transition:
    opacity 0.3s ease,
    transform 0.3s ease;

  @media (prefers-reduced-motion) {
    transition: unset;
  }
}

.select-chevron-icon {
  inset-inline-end: var(--space-medium);
}

.with-icon select {
  padding-inline-start: calc(var(--space-large) + var(--icon-size) + var(--space-small));
  transform: translateX(calc(-1 * (var(--icon-size) + var(--space-small))));
  transition: transform 0.3s ease;

  @media (prefers-reduced-motion) {
    transition: unset;
  }
}

.with-icon:has(select:not(:open)) {
  select {
    transform: translateX(0);
  }

  .select-option-icon {
    opacity: 1;
    transform: scale(1);
  }
}
