import { jsx as e, jsxs as m } from "react/jsx-runtime";
import { T as y, n as D, C as P, L as R, u as k } from "./TalkLoading-CJtNYhDp.js";
import { h as x, g as S, g0 as v, g1 as f, eM as B, s as L, eN as T } from "./main-CxoAwMiG.js";
import d, { useEffect as j, useState as M } from "react";
import { R as _, T as z, P as E, C as F, I as O } from "./useBreakpoint-Xy_wMP1Z.js";
const Q = ({
  selectedItems: r = [],
  selectable: o = !1,
  hiddenParticipant: s = !1,
  searchValue: a = "",
  onSelect: t,
  height: c,
  maxSelectable: h
}) => {
  const { contacts: n, loading: w, loadingFromDown: b, hasNext: C, nextOffset: N } = x((l) => l.contacts), I = x(
    (l) => l.threadParticipant.threadParticipants
  );
  let p = [];
  if (s) {
    const l = new Set(
      I.map((i) => i.contactId)
    );
    p = n.filter(
      (i) => !l.has(Number(i.id))
    );
  }
  const u = S();
  return j(() => {
    u(v()), u(f({ count: 20, offset: 0 }));
  }, []), w ? /* @__PURE__ */ e("div", { className: "mt-5", children: /* @__PURE__ */ e(y, {}) }) : a != null && a.length && n.length === 0 ? /* @__PURE__ */ e("div", { className: "w-full text-center mt-5 text-secondary text-sm", children: `مخاطبی با مشخصات "${a}" وجود ندارد` }) : n.length === 0 ? /* @__PURE__ */ e("div", { className: "w-full text-center mt-5 text-secondary text-sm", children: "مخاطبی وجود ندارد" }) : /* @__PURE__ */ e(
    D,
    {
      components: { Footer: () => b && /* @__PURE__ */ e(R, {}) },
      endReached: () => {
        C && u(f({ count: 21, offset: N }));
      },
      data: s ? p : n,
      className: "scroll-container",
      overscan: 100,
      style: {
        height: c || "100dvh",
        direction: "rtl"
      },
      itemContent: (l, i) => /* @__PURE__ */ e(
        P,
        {
          contact: i,
          maxSelectable: h,
          showIsNotMember: !0,
          showBlock: !0,
          showSelect: o,
          handleSelect: t,
          selectedContacts: r
        }
      )
    }
  );
}, $ = ({ handleChange: r }) => {
  const [o, s] = d.useState(""), a = (t) => {
    var c;
    s(t.target.value), r((c = t == null ? void 0 : t.target) == null ? void 0 : c.value);
  };
  return /* @__PURE__ */ m("div", { className: "flex-1 max-w-[161px] flex items-center gap-1 text-invertBlackWhite min-w-px", children: [
    /* @__PURE__ */ e(B, { size: 26, color: "var(--light-text)" }),
    /* @__PURE__ */ e(
      "input",
      {
        className: "min-w-0 bg-transparent focus:outline-none focus-visible:outline-none focus-visible:border-0",
        type: "text",
        placeholder: L.search,
        value: o,
        onChange: a
      }
    )
  ] });
}, A = d.memo($), g = [
  { value: "", label: "نام و نام خانوادگی " },
  { value: "uname:", label: "نام کاربری" },
  { value: "tel:", label: "موبایل" }
], H = ({ onSelect: r }) => {
  const [o, s] = M(g[0]), a = (t) => {
    s(t), r(t.value);
  };
  return /* @__PURE__ */ e("div", { children: /* @__PURE__ */ m(_, { dir: "rtl", children: [
    /* @__PURE__ */ m(z, { className: "flex gap-1 items-center text-secondary", children: [
      /* @__PURE__ */ e("span", { className: "whitespace-nowrap", children: o.label }),
      /* @__PURE__ */ e(T, { stroke: "var(--light-text)" })
    ] }),
    /* @__PURE__ */ e(E, { children: /* @__PURE__ */ e(
      F,
      {
        onPointerDown: (t) => t.preventDefault(),
        className: "bg-bgColor mt-4 rounded-[12px] text-right p-3 px-5 shadow-actionShadow z-chatDropDown",
        children: g.map((t, c) => /* @__PURE__ */ e(
          O,
          {
            className: "text-sm hover:text-accent rounded cursor-pointer text-text flex items-center py-2",
            onSelect: () => a(t),
            children: /* @__PURE__ */ e("span", { children: t.label })
          },
          c
        ))
      }
    ) })
  ] }) });
}, U = ({
  showType: r = !0,
  setSearchValue: o
}) => {
  const [s, a] = d.useState(""), t = d.useRef(s), c = S();
  d.useEffect(() => {
    t.current = s;
  }, [s]);
  const h = k(
    (n) => {
      o && o(n), c(v()), c(
        f({
          count: 20,
          offset: 0,
          name: t.current + n
        })
      );
    },
    1e3,
    { leading: !1, trailing: !0 }
    // fire after user pauses typing
  );
  return /* @__PURE__ */ m("div", { className: "bg-bgColor flex gap-2 items-center px-3 py-2 w-full  justify-between", children: [
    /* @__PURE__ */ e(A, { handleChange: (n) => h(n) }),
    r && /* @__PURE__ */ e(H, { onSelect: (n) => a(n) })
  ] });
};
export {
  Q as C,
  U as S
};
