@use "../mixins/function.scss" as *;
@use "../mixins/mixins.scss" as *;
@use "../common/var.scss" as *;

@include b(input-tag) {
  display: inline-flex;
  box-sizing: border-box;
  @include e(wrapper) {
    width: 100%;
    display: flex;
    align-items: center;
    overflow: hidden;
    color: getCssVar("color", "text-1");
    background-color: getCssVar("color", "bg-2");
    border: 1px solid getCssVar("color", "fill-3");
    font-size: getCssVar("font-size", "medium");
    padding: 0 8px;
    &:hover {
      border: 1px solid getCssVar("color", "fill-4");
    }
    &:focus-within {
      border-color: getCssVar("color", "primary-6");
    }
    @include when(disabled) {
      background-color: getCssVar("color", "fill-2");
      border-color: getCssVar("color", "fill-2");
      cursor: not-allowed;
    }
    @include when(error) {
      @include this-be(input-tag, wrapper) {
        border-color: getCssVar("color", "danger-6");
        &:hover {
          border-color: getCssVar("color", "danger-6");
        }
        &:focus-within {
          border-color: getCssVar("color", "danger-6");
        }
        @include when(filled) {
          background-color: getCssVar("color", "error-1");
          border-color: getCssVar("color", "error-1");
          &:hover {
            background-color: getCssVar("color", "error-2");
          }
          &:focus-within {
            background-color: getCssVar("color", "bg-2");
            border-color: getCssVar("color", "error-5");
          }
        }
      }
    }
    @include when(filled) {
      background-color: getCssVar("color", "fill-2");
      border: 1px solid getCssVar("color", "fill-2");
      &:hover {
        background-color: getCssVar("color", "fill-3");
      }
      &:focus-within {
        background-color: getCssVar("color", "bg-2");
        border-color: getCssVar("color", "primary-6");
      }
      @include be(input-tag, item) {
        background-color: getCssVar("color", "bg-3");
      }
    }
    @include be(input-tag, item) {
      background-color: getCssVar("color", "fill-2");
    }
  }
  @include e(prepend) {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 12px;
    color: getCssVar("color", "text-2");
    white-space: nowrap;
    background-color: getCssVar("color", "fill-2");
    border-right: 1px solid getCssVar("color", "fill-3");
  }
  @include e(prefix) {
    display: flex;
    align-items: center;
    justify-content: center;
  }
  @include e(inner) {
    flex: 1;
    height: 100%;
    display: flex;
    flex-wrap: wrap;
    overflow: hidden;
    gap: 4px;
    padding: 4px 0;
  }
  @include e(item) {
    padding: 0 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
  }
  @include e(item-close) {
    border-radius: getCssVar("radius", "circle");
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 2px;
    &:hover {
      background-color: getCssVar("color", "fill-3");
    }
  }
  @include e(input-wrapper) {
    flex: 1;
    padding-left: 4px;
    display: flex;
    align-items: center;
  }
  @include e(input) {
    width: 100%;
    font-size: inherit;
    padding: 0;
    outline: none;
    border: none;
    background: none;
    box-sizing: border-box;
    border-radius: 0;
    color: getCssVar("color", "text-1");
    cursor: inherit;
    -webkit-appearance: none;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
    &::placeholder {
      color: getCssVar("color", "text-3");
    }
  }
  @include e(clear) {
    height: 18px;
    width: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: getCssVar("font-size", "medium");
    border-radius: getCssVar("radius", "circle");
    cursor: pointer;
    user-select: none;
    &:hover {
      background-color: getCssVar("color", "fill-3");
    }
    &:active {
      background-color: getCssVar("color", "fill-2");
    }
  }
  @include e(suffix) {
    display: flex;
    align-items: center;
    justify-content: center;
  }
  @include e(append) {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 12px;
    color: getCssVar("color", "text-2");
    white-space: nowrap;
    background-color: getCssVar("color", "fill-2");
    border-left: 1px solid getCssVar("color", "fill-3");
  }

  @each $size in $size-list {
    @include m(#{$size}) {
      @include be(input-tag, wrapper) {
        min-height: getCssVar("size", $size);
        border-radius: getCssVar("radius", $size);
        @if $size == mini {
          font-size: getCssVar("font-size", $size);
        }
      }
      @include be(input-tag, item) {
        height: calc(getCssVar("size", $size) - 10px);
        line-height: calc(getCssVar("size", $size) - 10px);
        border-radius: getCssVar("radius", $size);
        @if $size == mini {
          font-size: getCssVar("font-size", $size);
        }
      }
      @include be(input-tag, item-close) {
        @if $size == mini {
          font-size: getCssVar("font-size", $size);
        }
      }
      @include be(input-tag, input-wrapper) {
        height: calc(getCssVar("size", $size) - 10px);
      }
      @include be(input-tag, input) {
        height: calc(getCssVar("size", $size) - 10px);
        line-height: calc(getCssVar("size", $size) - 10px);
        @if $size == mini {
          font-size: getCssVar("font-size", $size);
        }
      }
    }
  }
}
