@use "sass:math";

// base styles
$selectize: "selectize" !default;
$select-font-family: inherit !default;
$select-font-smoothing: inherit !default;
$select-font-size: 13px !default;
$select-line-height: 18px !default;

$select-color-rgb: 0,0,0 !default;
$select-color-text: RGBA($select-color-rgb, 0.83) !default;
$select-color-border: #d0d0d0 !default;
$select-color-highlight: rgba(125, 168, 208, 0.2) !default;
$select-color-input: #fff !default;
$select-color-input-full: $select-color-input !default;
$select-color-disabled: #fafafa !default;
$select-color-item: #f2f2f2 !default;
$select-color-item-text: $select-color-text !default;
$select-color-item-border: #d0d0d0 !default;
$select-color-item-active: #e8e8e8 !default;
$select-color-item-active-text: $select-color-text !default;
$select-color-item-active-border: #cacaca !default;
$select-color-dropdown: #fff !default;
$select-color-dropdown-border: $select-color-border !default;
$select-color-dropdown-border-top: #f0f0f0 !default;
$select-color-dropdown-item-active: #f5fafd !default;
$select-color-dropdown-item-active-text: #495c68 !default;
$select-color-dropdown-item-create-text: RGBA($select-color-rgb, 0.5) !default;
$select-color-dropdown-item-create-active-text: $select-color-dropdown-item-active-text !default;
$select-color-optgroup: $select-color-dropdown !default;
$select-color-optgroup-text: $select-color-text !default;
$select-lighten-disabled-item: 30% !default;
$select-lighten-disabled-item-text: 30% !default;
$select-lighten-disabled-item-border: 30% !default;
$select-opacity-disabled: 0.5 !default;

$select-shadow-input: inset 0 1px 1px rgba(0, 0, 0, 0.1) !default;
$select-shadow-input-focus: inset 0 1px 2px rgba(0, 0, 0, 0.15) !default;
$select-border: 1px solid $select-color-border !default;
$select-dropdown-border: 1px solid $select-color-dropdown-border !default;
$select-border-radius: 3px !default;

$select-width-item-border: 0px !default;
$select-max-height-dropdown: 200px !default;

$select-padding-x: 8px !default;
$select-padding-y: 8px !default;
$select-padding-item-x: 6px !default;
$select-padding-item-y: 2px !default;
$select-padding-dropdown-item-x: $select-padding-x !default;
$select-padding-dropdown-item-y: 5px !default;
$select-margin-item-x: 3px !default;
$select-margin-item-y: 3px !default;

$select-arrow-size: 5px !default;
$select-arrow-color: #808080 !default;
$select-arrow-offset: 15px !default;

$select-caret-margin: 0 0px !default;
$select-caret-margin-rtl: 0 4px 0 -2px !default;

$select-spinner-size: 30px;
$select-spinner-border-size: 5px;
$select-spinner-border-color: $select-color-border;

@mixin selectize-vertical-gradient($color-top, $color-bottom) {
  background-color: mix($color-top, $color-bottom, 60%);
  background-image: linear-gradient(to bottom, $color-top, $color-bottom);
  background-repeat: repeat-x;
}

@import "plugins/drag_drop.scss";
@import "plugins/dropdown_header.scss";
@import "plugins/optgroup_columns.scss";
@import "plugins/remove_button.scss";
@import "plugins/clear_button.scss";
@import "plugins/auto_position.scss";

.#{$selectize}-control {
  position: relative;
}

.#{$selectize}-dropdown,
.#{$selectize}-input,
.#{$selectize}-input input {
  color: $select-color-text;
  font-family: $select-font-family;
  font-size: $select-font-size;
  line-height: $select-line-height;
  font-smoothing: $select-font-smoothing;
}

.#{$selectize}-input,
.#{$selectize}-control.single .#{$selectize}-input.input-active {
  background: $select-color-input;
  cursor: text;
  display: inline-block;
}

.#{$selectize}-input {
  border: $select-border;
  padding: $select-padding-y $select-padding-x;
  display: inline-block;
  width: 100%;
  // overflow: hidden;
  position: relative;
  z-index: 1;
  box-sizing: border-box;
  box-shadow: $select-shadow-input;
  border-radius: $select-border-radius;

  .#{$selectize}-control.multi &.has-items {
    $padding-x: $select-padding-x;
    $padding-top: calc(
      #{$select-padding-y} - #{$select-padding-item-y} - #{$select-width-item-border}
    );
    $padding-bottom: calc(
      #{$select-padding-y} - #{$select-padding-item-y} - #{$select-margin-item-y} -
        #{$select-width-item-border}
    );
    padding: $padding-top $padding-x $padding-bottom;
  }

  &.full {
    background-color: $select-color-input-full;
  }
  &.disabled,
  &.disabled * {
    cursor: default !important;
  }
  &.focus {
    box-shadow: $select-shadow-input-focus;
  }
  &.dropdown-active {
    border-radius: $select-border-radius $select-border-radius 0 0;
  }

  > * {
    vertical-align: baseline;
    display: inline-block;
    zoom: 1;
  }
  .#{$selectize}-control.multi & > div {
    cursor: pointer;
    margin: 0 $select-margin-item-x $select-margin-item-y 0;
    padding: $select-padding-item-y $select-padding-item-x;
    background: $select-color-item;
    color: $select-color-item-text;
    border: $select-width-item-border solid $select-color-item-border;

    &.active {
      background: $select-color-item-active;
      color: $select-color-item-active-text;
      border: $select-width-item-border solid $select-color-item-active-border;
    }
  }
  .#{$selectize}-control.multi &.disabled > div {
    &,
    &.active {
      color: lighten(gray, $select-lighten-disabled-item-text);
      background: lighten(gray, $select-lighten-disabled-item);
      border: $select-width-item-border solid
        lighten(gray, $select-lighten-disabled-item-border);
    }
  }
  > input {
    &::-ms-clear {
      display: none;
    }
    display: inline-block !important;
    padding: 0 !important;
    min-height: 0 !important;
    max-height: none !important;
    max-width: 100% !important;
    margin: 0 !important;
    text-indent: 0 !important;
    border: 0 none !important;
    background: none !important;
    line-height: inherit !important;
    user-select: auto !important;
    box-shadow: none !important;
    &:focus {
      outline: none !important;
    }

    &[placeholder] {
      box-sizing: initial;
    }
  }
  &.has-items > input {
    margin: $select-caret-margin !important;
  }
}

