@import '../variable';

@mixin box-sizing() {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}

@mixin wrap-text() {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.select {
  font-family: Circe;
  font-size: 14px;
  font-weight: normal;
  font-style: normal;
  font-stretch: normal;
  line-height: normal;
  letter-spacing: normal;
  color: $color-main-black;
  position: relative;
  display: block;
  @include box-sizing;

  div,
  input,
  span {
    @include box-sizing;
  }

  [hidden] {
    display: none;
  }

  &-placeholder {
    color: $color-additional-grey-text;
  }

  & .select-has-value {
    .select-placeholder {
      display: none;
    }
  }

  &.select-searchable {
    .select-container .select-value-container .select-input {
      opacity: 1;
    }
  }

  &.select-opened .select-container {
    z-index: 1001;
  }

  &.select-disabled {
    .select-container {
      cursor: not-allowed;

      .select-value-container {
        .select-placeholder,
        .select-value {
          background: $color-spare-grey-text;
          border: none;
          user-select: none;
          cursor: not-allowed;
        }
      }
    }

    .select-arrow-wrapper {
      cursor: not-allowed;
    }
  }

  &.select-filtered {
    .select-placeholder {
      display: none;
    }
  }

  .select-container {
    align-items: center;
    background-color: $color-main-white;
    border: 1px solid #ccc;
    border-radius: $border-radius;
    color: $color-main-black;
    cursor: default;
    display: flex;
    min-height: 38px;
    outline: none;
    overflow: hidden;
    position: relative;
    width: 100%;

    &:hover {
      box-shadow: 0 1px 0 rgba(0, 0, 0, 0.06);
    }

    .select-value-container {
      display: flex;
      flex: 1;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      align-items: center;
      padding-left: 10px;
      flex-wrap: wrap;

      .select-input {
        opacity: 0;

        > input {
          box-sizing: content-box;
          background: none transparent;
          border: 0 none;
          box-shadow: none;
          outline: none;
          padding: 0;
          cursor: default;
          width: 100%;

          &::-ms-clear {
            display: none;
          }

          &[readonly] {
            user-select: none;
            width: 0;
            padding: 0;
          }
        }
      }
    }
  }

  &.select-single {
    &.select-filtered {
      .select-container .select-value-container .select-value {
        visibility: hidden;
      }
    }

    & .select-has-value {
      height: 36px;
      .select-placeholder {
        display: none;
      }
    }

    .select-container {
      height: 36px;

      .select-value-container {
        @include wrap-text;

        .select-value {
          @include wrap-text;

          .select-value-icon {
            display: none;
          }
        }

        .select-input {
          position: absolute;
          left: 0;
          width: 100%;
          top: 5px;
          padding-left: 10px;
          padding-right: 50px;
        }
      }
    }
  }

  &.select-multiple {
    &.select-disabled {
      > .select-container .select-value-container .select-value {
        .select-value-icon {
          display: none;
        }
      }
    }

    .select-container {
      .select-value-container {
        align-items: baseline;
        flex-direction: column;
        flex-wrap: wrap;
        max-width: 100%;

        .select-placeholder {
          position: absolute;
          top: 28%;
        }

        .select-value {
          font-size: 0.9em;
          margin: 5px 5px 5px 0;
          background-color: #ebf5ff;
          border-radius: 2px;
          max-width: calc(100% - 7px);
          white-space: normal;

          &.select-value-disabled {
            .select-value-icon {
              display: none;
            }
          }

          .select-value-icon {
            cursor: pointer;
            display: inline;
            padding: 1px 5px;
            vertical-align: middle;

            &.left {
              border-right: 1px solid #b8dbff;
            }
          }

          .select-value-label {
            max-width: 100%;
            display: inline;
            padding: 1px 5px;
            vertical-align: middle;
          }
        }

        .select-input {
          flex: 1;
          z-index: 2;
        }

        .select-placeholder {
          z-index: 1;
        }
      }
    }
  }

  .select-clear-wrapper {
    cursor: pointer;
    position: relative;
    width: 17px;
    user-select: none;

    .select-clear {
      display: inline-block;
      font-size: 18px;
      line-height: 1;
      pointer-events: none;
    }
  }

  .select-spinner-loader {
    border-radius: 50%;
    width: 17px;
    height: 17px;
    margin-right: 5px;
    font-size: 10px;
    position: relative;
    text-indent: -9999em;
    border-top: 2px solid rgba(66, 66, 66, 0.2);
    border-right: 2px solid rgba(66, 66, 66, 0.2);
    border-bottom: 2px solid rgba(66, 66, 66, 0.2);
    border-left: 2px solid #424242;
    transform: translateZ(0);
    animation: load8 0.8s infinite linear;

    &:after {
      border-radius: 50%;
      width: 17px;
      height: 17px;
    }

    @-webkit-keyframes load8 {
      0% {
        -webkit-transform: rotate(0deg);
        transform: rotate(0deg);
      }
      100% {
        -webkit-transform: rotate(360deg);
        transform: rotate(360deg);
      }
    }
    @keyframes load8 {
      0% {
        -webkit-transform: rotate(0deg);
        transform: rotate(0deg);
      }
      100% {
        -webkit-transform: rotate(360deg);
        transform: rotate(360deg);
      }
    }
  }

  .select-arrow-wrapper {
    color: $color-main-grey-text;
    cursor: pointer;
    padding-right: 5px;
    position: relative;
    text-align: center;
    user-select: none;
    width: 25px;

    .select-arrow {
      border-color: #999 transparent transparent;
      border-style: solid;
      border-width: 5px 5px 2.5px;
      cursor: pointer;
      pointer-events: none;
      display: inline-block;
      height: 0;
      width: 0;
      position: relative;
    }
  }
}

.select-dropdown-panel {
  background-color: $color-main-white;
  border: 1px solid #ccc;
  box-sizing: border-box;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.06);
  left: 0;
  position: absolute;
  opacity: 0;
  width: 100%;
  z-index: 1050;
  -webkit-overflow-scrolling: touch;

  &.select-bottom {
    top: 100%;
    border-top-color: #e6e6e6;
    margin-top: -4px;
  }

  .select-dropdown-panel-items {
    display: block;
    height: auto;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
    max-height: 240px;
    overflow-y: auto;

    .select-optgroup {
      @include wrap-text();
      user-select: none;
      padding: 8px 10px;
      font-weight: 500;
      color: rgba(0, 0, 0, 0.54);
      cursor: default;

      & ~ .select-option-child {
        padding-left: 22px;
      }
    }

    .select-option {
      background-color: $color-main-white;
      color: $color-main-black;
      box-sizing: border-box;
      cursor: pointer;
      display: block;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: normal;
      padding: 1px 10px;

      .select-option-label:empty:before {
        content: '\200b';
      }

      .highlighted {
        font-weight: bold;
        text-decoration: underline;
      }

      &.disabled {
        cursor: default;
      }
    }

    .select-option-marked {
      background-color: #f5faff;
      color: $color-main-black;
    }
  }

  .scroll-host {
    overflow: hidden;
    overflow-y: auto;
    position: relative;
    display: block;
    -webkit-overflow-scrolling: touch;
  }

  .scrollable-content {
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    position: absolute;
  }

  .total-padding {
    width: 1px;
    opacity: 0;
  }
}

.blackOutline {
  .select-container {
    border-color: $color-main-black;
  }
}

.searchForm {
  .select {
    .select-container {
      background: $color-spare-grey-text;
      border: none;
      min-height: 35px;
    }

    .select-arrow-wrapper {
      .select-arrow {
        border: none;
        color: #495057;
        margin-right: 16px;
      }
    }

    .select-placeholder {
      color: $color-main-black;
    }

    .select-arrow:before {
      font: 14px/1 FontAwesome;
      font-size: inherit;
      text-rendering: auto;
      content: '\f107';
    }
  }
}

.grey-input {
  .select {
    .select-container {
      background: $color-spare-grey-text;
      border: none;
    }
  }
}
