// JS Select

$vl-select-box-shadow: rgba($vl-border-color, 0.6);

// Without javascript
[data-vl-select] {
  .no-js & {
    @include select-default;
  }
}

.js-vl-select {
  position: relative;

  &.is-disabled {
    border-color: $vl-disabled-color;
    background-color: $vl-disabled-bg-color !important; // sass-lint:disable-line no-important
    outline: 0;

    .vl-select__item {
      color: $vl-disabled-color;
      cursor: default;
    }
  }

  &.is-focused {
    outline: none;
    border-color: $vl-outline-color;
    box-shadow: 0 0 0 0.2rem $vl-outline-color;
  }

  .vl-input-field {
    @include respond-to(small) {
      font-size: $vl-base-mobile-font-size;
    }
  }

  &[data-type*="select-one"] {
    background-color: $vl-page-bg;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3e%3cpath d='M0.42,9.77a3.27,3.27,0,0,1,.91-2.21,3.12,3.12,0,0,1,4.41,0L16,17.82,26.25,7.56A3.12,3.12,0,0,1,30.67,12L18.2,24.44a3.12,3.12,0,0,1-4.41,0L1.33,12A3.17,3.17,0,0,1,.42,9.77'/%3e%3ctext y='90'%3e' %26apos; %23 %25 %26amp; %c2%bf %f0%9f%94%a3%3c/text%3e%3c/svg%3e"); // sass-lint:disable-line max-line-length
    background-repeat: no-repeat;
    background-position: calc(100% - 1.5rem) 50%;
    background-size: 11px 11px; //should be in px rem doesn't work in ie 11
    cursor: pointer;

    .vl-input-field {
      display: block;
      padding: 0;
      color: $vl-text-color;
      overflow: hidden;
      white-space: nowrap;

      &:focus {
        outline: 2px solid $vl-amber;
      }
    }

    .vl-select__list--dropdown {
      .vl-input-field {
        width: calc(100% - 20px);
        margin: 10px;
        padding: 0 1rem;
        border: 1px solid $vl-border-color;
      }
    }

    .vl-select__item {
      &--selectable {
        display: flex;
        line-height: 33px;

        span {
          width: 100%;
          overflow: hidden;
        }
      }

      &[data-deletable] {
        span {
          width: calc(100% - 3.5rem);
        }
      }
    }

    .vl-select__inner {
      height: 3.5rem;
      line-height: 3.5rem;
    }

    &.is-open {
      &::after {
        transform: translateY(-7.5px);
        border-color: transparent transparent $vl-black;
      }
    }

    &[dir="rtl"] {
      &::after {
        right: auto;
        left: 11.5px;
      }

      .vl-select__button {
        right: auto;
        left: 0;
        margin-right: 0;
        margin-left: 25px;
      }

      .vl-pill__close {
        margin-right: auto;
        margin-left: 0;
      }
    }

    .vl-select__button {
      border: 0;
    }

    .vl-pill__close {
      @include vi;
      @include vi-cross;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      border: 0;
      text-decoration: none;
      margin-left: auto;
      padding-top: 0;
      padding-bottom: 0;

      &::before {
        display: inline-block;
        font-size: 1.1rem;
        text-indent: 0;
        line-height: 1;
      }

      &:hover,
      &:focus,
      &:active {
        color: $vl-action-hover-color;
      }
    }

    &.is-disabled,
    .vl-select__placeholder {
      .vl-pill__close {
        display: none;
      }
    }
  }

  &[data-type*="select-multiple"] {
    background-color: $vl-page-bg;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3e%3cpath d='M0.42,9.77a3.27,3.27,0,0,1,.91-2.21,3.12,3.12,0,0,1,4.41,0L16,17.82,26.25,7.56A3.12,3.12,0,0,1,30.67,12L18.2,24.44a3.12,3.12,0,0,1-4.41,0L1.33,12A3.17,3.17,0,0,1,.42,9.77'/%3e%3ctext y='90'%3e' %26apos; %23 %25 %26amp; %c2%bf %f0%9f%94%a3%3c/text%3e%3c/svg%3e"); // sass-lint:disable-line max-line-length
    background-repeat: no-repeat;
    background-position: calc(100% - 1.5rem) 50%;
    background-size: 11px 11px; //should be in px rem doesn't work in ie 11
    cursor: pointer;
  }

  &[data-type*="select-multiple"],
  &[data-type*="text"] {
    background-color: $vl-page-bg;

    .vl-select__inner {
      cursor: text;
    }

    .vl-select__button {
      @include vi;
      @include vi-cross;

      display: inline-block;
      width: 2.2rem;
      height: 2.3rem;

      margin-left: 0.5rem;
      transform: translateY(-1px);
      border-left: 1px solid $vl-ghost;

      color: $vl-dove-gray;
      text-align: center;
      text-decoration: none;

      &::before {
        padding: 0 0.4rem;
        font-size: 1.1rem;
        text-indent: 0;
      }

      &:hover,
      &:focus {
        opacity: 1;
      }
    }

    .vl-input-field {
      display: inline;
      padding: 0;
      height: 2.4rem;
      line-height: 2.2rem;

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

  &__group {
    padding: 0.3rem 0.5rem 0.3rem 0;
    border-top: 1px solid $vl-ghost;
    text-decoration: none;
  }

  .vl-select__inner {
    display: inline-block;
    width: 100%;
    max-width: 100%;
    padding: 0 4rem 5px 1.5rem;
    border: 1px solid $vl-ghost;
    color: $vl-dove-gray;
    font-family: $vl-base-font;
    font-size: $vl-form-font-size;
    box-shadow: $vl-select-box-shadow;
    overflow: hidden;
    vertical-align: top;

    .is-open & {
      border-bottom: 0;
    }
  }

  .vl-select__list {
    margin: 0;
    padding: 0;
    list-style: none;

    &--single {
      display: inline-block;
      width: 100%;
    }

    [dir="rtl"] &--single {
      padding-right: 5px;
      padding-left: 15px;
    }

    &--multiple {
      display: inline-flex;
      align-content: center;
      max-width: 100%;

      // Pills
      .vl-select__item {
        margin: 0.5rem 0.6rem 0 0;

        &[data-deletable] {
          padding-right: 0;
        }
      }

      [dir="rtl"] &--multiple {
        margin-right: 0;
        margin-left: 3.75px;
      }

      .vl-input-field {
        margin-bottom: 5px;
        padding: 4px 0 4px 2px;
      }
    }
  }

  .vl-select__list--dropdown {
    display: none;
    position: absolute;
    top: 100%;
    width: 100%;
    transform: translateY(-1px);
    border: 1px $vl-ghost solid;
    background-color: $vl-white;
    z-index: 1;

    &.is-active {
      display: block;
    }

    .vl-select__list {
      position: relative;
      max-height: 35vh;
      overflow: auto;
      will-change: scroll-position;

      -webkit-overflow-scrolling: touch; // sass-lint:disable-line no-vendor-prefixes
    }

    .vl-input-field + .vl-select__list {
      border-top: 1px solid $vl-ghost;
    }

    .vl-select__item {
      display: block;
      position: relative;
      width: 100%;
      padding: 0.7rem 0 0.5rem 3.2rem;
      border: 0;
      color: $vl-black;
      font-size: 1.6rem;
      font-weight: normal;
      text-align: left;
      text-decoration: none;
      cursor: pointer;

      [dir="rtl"] & {
        text-align: right;
      }

      &--selectable {
        @include respond-to(medium-up) {
          padding-right: 100px;

          &::after {
            position: absolute;
            top: 50%;
            right: 10px;
            transform: translateY(-50%);
            content: attr("data-select-text");
            opacity: 0;
          }

          [dir="rtl"] & {
            padding-right: 10px;
            padding-left: 100px;
            text-align: right;

            &::after {
              right: auto;
              left: 10px;
            }
          }
        }

        &.is-highlighted {
          position: relative;
          background-color: $vl-athens-gray;

          &::after {
            opacity: 0.5;
          }

          &:hover {
            color: $vl-action-text-color;
            text-decoration: underline;
          }
        }
      }
    }
  }

  &.is-flipped {
    .vl-select__list--dropdown {
      top: auto;
      bottom: 100%;
      transform: translateY(1px);
    }
  }

  .vl-select__item {
    &--selectable {
      cursor: pointer;
    }

    &--disabled {
      cursor: not-allowed;
      opacity: 0.5;
      user-select: none;
    }
  }

  .vl-select__heading {
    margin: 0 0 0 0.6rem;
    padding: 0.3rem 2.6rem;
    color: $vl-alt-text-color;
    font-weight: 400;
  }

  .vl-input-field {
    display: inline-block;
    max-width: 100%;
    border: 0;
    background-color: transparent;
    vertical-align: baseline;

    [dir="rtl"] & {
      padding-right: 2px;
      padding-left: 0;
    }
  }

  .vl-select__placeholder {
    opacity: 0.5;
  }

  .vl-select__group {
    border-top: 1px solid $vl-border-color;
    padding-top: 0.5rem;
    margin-top: 1rem;
    font-size: 16px;

    &:first-of-type {
      border-top: 0;
    }
  }

  .vl-select--error & {
    background-color: $vl-error-secondary-color;
    border: 0.2rem solid $vl-error-color;
    box-shadow: inset 0 0 0 1px $vl-error-color;

    &:focus {
      background-color: $vl-page-bg;
    }
  }

  .vl-select--success & {
    @include form-input-success;

    border-width: 2px;
    border-style: solid;
  }
}
