// Lightning Design System 2.264.0-beta.1
// Copyright (c) 2015-present, salesforce.com, inc. All rights reserved
// Licensed under BSD 3-Clause - see LICENSE.txt or git.io/sfdc-license

/**
 * @name base
 * @selector .slds-combobox_container
 * @restrict div
 * @support dev-ready
 * @variant
 */
.slds-combobox_container {
  display: flex;
  flex-direction: column;
  position: relative;

  /**
   * Opens listbox dropdown
   *
   * @selector .slds-is-open
   * @restrict .slds-combobox
   * @modifier
   */
  &.slds-is-open .slds-dropdown {
    display: block;
  }

  /**
   * @summary Apply when a combobox has a selection
   * @selector .slds-has-selection
   * @restrict .slds-combobox_container
   */
  &.slds-has-selection {

    .slds-combobox__input-value,
    .slds-combobox__input-value:focus {
      box-shadow: 0 0 0 2px var(--slds-g-color-neutral-base-100, #{$color-gray-1}) inset, 0 0 0 3px var(--slds-g-color-border-base-1, #{$color-border}) inset;
    }

    .slds-combobox__input-value:focus {
      outline: 2px solid var(--slds-g-color-brand-base-40);
    }
  }

  /**
   * @summary Icon only variant of a combobox
   * @selector .slds-has-icon-only
   * @restrict .slds-combobox_container
   */
  &.slds-has-icon-only {

    .slds-combobox__input,
    .slds-combobox__input:focus,
    .slds-combobox__input.slds-has-focus {
      width: 0;
      pointer-events: auto;
    }

    .slds-input__icon {
      z-index: 2;
      pointer-events: none;
    }
  }

  &.slds-has-object-switcher {

    .slds-listbox_object-switcher {

      .slds-button:focus {

        outline-offset: 0;
      }
    }
  }
}

/**
 * Container around form element with combobox input
 *
 * @selector .slds-combobox
 * @restrict .slds-combobox_container > div
 */
.slds-combobox {
  position: static;
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
}

/**
 * Form element with combobox input
 *
 * @selector .slds-combobox__form-element
 * @restrict .slds-combobox > div
 */
.slds-combobox__form-element {
  flex: 1 1 auto;
}

[role="combobox"] input[readonly],
input[readonly][role="combobox"] {
  padding-left: $spacing-small;
  border-color: var(--slds-g-color-border-base-4, #{$color-border-input});
  background-color: var(--slds-g-color-neutral-base-100, #{$color-background-input});
  font-size: inherit;
  font-weight: $font-weight-regular;

  &:focus,
  &.slds-has-focus {
    box-shadow: var(--slds-g-shadow-outline-focus-1, #{$shadow-button-focus});
  }

  &[disabled] {
    background-color: var(--slds-g-color-neutral-base-95, #{$color-background-input-disabled});
    border-color: var(--slds-g-color-border-base-1, #{$color-border-input-disabled});
  }
}

/**
 * Listbox container
 * @name listbox
 * @selector .slds-listbox
 * @restrict .slds-dropdown ul, .slds-dueling-list__options ul, .slds-pill_container ul, .slds-listbox_selection-group ul, .slds-combobox_container ul, .slds-form-element__control ul, .slds-popover__body ul
 * @support dev-ready
 * @variant
 */

/**
 * Inline listbox
 *
 * @selector .slds-listbox_inline
 * @restrict .slds-listbox
 * @modifier
 */
.slds-listbox_inline,
.slds-listbox--inline {
  display: inline-flex;
  flex-wrap: wrap;
  flex-shrink: 0;
  align-items: center;
  margin-left: $spacing-xxx-small;
  margin-right: $spacing-xxx-small;

  li {
    display: flex;
  }

  li + li {
    padding-left: $spacing-xxx-small;
  }
}

/**
 * Horizontal listbox
 *
 * @selector .slds-listbox_horizontal
 * @restrict .slds-listbox
 * @modifier
 */
.slds-listbox_horizontal,
.slds-listbox--horizontal {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;

  li {
    display: flex;
  }

  li + li {
    padding-left: $spacing-xxx-small;
  }
}

/**
 * Listbox item
 *
 * @selector .slds-listbox__item
 * @restrict .slds-listbox > li
 */

/**
 * Choosable option within listbox
 *
 * @selector .slds-listbox__option
 * @restrict .slds-listbox__item > div
 */
.slds-listbox__option {

  color: var(--slds-c-listbox-option-color);
  background-color: var(--slds-c-listbox-option-color-background);

  &:hover {
    cursor: pointer;
    color: var(--slds-c-listbox-option-color-hover);
    background-color: var(--slds-c-listbox-option-color-background-hover);
  }

  &:focus {
    outline: 0;
    color: var(--slds-c-listbox-option-color-focus);
    background-color: var(--slds-c-listbox-option-color-background-focus);
  }

  /**
   * If the listbox option is empty and slds-truncate is not present this fix the height of the option
   *
   * @selector .slds-media__body > :first-child
   * @restrict .slds-listbox__option
   */
  .slds-truncate, .slds-media__body > :first-child {
    display: inline-block;
    vertical-align: middle;
  }

  &[aria-disabled="true"],
  &[aria-disabled="true"]:hover,
  &[aria-disabled="true"]:focus {
    color: var(--slds-c-listbox-option-color-disabled, var(--slds-g-color-neutral-base-50, #{$color-text-button-default-disabled}));
    background-color: var(--slds-c-listbox-option-color-background-disabled);
  }
}

/**
 * @summary Header for choosable option within listbox
 * @selector .slds-listbox__option-header
 * @restrict .slds-listbox__option h3
 */
.slds-listbox__option-header {
  @include text-title;
}

/**
 * @summary Container for listbox option icon
 * @selector .slds-listbox__option-icon
 * @restrict .slds-listbox__option span
 */
.slds-listbox__option-icon {
  width: $square-icon-small-boundary;
  display: inline-flex;
  align-content: center;
  align-items: center;
  justify-content: center;
  color: var(--slds-g-color-neutral-base-50, #{$color-text-icon-default});
}

.slds-listbox__option[aria-disabled="true"] .slds-listbox__option-icon {
  color: currentColor;
}

/**
 * Creates a vertical listbox
 *
 * @selector .slds-listbox_vertical
 * @restrict .slds-listbox
 * @modifier
 */
.slds-listbox_vertical,
.slds-listbox--vertical {
  /**
   * Focus state of a vertical listbox option
   *
   * @selector .slds-has-focus
   * @restrict .slds-listbox__option
   * @modifier
   */
  .slds-listbox__option:focus,
  .slds-listbox__option:hover,
  .slds-listbox__option.slds-has-focus {
    text-decoration: none;
  }

  .slds-listbox__option:hover {
    background-color: var(--slds-c-listbox-option-color-background-hover, var(--slds-g-color-neutral-base-95, #{$color-background-row-hover}));
  }

  .slds-listbox__option:focus,
  .slds-listbox__option.slds-has-focus {
    background-color: var(--slds-c-listbox-option-color-background-focus, var(--slds-g-color-neutral-base-95, #{$color-background-row-hover}));
    box-shadow: var(--slds-g-shadow-inset-focus-1, #{$shadow-button-focus});
    outline: 0;
  }

  .slds-listbox__option[aria-disabled="true"],
  .slds-listbox__option[aria-disabled="true"]:hover,
  .slds-listbox__option[aria-disabled="true"]:focus,
  .slds-listbox__option[aria-disabled="true"].slds-has-focus,
  .slds-listbox__option[role="presentation"]:hover {
    background-color: var(--slds-c-listbox-option-color-background-disabled, transparent);
    cursor: default;
  }

  /**
   * Modifies the listbox option if it contains an entity object
   *
   * @selector .slds-listbox__option_entity
   * @restrict .slds-listbox__option
   */
  .slds-listbox__option_entity,
  .slds-listbox__option--entity {
    padding: $spacing-xx-small $spacing-small;

    .slds-media__figure {
      margin-right: $spacing-x-small;
    }
  }

  /**
   * Modifies the listbox option if it contains an plain object or string
   *
   * @selector .slds-listbox__option_plain
   * @restrict .slds-listbox__option
   */
  .slds-listbox__option_plain,
  .slds-listbox__option--plain {
    padding: $spacing-x-small $spacing-small;
  }

  .slds-listbox__option_term {
    padding: $spacing-x-small $spacing-small;
  }

  /**
   * If the listbox option has metadata or secondary information that sits below its primary text
   *
   * @selector .slds-listbox__option_has-meta
   * @restrict .slds-listbox__option
   */
  .slds-listbox__option_has-meta,
  .slds-listbox__option--has-meta {

    .slds-media__figure {
      margin-top: $spacing-xx-small;
    }
  }
}

.slds-dueling-list__options {

  .slds-listbox_vertical,
  .slds-listbox--vertical {

    .slds-listbox__option.slds-is-selected:focus,
    .slds-listbox__option.slds-is-selected.slds-has-focus {
      box-shadow: var(--slds-g-shadow-inset-inverse-focus-1);
    }
  }
}

/**
 * Class to target styling the value of a combobox input
 *
 * @selector .slds-combobox__input-value
 * @restrict .slds-combobox__input
 */
.slds-input-has-icon_left,
.slds-input-has-icon_left-right,
.slds-input-has-icon--left,
.slds-input-has-icon--left-right {

  & .slds-combobox__input[value],
  & .slds-combobox__input.slds-combobox__input-value {
    padding-left: ($square-icon-small-boundary + $spacing-small);
  }
}

.slds-input_faux:not(.slds-combobox__input-value) {
  color: var(--slds-g-color-neutral-base-50, #{$color-text-placeholder});
}

/**
 * If readonly selection is an entity, use this class
 *
 * @selector .slds-combobox__input-entity-icon
 * @restrict .slds-combobox__form-element span
 */
.slds-combobox__input-entity-icon {
  @include square($square-icon-x-small-boundary);
  position: absolute;
  top: 50%;
  left: calc(#{$spacing-xx-small} + 1px);
  transform: translateY(-50%);
  z-index: 2;

  .slds-icon {
    @include square($square-icon-x-small-boundary);
  }
}

/**
 * Icon that is a direct sibling of a combobox container. This is not the same as an input icon.
 *
 * @selector .slds-combobox_container__icon
 * @restrict .slds-combobox_container svg
 */
.slds-combobox_container__icon {
  color: var(--slds-g-color-neutral-base-50, #{$color-text-input-icon});
}

/**
 * The icon within a plain listbox that indicates if an option has been selected or not.
 *
 * @selector .slds-listbox__icon-selected
 * @restrict .slds-listbox__item svg
 */
.slds-listbox__icon-selected {
  opacity: 0;
  fill: $brand-accessible;
}

/**
 * Modifier that makes selected icon visible
 *
 * @selector .slds-is-selected
 * @restrict .slds-listbox__option
 * @modifier
 */
.slds-listbox__option.slds-is-selected {

  .slds-listbox__icon-selected {
    opacity: 1;
  }

  .slds-listbox__option-icon {
    color: $brand-accessible;
  }
}

/**
 * The main text of an entity listbox
 *
 * @selector .slds-listbox__option-text_entity
 * @restrict .slds-listbox__option span
 */
.slds-listbox__option-text_entity,
.slds-listbox__option-text--entity {
  @include truncate; // truncate mixin used so class wouldn't need to be repeated in DOM
  display: block;
  margin-bottom: $spacing-xxx-small;
}

/**
 * The metadata or secondary text of an entity listbox
 *
 * @selector .slds-listbox__option-meta
 * @restrict .slds-listbox__option span
 */
.slds-listbox__option-meta {
  display: block;
  margin-top: ($spacing-xx-small * -1); // Offset $line-height-text from result-text
  color: var(--slds-c-listbox-option-meta-color, var(--slds-g-color-neutral-base-30, #{$color-text-label}));

  .slds-listbox__option:hover & {
    color: var(--slds-c-listbox-option-meta-color-hover);
  }

  .slds-listbox__option:focus &,
  .slds-listbox__option.slds-has-focus & {
    color: var(--slds-c-listbox-option-meta-color-focus);
  }
}

.slds-listbox__option[aria-disabled="true"] .slds-listbox__option-meta {
  color: var(--slds-c-listbox-option-meta-color-disabled, currentColor);
}

.slds-listbox_object-switcher,
.slds-listbox--object-switcher {
  flex-shrink: 0;
  padding: $spacing-xxx-small;
}

/**
 * @summary Modifier that identifies the combobox as the object switcher, applies specific interactions for its context
 * @selector .slds-combobox_object-switcher
 * @restrict .slds-combobox-group div
 */
.slds-combobox_object-switcher {
  flex-shrink: 0;

  .slds-combobox__input {
    width: rem(120px);
    transition: width 80ms linear;
    font-size: $font-size-2;
    color: var(--slds-g-color-neutral-base-50, #{$color-text-placeholder});

    &:focus,
    &.slds-has-focus {
      width: rem(160px);
    }
  }
}

/**
 * @summary Input field within a combobox
 *
 * @selector .slds-combobox__input
 * @restrict .slds-combobox__form-element input, .slds-combobox__form-element button
 */
.slds-combobox__input {
  /**
   * @summary Force focus state of the input
   *
   * @selector .slds-has-focus
   * @restrict .slds-combobox__input
   */
  &:focus,
  &.slds-has-focus {
    box-shadow: var(--slds-g-shadow-outline-focus-1, #{$shadow-button-focus});
    outline: 0;
  }
}

/**
 * @summary Container for a combobox group
 * @name grouped
 * @selector .slds-combobox-group
 * @restrict div
 * @support dev-ready
 * @variant
 */
.slds-combobox-group {
  display: flex;
  flex-direction: row;

  .slds-combobox_container {
    flex: 1 1 auto;
  }

  .slds-combobox__input,
  .slds-combobox_object-switcher__button {
    border-radius: 0;
    margin-left: -1px;
    margin-right: -1px;
    // fixes Firefox issue where click event wasn't firing on inputs. Pos rel fixes that.
    position: relative;


    &:focus,
    &.slds-has-focus {
      z-index: 1;
    }
  }

  /**
   * @summary Modifier that notifies the combobox group that a selection has been made
   *
   * @selector .slds-has-selection
   * @restrict .slds-combobox-group, .slds-combobox_container
   */
  &.slds-has-selection {

    .slds-combobox-addon_start .slds-combobox__input {
      border-bottom-left-radius: 0;
    }

    .slds-combobox-addon_end .slds-combobox__input {
      border-bottom-right-radius: 0;
    }

    ~ .slds-listbox_selection-group {
      display: flex;
      position: relative;
      background: var(--slds-g-color-neutral-base-100, #{$color-background-alt});
      border: 1px solid var(--slds-g-color-border-base-4, #{$color-border});
      border-top: 0;
      border-bottom-left-radius: $border-radius-medium;
      border-bottom-right-radius: $border-radius-medium;
      left: -1px;
    }
  }

  .slds-listbox_horizontal li + li {
    padding: $spacing-xxx-small;
  }
}

/**
 * @summary The container of pill selections found inside of a combobox group
 * @selector .slds-listbox_selection-group
 * @restrict .slds-combobox-group ~ div, .slds-combobox_container ~ div
 */
.slds-listbox_selection-group {
  position: relative;
  padding: 0;
  padding-right: 3.75rem;
  height: $height-input;
  overflow: hidden;

  /**
   * @summary Expanded state of a selection group
   * @selector .slds-is-expanded
   * @restrict .slds-listbox_selection-group
   */
  &.slds-is-expanded {
    height: auto;
    padding: 0;
  }

  .slds-listbox {
    padding: 0 0 $spacing-xxx-small; // Matches horizontal spacing of each listbox item (2px)
  }

  .slds-listbox-item {
    padding: $spacing-xxx-small $spacing-xxx-small 0;
  }

  /**
   * @summary Toggle button to show all of the pill selections
   * @selector .slds-listbox-toggle
   * @restrict .slds-listbox_selection-group > span
   */
  .slds-listbox-toggle {
    @include vertical-center;
    right: $spacing-x-small;

    .slds-button {
      line-height: 1;
    }
  }
}

/**
 * @summary The first combobox in the combobox group
 * @selector .slds-combobox-addon_start
 * @restrict .slds-combobox-group div
 */
.slds-combobox-addon_start .slds-combobox__input {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
  border-top-left-radius: 4px;
  border-bottom-left-radius: 4px;
}

/**
 * @summary The last combobox in the combobox group
 * @selector .slds-combobox-addon_end
 * @restrict .slds-combobox-group div
 */
.slds-combobox-addon_end .slds-combobox__input {
  border-top-right-radius: 4px;
  border-bottom-right-radius: 4px;
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}

/**
 * If combo has a selection model that requires a listbox of pills to be displayed
 * inside of a combobox
 *
 * @selector .slds-has-inline-listbox
 * @restrict .slds-combobox_container
 */
.slds-has-inline-listbox,
.slds-has-object-switcher {
  flex-direction: row;
  background: var(--slds-g-color-neutral-base-100, #{$color-background-input});
  border: $border-width-thin solid var(--slds-g-color-border-base-4, #{$color-border});
  border-radius: $border-radius-medium;

  .slds-combobox {
    flex-basis: 50%;
    flex-shrink: 0;
  }

  .slds-combobox__input {
    min-height: 100%;
    line-height: calc(#{$height-input} - 2px);
    border: 0;
    padding-top: $spacing-xxx-small;
    padding-bottom: $spacing-xxx-small;

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

    &:focus {
      outline: 2px solid var(--slds-g-color-brand-base-40);
      outline-offset: rem(-4px);
    }
  }

  .slds-listbox_object-switcher ~ .slds-listbox_inline,
  .slds-listbox--object-switcher ~ .slds-listbox--inline,
  .slds-combobox_container__icon ~ .slds-listbox_inline,
  .slds-combobox_container__icon ~ .slds-listbox--inline {
    margin-left: $spacing-x-small;
  }

  /**
   * Modifier to the combobox when an SVG icon sits adjacent to the combobox form element
   *
   * @selector .slds-has-icon_left
   * @restrict .slds-combobox
   */
  &.slds-has-icon_left {
    padding-left: ($spacing-x-large + $spacing-xx-small);

    /**
     * SVG icon that sits adjacent to the combobox form element
     *
     * @selector .slds-combobox_container__icon
     * @restrict .slds-combobox_container svg
     */
    .slds-combobox_container__icon {
      @include square($square-icon-utility-small);
      position: absolute;
      left: ($spacing-medium + $spacing-xxx-small);
      top: 50%;
      margin-top: ($spacing-x-small * -1);
    }
  }
}

.slds-has-inline-listbox {

  [role="listbox"] {
    display: inline-flex;
    padding: 0 $spacing-xxx-small; // Matches the vertical spacing (4px)
  }

  .slds-combobox__input-value {
    box-shadow: 0 0 0 2px var(--slds-g-color-neutral-base-100, #{$color-gray-1}) inset, 0 0 0 3px var(--slds-g-color-border-base-1, #{$color-border}) inset;
  }
}
