@import (reference) url('./Dropdown.less');

.ComboInput {
  --ComboInput-listPadding: var(--gap-l);

  cursor: pointer;
  display: inline-flex;
  max-width: 100%;
  min-height: calc(var(--gap-s) * 2 + var(--Text-height));
  overflow: hidden;
  padding: var(--gap-s) calc(var(--gap-s) * 2 + var(--Icon-size)) var(--gap-s) 0;
  position: relative;
  text-overflow: ellipsis;
  vertical-align: middle;
  white-space: nowrap;
  width: 100%;

  &::before {
    border-color: var(--Input-borderColor);
    border-style: solid;
    border-width: 0 0 1px;
    bottom: 0;
    content: '';
    left: 0;
    pointer-events: none;
    position: absolute;
    right: 0;
    top: 0;
  }

  .ComboInput-icon::after {
    .Icon;

    bottom: calc(var(--gap-s) + (var(--Text-height) - var(--Icon-size)) / 2);
    content: 'arrow_drop_down';
    pointer-events: none;
    position: absolute;
    right: var(--gap-s);
    top: auto;
    transition: transform var(--time-xs);
  }

  &:hover,
  &:focus {
    &::before {
      border-color: var(--Input-focusColor);
    }

    .ComboInput-icon::after {
      color: var(--Input-focusColor);
    }
  }

  &:focus::before {
    border-bottom-width: 2px;
  }
}

.ComboInput-label {
  &[data-placeholder]:empty::before {
    color: var(--color-gray5);
    content: attr(data-placeholder);
    display: block;
    font-style: italic;
    overflow: hidden;
    padding-right: 2px;
    text-overflow: ellipsis;
  }
}

.ComboInput input[type].ComboInput-filter {
  background: transparent;
  display: none;

  &,
  &:focus {
    border: 0;
    padding: 0;
  }
}

.ComboInput-list {
  .Dropdown;

  max-width: 50vw;
  min-width: 300px;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  width: auto;
}

.ComboInput-heading {
  background: var(--color-white);
  border-bottom: 1px solid var(--color-gray3);
  font-size: var(--fontSize-xs);
  padding: var(--gap-s);
  position: sticky;
  text-transform: uppercase;
  top: calc(0 - var(--gap-s));
  z-index: 10;

  &[data-hidden='true'] {
    display: none;
  }
}

.ComboInput-option {
  padding: var(--gap-s) calc(var(--Icon-size) + var(--gap-m) * 2) var(--gap-s)
    calc(var(--gap-s) * 2 + var(--Icon-size));
  position: relative;

  &[aria-selected='true'] .ComboInput-check::before {
    .Icon;

    content: 'check';
    left: var(--gap-s);
    margin-right: var(--gap-s);
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
  }

  &.is-active:not([data-create='true'][role='button']),
  &.is-active > &-nestedLabel {
    background: var(--color-dominant1);
  }

  &.nested {
    padding: 0;
  }

  &.nested > &-nestedLabel,
  &.nested a {
    display: block;
    padding: var(--gap-s) calc(var(--Icon-size) + var(--gap-m) * 2) var(--gap-s)
      calc(var(--gap-s) * 2 + var(--Icon-size));
    width: 100%;
  }

  &.nested > ul,
  &.nested li {
    display: block;
    list-style: none;
    margin: 0;
    padding: 0;
    width: 100%;
  }

  &.is-empty::after {
    content: '\200b';
  }

  .ComboInput-check:empty::after {
    content: '\200b';
  }

  &[data-select-all='true'],
  &[data-create='true']:not(.nested),
  &.nested[data-create='true'][aria-expanded='true'] {
    border-bottom: 1px solid var(--color-gray3);
  }

  &.is-hidden,
  &[data-no-permission='true'],
  &[data-is-owner='true'] {
    display: none;
  }

  &-nestedLabel {
    border-bottom: 1px solid var(--color-gray3);
    user-select: none;
  }
}

.ComboInput-check {
  left: 0;
  position: absolute;
  top: var(--gap-s);
}

