@import '../helpers/variables';
@import '../helpers/helpers';
@import '../components/loader';

.header {
  &--search-v2 {
    .header-right {
      li {
        padding: 0;

        & + li {
          padding-left: 28px;
        }

        &:last-child {
          padding-right: 14px;
        }
      }
    }
  }

  &--search-active {
    position: initial;

    .search--active {
      &:before {
        content: none;
      }
    }
  }
}

.header-global-search {
  display: none;
  background: $blue-dark;
  width: 100%;
  height: 100%;
  position: absolute;
  left: 0;
  top: 0;
  z-index: 2;

  &__head {
    display: flex;
    width: 100%;
    align-items: center;
    height: 100%;
    justify-content: center;
    padding: 0 15px 0 12px;

    .btn {
      border: 0;

      &--clear {
        display: none;
        height: auto;
        line-height: 0;
        padding: 0 10px;
        margin-right: 7px;

        &:hover,
        &:focus,
        &:not(:disabled):not(.disabled):active {
          background-color: transparent;
          border: 0;
          color: $blue-transparent3;
        }
      }

      &--back {
        margin-right: 12px;
        height: auto;
        width: auto;
        background: transparent;
        color: $white;
        padding: 0;
      }

      &--search {
        display: flex;
        align-items: center;
        justify-content: center;
        background: $blue;
        border-radius: 50px;
        padding: 0 8px;
        width: 32px;
        height: 32px;

        svg.svg-inline--fa {
          color: $white;
          width: .96em;
          height: auto;
        }
      }

      &:hover,
      &:focus {
        opacity: .8;
        transition: .3s all;
      }
    }
  }

  &__form {
    width: 100%;
    max-width: 500px;
    display: flex;
    align-items: center;
    background: $white;
    border-radius: 40px;
    padding-right: 6px;
  }

  &__input {
    background: $white;
    border: 0;
    color: $gray-dark;
    padding: 9px 15px;
    outline: 0;
    height: 40px;
    width: 100%;
    border-radius: 25px;
    font-size: 1rem;
    line-height: 1.4rem;

    &::placeholder {
      color: $warm-grey;
    }
  }
}

.global-search {
  display: none;
  z-index: 101;
  background: $white;
  position: sticky;
  width: 100%;
  top: 0;
  padding: 0;
  min-height: 150px;

  a {
    color: $gray-dark;
    text-decoration: none;

    &:hover,
    &:focus {
      opacity: .8;
      transition: all .3s;
      color: $blue;
    }
  }

  &__suggestions {
    width: 100%;
    max-width: 540px;
    margin: 0 auto;
    padding: 15px;
    list-style-type: none;

    li {
      overflow: hidden;
      text-overflow: ellipsis;
      -webkit-box-orient: vertical;
      display: -webkit-box;
      -webkit-line-clamp: 3;
    }

    li + li {
      margin-top: 10px;
    }
  }

  &__body {
    background: $alice-blue;
    flex-direction: column;
    justify-content: flex-start;
    align-items: flex-start;
    height: 100%;

    &-head {
      display: flex;
      justify-content: space-between;
      text-align: left;
      list-style-type: none;
      padding-left: 0;
      width: 100%;
      margin: 0;

      li {
        flex: 1;
        position: relative;

        &:last-child {
          a span {
            margin-left: 0;
            margin-right: auto;
          }
        }

        a {
          text-decoration: none;
          color: $gray-dark;
          font-size: 1rem;
          display: block;
          font-weight: 500;
          padding: 0;

          &.nav-link--disable {
            pointer-events: none;

            span {
              margin: auto;
              max-width: 510px;
            }
          }

          span {
            display: block;
            width: 100%;
            max-width: 255px;
            margin-left: auto;
            padding: 15px;
          }
        }
      }
    }
  }

  &__result {
    display: flex;
    width: 100%;
    justify-content: center;
    padding: 15px 15px 25px;
    max-width: 540px;
    margin: 0 auto;

    .tab-pane:not(.active) {
      display: none;
    }
  }

  .search-loader {
    background: $white;

    .loader-spinner {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
    }
  }

  &__wrapper {
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: stretch;
  }
}