.#{$selectize}-input::after {
  content: " ";
  display: block;
  clear: left;
}

.#{$selectize}-input.dropdown-active::before {
  content: " ";
  display: block;
  position: absolute;
  background: $select-color-dropdown-border-top;
  height: 1px;
  bottom: 0;
  left: 0;
  right: 0;
}

.#{$selectize}-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  width: 100%;
  z-index: 10;

  border: $select-dropdown-border;
  background: $select-color-dropdown;
  margin: -1px 0 0 0;
  border-top: 0 none;
  box-sizing: border-box;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  border-radius: 0 0 $select-border-radius $select-border-radius;

  [data-selectable] {
    cursor: pointer;
    overflow: hidden;
    .highlight {
      background: $select-color-highlight;
      border-radius: 1px;
    }
  }
  .option,
  .optgroup-header,
  .no-results,
  .create {
    padding: $select-padding-dropdown-item-y $select-padding-dropdown-item-x;
  }
  .option,
  [data-disabled],
  [data-disabled] [data-selectable].option {
    cursor: inherit;
    opacity: 0.5;
  }
  [data-selectable].option {
    opacity: 1;
    cursor: pointer;
  }
  .optgroup:first-child .optgroup-header {
    border-top: 0 none;
  }
  .optgroup-header {
    color: $select-color-optgroup-text;
    background: $select-color-optgroup;
    cursor: default;
  }
  .active {
    background-color: $select-color-item-active;
    color: $select-color-item-active-text;
    &.create {
      color: $select-color-dropdown-item-create-active-text;
    }
  }

  .selected {
    background-color: $select-color-item-active;
    color: $select-color-item-active-text;
  }
  .create {
    color: $select-color-dropdown-item-create-text;
  }

  .active:not(.selected) {
    background: $select-color-dropdown-item-active;
    color: $select-color-dropdown-item-active-text;
  }
}

.#{$selectize}-dropdown-content {
  overflow-y: auto;
  overflow-x: hidden;
  max-height: $select-max-height-dropdown;
  overflow-scrolling: touch;
}

.#{$selectize}-dropdown-emptyoptionlabel {
	text-align: center;
}

.#{$selectize}-dropdown .spinner {
  display: inline-block;
  width: $select-spinner-size;
  height: $select-spinner-size;
  margin: $select-padding-dropdown-item-y $select-padding-dropdown-item-x;

  &:after {
    content: " ";
    display: block;
    width: $select-spinner-size * 0.8;
    height: $select-spinner-size * 0.8;
    margin: $select-spinner-size * 0.1;
    border-radius: 50%;
    border: $select-spinner-border-size solid $select-spinner-border-color;
    border-color: $select-spinner-border-color transparent
      $select-spinner-border-color transparent;
    animation: lds-dual-ring 1.2s linear infinite;
  }
  @keyframes lds-dual-ring {
    0% {
      transform: rotate(0deg);
    }
    100% {
      transform: rotate(360deg);
    }
  }
}

.#{$selectize}-control.single .#{$selectize}-input {
  &,
  input {
    cursor: pointer;
  }
  &.input-active,
  &.input-active input:not(:read-only) {
    cursor: text;
  }

  &:not(.no-arrow):after {
    content: " ";
    display: block;
    position: absolute;
    top: 50%;
    right: $select-arrow-offset;
    margin-top: round(divide(-1 * $select-arrow-size, 2));
    width: 0;
    height: 0;
    border-style: solid;
    border-width: $select-arrow-size $select-arrow-size 0 $select-arrow-size;
    border-color: $select-arrow-color transparent transparent transparent;
  }
  &:not(.no-arrow).dropdown-active:after {
    margin-top: $select-arrow-size * -0.8;
    border-width: 0 $select-arrow-size $select-arrow-size $select-arrow-size;
    border-color: transparent transparent $select-arrow-color transparent;
  }
}

.#{$selectize}-control.rtl {
  text-align: right;
  &.single .#{$selectize}-input:after {
    left: $select-arrow-offset;
    right: auto;
  }
  .#{$selectize}-input > input {
    margin: $select-caret-margin-rtl !important;
  }
}

.#{$selectize}-control .#{$selectize}-input.disabled {
  opacity: $select-opacity-disabled;
  background-color: $select-color-disabled;
}
