@import 'Variables';
@import 'Colors';

@mixin magic-box($height: 48px) {
  @include flex-grow(1);
  $padding: floor(1/4 * $height);
  $lineHeight: $height - $padding * 2;
  $fontSize: floor($lineHeight * 2 / 3);
  position: relative;
  text-align: left;
  color: $grey-900;
  .magic-box-input {
    background: $white;
    height: $height;
    overflow: hidden;
    position: relative;
    .magic-box-underlay,
    > input {
      color: $grey-900;
      text-align: left;
      padding: $padding $height+1 $padding $padding;
      text-indent: 0;
      font-family: arial, sans-serif;
      font-size: $fontSize;
      line-height: $lineHeight;
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: $height;
      white-space: pre;
      overflow: auto;
      box-sizing: border-box;
      display: block;
    }
    input {
      background: none;
      border: none;
      resize: none;
      outline: 0;
      &::-ms-clear {
        width: 0;
        height: 0;
      }
    }
    .magic-box-underlay {
      color: transparent;
      overflow: hidden;
      > span {
        text-indent: 0;
      }
      span {
        display: inline-block;
        vertical-align: top;
        &[data-value=''] {
          height: $lineHeight;
        }
      }
      .magic-box-ghost-text {
        visibility: hidden;
        color: $grey-400;
      }
      .magic-box-error {
        border-bottom: solid $red-500 2px;
        &.magic-box-error-empty {
          position: relative;
          &:before {
            content: ' ';
            border-bottom: solid $red-500 2px;
            position: absolute;
          }
        }
      }
      &:after {
        content: '';
        display: inline-block;
      }
    }
  }
  .magic-box-clear {
    position: relative;
    float: right;
    height: $height;
    line-height: $height;
    text-align: center;
    font-size: 24px;
    transition: visibility 0.3s, width 0.3s;
    cursor: pointer;
    background: $white;
    width: 0;
    visibility: hidden;
    overflow: hidden;
    .magic-box-icon {
      &:before {
        color: $grey-500;
        font-family: arial, sans-serif;
        content: 'X';
        font-size: 24px;
      }
    }
    &:before {
      content: '';
      border-left: $grey-300 1px solid;
      position: absolute;
      top: 15%;
      bottom: 15%;
      left: 0;
    }
  }
  &.magic-box-notEmpty {
    .magic-box-clear {
      width: $height;
      visibility: visible;
    }
  }
  &.magic-box-hasFocus {
    .magic-box-underlay .magic-box-ghost-text {
      visibility: visible;
    }
    .magic-box-suggestions.magic-box-hasSuggestion {
      display: block;
      .coveo-magicbox-suggestions {
        border: $default-low-contrast-border;
      }
      .coveo-suggestion-container {
        border: $default-low-contrast-border;
        .coveo-magicbox-suggestions {
          border: none;
        }
      }
    }
  }
  .magic-box-suggestions {
    clear: both;
    position: absolute;
    top: 100%;
    left: -1px;
    right: -1px;
    overflow: visible;
    background: $white;
    z-index: 1;
    display: none;
    font-family: arial, sans-serif;
    .magic-box-suggestion-seperator,
    .magic-box-suggestion {
      opacity: 1;
      transition: opacity 0.3s;
    }
    &.magic-box-suggestions-loading {
      .magic-box-suggestion-seperator,
      .magic-box-suggestion {
        opacity: 0;
      }
    }
    .magic-box-suggestion-seperator {
      padding: $padding $padding 0;
      line-height: $lineHeight;
      font-size: $fontSize;
      font-weight: bold;
      background: $white;
      overflow: hidden;
      height: $lineHeight + $padding;
      border-top: 1px solid $grey-300;
      color: $grey-500;
      &:first-child {
        border-top: none;
      }
      .magic-box-suggestion-seperator-label {
        float: left;
        margin-right: $padding;
        max-width: 75%;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
      }
      &:after {
        content: '';
        display: block;
        position: relative;
        top: 50%;
        height: 1px;
        overflow: hidden;
        background-color: $grey-300;
      }
      + .magic-box-suggestion {
        border-top: none;
      }
    }
    .magic-box-suggestion {
      cursor: pointer;
      line-height: $lineHeight;
      padding: $padding;
      font-size: $fontSize;
      background: $white;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      border-top: 1px solid $grey-50;
      color: $grey-900;
      .magic-box-hightlight {
        font-weight: bold;
        color: $black;
      }
      &:first-child {
        border-top: none;
      }
      &.magic-box-selected {
        background: $cyan-50 !important;
      }
      &:hover {
        background: $grey-100;
      }
    }
  }
  &.magic-box-inline {
    overflow: hidden;
    .magic-box-suggestions.magic-box-hasSuggestion {
      position: relative;
      display: block;
      top: 0;
      left: 0;
      right: 0;
      .coveo-magicbox-suggestions {
        border: none;
        border-top: $default-low-contrast-border;
      }
      .coveo-suggestion-container {
        border: none;
        border-top: $default-low-contrast-border;
        .coveo-magicbox-suggestions {
          border-top: none;
        }
      }
    }
  }
}
@mixin highlight($color, $left: true, $right: true) {
  position: relative;
  &:before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: $color;
  }
  @if ($left) {
    &:before {
      border-top-left-radius: 4px;
      border-bottom-left-radius: 4px;
      left: 1px;
    }
  }
  @if ($right) {
    &:before {
      border-top-right-radius: 4px;
      border-bottom-right-radius: 4px;
      right: 1px;
    }
  }
}
.magic-box {
  @include magic-box();
}
