import { defineComponent, vModelText, resolveComponent, resolveDirective, withDirectives, openBlock, createElementBlock, normalizeClass, createElementVNode, renderSlot, createCommentVNode, createVNode, withCtx, normalizeStyle, toDisplayString, createBlock, Fragment, renderList, resolveDynamicComponent, vShow } from 'vue';
import '../../../directives/index.mjs';
import { PsTooltip } from '../../tooltip/index.mjs';
import { PsTag } from '../../tag/index.mjs';
import { PsIcon } from '../../icon/index.mjs';
import PsSelectMenu from './select-dropdown.mjs';
import useSelect from './useSelect.mjs';
import { SelectProps } from './defaults.mjs';
import _export_sfc from '../../../_virtual/plugin-vue_export-helper.mjs';
import ClickOutside from '../../../directives/click-outside/index.mjs';

const _sfc_main = defineComponent({
  name: "PsSelectV2",
  components: {
    PsSelectMenu,
    PsTag,
    PsTooltip,
    PsIcon
  },
  directives: { ClickOutside, ModelText: vModelText },
  props: SelectProps,
  setup(props, { emit }) {
    const API = useSelect(props, emit);
    return API;
  }
});
const _hoisted_1 = { key: 0 };
const _hoisted_2 = ["id", "autocomplete", "aria-expanded", "aria-labelledby", "disabled", "readonly", "name", "unselectable"];
const _hoisted_3 = ["textContent"];
const _hoisted_4 = ["id", "aria-labelledby", "aria-expanded", "autocomplete", "disabled", "name", "readonly", "unselectable"];
const _hoisted_5 = ["textContent"];
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  var _a;
  const _component_ps_tag = resolveComponent("ps-tag");
  const _component_ps_icon = resolveComponent("ps-icon");
  const _directive_model_text = resolveDirective("model-text");
  const _directive_click_outside = resolveDirective("click-outside");
  return withDirectives((openBlock(), createElementBlock("div", {
    ref: "selectRef",
    class: normalizeClass([_ctx.nsSelectV2.b(), _ctx.nsSelectV2.m(_ctx.selectSize)])
  }, [
    createElementVNode("div", {
      ref: "selectionRef",
      class: normalizeClass([
        _ctx.nsSelectV2.e("wrapper"),
        _ctx.nsSelectV2.is("focused", _ctx.states.isComposing),
        _ctx.nsSelectV2.is("hovering", _ctx.states.comboBoxHovering),
        _ctx.nsSelectV2.is("filterable", _ctx.filterable),
        _ctx.nsSelectV2.is("disabled", _ctx.selectDisabled)
      ])
    }, [
      _ctx.$slots.prefix ? (openBlock(), createElementBlock("div", _hoisted_1, [
        renderSlot(_ctx.$slots, "prefix")
      ])) : createCommentVNode("v-if", true),
      _ctx.multiple ? (openBlock(), createElementBlock("div", {
        key: 1,
        class: normalizeClass(_ctx.nsSelectV2.e("selection"))
      }, [
        _ctx.collapseTags && _ctx.modelValue.length > 0 ? (openBlock(), createElementBlock("div", {
          key: 0,
          class: normalizeClass(_ctx.nsSelectV2.e("selected-item"))
        }, [
          createVNode(_component_ps_tag, {
            closable: !_ctx.selectDisabled && !((_a = _ctx.states.cachedOptions[0]) == null ? void 0 : _a.disable),
            size: _ctx.collapseTagSize,
            type: "info",
            "disable-transitions": ""
          }, {
            default: withCtx(() => {
              var _a2;
              return [
                createElementVNode("span", {
                  class: normalizeClass(_ctx.nsSelectV2.e("tags-text")),
                  style: normalizeStyle({
                    maxWidth: `${_ctx.tagMaxWidth}px`
                  })
                }, toDisplayString((_a2 = _ctx.states.cachedOptions[0]) == null ? void 0 : _a2.label), 7)
              ];
            }),
            _: 1
          }, 8, ["closable", "size"]),
          _ctx.modelValue.length > 1 ? (openBlock(), createBlock(_component_ps_tag, {
            key: 0,
            closable: false,
            size: _ctx.collapseTagSize,
            type: "info",
            "disable-transitions": ""
          }, {
            default: withCtx(() => [
              _ctx.collapseTagsTooltip ? (openBlock(), createElementBlock("span", {
                key: 0,
                class: normalizeClass(_ctx.nsSelectV2.e("tags-text")),
                style: normalizeStyle({
                  maxWidth: `${_ctx.tagMaxWidth}px`
                })
              }, "+ " + toDisplayString(_ctx.modelValue.length - 1), 7)) : (openBlock(), createElementBlock("span", {
                key: 1,
                class: normalizeClass(_ctx.nsSelectV2.e("tags-text")),
                style: normalizeStyle({
                  maxWidth: `${_ctx.tagMaxWidth}px`
                })
              }, "+ " + toDisplayString(_ctx.modelValue.length - 1), 7))
            ]),
            _: 1
          }, 8, ["size"])) : createCommentVNode("v-if", true)
        ], 2)) : (openBlock(true), createElementBlock(Fragment, { key: 1 }, renderList(_ctx.states.cachedOptions, (selected, idx) => {
          return openBlock(), createElementBlock("div", {
            key: idx,
            class: normalizeClass(_ctx.nsSelectV2.e("selected-item"))
          }, [
            (openBlock(), createBlock(_component_ps_tag, {
              key: _ctx.getValueKey(selected),
              closable: !_ctx.selectDisabled && !selected.disabled,
              size: _ctx.collapseTagSize,
              type: "info",
              "disable-transitions": ""
            }, {
              default: withCtx(() => [
                createElementVNode("span", {
                  class: normalizeClass(_ctx.nsSelectV2.e("tags-text")),
                  style: normalizeStyle({
                    maxWidth: `${_ctx.tagMaxWidth}px`
                  })
                }, toDisplayString(_ctx.getLabel(selected)), 7)
              ]),
              _: 2
            }, 1032, ["closable", "size"]))
          ], 2);
        }), 128)),
        createElementVNode("div", {
          class: normalizeClass([
            _ctx.nsSelectV2.e("selected-item"),
            _ctx.nsSelectV2.e("input-wrapper")
          ]),
          style: normalizeStyle(_ctx.inputWrapperStyle)
        }, [
          withDirectives(createElementVNode("input", {
            id: _ctx.id,
            ref: "inputRef",
            autocomplete: _ctx.autocomplete,
            "aria-autocomplete": "list",
            "aria-haspopup": "listbox",
            autocapitalize: "off",
            "aria-expanded": _ctx.expanded,
            "aria-labelledby": _ctx.label,
            class: normalizeClass([
              _ctx.nsSelectV2.is(_ctx.selectSize),
              _ctx.nsSelectV2.e("combobox-input")
            ]),
            disabled: _ctx.disabled,
            role: "combobox",
            readonly: !_ctx.filterable,
            spellcheck: "false",
            type: "text",
            name: _ctx.name,
            unselectable: _ctx.expanded ? "on" : void 0
          }, null, 10, _hoisted_2), [
            [_directive_model_text, _ctx.states.displayInputValue]
          ]),
          _ctx.filterable ? (openBlock(), createElementBlock("span", {
            key: 0,
            ref: "calculatorRef",
            "aria-hidden": "true",
            class: normalizeClass(_ctx.nsSelectV2.e("input-calculator")),
            textContent: toDisplayString(_ctx.states.displayInputValue)
          }, null, 10, _hoisted_3)) : createCommentVNode("v-if", true)
        ], 6)
      ], 2)) : (openBlock(), createElementBlock(Fragment, { key: 2 }, [
        createElementVNode("div", {
          class: normalizeClass([
            _ctx.nsSelectV2.e("selected-item"),
            _ctx.nsSelectV2.e("input-wrapper")
          ])
        }, [
          withDirectives(createElementVNode("input", {
            id: _ctx.id,
            ref: "inputRef",
            "aria-autocomplete": "list",
            "aria-haspopup": "listbox",
            "aria-labelledby": _ctx.label,
            "aria-expanded": _ctx.expanded,
            autocapitalize: "off",
            autocomplete: _ctx.autocomplete,
            class: normalizeClass(_ctx.nsSelectV2.e("combobox-input")),
            disabled: _ctx.disabled,
            name: _ctx.name,
            role: "combobox",
            readonly: !_ctx.filterable,
            spellcheck: "false",
            type: "text",
            unselectable: _ctx.expanded ? "on" : void 0
          }, null, 10, _hoisted_4), [
            [_directive_model_text, _ctx.states.displayInputValue]
          ])
        ], 2),
        _ctx.filterable ? (openBlock(), createElementBlock("span", {
          key: 0,
          ref: "calculatorRef",
          "aria-hidden": "true",
          class: normalizeClass([
            _ctx.nsSelectV2.e("selected-item"),
            _ctx.nsSelectV2.e("input-calculator")
          ]),
          textContent: toDisplayString(_ctx.states.displayInputValue)
        }, null, 10, _hoisted_5)) : createCommentVNode("v-if", true)
      ], 64)),
      _ctx.shouldShowPlaceholder ? (openBlock(), createElementBlock("span", {
        key: 3,
        class: normalizeClass([
          _ctx.nsSelectV2.e("placeholder"),
          _ctx.nsSelectV2.is("transparent", _ctx.states.isComposing || (_ctx.placeholder && _ctx.multiple ? _ctx.modelValue.length === 0 : !_ctx.hasModelValue))
        ])
      }, toDisplayString(_ctx.currentPlaceholder), 3)) : createCommentVNode("v-if", true),
      createElementVNode("span", {
        class: normalizeClass(_ctx.nsSelectV2.e("suffix"))
      }, [
        _ctx.iconComponent ? withDirectives((openBlock(), createBlock(_component_ps_icon, {
          key: 0,
          class: normalizeClass([_ctx.nsSelectV2.e("caret"), _ctx.nsInput.e("icon"), _ctx.iconReverse])
        }, {
          default: withCtx(() => [
            (openBlock(), createBlock(resolveDynamicComponent(_ctx.iconComponent)))
          ]),
          _: 1
        }, 8, ["class"])), [
          [vShow, !_ctx.showClearBtn]
        ]) : createCommentVNode("v-if", true),
        _ctx.showClearBtn && _ctx.clearIcon ? (openBlock(), createBlock(_component_ps_icon, {
          key: 1,
          class: normalizeClass([_ctx.nsSelectV2.e("caret"), _ctx.nsInput.e("icon")])
        }, {
          default: withCtx(() => [
            (openBlock(), createBlock(resolveDynamicComponent(_ctx.clearIcon)))
          ]),
          _: 1
        }, 8, ["class"])) : createCommentVNode("v-if", true),
        _ctx.validateState && _ctx.validateIcon ? (openBlock(), createBlock(_component_ps_icon, {
          key: 2,
          class: normalizeClass([_ctx.nsInput.e("icon"), _ctx.nsInput.e("validateIcon")])
        }, {
          default: withCtx(() => [
            (openBlock(), createBlock(resolveDynamicComponent(_ctx.validateIcon)))
          ]),
          _: 1
        }, 8, ["class"])) : createCommentVNode("v-if", true)
      ], 2)
    ], 2)
  ], 2)), [
    [_directive_click_outside, _ctx.handleClickOutside, _ctx.popperRef]
  ]);
}
var Select = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render], ["__file", "/Users/meng/workspace/element-ps/packages/components/select-v2/src/select.vue"]]);

export { Select as default };
//# sourceMappingURL=select.mjs.map
