@use 'sass:math';

@import '../core/style/menu-common';
@import '../core/style/list-common';
@import '../core/style/variables';
@import '../core/style/vendor-prefixes';
$oui-select-arrow-size: 5px !default;
$oui-select-arrow-margin: 4px !default;
$oui-select-panel-max-height: 256px !default;
$oui-select-item-height: 40px !default;
$oui-select-placeholder-arrow-space: 2 *
  ($oui-select-arrow-size + $oui-select-arrow-margin);
$gray-color: #eee;

%placeholder {
  font-size: 14px;
}

.oui-error {
  @extend %placeholder;
}
.oui-select {
  display: inline-block;
  width: 100%;
  outline: none;
  div {
    margin: 0;
    vertical-align: middle;
  }
  .oui-select-value {
    @extend %placeholder;
    line-height: 19px;
    padding: 2px 8px 2px 0;
  }
}

.oui-select-trigger {
  display: inline-table;
  cursor: pointer;
  position: relative;
  box-sizing: border-box;

  .oui-select-disabled & {
    @include user-select(none);
    cursor: default;
  }
}

.oui-select-value {
  display: table-cell;
  max-width: 0;
  width: 100%;
}

.oui-select-value-text {
  display: inline-block;
  width: 100%;
  @include oui-truncate-line();
  span img {
    max-width: 20px;
    max-height: 20px;
  }
}

.oui-select-arrow-wrapper {
  display: inline-block;
  vertical-align: middle;

  // When used in a box appearance form-field the arrow should be shifted up 50%.
  .oui-form-field-appearance-fill & {
    transform: translateY(-50%);
  }

  // When used in a outline form-field the arrow should be shifted up 25%.
  .oui-form-field-appearance-outline & {
    transform: translateY(-25%);
  }

  // Animate the arrow position, but only when the transitioning to empty (animate the arrow down)
  // This is in line with the oui-form-field label animation
  .oui-form-field-appearance-standard .oui-select.oui-select-empty & {
    transition: transform $swift-ease-out-duration
      $swift-ease-out-timing-function;
  }

  ._oui-animation-noopable.oui-form-field-appearance-standard
    .oui-select.oui-select-empty
    & {
    transition: none;
  }
}

.oui-select-arrow {
  width: 12px;
}

.oui-focused {
  .oui-select-arrow {
    transform: rotate(180deg);
  }
  .oui-select.oui-input:not(.oui-select-list-options-opened) {
    .oui-select-arrow {
      transform: rotate(0deg);
    }
  }
}

.oui-select-large {
  max-height: 392px !important;
}

// Override optgroup and option to scale based on font-size of the trigger.
.oui-select-panel {
  color: #333;
  -webkit-overflow-scrolling: touch; // for momentum scroll on mobile
  overflow-x: hidden;
  padding-bottom: 0;
  position: relative;
  border: 1px solid #c8c8c8;
  background-color: #ffffff;
  max-height: 272px;
  margin: 6px 0 0 -10px;
  box-sizing: border-box;
  min-width: 100px;
  font-family: 'Open Sans', Helvetica, Arial, sans-serif;
  box-shadow: 0 2px 4px -1px rgba(0, 0, 0, 0.2), 0 4px 5px 0 rgba(0, 0, 0, 0.14),
    0 1px 10px 0 rgba(0, 0, 0, 0.12);
  border-top: 0;
  .oui-select-options {
    -webkit-overflow-scrolling: touch; // for momentum scroll on mobile
    overflow-x: hidden;
    height: 100%;
    padding-top: 10px;
    box-sizing: border-box;
  }
  &.oui-select-input-outer {
    .oui-select-options {
      padding-top: 0px;
    }
  }
  &.action-item,
  &.single-action-item {
    padding-bottom: 56px;
  }
  .oui-option {
    line-height: $oui-select-item-height;
    height: $oui-select-item-height;
    padding: 0 10px;
    font-size: 14px;
    &.oui-active {
      background: $gray-color;
      color: #333;
    }
    &.oui-option-disabled {
      color: rgba(0, 0, 0, 0.38);
    }
    &:last-child {
      margin-bottom: 10px;
    }
    oui-checkbox {
      width: 100%;
      label {
        width: 100%;
        display: block;
      }
    }
  }
  .oui-option-multiple.oui-selected,
  .oui-option-multiple.oui-active {
    background: none;
  }
  .oui-optgroup-label {
    font-weight: 700;
    display: block;
    padding: 0 10px;
    font-size: 14px;
    line-height: $oui-select-item-height;
  }
}

