@import '../style/theme/color';
@import '../style/core/font';
@import '../style/theme/corner';
@import '../style/core/animation';
@import '../style/theme/z-index';

.devui-tree-select {
  position: relative;
  width: 100%;

  .devui-select-input {
    &:not([disabled]) {
      color: $devui-text;
    }

    &.devui-tree-select-input {
      font-size: $devui-font-size;
      padding: 2px 32px 2px 2px;
      height: unset;
      min-height: 28px;
      max-height: 52px;
      overflow-y: auto;
      line-height: 22px;
      display: flex;
      text-indent: 8px;

      &.devui-select-no-label {
        padding-left: 8px;
      }

      & > span.devui-tree-select-placeholder {
        text-indent: 0;
      }
    }
  }

  &:hover {
    & .clear {
      position: absolute;
      height: 14px;
      width: 14px;
      right: 12px;
      top: calc((100% - 14px) / 2);
      cursor: pointer;
      z-index: 1;

      &::after,
      &::before {
        position: absolute;
        content: '';
        height: 14px;
        width: 2px;
        background-color: $devui-icon-text;
        left: 50%;
      }

      &::before {
        transform: rotate(45deg);
      }

      &::after {
        transform: rotate(-45deg);
      }

      &:hover {
        &::after,
        &::before {
          background-color: $devui-icon-fill-active;
        }
      }
    }

    .allow-clear {
      opacity: 0;
    }
  }

  .devui-select-chevron-icon {
    right: 7px;
    top: calc((100% - 14px) / 2);
    position: absolute;
    user-select: none;
    pointer-events: none;
    height: 14px;
    line-height: 14px;
    z-index: 1;

    svg path {
      fill: $devui-text-weak;
    }

    &-animation svg {
      transition: transform $devui-animation-duration-slow $devui-animation-ease-in-out-smooth;
    }

    &.open {
      z-index: $devui-z-index-dropdown;

      svg {
        transform: rotate(180deg);
      }
    }

    &.clear {
      opacity: 0;
    }

    &.disabled {
      svg path {
        fill: $devui-disabled-text;
      }
    }
  }

  &:not(:hover) {
    .devui-select-chevron-icon:not(.disabled) {
      opacity: 1;
      transition: opacity $devui-animation-duration-fast $devui-animation-linear;
    }
  }
}

.devui-tree-select.devui-options-container {
  width: 100%;
  color: $devui-text;
  padding-left: 8px;
}

.devui-select-item {
  color: $devui-text;
  line-height: 16px;
  background-color: $devui-label-bg;
  border-radius: $devui-border-radius;
  border: 1px solid $devui-label-bg;
  display: inline-block;
  max-width: 100%;
  min-height: 20px;
  height: 20px;
  max-height: 20px;
  margin: 1px;
  padding: 0 5px;
  position: relative;
  text-indent: 0;

  &.devui-no-label-item {
    padding: 1px 0;
    background: transparent;
    border-color: transparent;
    display: inline-block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .devui-select-item-content {
    display: inline-block;
    cursor: pointer;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: baseline;
    height: 18px;
    line-height: 18px;
    max-width: 100%;
    padding-right: 30px;
    position: relative;

    &:hover {
      color: $devui-list-item-hover-text;
    }
  }

  & > .devui-select-item-clear-icon {
    width: 12px;
    height: 12px;
    line-height: 12px;
    text-align: center;
    margin-left: 12px;
    border-radius: 50%;
    background-color: $devui-line; // TODO: Color-Question
    display: inline-flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    transition: transform $devui-animation-duration-base ease;

    svg path {
      fill: $devui-light-text;
    }

    &:hover {
      background-color: $devui-icon-fill-active-hover;
    }
  }
}

.devui-select-list {
  display: flex;
  flex-wrap: wrap;
}

svg.svg-icon-search path {
  fill: $devui-text-weak;
}

// 此处设置默认宽度，使用组件时可以自定义宽度，尽量不要入侵组件内部样式。
:host {
  display: inline-block;
  width: 100%;
}

.devui-select-input.devui-tree-select-input.disabled {
  color: $devui-disabled-text;

  & .devui-select-item {
    background-color: $devui-disabled-bg;
    border-color: $devui-disabled-line;

    &.devui-no-label-item {
      background-color: transparent;
      border-color: transparent;
      color: $devui-disabled-text;
    }

    & > .devui-select-item-content {
      &,
      &:hover,
      &:focus {
        color: $devui-disabled-text;
        cursor: not-allowed;
        padding-right: 0;
      }
    }

    & > .devui-select-item-clear-icon {
      &,
      &:hover,
      &:focus {
        background-color: $devui-disabled-line;
        cursor: not-allowed;

        svg path {
          fill: $devui-disabled-bg;
        }
      }
    }
  }
}

.devui-tree-select {
  .devui-select-input.devui-tree-select-input {
    &:not(.icon):not([class^='icon-']):not([disabled]):not(.disabled):not(.devui-disabled) {
      // 为了增加层级覆盖form的样式
      color: $devui-placeholder;
    }
  }
}

::ng-deep .devui-tree-select.devui-search-container d-search {
  width: 100%;
}
