var mt = Object.defineProperty, pt = Object.defineProperties;
var ut = Object.getOwnPropertyDescriptors;
var Ie = Object.getOwnPropertySymbols;
var ft = Object.prototype.hasOwnProperty, xt = Object.prototype.propertyIsEnumerable;
var Se = (e, s, n) => s in e ? mt(e, s, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[s] = n, A = (e, s) => {
  for (var n in s || (s = {}))
    ft.call(s, n) && Se(e, n, s[n]);
  if (Ie)
    for (var n of Ie(s))
      xt.call(s, n) && Se(e, n, s[n]);
  return e;
}, U = (e, s) => pt(e, ut(s));
var z = (e, s, n) => new Promise((i, c) => {
  var r = (u) => {
    try {
      p(n.next(u));
    } catch (a) {
      c(a);
    }
  }, l = (u) => {
    try {
      p(n.throw(u));
    } catch (a) {
      c(a);
    }
  }, p = (u) => u.done ? i(u.value) : Promise.resolve(u.value).then(r, l);
  p((n = n.apply(e, s)).next());
});
import { jsxs as o, jsx as t, Fragment as P } from "react/jsx-runtime";
import _, { memo as Ne, useRef as ne, useEffect as j, useState as w, useLayoutEffect as ht, useMemo as ee, useCallback as te } from "react";
import { g as E, v as pe, h as N, P as y, Q as C, o as Ge, dX as gt, ad as se, s as J, e as q, U as be, dY as We, dZ as Nt, d_ as bt, d$ as vt, c2 as ue, e0 as He, V as ze, Z as Ct, _ as wt, c3 as yt, e1 as It, w as W, cG as xe, e2 as St, e3 as kt, e4 as Tt, e5 as Pt, e6 as Mt, a8 as Et, e7 as Dt, e8 as At, e9 as $e, ea as Bt, x as ae, eb as Ve, aa as $, ec as Lt, cE as Ke, cf as Ot, ed as ke, ee as Rt, ef as jt, eg as Ft, eh as qe, bN as Ut, ei as _t, ej as Gt, c7 as Wt, ek as Ht, el as zt, em as $t, bb as Vt, en as Kt, eo as Te, ep as qt, aB as Xt, cF as Zt, aF as he, ac as Xe, eq as Jt, aj as Ze, bB as O, er as Je, es as me, b2 as ve, L as Ce, I as Yt, et as Qt, b0 as en, eu as tn, ev as nn, ew as Pe, ex as sn, a9 as ln, al as Ye, ey as cn, ez as on, cX as ge, cY as an, eA as Qe, eB as rn, eC as dn, eD as mn, eE as Me, eF as pn, cg as Ee, eG as un, eH as fn, eI as xn, eJ as De, eK as hn, cK as Ae, eL as Be, bS as Le } from "./main-CxoAwMiG.js";
import { a as gn, u as Nn, $ as bn, k as vn, l as Cn, n as wn, D as B, C as yn, b as In, c as Sn } from "./helpers-DcTymofH.js";
import { S as kn, C as Tn } from "./SearchContactBox-B0sIw9AC.js";
import { A as ie, Z as et, p as K, f as le, L as G, n as de, u as tt, _ as Pn } from "./TalkLoading-CJtNYhDp.js";
import { C as Mn, u as nt } from "./unescapeHtml-ZZZvHhci.js";
import { i as En, C as Dn, D as An, Z as Bn, j as Ln, L as On, c as Rn, d as jn, k as Fn, F as Un, f as _n, l as Gn, e as Wn, S as Hn } from "./StartCall-BTU5dypV.js";
import { u as we } from "./useCopyToClipboard-DWdHcqke.js";
import { R as st, T as lt, P as it, C as ct, I as ot, u as ye } from "./useBreakpoint-Xy_wMP1Z.js";
import { A as zn } from "./AddContact-MhyucOkv.js";
import { A as Oe } from "./index-VlDs0kaJ.js";
import { I as $n } from "./ImageEditorModal-CCwTBVbA.js";
const ce = ({ title: e, onClose: s, showEdit: n, viewMode: i }) => {
  const c = E(), { isMobile: r } = pe(), { thread: l } = N((d) => d.threads), u = y(l).includes(C.P2P), a = () => {
    c(se(i));
  };
  return /* @__PURE__ */ o("div", { className: "flex flex-col", children: [
    /* @__PURE__ */ o("div", { className: "py-5 px-5 border-b bg-bgColor border-borderHead h-[60px] flex justify-between items-center", children: [
      /* @__PURE__ */ o("div", { className: "flex items-center gap-4", children: [
        /* @__PURE__ */ t("button", { className: "text-gray-500 text-xl", onClick: s, children: /* @__PURE__ */ t(Ge, { size: 22 }) }),
        /* @__PURE__ */ t("h2", { className: "text-sm text-secondary", children: e })
      ] }),
      n && (u || (l == null ? void 0 : l.admin)) && /* @__PURE__ */ t(
        "button",
        {
          disabled: l == null ? void 0 : l.closed,
          className: "text-accent disabled:text-iconSecondary disabled:cursor-not-allowed",
          onClick: a,
          children: /* @__PURE__ */ t(gt, {})
        }
      )
    ] }),
    r && /* @__PURE__ */ t(gn, {})
  ] });
}, Vn = ({
  onClick: e,
  disable: s
}) => /* @__PURE__ */ t(
  "button",
  {
    onClick: e,
    disabled: s,
    className: `${s ? "bg-[#707579]" : "bg-accent"} rounded-[4px] text-black w-full p-4 font-bold text-sm`,
    children: "افزودن"
  }
), Kn = ({
  selectedItems: e,
  onRemove: s
}) => {
  const n = ne(null), i = ne(0);
  if (j(() => {
    const c = n.current;
    if (!c)
      return;
    const r = e.length, l = i.current;
    r > l && c.scrollTo({
      top: c.scrollHeight,
      behavior: "smooth"
    }), i.current = r;
  }, [e]), !!e.length)
    return /* @__PURE__ */ t(
      "div",
      {
        ref: n,
        className: "bg-bgInput overflow-auto max-h-[150px] scroll-container   ",
        children: /* @__PURE__ */ t("div", { className: "flex flex-wrap gap-2   p-2", children: e.map((c) => {
          var l, p;
          const r = c.firstName ? c.firstName : (l = c.linkedUser) == null ? void 0 : l.name;
          return /* @__PURE__ */ o(
            "div",
            {
              className: "flex items-center gap-1  border border-gray-500 rounded-full px-1 py-1 text-xs",
              children: [
                /* @__PURE__ */ t(
                  ie,
                  {
                    firstName: r,
                    image: (p = c == null ? void 0 : c.linkedUser) == null ? void 0 : p.image,
                    size: "xxs"
                  }
                ),
                /* @__PURE__ */ t("span", { className: "text-secondary text-[10px]", children: r }),
                /* @__PURE__ */ t(
                  "button",
                  {
                    className: "text-closeIconAddToGroup",
                    onClick: () => s(c.id),
                    children: /* @__PURE__ */ t(Ge, {})
                  }
                )
              ]
            },
            c.id
          );
        }) })
      }
    );
}, qn = Ne(Kn), Xn = ({
  closeModal: e,
  open: s,
  onSubmit: n
}) => {
  const { theme: i } = Nn(), [c, r] = w(!1), [l, p] = w(null), { saturday: u, Sun: a, Mon: d, Tue: m, Wed: x, Thu: h, friday: f } = J, b = new bn();
  function I(g) {
    g || p(null), r(g);
  }
  return /* @__PURE__ */ o(
    q,
    {
      isDark: i === "dark",
      open: s,
      onOpenChange: e,
      title: /* @__PURE__ */ t("div", { className: "flex items-center justify-between p-4", children: /* @__PURE__ */ t("p", { className: "text-base font-bold text-text", children: "مشاهده پیام‌ها" }) }),
      size: "sm",
      titleStyle: "!mb-0",
      onConfirm: () => n(l),
      onCancel: e,
      confirmText: "تایید",
      cancelText: "انصراف",
      hasNotPadding: !0,
      children: [
        /* @__PURE__ */ t("p", { className: "text-invertBlackWhite text-[13px] p-2 pt-0 leading-7", children: "درصورتی که می‌خواهید نمایش پیام‌ها را محدود کنید، یک تاریخ انتخاب کنید، در غیر این‌صورت کاربر جدید همه پیام‌ها را مشاهده می‌کند." }),
        /* @__PURE__ */ t(be, { children: /* @__PURE__ */ o(
          "div",
          {
            onClick: () => I(!c),
            className: "flex items-center justify-between px-4 py-[9px] cursor-pointer hover:bg-bgHover border-b-2 border-divider",
            children: [
              /* @__PURE__ */ o("div", { className: "flex items-center gap-3", children: [
                /* @__PURE__ */ t("div", { className: "flex-shrink-0 text-menuIconColor", children: /* @__PURE__ */ t(Mn, { className: "w-5 h-5 text-gray-400 dark:text-gray-500" }) }),
                /* @__PURE__ */ t("p", { className: "text-[14px] font-bold text-invertBlackWhite", children: "نمایش براساس تاریخ" })
              ] }),
              /* @__PURE__ */ t("div", { className: "pointer-events-none", children: /* @__PURE__ */ t(We, { checked: c, onChange: () => {
              } }) })
            ]
          }
        ) }),
        /* @__PURE__ */ t(
          vn.Calendar,
          {
            disabled: !c,
            value: l,
            onChange: (g) => p(g),
            calendar: wn,
            locale: Cn,
            weekDays: [u, a, d, m, x, h, f],
            maxDate: b,
            numberOfMonths: 1,
            weekStartDayIndex: 0,
            highlightToday: !0,
            showOtherDays: !0,
            className: `${c ? "opacity-100" : "opacity-65"} orang rmdp-mobile w-full m-auto`
          },
          i
        )
      ]
    }
  );
}, Zn = () => {
  const e = E(), s = N((f) => f.threads.thread), n = () => e(se("threadInfo")), [i, c] = w([]), [r, l] = w(!1), p = (f) => {
    const I = i.some((g) => g.id === f.id) ? i.filter((g) => g.id !== f.id) : [...i, f];
    c(I);
  }, u = ne(null), [a, d] = w(0);
  ht(() => {
    u.current && d(u.current.clientHeight || 0);
  }, [i]), j(() => {
    e(Nt([]));
  }, []);
  const m = (f) => {
    c(
      (b) => b.filter((I) => String(I.id) !== String(f))
    );
  }, x = (f) => z(null, null, function* () {
    if (!(s != null && s.id))
      return;
    const b = i.map((g) => +g.id), I = i.map(
      (g) => {
        var S;
        return (S = g.linkedUser) == null ? void 0 : S.username;
      }
    );
    if (f) {
      const g = new Date(f.unix * 1e3);
      g.setHours(0, 0, 0, 0);
      const S = g.getTime();
      yield e(
        bt({
          threadId: s.id,
          contacts: I,
          selectedTime: S
        })
      );
    } else
      e(
        vt({
          threadId: s.id,
          contactIds: b
        })
      );
    n();
  });
  function h() {
    y(s).includes(C.PrivateGroup) ? l(!0) : x();
  }
  return /* @__PURE__ */ o("div", { className: "w-full h-full bg-bgColor", children: [
    /* @__PURE__ */ t(ce, { title: "افزودن اعضا", onClose: n }),
    /* @__PURE__ */ o("div", { className: " flex flex-col h-[calc(100dvh-60px)] xl2:h-[calc(100dvh-80px)]", children: [
      /* @__PURE__ */ t("div", { className: "flex-0", children: /* @__PURE__ */ t(kn, { showType: !1 }) }),
      /* @__PURE__ */ t("div", { ref: u, children: /* @__PURE__ */ t(
        qn,
        {
          onRemove: m,
          selectedItems: i
        }
      ) }),
      /* @__PURE__ */ t("div", { className: "flex-1 min-h-0  ", children: /* @__PURE__ */ t(
        Tn,
        {
          hiddenParticipant: !0,
          onSelect: p,
          selectable: !0,
          selectedItems: i,
          height: `calc(100dvh - ${195 + a}px)`
        }
      ) }),
      /* @__PURE__ */ t("div", { className: "py-3 px-4  z-10 bg-bgColor", children: /* @__PURE__ */ t(
        Vn,
        {
          disable: !i.length,
          onClick: h
        }
      ) }),
      /* @__PURE__ */ t(
        Xn,
        {
          closeModal: () => l(!1),
          onSubmit: x,
          open: r
        }
      )
    ] })
  ] });
}, at = ({ open: e, onClose: s, slides: n }) => /* @__PURE__ */ t(
  En,
  {
    open: e,
    carousel: {
      finite: !0
      // وقتی به آخر رسید، دکمه next غیرفعال می‌شه (ولی هنوز دیده می‌شه)
    },
    close: s,
    render: {
      iconPrev: () => /* @__PURE__ */ t("div", {}),
      iconNext: () => /* @__PURE__ */ t("div", {})
    },
    slides: n,
    captions: {
      // showToggle: true,
      descriptionTextAlign: "center",
      descriptionMaxLines: 2
    },
    plugins: [Dn, An, Bn]
  }
), Re = ({ thread: e }) => {
  var a, d;
  const [s, n] = _.useState(!1), i = e.lastParticipantName || e.lastParticipantLastName, c = e.id === ue && i ? `${e.lastParticipantName} ${e.lastParticipantLastName}` : e.title, r = (a = He(e == null ? void 0 : e.image)) == null ? void 0 : a.replace(
    "http://",
    "https://"
  ), l = et(r, "ACTUAL"), p = nt(c + ""), u = ee(
    () => K(p + "", {
      parentClassName: "overflow-hidden text-ellipsis whitespace-nowrap"
    }),
    [c]
  );
  return /* @__PURE__ */ o("div", { className: "p-4 flex items-center justify-center w-full flex-col bg-bgSpacer", children: [
    /* @__PURE__ */ o("div", { className: "mb-4", children: [
      /* @__PURE__ */ t(
        at,
        {
          open: s,
          onClose: () => n(!1),
          slides: [
            {
              src: l || "",
              description: /* @__PURE__ */ o("span", { children: [
                K(((d = e == null ? void 0 : e.title) == null ? void 0 : d.trim()) + "", {
                  parentClassName: "overflow-hidden text-ellipsis whitespace-nowrap"
                }),
                " "
              ] })
            }
          ]
        }
      ),
      /* @__PURE__ */ t(
        ie,
        {
          onClick: () => {
            e != null && e.image && n(!0);
          },
          size: "lg",
          firstName: c,
          image: e == null ? void 0 : e.image,
          inbox: (e == null ? void 0 : e.type) === ze.SELF
        }
      )
    ] }),
    /* @__PURE__ */ o("div", { className: "text-invertBlackWhite mb-[10px] text-[14px] flex items-center", children: [
      /* @__PURE__ */ o("span", { className: "text-center wordBreakBreakAll", children: [
        " ",
        u
      ] }),
      Ct(e) && /* @__PURE__ */ t("span", { children: wt() })
    ] }),
    /* @__PURE__ */ t("div", { className: "text-accent text-xs select-text ", children: J.lastSeen(yt.prettifySince(e == null ? void 0 : e.notSeenDuration)) })
  ] });
}, je = ({ thread: e }) => {
  var r, l, p;
  const [s, n] = _.useState(!1), i = (r = He(e == null ? void 0 : e.image)) == null ? void 0 : r.replace(
    "http://",
    "https://"
  ), c = et(i, "ACTUAL");
  if (e)
    return /* @__PURE__ */ o("div", { className: "flex items-center gap-3 px-4 py-[15px] bg-bgSpacer", children: [
      /* @__PURE__ */ t(
        at,
        {
          open: s,
          onClose: () => n(!1),
          slides: [
            {
              src: c || "",
              description: /* @__PURE__ */ o("span", { children: [
                K(((l = e == null ? void 0 : e.title) == null ? void 0 : l.trim()) + "", {
                  parentClassName: "overflow-hidden text-ellipsis whitespace-nowrap"
                }),
                " "
              ] })
            }
          ]
        }
      ),
      /* @__PURE__ */ t(
        ie,
        {
          onClick: () => {
            e != null && e.image && n(!0);
          },
          size: "md",
          firstName: e == null ? void 0 : e.title,
          image: e == null ? void 0 : e.image,
          inbox: (e == null ? void 0 : e.type) === ze.SELF
        }
      ),
      /* @__PURE__ */ o("div", { className: "font-bold text-sm text-text mb-[7px] select-text cursor-text  whitespace-pre-line leading-1 truncate w-full max-w-[350px]", children: [
        K(((p = e == null ? void 0 : e.title) == null ? void 0 : p.trim()) + "", {
          parentClassName: "overflow-hidden text-ellipsis select-text whitespace-nowrap"
        }),
        /* @__PURE__ */ o("div", { className: "text-xs py-1 text-secondary font-thin select-text", children: [
          e == null ? void 0 : e.participantCount,
          " عضو"
        ] })
      ] })
    ] });
}, Jn = () => {
  const [e, s] = w(null), { copyText: n } = we(), i = E(), c = N(
    (p) => p.threadParticipant.threadParticipants
  ), r = N((p) => p.threads.thread), l = c.find(
    (p) => p.id === (r == null ? void 0 : r.partner)
  );
  return j(() => {
    l != null && l.contactId && i(It(l.contactId)).unwrap().then((p) => {
      var u, a;
      (u = p.contacts[0]) != null && u.cellphoneNumber && s((a = p == null ? void 0 : p.contacts[0]) == null ? void 0 : a.cellphoneNumber);
    });
  }, [i, l == null ? void 0 : l.contactId]), e ? /* @__PURE__ */ o(P, { children: [
    /* @__PURE__ */ o(
      "div",
      {
        className: "p-2 cursor-pointer",
        onClick: () => n(e, "شماره همراه مورد نظر کپی شد"),
        children: [
          /* @__PURE__ */ t("div", { className: "text-xs mb-2 text-secondary", children: "شماره همراه" }),
          /* @__PURE__ */ t("div", { className: "text-sm text-text whitespace-pre-line leading-7", children: e })
        ]
      }
    ),
    /* @__PURE__ */ t(B, { height: "h-[0.75px]" })
  ] }) : null;
}, Yn = ({ thread: e }) => {
  var p, u;
  const [s, n] = w({ username: "", chatProfileVO: { bio: "" } }), i = !(e != null && e.uid), c = W();
  j(() => {
    e.id !== ue && c(
      xe({
        count: 26,
        offset: 0,
        threadId: e.id || 0
      })
    ).unwrap().then((a) => {
      const d = a.threadParticipants.find(
        (m) => m.id === e.partner || 0
      );
      d && n(d);
    });
  }, [e]);
  const { copyText: r } = we(), l = "https://" + window.location.host + (e == null ? void 0 : e.uid);
  return /* @__PURE__ */ o("div", { className: "bg-bgColor", children: [
    /* @__PURE__ */ o("div", { className: "flex items-center  w-full justify-between  ", children: [
      /* @__PURE__ */ o(
        "div",
        {
          className: "p-2 cursor-pointer",
          onClick: () => {
            r(
              (s == null ? void 0 : s.username) || (e == null ? void 0 : e.title),
              "نام کاربری مورد نظر کپی شد"
            );
          },
          children: [
            /* @__PURE__ */ t("div", { className: "text-xs mb-2 text-secondary ", children: "نام کاربری" }),
            /* @__PURE__ */ t("div", { className: "text-sm text-text select-text", children: (s == null ? void 0 : s.username) || (e == null ? void 0 : e.title) })
          ]
        }
      ),
      /* @__PURE__ */ t(
        le,
        {
          tooltipContent: i ? "برای دریافت لینک لطفا پیام بفرستید." : "",
          children: /* @__PURE__ */ t(
            "button",
            {
              disabled: i,
              onClick: () => !i && r(l, "لینک کاربر در تاک کپی شد"),
              className: `p-2 pl-[18px] ${i ? "cursor-not-allowed" : "cursor-pointer"}`,
              children: /* @__PURE__ */ t(
                "div",
                {
                  className: `text-xs text-white p-2 rounded-[10px] ${i ? "bg-gray-500" : "bg-accent"}`,
                  children: "لینک کاربر"
                }
              )
            }
          )
        }
      )
    ] }),
    /* @__PURE__ */ t(B, { height: "h-[0.75px]" }),
    /* @__PURE__ */ t(Jn, {}),
    (p = s == null ? void 0 : s.chatProfileVO) != null && p.bio ? /* @__PURE__ */ o("div", { className: "p-2", children: [
      /* @__PURE__ */ t("div", { className: "text-xs mb-2 text-secondary ", children: "درباره من" }),
      /* @__PURE__ */ t("div", { className: "text-sm text-text whitespace-pre-line leading-7 select-text", children: (u = s == null ? void 0 : s.chatProfileVO) == null ? void 0 : u.bio })
    ] }) : ""
  ] });
}, Fe = ({ thread: e }) => {
  var p, u;
  const { copyText: s } = we(), n = "https://" + window.location.host + "/join?tn=" + (e == null ? void 0 : e.uniqueName), i = "https://" + window.location.host + (e == null ? void 0 : e.uid), c = St(e), r = kt(e), l = Tt(e);
  return /* @__PURE__ */ o("div", { className: "bg-bgColor ", children: [
    /* @__PURE__ */ o("div", { className: "p-3", children: [
      /* @__PURE__ */ t("div", { className: "text-xs mb-3 text-secondary ", children: "توضیحات" }),
      /* @__PURE__ */ t("div", { className: "text-sm text-text whitespace-pre-line leading-7 select-text", children: (p = e == null ? void 0 : e.description) != null && p.trim() ? K(((u = e == null ? void 0 : e.description) == null ? void 0 : u.trim()) + "") : "بدون توضیحات!" })
    ] }),
    /* @__PURE__ */ t(B, { height: "h-[0.75px]" }),
    c && /* @__PURE__ */ o("div", { className: "p-3", children: [
      /* @__PURE__ */ t("div", { className: "text-xs mb-3 text-secondary min-w-0", children: "لینک دعوت" }),
      /* @__PURE__ */ t(
        "div",
        {
          dir: "ltr",
          className: "text-sm text-text cursor-pointer text-left truncate w-full",
          onClick: () => s(n, "لینک مورد نظر کپی شد"),
          children: n
        }
      )
    ] }),
    r && /* @__PURE__ */ o("div", { className: "p-3", children: [
      /* @__PURE__ */ t("div", { className: "text-xs mb-3 text-secondary min-w-0", children: `لینک ${l ? "گروه" : "کانال"} خصوصی` }),
      /* @__PURE__ */ t(
        "div",
        {
          dir: "ltr",
          className: "text-sm text-text cursor-pointer text-left truncate w-full",
          onClick: () => s(i, "لینک  کپی شد"),
          children: i
        }
      )
    ] })
  ] });
}, Qn = ({ thread: e }) => /* @__PURE__ */ o("div", { style: { boxShadow: "0 5px 10px rgba(0,0,0,0.1)" }, children: [
  y(e).includes("P2P") && /* @__PURE__ */ o("div", { className: "", children: [
    /* @__PURE__ */ t(Re, { thread: e }),
    /* @__PURE__ */ t(Yn, { thread: e })
  ] }),
  y(e).includes("SELF") && /* @__PURE__ */ t(Re, { thread: e }),
  y(e).includes("Channel") && /* @__PURE__ */ o("div", { className: "", children: [
    /* @__PURE__ */ t(je, { thread: e }),
    /* @__PURE__ */ t(Fe, { thread: e })
  ] }),
  y(e).includes("Group") && /* @__PURE__ */ o("div", { className: "", children: [
    /* @__PURE__ */ t(je, { thread: e }),
    /* @__PURE__ */ t(Fe, { thread: e })
  ] })
] }), es = ({ thread: e }) => {
  const s = E(), n = e != null && e.mute ? J.notificationOn : J.notificationOff;
  function i() {
    e && s(Et({ threadId: e.id, mute: !e.mute }));
  }
  return /* @__PURE__ */ t(le, { tooltipContent: n, children: /* @__PURE__ */ o(
    "button",
    {
      disabled: (e == null ? void 0 : e.closed) || !(e != null && e.id),
      className: "relative w-8 h-8 flex items-center justify-center text-accent disabled:text-iconSecondary disabled:cursor-not-allowed",
      onClick: i,
      children: [
        " ",
        e != null && e.mute ? /* @__PURE__ */ t(Pt, { className: "w-5 h-5" }) : /* @__PURE__ */ t(Mt, {})
      ]
    }
  ) });
}, ts = ({ thread: e }) => {
  const s = W(), [n, i] = w(!1);
  function c(r, l) {
    e && s(
      At({
        threadId: e.id,
        startTime: r,
        endTime: l
      })
    );
  }
  return /* @__PURE__ */ o(P, { children: [
    /* @__PURE__ */ t(
      yn,
      {
        isOpen: n,
        withTime: !1,
        range: !0,
        onClose: () => i(!1),
        onSelect: (r) => {
          typeof r == "object" && r !== null && "start" in r && "end" in r && c(r.start, r.end);
        }
      }
    ),
    /* @__PURE__ */ t(le, { tooltipContent: J.extractMessage, children: /* @__PURE__ */ t(
      "button",
      {
        disabled: e != null && e.group ? e == null ? void 0 : e.closed : !1,
        className: "text-accent disabled:text-iconSecondary disabled:cursor-not-allowed",
        onClick: () => i(!0),
        children: /* @__PURE__ */ t(Dt, {})
      }
    ) })
  ] });
}, ns = ({ thread: e }) => {
  const s = W();
  function n() {
    (e != null && e.admin || !(e != null && e.closed)) && e && s(Bt({ threadId: e.id }));
  }
  return /* @__PURE__ */ t(P, { children: /* @__PURE__ */ t(le, { tooltipContent: J.exportThreadParticipants, children: /* @__PURE__ */ t(
    "button",
    {
      disabled: !(e != null && e.admin) || (e == null ? void 0 : e.closed),
      className: "text-accent disabled:text-iconSecondary disabled:cursor-not-allowed",
      onClick: n,
      children: /* @__PURE__ */ t($e, {})
    }
  ) }) });
}, ss = ({ thread: e, open: s, setOpen: n }) => {
  const i = E(), c = ae(), r = () => z(null, null, function* () {
    if (e != null && e.id) {
      try {
        yield i(Ve({ threadId: e.id })).unwrap(), i($(!1)), c("/");
      } catch (a) {
        console.error("Failed to delete thread:", a);
      }
      n(!1);
    }
  }), l = y(e), p = () => {
    if (l.includes(C.Group))
      return "گروه";
    if (l.includes(C.Channel))
      return "کانال";
  }, u = K((e == null ? void 0 : e.title) + "", {
    parentClassName: "overflow-hidden   max-w-[200px]"
  });
  return /* @__PURE__ */ t(
    q,
    {
      confirmText: "حذف",
      cancelText: "انصراف",
      onConfirm: r,
      onCancel: () => n(!1),
      onOpenChange: n,
      size: "md",
      open: s,
      titleStyle: "font-normal mb-0 mt-2 text-invertBlackWhite",
      title: /* @__PURE__ */ o("span", { children: [
        "میخواهید ",
        p(),
        ' " ',
        u,
        ' " را حذف کنید؟'
      ] }),
      children: /* @__PURE__ */ t("p", { className: "mt-4 h-12 text-[13px] text-invertBlackWhite", children: ` بعد از حذف   ${p()}  دسترسی  برای تمام اعضا به این 
        ${p()} امکان پذیر نمی باشد.` })
    }
  );
}, ls = ({ thread: e, open: s, setOpen: n }) => {
  const i = E(), c = () => z(null, null, function* () {
    if (e != null && e.id)
      try {
        yield i(Lt({ threadId: e.id })).unwrap(), n(!1);
      } catch (r) {
        console.error("Failed to close thread:", r);
      }
  });
  return /* @__PURE__ */ t(P, { children: y(e).includes(C.Group) && /* @__PURE__ */ t(
    q,
    {
      confirmText: "بستن",
      cancelText: "انصراف",
      onConfirm: c,
      onCancel: () => n(!1),
      onOpenChange: n,
      size: "md",
      open: s,
      title: "آیا از بستن گروه مطمئن هستید؟",
      children: /* @__PURE__ */ t("p", { className: "mt-8 h-12 text-invertBlackWhite", children: "امکان فعالیت در گروه وجود ندارد ولی تاریخچه گفتگو همچنان در دسترس خواهد بود." })
    }
  ) });
}, is = ({ thread: e, open: s, setOpen: n }) => {
  const i = E(), c = ae(), r = () => z(null, null, function* () {
    if (e != null && e.id)
      try {
        yield i(Ke({ threadId: e.id })).unwrap(), c("/", { replace: !0 }), n(!1);
      } catch (l) {
        console.error("Failed to leave thread:", l);
      }
  });
  return /* @__PURE__ */ t(P, { children: y(e).includes(C.P2P) && /* @__PURE__ */ t(
    q,
    {
      confirmText: "حذف",
      cancelText: "انصراف",
      onConfirm: r,
      onCancel: () => n(!1),
      onOpenChange: n,
      size: "md",
      open: s,
      title: " آیا از پاک کردن  این گفتگو اطمینان دارید ",
      children: /* @__PURE__ */ t("p", { className: "mt-8 h-12 text-invertBlackWhite", children: "تمامی تاریخچه گفتگو برای شما پاک میشود" })
    }
  ) });
}, cs = ({
  thread: e,
  participantId: s,
  blocked: n,
  open: i,
  setOpen: c
}) => {
  const r = W(), l = () => {
    r(
      Ot({
        id: s,
        block: !n,
        withBlockId: !1
      })
    ), c(!1);
  };
  return /* @__PURE__ */ t(P, { children: y(e).includes(C.P2P) && /* @__PURE__ */ t(
    q,
    {
      confirmText: "قبول",
      cancelText: "انصراف",
      onConfirm: l,
      onCancel: () => c(!1),
      onOpenChange: c,
      size: "md",
      open: i,
      title: "از انجام این کار اطمینان دارید؟"
    }
  ) });
}, os = ({ thread: e }) => {
  const s = ee(() => y(e), [e]), n = s.includes(C.SELF), c = N(
    (f) => f.threadParticipant.threadParticipants
  ).find(
    (f) => f.id === (e == null ? void 0 : e.partner) || 0
  ), r = ee(() => {
    const f = !!(e != null && e.closed), b = !!(e != null && e.group), I = !!(e != null && e.admin);
    return !n && !f && (!b || I);
  }, [e, n]), [l, p] = w(!1), [u, a] = w(null), d = te((f) => {
    p(!1), a(f);
  }, []), m = te(() => a(null), []), x = c == null ? void 0 : c.blocked, h = ee(
    () => [
      {
        title: "حذف گفتگو",
        type: C.P2P,
        onSelect: () => d("deleteP2P")
      },
      {
        title: x ? "رفع مسدود سازی" : "مسدودسازی",
        type: C.P2P,
        onSelect: () => d("blockP2P")
      },
      {
        title: "حذف گروه",
        type: C.Group,
        onSelect: () => d("deleteGroup")
      },
      {
        title: "بستن گروه",
        type: C.Group,
        onSelect: () => d("closeGroup")
      },
      {
        title: "حذف کانال",
        type: C.Channel,
        onSelect: () => d("deleteGroup")
      }
    ],
    [d, c]
  );
  return r ? /* @__PURE__ */ o(P, { children: [
    u === "deleteGroup" && /* @__PURE__ */ t(ss, { thread: e, open: !0, setOpen: m }),
    u === "closeGroup" && /* @__PURE__ */ t(ls, { thread: e, open: !0, setOpen: m }),
    u === "deleteP2P" && /* @__PURE__ */ t(is, { thread: e, open: !0, setOpen: m }),
    u === "blockP2P" && /* @__PURE__ */ t(
      cs,
      {
        blocked: (c == null ? void 0 : c.blocked) || !1,
        participantId: (c == null ? void 0 : c.id) || 0,
        thread: e,
        open: !0,
        setOpen: m
      }
    ),
    /* @__PURE__ */ o(
      st,
      {
        dir: "rtl",
        open: l,
        onOpenChange: p,
        children: [
          /* @__PURE__ */ t(lt, { className: "flex gap-1 items-center text-accent outline-none", children: /* @__PURE__ */ t(ke, {}) }),
          /* @__PURE__ */ t(it, { children: /* @__PURE__ */ t(
            ct,
            {
              onPointerDown: (f) => f.preventDefault(),
              className: "bg-bgColor shadow-dropDown rounded-[12px] text-right p-3 w-[150px] z-chatDropDown",
              sideOffset: 8,
              align: "end",
              side: "bottom",
              children: h.filter((f) => s.includes(f.type)).map((f) => /* @__PURE__ */ t(
                ot,
                {
                  onSelect: (b) => {
                    b.preventDefault(), f.onSelect();
                  },
                  className: "text-sm hover:text-accent rounded cursor-pointer text-text flex items-center py-3 outline-none",
                  children: f.title
                },
                f.title
              ))
            }
          ) })
        ]
      }
    )
  ] }) : /* @__PURE__ */ t("div", { className: "flex gap-1 items-center text-iconSecondary  cursor-not-allowed ", children: /* @__PURE__ */ t(ke, {}) });
}, as = ({ thread: e }) => {
  const [s, n] = _.useState(!1), [i, c] = _.useState(!1), l = N(
    (f) => f.threadParticipant.threadParticipants
  ).find(
    (f) => f.id === (e == null ? void 0 : e.partner) || 0
  ), u = y(e).includes(C.P2P), a = () => {
    n(!0);
  }, d = () => {
    c(!0);
  }, m = W(), x = () => {
    m(
      Ft({ id: (l == null ? void 0 : l.contactId) || (e == null ? void 0 : e.contactId) })
    ).unwrap().then((f) => {
      f.hasError || (m(
        qe({
          new_data: {
            coreUserId: l == null ? void 0 : l.coreUserId,
            contactId: 0
          }
        })
      ), m(
        Ut({
          threadId: e == null ? void 0 : e.id,
          newData: { contactId: 0 }
        })
      ), n(!1));
    });
  }, h = (l == null ? void 0 : l.contactId) || (e == null ? void 0 : e.contactId);
  return /* @__PURE__ */ t(P, { children: u && /* @__PURE__ */ t("div", { children: h ? /* @__PURE__ */ o(P, { children: [
    /* @__PURE__ */ t(le, { tooltipContent: "حذف مخاطب", children: /* @__PURE__ */ t(
      "button",
      {
        className: "flex items-center text-accent",
        onClick: a,
        children: /* @__PURE__ */ t(Rt, {})
      }
    ) }),
    /* @__PURE__ */ t(
      q,
      {
        confirmText: "حذف",
        cancelText: "انصراف",
        onConfirm: x,
        onCancel: () => n(!1),
        onOpenChange: n,
        size: "md",
        open: s,
        description: /* @__PURE__ */ t("p", { className: "font-bold text-invertBlackWhite", children: `میخواهید "${e == null ? void 0 : e.title}" را از لیست مخاطبینتان حذف کنید؟` }),
        children: /* @__PURE__ */ t("p", {})
      }
    )
  ] }) : /* @__PURE__ */ o(P, { children: [
    /* @__PURE__ */ t(le, { tooltipContent: "اضافه کردن مخاطب", children: /* @__PURE__ */ t(
      "button",
      {
        className: "flex items-center text-accent",
        onClick: d,
        children: /* @__PURE__ */ t(jt, {})
      }
    ) }),
    /* @__PURE__ */ t(
      zn,
      {
        init: {
          firstName: (l == null ? void 0 : l.firstName) || (e == null ? void 0 : e.lastParticipantName) || "",
          lastName: (l == null ? void 0 : l.lastName) || (e == null ? void 0 : e.lastParticipantLastName) || "",
          username: (l == null ? void 0 : l.username) || (e == null ? void 0 : e.title) || ""
        },
        open: i,
        setOpen: c
      }
    )
  ] }) }) });
}, fe = (e) => y(e).includes(C.Channel) ? "کانال" : "گروه", rs = ({ thread: e }) => {
  const [s, n] = _.useState(!1), i = W(), c = ae(), r = N(
    (x) => x.threadParticipant.threadParticipants
  ), l = ee(() => !(e != null && e.admin) || !(e != null && e.id) ? !1 : r.filter(
    (h) => h.threadId === e.id && h.admin
  ).length === 1, [e == null ? void 0 : e.admin, e == null ? void 0 : e.id, r]), p = y(e), u = () => {
    n((x) => !x);
  }, a = {
    width: "20px",
    height: "20px"
    // cursor: thread?.closed ? "not-allowed" : "pointer"
  }, d = () => z(null, null, function* () {
    if (e != null && e.id)
      try {
        yield i(Ke({ threadId: e.id })).unwrap(), n(!1), c("/");
      } catch (x) {
        console.error("Failed to leave thread:", x);
      }
  }), m = K((e == null ? void 0 : e.title) + "", {
    parentClassName: "overflow-hidden   max-w-[200px]"
  });
  return /* @__PURE__ */ t("div", { children: /* @__PURE__ */ o("div", { children: [
    /* @__PURE__ */ t(
      le,
      {
        tooltipContent: p.includes(C.Channel) ? J.leaveChannel : J.leaveGroup,
        children: /* @__PURE__ */ t(
          "button",
          {
            disabled: e == null ? void 0 : e.closed,
            onClick: u,
            className: "flex items-center disabled:text-iconSecondary disabled:cursor-not-allowed",
            children: /* @__PURE__ */ t(
              _t,
              {
                style: a,
                fill: `${e != null && e.closed ? "var(--icon-secondary)" : "var(--orange)"}`
              }
            )
          }
        )
      }
    ),
    /* @__PURE__ */ t(
      q,
      {
        confirmText: "ترک",
        cancelText: l ? /* @__PURE__ */ t("span", { className: "text-accent", children: "متوجه شدم" }) : "انصراف",
        onConfirm: l ? void 0 : d,
        onCancel: () => n(!1),
        onOpenChange: n,
        size: "md",
        open: s,
        title: l ? null : /* @__PURE__ */ o("span", { children: [
          " ",
          "میخواهید ",
          fe(e),
          ' " ',
          m,
          ' " را ترک کنید؟',
          " "
        ] }),
        children: /* @__PURE__ */ t(
          "p",
          {
            className: `h-12 text-invertBlackWhite leading-6 ${!l && "mt-8"}`,
            children: l ? "شما تنها ادمین کانال هستید و امکان ترک کانال برای شما نیست . برای ترک کانال ، نیاز به ارتقای حداقل یکی از اعضا به ادمین میباشد . " : ` بعد از ترک ${fe(e)}
          دسترسی به پیام های این    ${fe(e)} برای شما امکان پذیر نمی باشد.`
          }
        )
      }
    )
  ] }) });
}, ds = ({ thread: e }) => {
  const n = y(e).includes(C.P2P);
  return /* @__PURE__ */ t(P, { children: n ? /* @__PURE__ */ t(Gt, {}) : /* @__PURE__ */ o(P, { children: [
    /* @__PURE__ */ t("span", { className: "text-iconSecondary", children: /* @__PURE__ */ t(Wt, {}) }),
    /* @__PURE__ */ t(Ht, { stroke: "var(--icon-secondary)" })
  ] }) });
}, ms = ({ thread: e }) => {
  const n = y(e).includes(C.P2P);
  return /* @__PURE__ */ o("div", { className: "flex align-center items-center gap-2 py-7   justify-evenly bg-bgColor shadow-sm", children: [
    e != null && e.group ? /* @__PURE__ */ t(rs, { thread: e }) : /* @__PURE__ */ t(as, { thread: e }),
    !n && !(e != null && e.group) && /* @__PURE__ */ t("span", { className: "text-iconSecondary", children: /* @__PURE__ */ t(zt, { height: "24", width: "24" }) }),
    ((e == null ? void 0 : e.group) || n) && /* @__PURE__ */ t(es, { thread: e }),
    /* @__PURE__ */ t(ts, { thread: e }),
    e != null && e.group ? null : /* @__PURE__ */ t(ds, { thread: e }),
    (e == null ? void 0 : e.group) && /* @__PURE__ */ t(ns, { thread: e }),
    /* @__PURE__ */ t(os, { thread: e })
  ] });
}, ps = ({
  admin: e,
  isGroup: s,
  threadId: n,
  participantId: i,
  participantName: c
}) => {
  const r = E(), [l, p] = w(!1), u = [
    e ? {
      title: "برکناری از مدیریت",
      icon: /* @__PURE__ */ t(Te, {}),
      onClick: () => {
        r(qt({ threadId: n, userId: i }));
      }
    } : {
      title: "ارتقا به مدیریت",
      icon: /* @__PURE__ */ t(Te, {}),
      onClick: () => {
        r(Kt({ threadId: n, userId: i }));
      }
    },
    {
      title: s ? "حذف از گروه" : "حذف از کانال",
      icon: /* @__PURE__ */ t(Xt, {}),
      onClick: () => {
        p(!0);
      }
    }
  ], a = K(c + "", {
    parentClassName: "overflow-hidden   max-w-[200px]"
  });
  return /* @__PURE__ */ o(P, { children: [
    /* @__PURE__ */ t(
      q,
      {
        open: l,
        onOpenChange: p,
        title: s ? "حذف از گروه" : "حذف از کانال",
        description: /* @__PURE__ */ o("span", { children: [
          "می خواهید « ",
          a,
          "» از ",
          s ? "گروه" : "کانال",
          " حذف کنید؟"
        ] }),
        onConfirm: () => r(
          $t({ threadId: n, participantIds: [i] })
        ),
        onCancel: () => p(!1),
        confirmText: "حذف",
        cancelText: "انصراف",
        closable: !0,
        size: "xs"
      }
    ),
    /* @__PURE__ */ o(st, { dir: "rtl", children: [
      /* @__PURE__ */ t(lt, { children: /* @__PURE__ */ t("div", { className: "text-textGrayColor  w-5 h-5 flex justify-center items-center", children: /* @__PURE__ */ t(Vt, { width: "6", height: "18" }) }) }),
      /* @__PURE__ */ t(it, { children: /* @__PURE__ */ t(
        ct,
        {
          side: "bottom",
          align: "end",
          sideOffset: 4,
          onPointerDown: (d) => d.stopPropagation(),
          className: "bg-bgColor w-52 shadow-dropDown rounded-[12px] text-right  px-3 py-2 z-chatDropDown",
          children: /* @__PURE__ */ t("div", { className: "px-[2px]", children: u.map((d, m) => /* @__PURE__ */ t(
            "div",
            {
              className: "flex items-center py-3 ",
              children: /* @__PURE__ */ t(
                ot,
                {
                  className: "text-sm hover:text-accent rounded cursor-pointer text-text",
                  onSelect: d.onClick,
                  children: /* @__PURE__ */ o("div", { className: "flex justify-center items-center w-full h-full gap-2", children: [
                    /* @__PURE__ */ t("span", { className: "text-gray-400", children: d.icon }),
                    /* @__PURE__ */ t("span", { children: d.title })
                  ] })
                },
                m
              )
            },
            m + "admin-drop-down"
          )) })
        }
      ) })
    ] })
  ] });
}, us = ({
  admin: e,
  threadId: s,
  searchQuery: n,
  searchType: i
}) => {
  const { xxl: c } = ye(), r = ae(), { threadParticipants: l, nextOffset: p, hasNext: u, loading: a, loadingFromDown: d } = N((D) => D.threadParticipant), { thread: m, threads: x } = N(
    (D) => D.threads
  ), h = y(m).includes(C.Group), f = E();
  j(() => {
    if (f(Zt()), m != null && m.group && !(m != null && m.closed)) {
      const D = (n == null ? void 0 : n.trim()) || null;
      f(
        xe({
          count: 25,
          offset: 0,
          threadId: m.id,
          name: D
        })
      );
    }
  }, [
    n,
    m == null ? void 0 : m.id,
    m == null ? void 0 : m.group,
    m == null ? void 0 : m.closed,
    f
  ]);
  const b = () => {
    if (u) {
      const D = (n == null ? void 0 : n.trim()) || null;
      f(
        xe({
          count: 25,
          offset: p,
          threadId: (m == null ? void 0 : m.id) || 0,
          name: D
        })
      );
    }
  }, { openOrCreateThread: I } = In(), g = (D) => z(null, null, function* () {
    const {
      coreUserId: k,
      username: Y,
      contactId: V,
      firstName: v,
      lastName: L,
      notSeenDuration: Q,
      image: re,
      id: X
    } = D;
    if (he() === X)
      return;
    const Z = x.find((T) => T.partner === X);
    if (Z)
      return f($(!1)), (Z == null ? void 0 : Z.id) === (m == null ? void 0 : m.id) ? void 0 : (r("/thread", { replace: !1 }), f(Xe(Z)));
    yield I({
      coreUserId: k,
      username: Y,
      participantInfo: { firstName: v, lastName: L, notSeenDuration: Q, image: re, id: X },
      contactId: V
    });
  });
  if (m != null && m.closed)
    return /* @__PURE__ */ t("div", { className: "bg-bgColor text-iconColor  flex  ", children: /* @__PURE__ */ t("p", { className: "text-center w-full mt-[14px] text-[14px]", children: "این گروه توسط مدیر بسته شده است." }) });
  if (a)
    return /* @__PURE__ */ t("div", { className: "bg-bgColor text-text relative w-full overflow-hidden     ", children: /* @__PURE__ */ t("div", { className: "h-[50px] flex justify-center", children: /* @__PURE__ */ t(G, {}) }) });
  if (!a && l.length === 0)
    return /* @__PURE__ */ t("div", { className: "bg-bgColor text-text relative w-full overflow-hidden    ", children: /* @__PURE__ */ t("p", { className: "text-center p-[10px] text-[14px]", children: "نتیجه ای وجود ندارد" }) });
  const S = e ? 63 : 0, M = `calc(100vh - ${c ? 183 + S : 163 + S}px)`;
  return /* @__PURE__ */ t("div", { className: "bg-bgColor text-text", children: /* @__PURE__ */ t(
    de,
    {
      data: l,
      className: "scrollbar-hidden ",
      overscan: 100,
      endReached: b,
      style: {
        height: M,
        direction: "rtl"
      },
      totalCount: l.length,
      components: {
        Footer: () => d && /* @__PURE__ */ t("div", { className: "flex justify-center items-center space-x-2 space-x-reverse p-3 ", children: /* @__PURE__ */ t(G, {}) })
      },
      itemContent: (D, k) => {
        var v;
        const Y = ((v = m == null ? void 0 : m.inviter) == null ? void 0 : v.id) !== k.id && k.id !== he() && (m == null ? void 0 : m.admin), V = (k == null ? void 0 : k.contactName) || (k == null ? void 0 : k.name);
        return /* @__PURE__ */ t(be, { children: /* @__PURE__ */ o(
          "div",
          {
            onClick: (L) => {
              L.preventDefault(), g(k);
            },
            className: "flex items-center justify-between pl-3  cursor-pointer hover:bg-bgHover",
            children: [
              /* @__PURE__ */ o("div", { className: "flex-1 min-w-0 flex items-center space-x-2 space-x-reverse p-3", children: [
                /* @__PURE__ */ t(
                  ie,
                  {
                    size: "sm",
                    firstName: V,
                    image: k.image
                  }
                ),
                /* @__PURE__ */ t("div", { className: "text-sm font-bold overflow-hidden text-ellipsis whitespace-nowrap", children: V })
              ] }),
              /* @__PURE__ */ o(
                "div",
                {
                  className: "flex items-center space-x-2 space-x-reverse p-3",
                  onClick: (L) => {
                    L.stopPropagation();
                  },
                  children: [
                    k.admin && /* @__PURE__ */ t("div", { className: "text-xs text-accent font-semibold", children: "مدیر" }),
                    /* @__PURE__ */ t("div", { className: "w-4", children: Y && /* @__PURE__ */ t(
                      ps,
                      {
                        admin: k.admin,
                        isGroup: h,
                        threadId: s,
                        participantId: k.id,
                        participantName: V
                      }
                    ) })
                  ]
                }
              )
            ]
          },
          D
        ) });
      }
    }
  ) });
}, fs = () => {
  const e = E(), s = N((c) => c.threads), { thread: n } = s, i = () => {
    e(se("chooseMemberBox"));
  };
  return /* @__PURE__ */ o(
    "button",
    {
      disabled: n == null ? void 0 : n.closed,
      className: "p-4 text-accent bg-bgColor flex gap-2 items-center cursor-pointer disabled:text-iconSecondary",
      onClick: i,
      children: [
        /* @__PURE__ */ t(
          Jt,
          {
            stroke: "currenColor",
            style: {
              // color: thread?.closed ? "gray-100" : "orange-500"
            }
          }
        ),
        /* @__PURE__ */ t("span", { className: "text-[14px]", children: "افزودن اعضا" })
      ]
    }
  );
}, xs = ({ thread: e }) => {
  const [s, n] = w(""), [i, c] = w("name"), r = tt((u) => {
    n(u);
  }, 500), l = (u) => {
    r(u);
  };
  return N(
    (u) => u.setting.showThreadInfo,
    Ze
  ) ? /* @__PURE__ */ o("div", { className: "flex-1 overflow-y-auto scroll-container", children: [
    /* @__PURE__ */ o("div", { children: [
      /* @__PURE__ */ t(
        Ln,
        {
          showSelect: !0,
          handleChange: l,
          searchType: i,
          onSearchTypeChange: c
        }
      ),
      (e == null ? void 0 : e.admin) && /* @__PURE__ */ o(P, { children: [
        /* @__PURE__ */ t(fs, {}),
        /* @__PURE__ */ t(B, {})
      ] })
    ] }),
    /* @__PURE__ */ t(
      us,
      {
        admin: e == null ? void 0 : e.admin,
        threadId: (e == null ? void 0 : e.id) || 0,
        searchQuery: s,
        searchType: i
      }
    )
  ] }) : null;
}, hs = ({
  threadId: e,
  isArchiveThread: s
}) => {
  const n = E(), i = O.POD_SPACE_PICTURE, { isMobile: c } = pe(), r = ae(), {
    messages: l = [],
    nextOffset: p = 0,
    hasNext: u = !1,
    loading: a = !1,
    loadingFromDown: d = !1
  } = N(
    (g) => g.filteredHistory[i] || {}
  ), [m, x] = w(0);
  j(() => {
    n(Je({ messageType: i })), n(
      me({
        count: 30,
        offset: p != null ? p : 0,
        threadId: e,
        messageType: i
      })
    );
  }, [n, i, e]);
  const h = () => {
    u && n(
      me({
        count: 21,
        offset: l.length,
        threadId: e,
        messageType: i
      })
    );
  }, f = (g) => {
    const S = l.findIndex((M) => M.id === g.id);
    S >= 0 && (x(S), r(s ? "/folders?thread&slider" : "/thread?slider", { replace: !1 }));
  };
  if (!a && l.length === 0)
    return /* @__PURE__ */ t("div", { className: "flex h-[calc(100dvh-100px)] justify-center items-start text-center w-full gap-2 p-4 text-invertBlackWhite", children: "نتیجه‌ای وجود ندارد" });
  const b = (g) => g ? /* @__PURE__ */ t(
    "img",
    {
      src: g,
      alt: "",
      style: { boxShadow: "rgba(0,0,0,.24) 0px 3px 8px" },
      className: "w-full aspect-square object-cover rounded-xl shadow-xl cursor-pointer"
    }
  ) : /* @__PURE__ */ t(
    "div",
    {
      className: "w-full aspect-square rounded-xl shadow-xl",
      style: { background: "#eee" }
    }
  ), I = new URLSearchParams(location.search);
  return /* @__PURE__ */ o(P, { children: [
    /* @__PURE__ */ t(
      On,
      {
        onGo: (g) => {
          c && n($(!1)), ve(n, e, g);
        },
        onEndReached: () => {
          h();
        },
        setCurrentIndex: x,
        open: I.has("slider"),
        index: m,
        onClose: () => r(-1),
        slides: l
      }
    ),
    /* @__PURE__ */ t(
      Pn,
      {
        endReached: h,
        totalCount: l.length,
        data: l,
        overscan: 100,
        style: {
          // height: `calc(100dvh - ${xxl ? "145" : "125"}px)`,
          direction: "rtl"
        },
        listClassName: "grid grid-cols-3 gap-3 p-3 my-3 ",
        className: "scroll-container  scrollbar-hidden",
        components: {
          Footer: () => d && /* @__PURE__ */ t("div", { className: "flex justify-center items-center space-x-2 space-x-reverse p-3 ", children: /* @__PURE__ */ t(G, {}) })
        },
        itemContent: (g, S) => /* @__PURE__ */ o(
          "div",
          {
            className: "relative group cursor-pointer overflow-hidden rounded-xl",
            onClick: () => f(S),
            children: [
              /* @__PURE__ */ t(
                Rn,
                {
                  size: "SMALL",
                  item: { id: S.id, metadata: S.metadata },
                  children: (M) => b(M)
                }
              ),
              /* @__PURE__ */ t(
                "div",
                {
                  className: `text-center absolute bottom-0 left-0 w-full bg-invertWhiteBlack text-invertBlackWhite text-xs px-2 py-1
               opacity-0 group-hover:bg-invertWhiteBlack group-hover:opacity-60  transition-opacity duration-200 `,
                  children: Ce(S.time, "fa", !1)
                }
              )
            ]
          }
        )
      }
    )
  ] });
}, gs = ({ message: e }) => {
  var r;
  const s = N((l) => l.threads.thread), { currentUser: n } = N((l) => l.chat), i = e.participant.id === (n == null ? void 0 : n.id), c = Yt({
    lastMessageVO: e,
    user: i,
    thread: s,
    isGroup: (s == null ? void 0 : s.group) || !1
  });
  return ((r = e.callHistory) == null ? void 0 : r.status) === 0 || !e.callHistory ? null : /* @__PURE__ */ o(
    "li",
    {
      className: "flex items-center justify-between  border-b-[1px] border-divider px-1 py-3 bg-bgColor text-sm rtl text-invertBlackWhite",
      children: [
        /* @__PURE__ */ o("div", { className: "flex items-center gap-2", children: [
          c == null ? void 0 : c.Icon2(),
          /* @__PURE__ */ t("span", { className: "text-xs", children: c == null ? void 0 : c.Text() })
        ] }),
        /* @__PURE__ */ t(jn, { className: "text-green-500", children: /* @__PURE__ */ t(Qt, { size: 20 }) })
      ]
    },
    e == null ? void 0 : e.id
  );
};
function Ns(e) {
  return en({ attr: { viewBox: "0 0 448 512" }, child: [{ tag: "path", attr: { d: "M424.4 214.7L72.4 6.6C43.8-10.3 0 6.1 0 47.9V464c0 37.5 40.7 60.1 72.4 41.3l352-208c31.4-18.5 31.5-64.1 0-82.6z" }, child: [] }] })(e);
}
const bs = ({ item: e, isFile: s, onSelect: n, onIconClick: i }) => {
  const c = JSON.parse(e.metadata);
  return /* @__PURE__ */ o(P, { children: [
    /* @__PURE__ */ o(
      "div",
      {
        className: "flex items-center gap-3 p-4 hover:bg-bgHover cursor-pointer transition text-invertBlackWhite",
        onClick: n,
        children: [
          /* @__PURE__ */ t("div", { className: "text-accent w-[40px]", onClick: i, children: /* @__PURE__ */ t("span", { className: "w-[36px] h-[36px] rounded-full bg-accent flex justify-center items-center !text-white", children: s ? /* @__PURE__ */ t(Fn, { size: 24 }) : /* @__PURE__ */ t(Ns, { size: 15 }) }) }),
          /* @__PURE__ */ o("div", { className: "w-[calc(100%-40px)]", children: [
            /* @__PURE__ */ t(Un, { file: c.file, textFromLeft: !1 }),
            /* @__PURE__ */ o("div", { className: "text-[10px] text-gray-500 flex gap-1 ", children: [
              _n(c.file.size),
              /* @__PURE__ */ t("span", { style: { direction: "ltr" }, children: Ce(e.time, "fa", !0) })
            ] })
          ] })
        ]
      }
    ),
    /* @__PURE__ */ t(B, { height: "h-[0.75px]", bg: "bg-divider" })
  ] });
}, vs = ({ message: e, onItemClick: s }) => {
  const n = e.message.match(tn);
  if (n)
    return n == null ? void 0 : n.map((i) => /* @__PURE__ */ o(P, { children: [
      /* @__PURE__ */ o(
        "div",
        {
          onClick: () => s(e.time),
          className: "flex items-center gap-2 p-4 cursor-pointer",
          children: [
            /* @__PURE__ */ t("span", { className: "bg-accent p-1 rounded-md ", children: /* @__PURE__ */ t(nn, {}) }),
            /* @__PURE__ */ t(
              "div",
              {
                className: "w-[calc(100%-40px)] text-xs font-bold truncate text-invertBlackWhite  ",
                dir: "ltr",
                children: i
              }
            )
          ]
        }
      ),
      /* @__PURE__ */ t(B, { height: "h-[0.75px]", bg: "bg-divider" })
    ] }));
}, oe = ({ messageType: e, isFile: s, threadId: n }) => {
  const { isMobile: i } = pe(), { xxl: c } = ye(), r = E(), { messages: l, nextOffset: p, hasNext: u, loading: a, loadingFromDown: d } = N((h) => h.filteredHistory[e] || {});
  j(() => {
    r(Je({ messageType: e })), r(
      me({
        count: 30,
        offset: p,
        threadId: n,
        messageType: e
      })
    );
  }, [e]);
  const m = () => {
    u && r(
      me({
        count: 21,
        offset: l.length,
        threadId: n,
        messageType: e
      })
    );
  }, x = (h, f) => {
    i && r($(!1)), ve(r, n, h, !0, !!f);
  };
  return a ? /* @__PURE__ */ t("div", { className: "bg-bgColor text-text relative w-full overflow-hidden h-[calc(100dvh-100px)]     ", children: /* @__PURE__ */ t("div", { className: "h-[50px] flex justify-center", children: /* @__PURE__ */ t(G, {}) }) }) : !a && l.length === 0 ? /* @__PURE__ */ t("div", { className: "bg-bgColor text-text relative mt-4 w-full overflow-hidden h-[calc(100dvh-100px)]    ", children: /* @__PURE__ */ t("p", { className: "text-center p-[10px] text-[14px]", children: "نتیجه ای وجود ندارد" }) }) : /* @__PURE__ */ t("div", { className: "flex flex-col", style: { height: "100%" }, children: /* @__PURE__ */ t(
    de,
    {
      endReached: m,
      style: {
        height: `calc(100vh - ${c ? 130 : 110}px)`,
        direction: "rtl"
      },
      totalCount: l.length,
      data: l,
      overscan: 100,
      className: "scroll-container",
      components: { Footer: () => d && /* @__PURE__ */ t(G, {}) },
      itemContent: (h, f) => {
        switch (e) {
          case O.POD_SPACE_VIDEO:
          case O.POD_SPACE_SOUND:
          case O.POD_SPACE_VOICE:
          case O.POD_SPACE_FILE:
            return /* @__PURE__ */ t(
              bs,
              {
                isFile: !!s,
                item: f,
                onSelect: () => x(f.time),
                onIconClick: (b) => {
                  b.stopPropagation(), x(f.time, !0);
                }
              }
            );
          case O.LINK:
            return /* @__PURE__ */ t(vs, { message: f, onItemClick: x });
          case O.END_CALL:
            return /* @__PURE__ */ t(gs, { message: f });
        }
      }
    }
  ) });
}, Cs = () => {
  const e = E(), s = ae(), { mutualGroups: n, hasNext: i, loading: c, loadingFromDown: r } = N(
    (x) => x.mutualGroup
  ), l = N(
    (x) => x.threadParticipant.threadParticipants
  ), p = N((x) => x.threads.thread), u = N((x) => x.threads.threads), a = l.find(
    (x) => x.id === (p == null ? void 0 : p.partner) || 0
  );
  j(() => {
    if (a != null && a.username)
      return e(
        Pe({
          id: a == null ? void 0 : a.username,
          idType: "TO_BE_USER_USERNAME",
          count: 30,
          offset: 0
        })
      ), () => {
        e(sn());
      };
  }, [a == null ? void 0 : a.username]);
  const d = () => {
    i && (a != null && a.username) && e(
      Pe({
        id: a == null ? void 0 : a.username,
        idType: "TO_BE_USER_USERNAME",
        count: 30,
        offset: n.length
      })
    );
  }, m = (x) => z(null, null, function* () {
    e($(!1));
    let h = u.find((f) => f.id === x.id);
    h || (h = (yield e(
      ln({
        archived: null,
        count: 50,
        offset: 0,
        threadIds: [x.id]
      })
    )).payload[0]), s("/thread", { replace: !1 }), e(Xe(h));
  });
  return c ? /* @__PURE__ */ t("div", { className: "bg-bgColor text-text relative w-full overflow-hidden h-[calc(100vh-100px)]     ", children: /* @__PURE__ */ t("div", { className: "h-[50px] flex justify-center", children: /* @__PURE__ */ t(G, {}) }) }) : !c && n.length === 0 ? /* @__PURE__ */ t("div", { className: "bg-bgColor text-text relative w-full overflow-hidden h-[calc(100vh-100px)]    ", children: /* @__PURE__ */ t("p", { className: "text-center p-[10px] text-[14px]", children: "نتیجه ای وجود ندارد" }) }) : /* @__PURE__ */ t("div", { className: "flex flex-col bg-bgColor", style: { height: "100%" }, children: /* @__PURE__ */ t(
    de,
    {
      endReached: d,
      data: n,
      className: "scroll-container",
      overscan: 100,
      style: {
        // height: `calc(100dvh - ${xxl ? 120 : 100}px)`,
        direction: "rtl"
      },
      totalCount: n.length,
      itemContent: (x, h) => /* @__PURE__ */ o(
        "div",
        {
          onClick: () => m(h),
          className: "flex items-center space-x-2 space-x-reverse p-3 cursor-pointer hover:bg-bgHover text-invertBlackWhite",
          children: [
            /* @__PURE__ */ t(ie, { size: "sm", firstName: h.title, image: h.image }),
            /* @__PURE__ */ t("div", { className: "text-sm font-medium overflow-hidden text-ellipsis whitespace-nowrap", children: nt(h.title) })
          ]
        }
      ),
      components: {
        Footer: () => r && /* @__PURE__ */ t("div", { className: "flex justify-center items-center space-x-2 space-x-reverse p-3 ", children: /* @__PURE__ */ t(G, {}) })
      }
    }
  ) });
}, ws = (e) => {
  const n = y(e).includes(C.Channel), i = (e == null ? void 0 : e.admin) || !1;
  return [
    ...!n || n && i ? [{ title: "اعضا", component: /* @__PURE__ */ t(xs, { thread: e }), id: 1 }] : [],
    {
      title: "تصاویر",
      component: /* @__PURE__ */ t(
        hs,
        {
          threadId: (e == null ? void 0 : e.id) || 0,
          isArchiveThread: (e == null ? void 0 : e.archiveThread) || !1
        }
      ),
      id: 2
    },
    {
      title: "ویدیوها",
      component: /* @__PURE__ */ t(
        oe,
        {
          messageType: O.POD_SPACE_VIDEO,
          threadId: (e == null ? void 0 : e.id) || 0
        }
      ),
      id: 3
    },
    {
      title: "آهنگ‌ها",
      component: /* @__PURE__ */ t(
        oe,
        {
          messageType: O.POD_SPACE_SOUND,
          threadId: (e == null ? void 0 : e.id) || 0
        }
      ),
      id: 4
    },
    {
      title: "صداها",
      component: /* @__PURE__ */ t(
        oe,
        {
          messageType: O.POD_SPACE_VOICE,
          threadId: (e == null ? void 0 : e.id) || 0
        }
      ),
      id: 5
    },
    {
      title: "فایل‌ها",
      component: /* @__PURE__ */ t(
        oe,
        {
          isFile: !0,
          messageType: O.POD_SPACE_FILE,
          threadId: (e == null ? void 0 : e.id) || 0
        }
      ),
      id: 6
    },
    ...n ? [] : [
      {
        title: "تماس",
        component: /* @__PURE__ */ t(
          oe,
          {
            messageType: O.END_CALL,
            threadId: (e == null ? void 0 : e.id) || 0
          }
        ),
        id: 7
      }
    ],
    {
      title: "لینک‌ها",
      component: /* @__PURE__ */ t(oe, { messageType: O.LINK, threadId: (e == null ? void 0 : e.id) || 0 }),
      id: 8
    },
    // { title: "تماس", component: <CallsTab messageType={MessageType.END_CALL} />, id: 7 },
    // { title: "لینک", component: <LinkTab messageType={MessageType.LINK} />, id: 8 },
    { title: "گروه‌ها", component: /* @__PURE__ */ t(Cs, {}), id: 9 }
  ];
}, ys = ({
  thread: e,
  handleScrollBottom: s
}) => {
  const n = ne(null), [i, c] = w(!1), [r, l] = w(0), [p, u] = w(0), d = y(e).includes(C.Channel), m = (e == null ? void 0 : e.admin) || !1, x = () => !(e != null && e.group) || d && !m ? 2 : 1, [h, f] = w(x()), b = ne(null), I = (v, L) => {
    f(v), s(), L.scrollIntoView({
      behavior: "smooth",
      inline: "center",
      block: "nearest"
    });
  }, g = ws(e), S = (() => {
    let v = g;
    const Q = y(e).includes(C.SELF);
    return e != null && e.group ? v = g.slice(0, -1) : v = g.slice(1), Q && v[5] !== void 0 && (v = v.filter((re, X) => ![5, 7].includes(X))), v;
  })(), M = S.find(
    (v) => v.id === h
  ), D = (v) => {
    n.current && (c(!0), l(v.pageX - n.current.offsetLeft), u(n.current.scrollLeft));
  }, k = () => {
    c(!1);
  }, Y = () => {
    c(!1);
  }, V = (v) => {
    if (!i || !n.current)
      return;
    v.preventDefault();
    const Q = (v.pageX - n.current.offsetLeft - r) * 2;
    n.current.scrollLeft = p - Q;
  };
  return (e == null ? void 0 : e.id) === ue ? null : /* @__PURE__ */ o("div", { className: "flex flex-col h-screen overflow-auto", children: [
    /* @__PURE__ */ t(
      "div",
      {
        ref: n,
        className: `flex items-center justify-around
         text-sm font-medium h-[53px]
       overflow-x-auto scroll-container bg-threadInfoPersonHeadBg shadow-md`,
        onMouseDown: D,
        onMouseLeave: k,
        onMouseUp: Y,
        onMouseMove: V,
        children: S.map((v) => /* @__PURE__ */ t(
          "button",
          {
            className: `px-3 py-2 text-iconSecondary border-b-[3px] ${h === v.id ? "border-accent" : "border-transparent"}`,
            onClick: (L) => I(v.id, L.currentTarget),
            children: v.title
          },
          v.id
        ))
      }
    ),
    /* @__PURE__ */ t(
      "div",
      {
        className: "bg-bgColor h-[calc(100%-115px)] xl2:h-[calc(100%-135px)]",
        ref: b,
        children: M == null ? void 0 : M.component
      }
    )
  ] });
}, Is = () => {
  const e = E(), { thread: s } = N((u) => u.threads), i = y(s).includes(C.Group), c = s != null && s.group ? i ? "گروه" : "کانال" : "مخاطب", r = () => {
    e($(!1));
  }, l = ne(null), p = () => {
    l.current && setTimeout(() => {
      var u, a;
      (a = l.current) == null || a.scrollTo({
        top: (u = l.current) == null ? void 0 : u.scrollHeight,
        behavior: "smooth"
      });
    }, 0);
  };
  if (s)
    return /* @__PURE__ */ o(P, { children: [
      /* @__PURE__ */ t(
        ce,
        {
          onClose: r,
          title: `اطلاعات ${c} `,
          showEdit: s.id !== ue,
          viewMode: s != null && s.group ? "editGroupChannel" : "editUser"
        }
      ),
      /* @__PURE__ */ o(
        "div",
        {
          ref: l,
          id: "threadInfoMain",
          className: "overflow-y-auto h-[calc(100%-60px)] scroll-container ",
          children: [
            /* @__PURE__ */ t(Qn, { thread: s }),
            /* @__PURE__ */ t(B, { className: "shadow-dividerShadow" }),
            /* @__PURE__ */ t(ms, { thread: s }),
            /* @__PURE__ */ t(B, { className: "shadow-dividerShadow" }),
            /* @__PURE__ */ t("div", { className: "bg-invertWhiteBlack sticky top-[0] h-[calc(100%-200px)] scroll-container", children: /* @__PURE__ */ t(
              ys,
              {
                thread: s,
                handleScrollBottom: p
              }
            ) })
          ]
        }
      )
    ] });
}, Ue = ({
  item: e,
  onToggle: s
}) => /* @__PURE__ */ t(
  Ye.div,
  {
    layout: !0,
    layoutId: `emoji-${e.id}`,
    className: "p-[10px]",
    initial: { scale: 0.8, opacity: 0 },
    animate: { scale: 1, opacity: 1 },
    exit: { scale: 0.8, opacity: 0 },
    transition: { type: "spring", stiffness: 400, damping: 30 },
    children: /* @__PURE__ */ o(
      "button",
      {
        onClick: s,
        className: "text-3xl flex p-0 hover:scale-110 transition-transform duration-150",
        children: [
          /* @__PURE__ */ t("span", { className: "ml-[-5px] z-10 mt-[4px] rounded-full pointer-events-none", children: e.selected ? /* @__PURE__ */ t(cn, {}) : /* @__PURE__ */ t(on, {}) }),
          /* @__PURE__ */ t("span", { children: e.icon })
        ]
      }
    )
  }
), Ss = Gn.map((e) => ({
  id: e,
  reaction: e,
  selected: !1,
  icon: K(Wn(e).emoji + "", {
    className: "w-[30px] pb-[2px]"
  })
})), ks = () => {
  const e = E(), s = N((a) => a.threads.thread), [n, i] = w(
    () => Ss.map((a) => A({}, a))
  );
  j(() => {
    s && s.reactionStatus === ge.CUSTOM && e(an({ threadId: s.id }));
  }, [s == null ? void 0 : s.id, s == null ? void 0 : s.reactionStatus, e]), j(() => {
    var d;
    if (!((d = s == null ? void 0 : s.allowedReaction) != null && d.length))
      return;
    const a = new Set(s.allowedReaction);
    i(
      (m) => m.map((x) => U(A({}, x), { selected: a.has(x.reaction) }))
    );
  }, [s == null ? void 0 : s.allowedReaction]);
  const c = te((a) => {
    i((d) => {
      const m = d.findIndex((h) => h.reaction === a);
      if (m === -1)
        return d;
      const x = [...d];
      return x[m] = U(A({}, x[m]), { selected: !x[m].selected }), x;
    });
  }, []), { selected: r, unselected: l } = ee(() => {
    const a = [], d = [];
    return n.forEach((m) => m.selected ? a.push(m) : d.push(m)), { selected: a, unselected: d };
  }, [n]), p = te(() => {
    e(se("editGroupChannel"));
  }, [e]), u = te(() => {
    s && (e(
      Qe({
        threadId: s.id,
        reactionStatus: 3,
        allowedReactions: r.map((a) => a.reaction)
      })
    ), p());
  }, [s, r, e, p]);
  return /* @__PURE__ */ o("div", { className: "bg-invertWhiteBlack h-full flex flex-col overflow-y-auto", children: [
    /* @__PURE__ */ t(ce, { onClose: p, title: "ری‌اکشن‌های سفارشی" }),
    /* @__PURE__ */ o("div", { className: "flex justify-between flex-col h-full", children: [
      /* @__PURE__ */ o("div", { className: "p-3 flex flex-col gap-6", children: [
        /* @__PURE__ */ t("span", { className: "text-sm text-invertBlackWhite block mb-2", children: "ری‌اکشن‌های انتخاب ‌شده" }),
        r.length === 0 ? /* @__PURE__ */ t("div", { className: "flex flex-wrap min-h-[100px] justify-center items-center", children: /* @__PURE__ */ t(
          Ye.span,
          {
            initial: { opacity: 0 },
            animate: { opacity: 0.7 },
            className: "text-xs text-invertBlackWhite",
            children: "موردی انتخاب نشده است"
          }
        ) }) : /* @__PURE__ */ t("div", { className: "flex flex-wrap min-h-[100px] justify-end items-center", children: /* @__PURE__ */ t(Oe, { children: r.map((a) => /* @__PURE__ */ t(
          Ue,
          {
            item: a,
            onToggle: () => c(a.reaction)
          },
          a.id
        )) }) }),
        /* @__PURE__ */ t("span", { className: "text-sm text-invertBlackWhite block mb-2", children: "ایموجی‌ها" }),
        /* @__PURE__ */ o("div", { className: "flex flex-wrap justify-end", children: [
          /* @__PURE__ */ t(Oe, { children: l.map((a) => /* @__PURE__ */ t(
            Ue,
            {
              item: a,
              onToggle: () => c(a.reaction)
            },
            a.id
          )) }),
          l.length === 0 && /* @__PURE__ */ t("span", { className: "text-xs text-invertBlackWhite text-center w-full opacity-70", children: "همه ایموجی‌ها انتخاب شده‌اند" })
        ] })
      ] }),
      /* @__PURE__ */ t("div", { className: "p-3 sticky bottom-0 bg-bgColor border-t border-borderColor", children: /* @__PURE__ */ t(
        "button",
        {
          disabled: r.length === 0,
          onClick: u,
          className: "rounded-sm mt-2 px-2 py-3 text-sm text-white font-bold flex justify-center items-center bg-accent w-full hover:bg-accent/90 transition-colors  disabled:opacity-50 disabled:cursor-not-allowed",
          children: "اعمال"
        }
      ) })
    ] })
  ] });
}, Ts = () => /* @__PURE__ */ t("span", { className: "absolute bottom-0 left-0 ", children: /* @__PURE__ */ t(rn, {}) }), Ps = ({
  threadId: e,
  isGroup: s
}) => {
  const [n, i] = _.useState(!1), c = W(), r = () => z(null, null, function* () {
    e && (i(!1), yield c(Ve({ threadId: e })).unwrap().then(() => {
      c($(!1));
    }));
  }), l = s ? "گروه" : "کانال";
  return /* @__PURE__ */ o("div", { className: "", children: [
    /* @__PURE__ */ t(
      q,
      {
        confirmText: "حذف",
        cancelText: "انصراف",
        onConfirm: r,
        onCancel: () => i(!1),
        onOpenChange: i,
        size: "md",
        open: n,
        title: `آیا از حذف ${l} مطمئن هستید؟`,
        children: /* @__PURE__ */ o("p", { className: "mt-8 h-12 text-invertBlackWhite", children: [
          "بعد از حذف ",
          l,
          " دسترسی برای تمام اعضا به این کانال امکان پذیر نمی باشد."
        ] })
      }
    ),
    /* @__PURE__ */ o(
      "div",
      {
        onClick: () => i(!0),
        className: "flex gap-2 p-4 items-center cursor-pointer",
        children: [
          /* @__PURE__ */ t("span", { className: "text-menuIconColor", children: /* @__PURE__ */ t(dn, {}) }),
          /* @__PURE__ */ o("span", { className: "text-base text-iconRed", children: [
            "حذف ",
            l
          ] })
        ]
      }
    )
  ] });
}, _e = ({
  inputType: e = "input",
  label: s,
  name: n,
  id: i,
  required: c = !1,
  value: r,
  onChange: l,
  placeholder: p,
  maxLength: u,
  error: a,
  className: d = ""
}) => {
  const m = i || n, x = {
    id: m,
    name: n,
    placeholder: p,
    maxLength: u,
    value: r,
    onChange: l,
    className: `w-full px-3 py-[14px] bg-bgInput text-invertBlackWhite scroll-container ${d}`
  };
  return /* @__PURE__ */ o("div", { children: [
    /* @__PURE__ */ o(
      "label",
      {
        htmlFor: m,
        className: "mb-2 mr-1 flex items-center gap-1 text-xs font-medium",
        children: [
          /* @__PURE__ */ t("span", { className: "text-invertBlackWhite text-xs", children: s }),
          /* @__PURE__ */ t("span", { className: "text-invertBlackWhite text-xs", children: c ? "(اجباری)" : "(اختیاری)" })
        ]
      }
    ),
    e === "input" ? /* @__PURE__ */ t("input", A({}, x)) : /* @__PURE__ */ t("textarea", A({}, x)),
    a && /* @__PURE__ */ t("p", { className: "text-xs text-iconRed mt-3", children: a })
  ] });
}, Ms = () => {
  var re, X, Z;
  const e = E(), s = _.useRef(null), [n, i] = _.useState(null), [c, r] = _.useState(!1), [l, p] = _.useState(null), [u, a] = w({ title: "", description: "" }), { thread: d } = N((T) => T.threads), m = y(d), x = m.includes(C.Group), h = m.includes(C.PublicGroup) || m.includes(C.PublicChannel), f = x ? "گروه" : "کانال", b = () => e(se("threadInfo")), I = (T) => {
    const R = T.target.checked;
    d && e(
      Qe({
        threadId: d == null ? void 0 : d.id,
        reactionStatus: R ? 2 : 1,
        allowedReactions: []
      })
    );
  }, g = N(
    (T) => T.threadParticipant.threadParticipants
  ), S = mn(g), [M, D] = w({
    image: (re = d == null ? void 0 : d.image) != null ? re : null,
    title: (X = d == null ? void 0 : d.title) != null ? X : "",
    description: (Z = d == null ? void 0 : d.description) != null ? Z : ""
  }), k = (T) => {
    const { name: R, value: H } = T.target;
    if (R === "title" && (H.trim().length ? a((F) => U(A({}, F), { title: "" })) : a((F) => U(A({}, F), { title: "تکمیل بفرمایید" }))), R === "description")
      if (H.length > 255) {
        a((F) => U(A({}, F), {
          description: "امکان تایپ بیشتر وجود ندارد"
        }));
        return;
      } else
        u.description && a((F) => U(A({}, F), { description: "" }));
    D((F) => U(A({}, F), { [R]: H }));
  }, Y = (T) => {
    if (T.preventDefault(), !d)
      return;
    const R = l ? U(A({}, M), { image: l }) : { title: M.title, description: M.description };
    e(fn({ thread: d, metadata: R })).unwrap().then(() => {
      p(null), b();
    }).catch((H) => {
      console.error("error:", H);
    });
  }, V = () => {
    e(se("customReactions"));
  }, v = (T) => {
    var H;
    const R = (H = T.target.files) == null ? void 0 : H[0];
    if (R) {
      const F = URL.createObjectURL(R);
      i(F), r(!0), s.current && (s.current.value = "");
    }
  }, L = (T) => {
    p(T);
    const R = URL.createObjectURL(T);
    D((H) => U(A({}, H), { image: R }));
  }, Q = () => {
    r(!1), n && (URL.revokeObjectURL(n), i(null));
  };
  return /* @__PURE__ */ o("div", { className: "bg-invertWhiteBlack h-full flex flex-col", children: [
    /* @__PURE__ */ t(ce, { onClose: b, title: `ویرایش ${f}` }),
    /* @__PURE__ */ o(
      "form",
      {
        className: "flex flex-col flex-1 justify-between overflow-y-auto scroll-container",
        onSubmit: Y,
        noValidate: !0,
        children: [
          /* @__PURE__ */ o("div", { children: [
            /* @__PURE__ */ t("div", { className: "p-3 mt-3 flex justify-center items-center py-3  relative", children: /* @__PURE__ */ o("div", { className: "flex ", children: [
              /* @__PURE__ */ t(
                ie,
                {
                  cache: !1,
                  firstName: d == null ? void 0 : d.title,
                  image: M.image,
                  size: "",
                  className: "w-[96px] h-[96px]"
                }
              ),
              /* @__PURE__ */ o(
                "div",
                {
                  onClick: () => {
                    var T;
                    return (T = s == null ? void 0 : s.current) == null ? void 0 : T.click();
                  },
                  className: "relative left-0 bottom-0 cursor-pointer",
                  children: [
                    /* @__PURE__ */ t(Ts, {}),
                    /* @__PURE__ */ t(
                      "input",
                      {
                        ref: s,
                        id: "avatar",
                        type: "file",
                        accept: "image/*",
                        className: "hidden",
                        onChange: v
                      }
                    )
                  ]
                }
              )
            ] }) }),
            /* @__PURE__ */ t(B, {}),
            /* @__PURE__ */ o("div", { className: "p-3", children: [
              /* @__PURE__ */ t(
                _e,
                {
                  label: `نام ${f}`,
                  name: "title",
                  onChange: k,
                  value: Me(M.title),
                  className: "w-full px-3 py-[14px] bg-bgInput outline-none text-invertBlackWhite",
                  error: u.title,
                  id: "title",
                  maxLength: 100,
                  placeholder: `نام ${f}`,
                  required: !0
                }
              ),
              /* @__PURE__ */ t("div", { className: "mt-4", children: /* @__PURE__ */ t(
                _e,
                {
                  inputType: "textarea",
                  label: "توضیحات",
                  name: "description",
                  onChange: k,
                  value: Me(M.description),
                  className: "w-full px-3 py-[14px] bg-bgInput outline-none text-invertBlackWhite",
                  error: u.description,
                  id: "description",
                  placeholder: "توضیحات"
                }
              ) })
            ] }),
            /* @__PURE__ */ t(B, {}),
            /* @__PURE__ */ o("div", { children: [
              /* @__PURE__ */ o("div", { className: "flex items-center gap-2 text-sm p-4 ", children: [
                /* @__PURE__ */ t("span", { className: "text-menuIconColor", children: /* @__PURE__ */ t($e, {}) }),
                /* @__PURE__ */ o("span", { className: "text-invertBlackWhite", children: [
                  f,
                  " ",
                  h ? "عمومی" : "خصوصی"
                ] })
              ] }),
              /* @__PURE__ */ t(B, { height: "h-[0.75px]" }),
              /* @__PURE__ */ o("div", { className: "flex justify-between items-center p-4 ", children: [
                /* @__PURE__ */ o("div", { className: "flex items-center gap-2 text-sm ", children: [
                  /* @__PURE__ */ t("span", { className: "text-menuIconColor", children: /* @__PURE__ */ t(pn, {}) }),
                  /* @__PURE__ */ t("span", { className: "text-invertBlackWhite", children: "مدیران" })
                ] }),
                /* @__PURE__ */ t("span", { className: "text-accent text-md font-bold", children: S })
              ] }),
              /* @__PURE__ */ t(B, { height: "h-[0.75px]" }),
              /* @__PURE__ */ o("div", { className: "flex justify-between items-center p-4 ", children: [
                /* @__PURE__ */ o("div", { className: "flex items-center gap-2 text-sm   ", children: [
                  /* @__PURE__ */ t("span", { className: "text-menuIconColor", children: /* @__PURE__ */ t(Ee, {}) }),
                  /* @__PURE__ */ t("span", { className: "text-invertBlackWhite", children: "فعال‌سازی ری‌اکشن" })
                ] }),
                /* @__PURE__ */ t(
                  We,
                  {
                    id: "enableReaction",
                    checked: (d == null ? void 0 : d.reactionStatus) !== ge.NONE,
                    onChange: I
                  }
                )
              ] }),
              /* @__PURE__ */ t(B, { height: "h-[0.75px]" }),
              (d == null ? void 0 : d.reactionStatus) !== ge.NONE && /* @__PURE__ */ o(
                "div",
                {
                  className: "flex justify-between items-center p-4 cursor-pointer",
                  onClick: V,
                  children: [
                    /* @__PURE__ */ o("div", { className: "flex items-center gap-2 text-sm   ", children: [
                      /* @__PURE__ */ t("span", { className: "text-menuIconColor", children: /* @__PURE__ */ t(Ee, {}) }),
                      /* @__PURE__ */ t("span", { className: "text-invertBlackWhite", children: "ری‌اکشن‌های سفارشی" })
                    ] }),
                    /* @__PURE__ */ t("span", { className: "text-iconSecondary", children: /* @__PURE__ */ t(un, {}) })
                  ]
                }
              ),
              /* @__PURE__ */ t(B, {}),
              /* @__PURE__ */ t(Ps, { isGroup: x, threadId: (d == null ? void 0 : d.id) || 0 })
            ] })
          ] }),
          /* @__PURE__ */ t("div", { className: "p-3 sticky bottom-0 bg-bgColor", children: /* @__PURE__ */ t(
            "button",
            {
              disabled: !!u.title,
              type: "submit",
              className: `rounded-sm mt-2 px-2 py-3 text-sm font-bold flex justify-center items-center w-full 
            ${u.title ? "bg-gray-400 text-gray-200 cursor-not-allowed" : "bg-accent text-white hover:bg-accent/80"}`,
              children: "اعمال"
            }
          ) })
        ]
      }
    ),
    n && /* @__PURE__ */ t(
      $n,
      {
        open: c,
        onClose: Q,
        imageUrl: n,
        onSave: L
      }
    )
  ] });
}, Es = () => {
  const e = N(
    (d) => d.threadParticipant.threadParticipants
  ), s = N((d) => d.threads.thread), n = e.find(
    (d) => d.id === (s == null ? void 0 : s.partner) || 0
  ), [i, c] = w({
    firstName: n != null && n.contactId ? n == null ? void 0 : n.contactFirstName : n == null ? void 0 : n.firstName,
    lastName: n != null && n.contactId ? n == null ? void 0 : n.contactLastName : n == null ? void 0 : n.lastName,
    username: n == null ? void 0 : n.username
  }), r = (d) => {
    const { name: m, value: x } = d.target;
    c((h) => U(A({}, h), { [m]: x }));
  }, l = (d) => z(null, null, function* () {
    if (d.preventDefault(), !i.firstName || !i.username)
      return;
    const m = yield p(
      xn({
        firstName: i.firstName,
        addBy: i.username,
        lastName: i.lastName
      })
    ).unwrap();
    m.hasError || !m.linkedUser || (p(
      qe({
        new_data: {
          coreUserId: m.linkedUser.coreUserId,
          contactFirstName: m.firstName,
          contactLastName: m.lastName
        }
      })
    ), a());
  }), p = E(), u = i.lastName && i.lastName.length > 30, a = () => p(se("threadInfo"));
  return /* @__PURE__ */ o("div", { className: "bg-invertWhiteBlack h-full flex flex-col", children: [
    /* @__PURE__ */ t(ce, { onClose: a, title: " ویرایش  کاربر" }),
    /* @__PURE__ */ o("form", { className: "flex flex-col flex-1 justify-between ", noValidate: !0, children: [
      /* @__PURE__ */ o("div", { className: "flex-1 p-4", children: [
        /* @__PURE__ */ o("div", { className: "mb-10", children: [
          /* @__PURE__ */ o(
            "label",
            {
              className: "mb-2 mr-1 flex items-center gap-1 text-xs font-medium",
              htmlFor: "firstName",
              children: [
                /* @__PURE__ */ t("span", { className: "text-invertBlackWhite text-xs", children: "نام" }),
                /* @__PURE__ */ t("span", { className: "text-textGrayColor text-xs", children: "( اجباری )" })
              ]
            }
          ),
          /* @__PURE__ */ t(
            "input",
            {
              placeholder: "نام",
              id: "firstName",
              name: "firstName",
              value: i.firstName,
              maxLength: 15,
              onChange: r,
              className: "w-full px-3 py-[14px] bg-bgInput outline-none text-invertBlackWhite"
            }
          )
        ] }),
        /* @__PURE__ */ o("div", { className: "mb-10", children: [
          /* @__PURE__ */ t(
            "label",
            {
              className: "mb-2 mr-1 flex text-invertBlackWhite text-xs",
              htmlFor: "lastName",
              children: /* @__PURE__ */ t("span", { children: "نام خانوادگی" })
            }
          ),
          /* @__PURE__ */ t(
            "input",
            {
              placeholder: "نام خانوادگی",
              id: "lastName",
              name: "lastName",
              value: i.lastName,
              onChange: r,
              maxLength: 31,
              className: "w-full px-3 py-[14px] outline-none bg-bgInput text-invertBlackWhite"
            }
          ),
          u && /* @__PURE__ */ t("p", { className: "text-red-600 text-[10px] mt-1", children: "امکان تایپ بیشتر وجود ندارد" })
        ] })
      ] }),
      /* @__PURE__ */ t("div", { className: "p-3", children: /* @__PURE__ */ t(
        "button",
        {
          disabled: !i.firstName || !!u,
          onClick: l,
          className: "rounded-sm mt-2 px-2 py-3 disabled:!bg-[#4c382e] text-sm text-white font-bold flex justify-center items-center bg-accent w-full",
          children: "اعمال"
        }
      ) })
    ] })
  ] });
}, rt = Ne(({ contact: e }) => {
  var n;
  const s = (n = (e == null ? void 0 : e.contactName) || (e == null ? void 0 : e.name)) != null ? n : "نامشخص";
  return /* @__PURE__ */ t(be, { children: /* @__PURE__ */ t("div", { className: "flex justify-between items-center px-3 py-4 hover:bg-bgHover cursor-pointer", children: /* @__PURE__ */ o("div", { className: "flex items-center gap-3", children: [
    /* @__PURE__ */ t(ie, { size: "sm", firstName: s, image: e == null ? void 0 : e.image }),
    /* @__PURE__ */ t("div", { className: "flex flex-col", children: /* @__PURE__ */ t("span", { className: "text-sm font-bold text-invertBlackWhite", children: s }) })
  ] }) }) });
}), Ds = Ne(() => {
  const e = W(), s = he(), {
    participants: n = [],
    hasNext: i,
    loading: c,
    nextOffset: r,
    selectedMessageId: l,
    loadingFromDown: p
  } = N((d) => d.seenMessage);
  j(() => {
    l && e(
      De({
        messageId: l,
        count: 20,
        offset: 0
      })
    );
  }, [l, e]);
  const u = te(() => {
    !i || p || !l || e(
      De({
        messageId: l,
        count: 20,
        offset: r
      })
    );
  }, [
    e,
    i,
    p,
    l,
    r,
    c
  ]), a = n == null ? void 0 : n.filter(
    (d) => d.id !== s
  );
  return l ? !c && a.length === 0 ? /* @__PURE__ */ t("div", { className: "flex justify-center h-[30px]", children: /* @__PURE__ */ t("p", { className: "text-[14px] text-invertBlackWhite pt-4 ", children: "کسی این پیام را نخوانده" }) }) : c ? /* @__PURE__ */ t("div", { className: "flex justify-center h-[30px]", children: /* @__PURE__ */ t(G, {}) }) : /* @__PURE__ */ t(
    de,
    {
      className: "scroll-container",
      style: { direction: "rtl" },
      data: a,
      endReached: u,
      overscan: 200,
      components: { Footer: () => p && /* @__PURE__ */ t(G, {}) },
      itemContent: (d, m) => /* @__PURE__ */ t(rt, { contact: m }, d)
    }
  ) : null;
});
rt.displayName = "ReaderItem";
const dt = () => {
  const e = W(), s = te(() => {
    e($(!1));
  }, [e]);
  return /* @__PURE__ */ o(_.Fragment, { children: [
    /* @__PURE__ */ t(ce, { onClose: s, title: "لیست خواننده‌ها" }),
    /* @__PURE__ */ t("div", { className: "h-[calc(100dvh-60px)] bg-bgColor", children: /* @__PURE__ */ t(Ds, {}) })
  ] });
};
dt.displayName = "ReadersListBox";
const As = ({ query: e }) => {
  const { messages: s, loading: n, nextOffset: i, hasNext: c, loadingFromDown: r } = N((h) => h.searchHistory), l = W(), { isMobile: p } = pe(), { xxl: u } = ye(), a = N((h) => h.threads.thread), d = (h) => {
    p && l($(!1)), ve(l, (a == null ? void 0 : a.id) || 0, h.time);
  }, m = tt(
    (h, f) => {
      const b = Ae();
      l(
        Be({
          uniqueId: b,
          count: Le,
          offset: 0,
          threadId: f,
          query: h
        })
      );
    },
    1e3,
    { leading: !1, trailing: !0 }
    // fire after user pauses typing
  );
  j(() => {
    if (a != null && a.id) {
      if (!e) {
        l(hn());
        return;
      }
      m(e, a.id);
    }
  }, [e, a == null ? void 0 : a.id]);
  const x = () => {
    if (!a || !c || n || i < s.length || r)
      return;
    const h = Ae();
    l(
      Be({
        uniqueId: h,
        count: Le,
        offset: i,
        threadId: a.id,
        query: e
      })
    );
  };
  return n ? /* @__PURE__ */ t("div", { className: "bg-bgColor text-text relative w-full overflow-hidden h-[calc(100dvh-110px)]     ", children: /* @__PURE__ */ t("div", { className: "h-[50px] flex justify-center", children: /* @__PURE__ */ t(G, {}) }) }) : !n && s.length === 0 ? /* @__PURE__ */ t("div", { className: "bg-bgColor text-text relative w-full overflow-hidden h-[calc(100dvh-110px)]    ", children: /* @__PURE__ */ t("p", { className: "text-center p-[10px] text-[14px]", children: "نتیجه ای وجود ندارد" }) }) : /* @__PURE__ */ t("div", { className: "overflow-y-auto h-[calc(100vh-60px)] scroll-container thin-scroll bg-bgColor", children: /* @__PURE__ */ t(
    de,
    {
      endReached: x,
      data: s,
      className: "",
      overscan: 100,
      style: {
        height: `calc(100dvh - ${u ? 134 : 110}px)`,
        direction: "rtl"
      },
      itemContent: (h, f) => {
        var b, I;
        return /* @__PURE__ */ o(
          "div",
          {
            className: "min-w-0 text-invertBlackWhite p-[10px] flex items-center cursor-pointer",
            onClick: () => d(f),
            children: [
              /* @__PURE__ */ o("div", { className: "min-w-0 flex-1", children: [
                /* @__PURE__ */ t("p", { className: "truncate  ", children: f.message }),
                /* @__PURE__ */ t("div", { className: "text-xs text-lightText mt-3", children: Ce(f.time, "fa", !0) })
              ] }),
              /* @__PURE__ */ t("div", { className: "text-xs", children: ((b = f == null ? void 0 : f.participant) == null ? void 0 : b.contactName) || ((I = f == null ? void 0 : f.participant) == null ? void 0 : I.name) })
            ]
          }
        );
      },
      components: {
        Footer: () => r ? /* @__PURE__ */ t("div", { className: "py-6 flex justify-center", children: /* @__PURE__ */ t(G, {}) }) : null
      }
    }
  ) });
}, Bs = () => {
  const e = W(), [s, n] = w("");
  return /* @__PURE__ */ o("div", { children: [
    /* @__PURE__ */ t(ce, { onClose: () => {
      e($(!1));
    }, title: "جستجو پیامها" }),
    /* @__PURE__ */ t(Hn, { handleChange: (r) => {
      n(r);
    }, focus: !0 }),
    /* @__PURE__ */ t(As, { query: s })
  ] });
}, Ls = {
  threadInfo: Is,
  chooseMemberBox: Zn,
  editGroupChannel: Ms,
  editUser: Es,
  customReactions: ks,
  readersList: dt,
  searchInThreadHistory: Bs
}, Xs = () => {
  const { showThreadInfo: e, viewModeLeftSide: s, threadId: n } = N(
    (p) => {
      var u;
      return {
        showThreadInfo: p.setting.showThreadInfo,
        viewModeLeftSide: p.threadInfo.viewModeLeftSide,
        threadId: ((u = p.threads.thread) == null ? void 0 : u.id) || -1
      };
    },
    Ze
    // Prevents re-render if values are referentially equal
  ), i = Sn(), c = ne(-1), r = ee(
    () => Ls[s] || null,
    [s]
  );
  e && (c.current = n);
  const l = c.current === n;
  return /* @__PURE__ */ t(
    "aside",
    {
      className: `h-full ${i ? "lg:block" : "hidden lg:block "} bg-bgInput
       fixed
       lg:static
        top-0 
       left-0 
       overflow-hidden 
      ${e ? "w-full  max-w-[100%]   sm:w-full    lg:w-1/4  lg:max-w-[400px]" : "w-[0px]"}
    
      transition-all duration-100 will-change-transform ease-linear
       
       shadow-md border-l border-borderHead z-chatThreadInfo flex flex-col`,
      children: l ? /* @__PURE__ */ t(r, {}) : null
    }
  );
};
export {
  Xs as default
};