.ComboInput-option-favorite,
.ComboInput-option-arrow {
  background: none;
  border: none;
  margin: 0;
  padding: 0;
  position: absolute;
  right: var(--gap-m);
  top: 0;

  .ComboInput-option-favorite-icon,
  .ComboInput-option-arrow-icon {
    .IconButton;

    top: calc((var(--Text-height) - var(--Icon-size)) / 2);
  }

  .ComboInput-option-favorite-icon {
    --Icon-size: var(--iconSize-xs);
    --IconButton-name: 'star';
  }

  .ComboInput-option-arrow-icon {
    --Icon-size: var(--iconSize-s);
    --IconButton-name: 'keyboard_arrow_down';

    transition: transform var(--time-xs);
    transition-property: transform;
  }

  &.is-unstarred {
    .ComboInput-option-favorite-icon {
      --IconButton-name: 'star_border';

      &::before {
        --Icon-fill: 'FILL' 0;
      }
    }

    visibility: hidden;
  }

  &:focus-visible {
    z-index: 11;
  }
}

.ComboInput-option.nested[aria-expanded='true'] .ComboInput-option-arrow-icon {
  transform: rotate(180deg);
}

.ComboInput-list.is-expanded
  .ComboInput-option.is-active
  .ComboInput-option-favorite.is-unstarred {
  visibility: visible;
}

.ComboInput-option > a[data-create='true']::before {
  content: '';
  height: 100%;
  left: 0;
  position: absolute;
  top: 0;
  width: 100%;
}

.ComboInput-option-iframe {
  pointer-events: none;

  .ComboInput-label & {
    display: inline-block;
  }
}

.ComboInput {
  .ComboInput-label,
  .ComboInput-selected {
    width: 100%;
  }

  .ComboInput-selected {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

.ComboInput[aria-expanded='true'] {
  background: var(--Input-focusBackground);

  &::before {
    border-bottom: solid 2px var(--Input-borderColor);
    border-color: var(--Input-focusColor);
    bottom: 0;
    content: '';
    left: 0;
    position: absolute;
    right: 0;
    top: 0;
  }

  .ComboInput-icon::after {
    color: var(--Input-focusColor);
    transform: rotate(-180deg);
  }

  input[type].ComboInput-filter {
    display: block;
  }

  .ComboInput-label {
    display: none;
  }
}

.ComboInput-list.is-expanded {
  .Dropdown.is-open;

  cursor: pointer;
}

.ComboInput-list:not(.is-expanded) {
  z-index: -1;
}

.ComboInput-placeholder-option {
  display: none;
}

.ContentSelector-select + .ComboInput {
  max-width: calc(100% - var(--gap-s) * 6 - var(--Icon-size) * 3);
  width: 50%;
}

.DashboardWidget-filters {
  .ComboInput {
    --ComboInput-listPadding: calc(var(--gap-l) / 2);

    min-height: calc(var(--ComboInput-listPadding) * 2 + var(--Text-height));
    width: auto;

    &::before {
      display: none;
    }

    .ComboInput-icon::after {
      bottom: calc(
        var(--ComboInput-listPadding) + (var(--Text-height) - var(--Icon-size)) /
          2
      );
      right: var(--ComboInput-listPadding);
    }

    &:hover::before,
    &:focus::before {
      display: block;
    }

    &:focus-visible {
      box-shadow: none;
      outline: var(--color-dominant5) auto thin;
    }

    &,
    &:focus {
      padding: var(--ComboInput-listPadding);
      padding-right: calc(
        var(--gap-xs) + var(--Icon-size) + var(--ComboInput-listPadding)
      );
    }

    &:hover,
    &:focus {
      background: var(--color-gray2);
    }
  }
}

.Pagination .ComboInput {
  &::before {
    display: none;
  }
}

// Table rows are bordered, so ComboInput borders are unnecessary in this context.
th > .ComboInput,
td > .ComboInput {
  &::before {
    display: none;
  }
}

// Styling for site access widget dropdowns
.ComboInput-option[data-select-option] {
  border-bottom: 1px solid var(--color-gray3);
  padding-left: var(--gap-m);
}

.ComboInput-selectOption {
  .IconButton;
  .Icon.is-s;

  --IconButton-name: 'check_box_outline_blank';

  position: absolute;
  right: var(--gap-m);
  top: 0;

  &.is-checked {
    --IconButton-name: 'check_box';
  }

  &:hover,
  &:focus {
    &::after {
      opacity: 0;
    }

    &::before {
      color: inherit;
    }
  }
}
