@use 'sass:map';

@use 'mixins/mixins' as *;
@use 'mixins/var' as *;
@use 'common/var' as *;

@include b(cascade) {
  @include set-component-css-var('cascade', $cascade);
  width: 100%;

  display: inline-block;
  position: relative;
  font-size: getCssVar('font-size', 'base');
  line-height: map.get($input-height, 'default');
  // height: map.get($input-height, 'default');
  outline: none;

  &:not(.is-disabled):hover {
    .#{$namespace}-input__wrapper {
      cursor: pointer;
      box-shadow: 0 0 0 1px getCssVar('input', 'hover-border-color') inset;
    }
  }

  .#{$namespace}-input {
    cursor: pointer;

    .#{$namespace}-input__inner {
      text-overflow: ellipsis;
      cursor: pointer;

      &::selection {
        outline: none;
      }
    }

    .#{$namespace}-input__suffix-inner {
      .#{$namespace}-icon {
        height: calc(100% - 2px);

        svg {
          vertical-align: middle;
        }
      }
    }

    .icon-arrow-down {
      transition: transform getCssVar('transition-duration');
      font-size: 14px;

      @include when(reverse) {
        transform: rotateZ(180deg);
      }
    }

    .icon-circle-close:hover {
      color: var(
        #{getCssVarName('input', 'clear-hover-color')},
        map.get($input, 'clear-hover-color')
      );
    }

    @include when(focus) {
      .#{$namespace}-input__wrapper {
        box-shadow: 0 0 0 1px
          var(
            #{getCssVarName('input', 'focus-border-color')},
            map.get($input, 'focus-border-color')
          )
          inset;
      }
    }
  }

  @each $size in (large, small) {
    @include m($size) {
      font-size: map.get($input-font-size, $size);
      line-height: map.get($input-height, $size);
      height: map.get($input-height, $size);
    }
  }

  @include when(disabled) {
    .#{$namespace}-cascade__label {
      z-index: calc(getCssVar('index', 'normal') + 1);
      color: getCssVar('disabled-text-color');
    }
  }

  @include e(dropdown) {
    @include set-component-css-var('cascade', $cascade);
  }

  @include e(dropdown) {
    font-size: getCssVar('cascade-menu-font-size');
    border-radius: getCssVar('cascade-menu-radius');

    @include picker-popper(
      getCssVar('cascade-menu-fill'),
      getCssVar('cascade-menu-border'),
      getCssVar('cascade-menu-shadow')
    );

    &.#{$namespace}-popper {
      box-shadow: getCssVar('cascade-menu-shadow');
    }
  }

  @include e(tags) {
    position: absolute;
    left: 0;
    right: 30px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-wrap: wrap;
    line-height: normal;
    text-align: left;
    box-sizing: border-box;

    .#{$namespace}-tag {
      display: inline-flex;
      align-items: center;
      max-width: 100%;
      margin: 2px 0 2px 6px;
      text-overflow: ellipsis;
      background: getCssVar('cascade-tag-background');

      &:not(.is-hit) {
        border-color: transparent;
      }

      > span {
        flex: 1;
        overflow: hidden;
        text-overflow: ellipsis;
      }

      .#{$namespace}-icon-close {
        flex: none;
        background-color: getCssVar('text-color', 'placeholder');
        color: getCssVar('color-white');

        &:hover {
          background-color: getCssVar('text-color', 'secondary');
        }
      }
    }
  }

  @include e(collapse-tags) {
    white-space: normal;
    z-index: getCssVar('index-normal');
    display: flex;
    align-items: center;
    flex-wrap: wrap;
  }

  @include e(collapse-tag) {
    line-height: inherit;
    height: inherit;
    display: flex;
  }

  @include e(suggestion-panel) {
    border-radius: getCssVar('cascade-menu', 'radius');
  }

  @include e(suggestion-list) {
    max-height: 204px;
    margin: 0;
    padding: 6px 0;
    font-size: getCssVar('font-size', 'base');
    color: getCssVar('cascade-menu', 'text-color');
    text-align: center;
  }

  @include e(suggestion-item) {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 34px;
    padding: 0 15px;
    text-align: left;
    outline: none;
    cursor: pointer;

    &:hover,
    &:focus {
      background: getCssVar('cascade-node', 'background-hover');
    }

    &.is-checked {
      color: getCssVar('cascade', 'menu-selected-text-color');
      font-weight: bold;
    }

    > span {
      margin-right: 10px;
    }
  }

  @include e(empty-text) {
    margin: 10px 0;
    color: getCssVar('cascade', 'color-empty');
  }

  @include e(search-input) {
    flex: 1;
    height: 24px;
    min-width: 60px;
    margin: 2px 0 2px map.get($input-padding-horizontal, 'default')-$border-width;
    padding: 0;
    color: getCssVar('cascade', 'menu-text-color');
    border: none;
    outline: none;
    box-sizing: border-box;

    background: transparent;

    &::placeholder {
      // two input overlap
      color: transparent;
    }
  }
}