.oui-form-field-type-oui-select {
  &:not(.oui-form-field-disabled) .oui-form-field-flex {
    cursor: pointer;
  }

  .oui-form-field-label {
    width: calc(100% - #{$oui-select-placeholder-arrow-space});
  }
}

.oui-select-placeholder {
  // Delay the transition until the label has animated about a third of the way through, in
  // order to prevent the placeholder from overlapping for a split second.
  @include oui-truncate-line();
  display: inline-block;
  width: 100%;
  transition: color $swift-ease-out-duration
    math.div($swift-ease-out-duration, 3) $swift-ease-out-timing-function;
  color: #666;
  ._oui-animation-noopable & {
    transition: none;
  }

  .oui-form-field-hide-placeholder & {
    color: transparent;

    // Overwrite browser specific CSS properties that can overwrite the `color` property.
    // Some developers seem to use this approach to easily overwrite the placeholder / label color.
    -webkit-text-fill-color: transparent;

    // Remove the transition to prevent the placeholder
    // from overlapping when the label comes back down.
    transition: none;
    // Prevents the '...' from showing on the parent element.
    display: block;
  }
}
/*-- search dropdown --*/

.oui-select-input-outer {
  box-sizing: border-box;
}

/*-- search dropdown --*/

/*-- search ddropdown --*/
.ui-select-overlay-container {
  position: absolute;
}
.oui-select-has-a-panel
  .oui-option.oui-selected:not(.oui-option-multiple):not(.oui-option-disabled) {
  background: rgba(0, 0, 0, 0.12);
  color: #3f51b5;
  font-weight: 500;
}
.oui-select-has-a-panel .oui-option:hover:not(.oui-option-disabled) {
  background: rgba(0, 0, 0, 0.04);
}

/*-- search ddropdown --*/

/*-- search dropdown underline --*/
.oui-form-field-appearance-underline {
  .oui-select-trigger {
    margin-left: 9px;
    .oui-select-value {
      overflow: visible;
      .oui-select-placeholder,
      .oui-select-value-text {
        width: 100%;
        @include oui-truncate-line();
        margin-left: -9px;
        display: block;
        height: 19px;
      }
    }
  }
  .oui-select.oui-input {
    border: 1px solid transparent;
    padding-left: 0;
    padding-right: 0;
    border-bottom: 1px solid #c8c8c8;
    > div {
      padding-right: 9px;
    }
    &:after {
      content: '';
      height: 1px;
      width: 100%;
      background: #c8c8c8;
      position: absolute;
      left: 0;
      bottom: 0;
    }
  }
}

.oui-form-field.oui-form-field-appearance-underline .oui-select.oui-input {
  &.oui-select-disabled {
    border: 1px solid transparent;
    border-bottom: 1px solid #e4e4e4;
    background: transparent;
    &:after {
      background: #e4e4e4;
    }
  }
}
.oui-form-field .oui-select.oui-input {
  &.oui-select-disabled {
    border: 1px solid #e4e4e4;
    background-color: #f9f9f9;
    color: #9b9b9b;
    cursor: default;
    .oui-select-arrow svg path {
      fill: #c8c8c8;
    }
  }
  &.oui-form-field-appearance-underline {
    .oui-select.oui-input {
      transition: border 0.5s, padding 0.5s;
    }
  }
}

/*-- search dropdown underline --*/

.oui-option:focus:not(.oui-option-disabled),
.oui-option:hover:not(.oui-option-disabled),
.oui-option.oui-selected:not(.oui-option-multiple):not(.oui-option-disabled) {
  background: $gray-color;
}

.select-overlay-top.oui-select-panel {
  margin-bottom: 9px;
  border-top: 1px solid #c8c8c8;
}

.noResults {
  color: #333333;
  font-size: 14px;
  line-height: 22px;
  padding: 0 10px;
  margin: 17px 0 21px;
  word-break: break-all;
}

oui-select-search {
  height: 60px;
  display: block;
}
.oui-select-disabled .oui-select-placeholder {
  color: #9b9b9b;
}
.oui-select-action-wrapper {
  height: 56px;
  box-sizing: border-box;
  background: #fff;
  display: block;
  width: 100%;
  position: absolute;
  bottom: 0px;
  left: 0px;
}

.oui-select-action-items {
  position: absolute;
  border-top: 1px solid #ddd;
  height: 100%;
  padding: 10px;
  background: #fff;
  bottom: 1px;
  z-index: 100;
  box-sizing: border-box;
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  &.single-action-items {
    padding: 10px 0px !important;
    button {
      width: 100%;
      padding: 0px 10px !important;
      text-align: left;
      font-size: 14px;
      color: #333333 !important;
      border-radius: 0px;
      line-height: 40px;
      &:hover,
      &:focus {
        background-color: #eeeeee;
        box-shadow: none !important;
        text-decoration: none !important;
      }
    }
  }
}
