import ie from "../../../@babel/runtime/helpers/esm/defineProperty.mjs";
import P from "../../../@babel/runtime/helpers/esm/slicedToArray.mjs";
import * as n from "react";
import { useState as M } from "react";
import ue from "../../../classnames/index.mjs";
import se from "../../../rc-util/es/pickAttrs.mjs";
import me from "../../../rc-overflow/es/Overflow.mjs";
import de from "../TransBtn.mjs";
import fe from "./Input.mjs";
import ve from "../hooks/useLayoutEffect.mjs";
import { getTitle as ge } from "../utils/commonUtil.mjs";
function he(u) {
  var e;
  return (e = u.key) !== null && e !== void 0 ? e : u.value;
}
var N = function(e) {
  e.preventDefault(), e.stopPropagation();
}, Te = function(e) {
  var F = e.id, C = e.prefixCls, x = e.values, s = e.open, _ = e.searchValue, I = e.autoClearSearchValue, K = e.inputRef, V = e.placeholder, p = e.disabled, m = e.mode, k = e.showSearch, A = e.autoFocus, B = e.autoComplete, L = e.activeDescendantId, O = e.tabIndex, W = e.removeIcon, z = e.maxTagCount, v = e.maxTagTextLength, b = e.maxTagPlaceholder, g = b === void 0 ? function(t) {
    return "+ ".concat(t.length, " ...");
  } : b, S = e.tagRender, $ = e.onToggleOpen, j = e.onRemove, q = e.onInputChange, G = e.onInputPaste, H = e.onInputKeyDown, J = e.onInputMouseDown, Q = e.onInputCompositionStart, U = e.onInputCompositionEnd, w = n.useRef(null), X = M(0), D = P(X, 2), Y = D[0], Z = D[1], ee = M(!1), y = P(ee, 2), te = y[0], E = y[1], a = "".concat(C, "-selection"), d = s || m === "multiple" && I === !1 || m === "tags" ? _ : "", ne = m === "tags" || m === "multiple" && I === !1 || k && (s || te);
  ve(function() {
    Z(w.current.scrollWidth);
  }, [d]);
  function R(t, o, l, i, r) {
    return /* @__PURE__ */ n.createElement("span", {
      className: ue("".concat(a, "-item"), ie({}, "".concat(a, "-item-disabled"), l)),
      title: ge(t)
    }, /* @__PURE__ */ n.createElement("span", {
      className: "".concat(a, "-item-content")
    }, o), i && /* @__PURE__ */ n.createElement(de, {
      className: "".concat(a, "-item-remove"),
      onMouseDown: N,
      onClick: r,
      customizeIcon: W
    }, "×"));
  }
  function oe(t, o, l, i, r) {
    var c = function(f) {
      N(f), $(!s);
    };
    return /* @__PURE__ */ n.createElement("span", {
      onMouseDown: c
    }, S({
      label: o,
      value: t,
      disabled: l,
      closable: i,
      onClose: r
    }));
  }
  function ae(t) {
    var o = t.disabled, l = t.label, i = t.value, r = !p && !o, c = l;
    if (typeof v == "number" && (typeof l == "string" || typeof l == "number")) {
      var h = String(c);
      h.length > v && (c = "".concat(h.slice(0, v), "..."));
    }
    var f = function(T) {
      T && T.stopPropagation(), j(t);
    };
    return typeof S == "function" ? oe(i, c, o, r, f) : R(t, c, o, r, f);
  }
  function le(t) {
    var o = typeof g == "function" ? g(t) : g;
    return R({
      title: o
    }, o, !1);
  }
  var re = /* @__PURE__ */ n.createElement("div", {
    className: "".concat(a, "-search"),
    style: {
      width: Y
    },
    onFocus: function() {
      E(!0);
    },
    onBlur: function() {
      E(!1);
    }
  }, /* @__PURE__ */ n.createElement(fe, {
    ref: K,
    open: s,
    prefixCls: C,
    id: F,
    inputElement: null,
    disabled: p,
    autoFocus: A,
    autoComplete: B,
    editable: ne,
    activeDescendantId: L,
    value: d,
    onKeyDown: H,
    onMouseDown: J,
    onChange: q,
    onPaste: G,
    onCompositionStart: Q,
    onCompositionEnd: U,
    tabIndex: O,
    attrs: se(e, !0)
  }), /* @__PURE__ */ n.createElement("span", {
    ref: w,
    className: "".concat(a, "-search-mirror"),
    "aria-hidden": !0
  }, d, " ")), ce = /* @__PURE__ */ n.createElement(me, {
    prefixCls: "".concat(a, "-overflow"),
    data: x,
    renderItem: ae,
    renderRest: le,
    suffix: re,
    itemKey: he,
    maxCount: z
  });
  return /* @__PURE__ */ n.createElement(n.Fragment, null, ce, !x.length && !d && /* @__PURE__ */ n.createElement("span", {
    className: "".concat(a, "-placeholder")
  }, V));
};
export {
  Te as default
};
