.ts-wrapper.single,
.ts-wrapper.multi {
  min-height: 40px;

  &.input-active {
    .ts-control {
      border-color: $orient;
      background-color: $lighter-grey;

      input {
        &::placeholder {
          color: $medium-light-grey;
        }
      }
    }
  }

  .ts-control {
    box-shadow: none;
    border: $border-input;
    border-radius: $border-radius;
    background-image: none;

    input {
      font-size: $body-font-size;
      height: auto;

      &::placeholder {
        color: $near-black;
      }
    }

    .item {
      margin-top: 2px; // Ensure it lines up with the input. I have no idea why it's necessary.
    }
  }

  .ts-dropdown {
    // Unstyled, we style the dropdown-content instead
    margin: 0;
    background: none;
    border: none;
    box-shadow: none;

    min-width: 10em; // Ensure content doesn't wrap too much
    // We could consider always stretching to fit with width: max-content;
  }

  .ts-dropdown-content {
    margin-top: 4px;
    color: $near-black;
    background-color: $color-body-bg;
    @include border-radius($border-radius);
    box-shadow: $shadow-dropdown;

    max-height: 21em; // Show up to 8 items without scrolling

    .option {
      padding: 8px;
      border-left: 3px solid transparent;
      line-height: 20px;

      &.selected,
      &.active {
        border-left: 3px solid $orient;
        background-color: $lighter-grey;
        color: $near-black;
      }
    }
  }
}

// Style the select tags filter
.ts-wrapper {
  &.multi {
    &.has-items {
      .ts-control {
        [data-value] {
          background-image: none;
          background-color: $teal;
          box-shadow: none;
          border: none;
        }
      }
    }
  }

  &.plugin-remove_button:not(.rtl) {
    .item {
      .remove {
        border-left: 1px solid darken($teal, 5);
        margin-left: 6px;
      }
    }
  }
}

.plugin-dropdown_input {
  .ts-dropdown {
    // Cover up the control with the input
    top: 0;
    z-index: $ts-dropdown-z-index;
  }

  .dropdown-input-wrap::after {
    position: absolute;
    content: "\f077"; // chevron-up
    font-family: FontAwesome;
    border: none;
    top: 0.7em;
    right: 0.7em;
    font-size: 13px;
  }

  .dropdown-input {
    background-color: $color-body-bg;
    border: 1px solid $lighter-grey;
    box-shadow: none;
    padding: 0.6em 0.75em;

    &:focus {
      border: 1px solid $orient;
    }
  }
}

// For the "single" tom_select, be as close as possible to native select boxes
// without too many options
.ts-wrapper.single {
  max-height: 40px;
  max-width: 100%;

  .ts-control {
    padding: 0.5em 0.75em;
    padding-right: 1em !important; // ts has a clever variable-based rule here, but it doesn't seem to work right.
    overflow: hidden;

    // Icon: Override TS icon with icon-chevron-down
    &::after {
      content: "\f078";
      font-family: FontAwesome;
      border: none;
      top: 1em;
    }
    &:not(.rtl)::after {
      right: 1.9em;
    }

    .item {
      margin-right: 1em;
      // Hide overflow with an ellipsis if a width has been set
      overflow: hidden;
      text-overflow: ellipsis;
      text-wrap: nowrap;
    }
  }

  &.dropdown-active .ts-control {
    &::after {
      content: "\f077"; // chevron-up
    }
  }
}

// 'no-input' mode, like a native select (hide text input).
.ts-wrapper.single.no-input {
  .ts-control input {
    // Hide input, while keeping it focusable for keyboard events.
    height: 0;
  }

  .ts-dropdown {
    position: absolute;
    top: 0; // we don't need to see the currently selected option, because it's visible in the dropdown
  }

  .ts-dropdown-content {
    margin-top: 0;
  }
}

// Appears just like other text on the page.
// See table.products tr:hover for example of revealing them
.naked_inputs .ts-wrapper {
  height: auto;
  min-height: 0;

  .ts-control {
    padding: ($vpadding-txt - 1px) ($hpadding-txt - 1px); // Minus 1px for border

    height: auto;
    min-height: 0;
    font-size: inherit;
    font-weight: inherit;
    border-color: transparent;
    line-height: 22px;
    background-color: $color-body-bg;

    &::after {
      display: none; // hide until hover
      top: 0.8em;
      right: 1em;
      font-size: 0.75em;
    }

    .item {
      margin-top: 0;
      margin-right: 0; // full width until hover
    }

    &:hover {
      &::after {
        display: block;
      }
      .item {
        margin-right: 1em;
      }
    }
  }
}

// Errors
.field_with_errors .ts-wrapper {
  .ts-control {
    border-color: $color-error;
  }
}

// Display as "changed" if sibling select is marked as changed.
select.changed + .ts-wrapper {
  &.single,
  &.multi {
    .ts-control {
      border-color: $color-txt-changed-brd;
    }
  }
}