.search-item {
  list-style-type: none;
  padding-left: 0;
  width: 100%;
  margin-bottom: 0;

  li {
    & + li {
      margin-top: 10px;
    }

    a {
      height: 86px;
      background: $white;
      border-radius: 10px;
      padding: 10px;
      display: flex;
      align-items: flex-start;
    }

    p {
      margin-bottom: 0;
      overflow: hidden;
      text-overflow: ellipsis;
      -webkit-box-orient: vertical;
      display: -webkit-box;
      -webkit-line-clamp: 3;
      font-weight: 500;
      line-height: inherit;
    }
  }

  &__img {
    margin-right: 10px;
    width: 100%;
    height: 100%;
    max-width: 65px;
    display: flex;
    align-items: center;
    justify-content: center;

    img {
      max-height: 65px;
      max-width: 65px;
    }
  }
}

@include media-breakpoint-only(xs) {
  .global-search__body-head li a span {
    padding-top: 12px;
    padding-bottom: 12px;
  }
}

@include media-breakpoint-down(sm) {
  .global-search__body-head {
    background: $white;

    li a {
      background: $gray-bg;
      border-radius: 10px 10px 0 0;

      &.active {
        color: $blue-dark;
        background: $alice-blue;
        opacity: 1;
      }
    }
  }
}

@include media-breakpoint-up(md) {
  .header--search-active {
    position: relative;
  }

  .header-global-search {
    display: block;
    position: initial;
    background: transparent;
    flex: 1;

    &__form {
      &.active,
      &.active .header-global-search__input,
      &.active .btn--clear {
        background: $alice-blue;
      }
    }
  }

  .btn--back {
    display: none;
  }

  .global-search {
    position: absolute;
    top: 76px;
    min-height: 126px;
    left: 50%;
    transform: translate(-50%, 0);
    border-radius: 10px;
    box-shadow: 0 1px 5px rgba(0, 0, 0, .12), 0 2px 2px rgba(0, 0, 0, .14), 0 3px 1px -2px rgba(0, 0, 0, .2);
    padding: 15px;

    &__body {
      height: auto;
      border-radius: 10px;
      width: 100%;

      &-head li {
        text-align: left;

        a {
          pointer-events: none;
          color: $blue-dark;

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

          &.active {
            border-bottom: 0;
          }

          span {
            max-width: 100%;
            margin-right: 0;
            margin-left: 0;
          }

          &.nav-link--disable span {
            max-width: 100%;
          }
        }
      }
    }

    &__wrapper {
      flex-direction: row;
    }

    &__suggestions {
      max-width: 180px;
      margin: 0;
    }

    &__result {
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
      grid-gap: 30px;
      padding-top: 5px;
      max-width: 100%;
    }
  }

  .search-item {
    display: grid !important;
    grid-template-columns: repeat(auto-fit, minmax(225px, 1fr));
    grid-gap: 10px;
    opacity: 1 !important;
    height: auto !important;
    position: static !important;
    align-content: baseline;

    li {
      width: 100%;

      & + li {
        margin-top: 0;
      }
    }
  }

  .search-loader {
    border-radius: 10px;
  }
}

@include media-breakpoint-up(lg) {
  .header-global-search {
    &__form {
      max-width: 451px;
    }
  }

  .global-search {
    top: 107px;

    &__body {
      height: 100%;
    }
  }

  .search-item {
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  }
}

@include media-breakpoint-up(xl) {
  .header-global-search {
    &__form {
      max-width: 608px;
    }
  }

  .search-item {
    grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  }

  .global-search {
    &__suggestions {
      max-width: 215px;
      margin-right: 10px;
    }

    &__wrapper {
      justify-content: space-between;
    }
  }
}
