@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 {
    flex-direction: column;
    justify-content: flex-start;
    align-items: flex-start;
    height: 100%;

    .fake-nav-item {
      display: none;
    }

    &-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;
    max-width: 540px;
    margin: 0 auto;

    .tab-pane {
      padding: 0 15px 15px;
    }

    .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: 8px 10px;
      display: flex;
      align-items: flex-start;
    }

    p {
      font-size: .75rem;
      margin-bottom: 0;
      overflow: hidden;
      text-overflow: ellipsis;
      -webkit-box-orient: vertical;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      font-weight: 500;
      flex-shrink: 0;
    }
  }

  &__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;
    }
  }

  &__content {
    width: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    height: 65px;
  }

  &__footer {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
  }
}

#contentPages {
  p {
    font-size: .875rem;
  }
}

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

  .autocomplete__dataset-products {
    .search-item__img {
      max-width: 50px;

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

@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;
      }
    }
  }

  .global-search__body {
    background: $alice-blue;
  }

  .global-search__result .tab-pane {
    padding: 15px;
  }
}

@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: 0;
      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;
  }

  #products-tab {
    background: $alice-blue;
    border-top-left-radius: 10px;
    border-top-right-radius: 10px;
  }

  #products {
    background: $alice-blue;
    border-bottom-left-radius: 10px;
    border-bottom-right-radius: 10px;
  }

  #contentPages {
    li a {
      border: 1px solid $gray-light;
    }
  }
}

@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;
    }
  }
}

@include media-breakpoint-only(md) {
  .global-search__result {
    display: flex;
    flex-direction: column;

    .search-item {
      display: flex;
      grid-template-columns: 1fr;
    }

    .fake-nav-item {
      display: block;
      color: $blue-dark;
      font-size: 1rem;
      font-weight: 500;
      padding: 15px;
    }
  }

  .global-search__body-head {
    .nav-item:nth-of-type(2), #content-page-tab {
      display: none;
    }
  }
}

.search_reviews {
  color: $warm-grey;
  line-height: 16px;
  font-size: .75rem;
  margin: 0;
  transform: translateY(3px);
  margin-right: .5em;

  .product-rating {
    display: flex;
    justify-content: flex-start;
    align-items: baseline;

    .rating-bg {
      color: $gray;
      position: relative;
      padding-right: 5px;
      display: flex;

      .fa-star {
        display: block;
        margin-right: 2px;
        font-size: .88em;
      }
    }

    .rating-overlay {
      color: $yellow;
      position: absolute;
      left: 0;
      top: 0;
      display: flex;
    }

    .star-overlay {
      display: inline-block;
      margin-right: 2px;
      overflow: hidden;
      margin: 0 2px 0 0;

      .fa-star {
        margin-right: 0;
      }
    }
  }
}

.search-price {
  font-size: .875rem;
  color: $blue-dark;
  font-weight: 700;
  display: flex;
  margin-left: auto;

  &__old-price {
    font-size: .625rem;
    color: $warm-grey;
    font-weight: 500;
    line-height: 1.375rem;
    margin-right: 4px;
    margin-top: .1rem;
  }

  &__new-price {
    color: $red;
  }
}
