//
// Copyright IBM Corp. 2016, 2018
//
// This source code is licensed under the Apache-2.0 license found in the
// LICENSE file in the root directory of this source tree.
//

//-----------------------------
// Search
//-----------------------------

@import '../../globals/scss/vars';
@import '../../globals/scss/helper-mixins';
@import '../../globals/scss/css--reset';
@import '../../globals/scss/typography';
@import '../../globals/scss/import-once';

/// Search styles
/// @access private
/// @group search
@mixin search {
  .#{$prefix}--search {
    display: flex;
    align-items: center;
    position: relative;
    width: 100%;
  }

  .#{$prefix}--search .#{$prefix}--label {
    @include hidden;
  }

  .#{$prefix}--search-input {
    @include reset;
    @include type-style('body-short-02');
    @include focus-outline('reset');
    appearance: none;
    border: none;
    background-color: $field-01;
    color: $text-01;
    padding: 0 $carbon--spacing-08;
    text-overflow: ellipsis;
    width: 100%;
    order: 1;
    transition: background-color $duration--fast-02 motion(standard, productive),
      outline $duration--fast-02 motion(standard, productive);
    border-bottom: 1px solid $ui-04;

    &:focus {
      @include focus-outline('outline');
    }

    &::placeholder {
      color: $text-05;
      font-weight: 400;
    }

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

  .#{$prefix}--search-input[disabled] {
    color: $disabled;
    background-color: $disabled-background-color;
    border-bottom: 1px solid transparent;
    cursor: not-allowed;

    &::placeholder {
      color: $disabled;
      font-weight: 400;
    }
  }

  .#{$prefix}--search-input[disabled] ~ .#{$prefix}--search-magnifier {
    fill: $disabled;
  }

  .#{$prefix}--search--light .#{$prefix}--search-input {
    background: $field-02;
  }

  .#{$prefix}--search--sm .#{$prefix}--search-input {
    @include type-style('body-short-01');
    height: rem(32px);
  }

  .#{$prefix}--search--lg .#{$prefix}--search-input {
    @include type-style('body-short-02');
    height: rem(40px);
  }

  .#{$prefix}--search--xl .#{$prefix}--search-input {
    @include type-style('body-short-02');
    height: rem(48px);
    padding: 0 rem(64px) 0 rem(48px);
  }

  .#{$prefix}--search-magnifier {
    left: 0.75rem;
    z-index: 2;
    position: absolute;
    height: rem(16px);
    width: rem(16px);
    top: 50%;
    transform: translateY(-50%);
    // Ensure clear icon is rendered in Firefox (#1127)
    fill: $text-02;
    pointer-events: none;
  }

  .#{$prefix}--search--xl .#{$prefix}--search-magnifier {
    height: rem(20px);
    width: rem(20px);
    left: rem(24px);
    transform: translate(-50%, -50%);
  }

  .#{$prefix}--search-close {
    @include button-reset(false);
    @include focus-outline('reset');
    position: absolute;
    right: 0;

    &::before {
      content: '';
      display: block;
      position: absolute;
      left: 0;
      top: rem(1px);
      height: calc(100% - 2px);
      width: 2px;
      background-color: $field-01;
      transition: background-color $duration--fast-02
        motion(standard, productive);
    }

    &:hover {
      border-bottom: 1px solid $ui-04;
    }
  }

  .#{$prefix}--search-button {
    flex-shrink: 0;
    margin-left: $carbon--spacing-01;
    background-color: $field-01;

    svg {
      vertical-align: middle;
      fill: currentColor;
    }
  }

  .#{$prefix}--search-close,
  .#{$prefix}--search-button {
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity $duration--fast-02 motion(standard, productive),
      background-color $duration--fast-02 motion(standard, productive),
      outline $duration--fast-02 motion(standard, productive),
      border $duration--fast-02 motion(standard, productive);
    cursor: pointer;
    visibility: visible;
    opacity: 1;
    height: rem(40px);
    width: rem(40px);
    fill: $icon-01;
    border-style: solid;
    border-color: transparent;
    border-width: 1px 0;

    &:hover {
      background-color: $hover-field;
    }

    &:focus {
      @include focus-outline('outline');
    }

    &:active {
      @include focus-outline('outline');
      background-color: $selected-ui;
    }
  }

  .#{$prefix}--search-close:hover {
    &::before {
      background-color: $hover-field;
    }
  }

  .#{$prefix}--search-close:focus,
  .#{$prefix}--search-close:active {
    &::before {
      background-color: $focus;
    }
  }

  .#{$prefix}--search-input:focus ~ .#{$prefix}--search-close:hover {
    @include focus-outline('outline');
  }

  .#{$prefix}--search--sm {
    .#{$prefix}--search-close,
    ~ .#{$prefix}--search-button {
      height: rem(32px);
      width: rem(32px);
    }
  }

  .#{$prefix}--search--lg {
    .#{$prefix}--search-close,
    ~ .#{$prefix}--search-button {
      height: rem(40px);
      width: rem(40px);
    }
  }

  .#{$prefix}--search--xl {
    .#{$prefix}--search-close,
    ~ .#{$prefix}--search-button {
      height: rem(48px);
      width: rem(48px);
    }
  }

  .#{$prefix}--search-close--hidden {
    visibility: hidden;
    opacity: 0;
  }

  .#{$prefix}--search--xl.#{$prefix}--skeleton .#{$prefix}--search-input,
  .#{$prefix}--search--lg.#{$prefix}--skeleton .#{$prefix}--search-input,
  .#{$prefix}--search--sm.#{$prefix}--skeleton .#{$prefix}--search-input {
    @include skeleton;
    width: 100%;

    &::placeholder {
      color: transparent;
    }
  }
}

@include exports('search') {
  @include search;
}
