var $e = Object.defineProperty, Fe = Object.defineProperties;
var Pe = Object.getOwnPropertyDescriptors;
var X = Object.getOwnPropertySymbols;
var ue = Object.prototype.hasOwnProperty, me = Object.prototype.propertyIsEnumerable;
var de = (e, t, n) => t in e ? $e(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n, te = (e, t) => {
  for (var n in t || (t = {}))
    ue.call(t, n) && de(e, n, t[n]);
  if (X)
    for (var n of X(t))
      me.call(t, n) && de(e, n, t[n]);
  return e;
}, he = (e, t) => Fe(e, Pe(t));
var fe = (e, t) => {
  var n = {};
  for (var a in e)
    ue.call(e, a) && t.indexOf(a) < 0 && (n[a] = e[a]);
  if (e != null && X)
    for (var a of X(e))
      t.indexOf(a) < 0 && me.call(e, a) && (n[a] = e[a]);
  return n;
};
var pe = (e, t, n) => new Promise((a, r) => {
  var i = (c) => {
    try {
      o(n.next(c));
    } catch (h) {
      r(h);
    }
  }, l = (c) => {
    try {
      o(n.throw(c));
    } catch (h) {
      r(h);
    }
  }, o = (c) => c.done ? a(c.value) : Promise.resolve(c.value).then(i, l);
  o((n = n.apply(e, t)).next());
});
import { jsxs as u, jsx as s, Fragment as Z } from "react/jsx-runtime";
import A, { useContext as Ve, useState as H, useEffect as _, useMemo as q, useCallback as je, createElement as T, useId as Ee, isValidElement as Ue } from "react";
import { u as ze, L as ye, p as le, A as He, T as We, n as Ge, C as Be, O as Je } from "./TalkLoading-CJtNYhDp.js";
import { u as ve, H as qe, J as Ke } from "./JoinThreadDialog-N2K5Qro0.js";
import { u as we, D as be, C as Qe, a as Xe, b as Ye, c as Ne, i as Ze, d as _e } from "./helpers-DcTymofH.js";
import { c as et, i as tt, u as Ce, m as st, M as nt, a as at, b as rt, f as it, d as se, e as Te, s as m, g as ee, h as D, j as ne, k as ae, l as re, n as ie, o as Y, F as ct, r as Ie, p as ke, R as oe, q as ot, T as lt, C as dt, t as ut, v as Se, w as mt, x as Me, y as ht, z as ft, S as pt, A as gt, B as xt, D as yt, E as vt, G as wt, H as bt, I as Nt, J as Ct, K as Tt, L as It, N as kt, O as St, P as Mt, Q as ce, U as Dt, V as De, W as At, X as Lt, Y as Ot, Z as Rt, _ as $t, $ as Ft, a0 as Pt, a1 as Vt, a2 as jt, a3 as Et, a4 as Ut, a5 as zt, a6 as Ht, a7 as Wt, a8 as Gt, a9 as Bt, aa as Jt, ab as qt, ac as Kt, ad as Qt, ae as Xt, af as Yt, ag as Zt, ah as _t, ai as es } from "./main-CxoAwMiG.js";
import { C as ge, u as ts } from "./unescapeHtml-ZZZvHhci.js";
import { X as ss, s as Ae, T as ns, P as as, C as rs, I as is, R as cs, a as os } from "./TypingView-B0vffagz.js";
const ls = [
  ["path", { d: "m22 7-8.991 5.727a2 2 0 0 1-2.009 0L2 7", key: "132q7q" }],
  ["rect", { x: "2", y: "4", width: "20", height: "16", rx: "2", key: "izxlao" }]
], ds = et("mail", ls);
function us(...e) {
  const t = !Array.isArray(e[0]), n = t ? 0 : -1, a = e[0 + n], r = e[1 + n], i = e[2 + n], l = e[3 + n], o = tt(r, i, l);
  return t ? o(a) : o;
}
function Le(e) {
  const t = Ce(() => st(e)), { isStatic: n } = Ve(nt);
  if (n) {
    const [, a] = H(e);
    _(() => t.on("change", a), []);
  }
  return t;
}
function Oe(e, t) {
  const n = Le(t()), a = () => n.set(t());
  return a(), at(() => {
    const r = () => it.preRender(a, !1, !0), i = e.map((l) => l.on("change", r));
    return () => {
      i.forEach((l) => l()), rt(a);
    };
  }), n;
}
function ms(e) {
  se.current = [], e();
  const t = Oe(se.current, e);
  return se.current = void 0, t;
}
function hs(e, t, n, a) {
  if (typeof e == "function")
    return ms(e);
  const i = typeof t == "function" ? t : us(t, n, a), l = Array.isArray(e) ? xe(e, i) : xe([e], ([c]) => i(c)), o = Array.isArray(e) ? void 0 : e.accelerate;
  return o && !o.isTransformed && typeof t != "function" && Array.isArray(n) && (a == null ? void 0 : a.clamp) !== !1 && (l.accelerate = he(te({}, o), {
    times: t,
    keyframes: n,
    isTransformed: !0
  })), l;
}
function xe(e, t) {
  const n = Ce(() => []);
  return Oe(e, () => {
    n.length = 0;
    const a = e.length;
    for (let r = 0; r < a; r++)
      n[r] = e[r].get();
    return t(n);
  });
}
const fs = (r) => {
  var i = r, {
    parentClassname: e,
    prefixIcon: t,
    postfixIcon: n
  } = i, a = fe(i, [
    "parentClassname",
    "prefixIcon",
    "postfixIcon"
  ]);
  return /* @__PURE__ */ u("div", { className: e != null ? e : "", children: [
    t && /* @__PURE__ */ s("span", { className: "prefix", children: t }),
    /* @__PURE__ */ s("input", te({}, a)),
    n && /* @__PURE__ */ s("span", { className: "postfix", children: n })
  ] });
}, ps = ({
  searchingThread: e,
  showSearchFilter: t,
  handleShowSearchFilter: n,
  showUnread: a,
  setShowUnread: r,
  selectedDateRange: i,
  setSelectedDateRange: l,
  onApply: o
}) => {
  const { theme: c } = we(), [h, x] = H(!1), y = (g, k) => {
    l({ startDate: g, endDate: k }), x(!1);
  }, w = () => {
    x(!1);
  }, f = () => {
    if (i) {
      l(null);
      return;
    }
    x(!0);
  }, I = (g) => new Date(g).toLocaleDateString("fa-IR"), C = () => {
    if (!i)
      return null;
    const g = I(i.startDate), k = I(i.endDate);
    return `${m.fromDate} ${g} ${m.to} ${k}`;
  };
  return /* @__PURE__ */ u(
    Te,
    {
      isDark: c === "dark",
      open: t || !1,
      onOpenChange: () => {
      },
      title: /* @__PURE__ */ s("div", { className: "flex items-center justify-between p-4 pb-0", children: /* @__PURE__ */ s("p", { className: "text-base font-bold text-text", children: m.filter }) }),
      size: "sm",
      onConfirm: o,
      onCancel: n,
      confirmText: m.apply,
      cancelText: m.cancel,
      hasNotPadding: !0,
      children: [
        /* @__PURE__ */ u("div", { className: "flex flex-col items-stretch w-full gap-4 p-4 overflow-hidden text-right text-gray-700 bg-white dark:text-gray-300 dark:bg-inherit rounded-xl", children: [
          /* @__PURE__ */ u("label", { className: "relative inline-flex items-center cursor-pointer flex items-center justify-between", children: [
            /* @__PURE__ */ u("div", { className: "flex items-center gap-2", children: [
              /* @__PURE__ */ s(ds, { className: "w-5 h-5 text-gray-400 dark:text-gray-500" }),
              /* @__PURE__ */ s("span", { className: "text-sm", children: m.showUnreadMessage })
            ] }),
            /* @__PURE__ */ s(
              "input",
              {
                type: "checkbox",
                checked: a,
                onChange: (g) => r(g.target.checked),
                className: "sr-only peer"
              }
            ),
            /* @__PURE__ */ s("div", { className: "w-10 h-5 bg-gray-200 dark:bg-gray-600 rounded-full peer peer-checked:bg-[#F29727] after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white dark:after:bg-gray-200 after:h-4 after:w-4 after:rounded-full after:transition-all peer-checked:after:translate-x-5" })
          ] }),
          /* @__PURE__ */ s(be, { height: "h-[0.75px]", bg: "bg-divider" }),
          /* @__PURE__ */ u("div", { className: "flex items-center justify-between", children: [
            /* @__PURE__ */ u("div", { className: "flex items-center gap-2 text-gray-700 dark:text-gray-300", children: [
              /* @__PURE__ */ s(ge, { className: "w-5 h-5 text-gray-400 dark:text-gray-500" }),
              /* @__PURE__ */ u("div", { className: "flex flex-row gap-3", children: [
                /* @__PURE__ */ s("span", { className: "text-sm", children: m.period }),
                i && /* @__PURE__ */ s("span", { className: "font-medium ", children: C() })
              ] })
            ] }),
            /* @__PURE__ */ s(
              "button",
              {
                onClick: f,
                className: "p-3 text-white transition rounded-full shadow-md bg-[#F29727] hover:bg-[#F29727]",
                children: i ? /* @__PURE__ */ s(ss, { className: "w-5 h-5" }) : /* @__PURE__ */ s(ge, { className: "w-5 h-5" })
              }
            )
          ] })
        ] }),
        /* @__PURE__ */ s(
          Qe,
          {
            hasDivider: !0,
            isOpen: h,
            range: !0,
            onClose: w,
            onSelect: (g) => {
              typeof g == "object" && g !== null && "start" in g && "end" in g && y(g.start, g.end);
            },
            withTime: !0
          }
        )
      ]
    }
  );
}, gs = () => {
  const [e, t] = H(""), [n, a] = H(!1), [r, i] = H(!1), [l, o] = H(null), c = ee(), { filters: h, showSearchInput: x } = D(
    (N) => N.filteredThreads
  ), y = ze(
    (N) => {
      const b = N.trim();
      c(ie(b)), c(b ? ot({ query: b }) : re());
    },
    500,
    { leading: !1, trailing: !0 }
  ), w = (N) => {
    const b = N.target.value;
    t(b), y(b);
  }, f = () => {
    t(""), c(ie("")), c(re());
  }, I = () => {
    r && c(
      ke({
        count: oe,
        offset: 0
      })
    ), c(ne(r)), c(ae(l)), a(!1);
  };
  _(
    () => () => {
      t(""), i(!1), o(null), c(ne(!1)), c(ae(null)), c(re()), c(ie(""));
    },
    [x, c]
  );
  const C = !!h.showUnread || !!h.selectedDateRange, g = (N) => new Date(N).toLocaleDateString("fa-IR"), k = (N) => {
    if (!N)
      return null;
    const b = g(N.startDate), p = g(N.endDate);
    return `${m.fromDate} ${b} ${m.to} ${p}`;
  };
  return /* @__PURE__ */ u("div", { className: "flex flex-col", children: [
    /* @__PURE__ */ u(
      "div",
      {
        className: `px-[15px] gap-3 overflow-hidden transition-all duration-300 ease-in-out bg-bgInput flex justify-between items-center ${x ? "max-h-[47px]" : "max-h-0"}`,
        children: [
          x && /* @__PURE__ */ s(
            fs,
            {
              autoFocus: !0,
              placeholder: m.search,
              onChange: w,
              value: e,
              parentClassname: "w-full flex items-center w-full",
              className: "bg-bgInput h-[47px] w-full my-[10px] border-none focus:outline-none focus:ring-0 text-invertBlackWhite",
              postfixIcon: e !== "" && /* @__PURE__ */ s(
                Y,
                {
                  size: 24,
                  onClick: f,
                  className: "cursor-pointer text-accent"
                }
              )
            }
          ),
          /* @__PURE__ */ u("div", { className: "relative", children: [
            /* @__PURE__ */ s(
              "button",
              {
                onClick: () => a((N) => !N),
                className: "text-accent",
                children: /* @__PURE__ */ s(ct, {})
              }
            ),
            C && /* @__PURE__ */ s("div", { className: "absolute -top-1 -left-1 w-3 h-3 rounded-full bg-accent" })
          ] }),
          /* @__PURE__ */ s(
            ps,
            {
              showSearchFilter: n,
              handleShowSearchFilter: () => a((N) => !N),
              showUnread: r,
              setShowUnread: i,
              selectedDateRange: l,
              setSelectedDateRange: o,
              onApply: I
            }
          )
        ]
      }
    ),
    x && C && /* @__PURE__ */ s("div", { className: "px-[15px] pb-2 bg-bgInput dark:text-white", children: /* @__PURE__ */ u("div", { className: "flex flex-wrap gap-2", children: [
      h.showUnread && /* @__PURE__ */ u("div", { className: "flex items-center gap-1 px-0 py-2 text-xs bg-spaceItems rounded-full", children: [
        /* @__PURE__ */ s("span", { children: m.unreadMessage }),
        /* @__PURE__ */ s(
          "button",
          {
            onClick: () => {
              c(ne(!1)), c(Ie()), i(!1);
            },
            className: "ml-1",
            children: /* @__PURE__ */ s(Y, { size: 14 })
          }
        )
      ] }),
      h.selectedDateRange && /* @__PURE__ */ u("div", { className: "flex items-center gap-1 px-0 py-2 text-xs bg-spaceItems rounded-full text-invertBlackWhite", children: [
        /* @__PURE__ */ s("span", { children: k(h.selectedDateRange) }),
        /* @__PURE__ */ s(
          "button",
          {
            onClick: () => {
              c(ae(null)), o(null);
            },
            className: "ml-1",
            children: /* @__PURE__ */ s(Y, { size: 14 })
          }
        )
      ] })
    ] }) })
  ] });
}, xs = () => {
  const { isConnected: e, isDisconnected: t, isReconnecting: n, timeUntilReconnect: a } = D((o) => o.connectionState), r = D(
    (o) => o.threads.loading.normal
  ), l = {
    reconnecting: /* @__PURE__ */ s("b", { className: "font-bold text-base text-accentWhite", children: "در انتظار شبکه... " }),
    disconnected: /* @__PURE__ */ u(Z, { children: [
      /* @__PURE__ */ s("b", { className: "font-bold text-base text-accentWhite", children: "عدم ارتباط... " }),
      /* @__PURE__ */ s("span", { className: "text-iconSecondary cursor-pointer", onClick: () => {
        ut().reconnect();
      }, children: "تلاش دوباره" }),
      /* @__PURE__ */ u("span", { className: "text-white text-[10px]", children: [
        "(",
        /* @__PURE__ */ s(dt, { initialSeconds: a / 1e3 }),
        ")"
      ] })
    ] })
  };
  return e ? /* @__PURE__ */ u(Z, { children: [
    /* @__PURE__ */ s(lt, { className: "text-accentWhite" }),
    r && /* @__PURE__ */ s(ye, { size: 5, color: "var(--color-white)" })
  ] }) : n ? /* @__PURE__ */ s("div", { className: "flex items-center gap[5px]", children: l.reconnecting }) : t ? /* @__PURE__ */ s("div", { className: "flex items-center gap-[5px]", children: l.disconnected }) : null;
}, ys = () => {
  const { showSearchInput: e } = D(
    (o) => o.filteredThreads
  ), { showRightMenu: t } = ve(), { isMobile: n } = Se(), a = mt(), r = Me(), i = () => {
    r("/setting"), r("/setting/proxy");
  }, { CUSTOMIZATION: l } = ht();
  return /* @__PURE__ */ u("div", { children: [
    /* @__PURE__ */ u("div", { className: "bg-asideHeadBg flex items-center justify-between    h-[60px]  border-b-[1px] border-b-borderHead ", children: [
      /* @__PURE__ */ u("div", { className: "flex items-center pr-[2px]", children: [
        /* @__PURE__ */ s(qe, {}),
        /* @__PURE__ */ s(xs, {})
      ] }),
      /* @__PURE__ */ u("div", { className: "flex items-center gap-0", children: [
        l.PROXY && /* @__PURE__ */ s(
          "div",
          {
            onClick: i,
            className: `cursor-pointer ${t ? "invisible" : "visible"}`,
            children: /* @__PURE__ */ s(ft, { size: 20, className: "text-accentWhite" })
          }
        ),
        /* @__PURE__ */ s(
          "div",
          {
            onClick: () => {
              a(gt()), a(Ie());
            },
            className: `p-3 cursor-pointer ${t ? "invisible" : "visible"}`,
            children: e ? /* @__PURE__ */ s(Y, { size: 24, className: "text-accentWhite" }) : /* @__PURE__ */ s(pt, { className: "rotate-90 text-accentWhite" })
          }
        )
      ] })
    ] }),
    n && /* @__PURE__ */ s(Xe, {}),
    /* @__PURE__ */ s(gs, {})
  ] });
}, vs = ({
  draft: e,
  isActive: t
}) => {
  const n = "text-lightText h-[20px] ", a = t ? "text-lightText" : "text-colorRedLight", r = le(Ae(e != null ? e : ""), {
    basePath: "/assets/emoji-sprites",
    ext: ".png",
    ignoreSanitize: !1,
    className: "emoji-sprite w-[20px] h-[20px]"
    // کلاس خودمون
  });
  return /* @__PURE__ */ u("div", { className: "flex items-center  max-w-[220px]", children: [
    /* @__PURE__ */ u("span", { className: `${a} truncate flex-shrink-0`, children: [
      m.draft,
      ":"
    ] }),
    /* @__PURE__ */ s(
      "span",
      {
        className: `${n} truncate`,
        children: r
      }
    )
  ] });
}, ws = A.memo(vs), bs = ({
  payload: e,
  isActive: t
}) => {
  var r;
  if (!e)
    return null;
  const n = "text-gray-400", a = typeof e == "string" ? e : (r = e == null ? void 0 : e.text) != null ? r : String(e);
  return /* @__PURE__ */ s("div", { className: `text-xs  ${n}`, children: a });
}, Ns = A.memo(bs), Cs = ({
  payload: e,
  isActive: t
}) => {
  var i;
  if (!e)
    return null;
  const n = "text-gray-400", a = (i = e.Icon) != null ? i : null, r = e.Text();
  return /* @__PURE__ */ u("div", { className: "flex items-center gap-1 text-xs ", children: [
    a ? /* @__PURE__ */ s(a, {}) : null,
    /* @__PURE__ */ s("div", { className: `truncate ${n}`, children: r })
  ] });
}, Ts = A.memo(Cs), Is = ({ message: e, isMessageByMe: t, isGroup: n }) => {
  var h, x;
  const a = "text-lightText h-auto ", r = "text-[var(--color-accent)]", i = e || { message: "" }, l = (x = (h = i.message) != null ? h : i.text) != null ? x : "", o = q(
    () => {
      var y;
      return le((y = Ae(l)) != null ? y : "");
    },
    [l]
  ), c = q(() => {
    var y, w, f;
    return n ? t ? m.you : ((y = i.participant) == null ? void 0 : y.contactName) || ((w = i.participant) == null ? void 0 : w.name) || ((f = i.participant) == null ? void 0 : f.username) || "" : "";
  }, [n, t, i.participant]);
  return xt(i) ? /* @__PURE__ */ u("div", { className: "flex items-center gap-1 text-xs max-w-[220px]", children: [
    c && /* @__PURE__ */ u("span", { className: r, children: [
      c,
      ":"
    ] }),
    /* @__PURE__ */ s("span", { className: a, children: t ? m.sendLocation : m.receiveLocation })
  ] }) : yt(i) ? /* @__PURE__ */ u("div", { className: "flex items-center gap-1 text-xs max-w-[220px]", children: [
    c && /* @__PURE__ */ u("span", { className: r, children: [
      c,
      ":"
    ] }),
    /* @__PURE__ */ s("span", { className: a, children: t ? m.sendVoice : m.receiveVoice })
  ] }) : vt(i) ? /* @__PURE__ */ u("div", { className: "flex items-center gap-1 text-xs max-w-[220px]", children: [
    c && /* @__PURE__ */ u("span", { className: r, children: [
      c,
      ":"
    ] }),
    /* @__PURE__ */ s("span", { className: a, children: t ? m.sendImage : m.receiveImage })
  ] }) : wt(i) ? /* @__PURE__ */ u("div", { className: "flex items-center gap-1 text-xs max-w-[220px]", children: [
    c && /* @__PURE__ */ u("span", { className: r, children: [
      c,
      ":"
    ] }),
    /* @__PURE__ */ s("span", { className: a, children: t ? m.sendFile : m.receiveFile })
  ] }) : /* @__PURE__ */ u("div", { className: "flex items-baseline", children: [
    c && /* @__PURE__ */ u("span", { className: r, children: [
      c,
      ":"
    ] }),
    /* @__PURE__ */ s(
      "p",
      {
        className: `${a} overflow-hidden text-ellipsis whitespace-nowrap text-[12px] ml-4`,
        children: o
      }
    )
  ] });
}, ks = A.memo(Is), Ss = ({ inviter: e, isActive: t, isGroup: n, threadType: a }) => {
  const r = t ? "text-gray-400" : "text-orange-300", i = t ? "text-gray-400" : "text-orange-300", l = (e == null ? void 0 : e.contactName) || (e == null ? void 0 : e.name) || "someone", o = {
    8: m.createChannel,
    1: m.createGroup,
    2: m.createGroup,
    0: m.createChat,
    64: m.createChannel
  }, c = () => typeof a == "number" ? o[a] : n ? m.createGroup : m.createChannel;
  return /* @__PURE__ */ u("div", { className: "flex items-center gap-1 text-xs max-w-[220px]", children: [
    /* @__PURE__ */ s("span", { className: `${i} truncate`, children: l }),
    /* @__PURE__ */ s("span", { className: `${r} truncate`, children: c() })
  ] });
}, Ms = A.memo(Ss);
function Ds(e) {
  const {
    lastMessageVO: t,
    lastMessage: n,
    isTyping: a,
    isGroup: r,
    isChannel: i,
    inviter: l,
    isMessageByMe: o,
    thread: c,
    user: h
  } = e;
  return q(() => {
    var f;
    if (!!(a && a.isTyping))
      return { state: "typing" };
    const y = typeof window != "undefined" ? localStorage.getItem(`DRAFT_MESSAGE_${c.id}`) : null;
    if (y)
      return { state: "draft", draft: y };
    const w = !!(n || t);
    if (!i && t && bt(t)) {
      const I = Nt({
        lastMessageVO: t,
        user: o,
        thread: c,
        isGroup: r
      });
      if (I)
        return { state: "call", payload: I };
    }
    return t && Ct(t) ? { state: "history", payload: Tt({
      message: t,
      conditionUser: (h == null ? void 0 : h.username) === ((f = t == null ? void 0 : t.participant) == null ? void 0 : f.username)
    }) } : w ? {
      state: "message",
      payload: t != null ? t : { text: n != null ? n : "" }
    } : l ? { state: "created", inviter: l } : { state: "created" };
  }, [
    t,
    n,
    a,
    r,
    i,
    l,
    o,
    c
  ]);
}
const As = (e) => {
  const { thread: t } = e, { lastMessageVO: n, inviter: a } = t, r = t.group, i = t.type === 8, l = D((y) => y.chat.currentUser), o = !!e.IsActiveThread, c = t.isTyping || null, h = n && l ? n.ownerId === l.id : !1, x = Ds({
    lastMessageVO: n,
    isGroup: r,
    isChannel: i,
    thread: t,
    inviter: a,
    isMessageByMe: h,
    user: l,
    isTyping: c
  });
  switch (x.state) {
    case "call":
      return /* @__PURE__ */ s(Ts, { payload: x.payload, isActive: o });
    case "typing":
      return /* @__PURE__ */ s(ns, {});
    case "draft":
      return /* @__PURE__ */ s(ws, { draft: t.draft, isActive: o });
    case "history":
      return /* @__PURE__ */ s(Ns, { payload: x.payload, isActive: o });
    case "message":
      return /* @__PURE__ */ s(
        ks,
        {
          message: x.payload,
          isActive: o,
          isMessageByMe: h,
          isGroup: r
        }
      );
    case "created":
      return /* @__PURE__ */ s(
        Ms,
        {
          inviter: a,
          isActive: o,
          isGroup: r,
          threadType: t.type
        }
      );
    default:
      return null;
  }
}, Ls = A.memo(As);
function Os(e = 0) {
  const t = Le(e), n = hs(t, Math.round);
  return _(() => {
    let a = null, r = 0;
    const i = 10, l = t.get(), o = (c) => {
      a || (a = c);
      const h = Math.min((c - a) / i, 1), x = 1 - Math.pow(1 - h, 4), y = l + (e - l) * x;
      t.set(y), h < 1 && (r = requestAnimationFrame(o));
    };
    return r = requestAnimationFrame(o), () => cancelAnimationFrame(r);
  }, [e, t]), { unreadCount: n };
}
const Rs = A.memo(
  ({
    thread: e,
    isSearching: t = !1,
    searchQuery: n = "",
    title: a,
    onSelect: r,
    onJoinToCall: i,
    isActive: l,
    isPinned: o = !1,
    showContextTick: c = !1,
    activeCall: h = 0
  }) => {
    var G, R, E, U, z;
    const x = It(e.time, "fa"), y = ts(a + ""), w = q(
      () => le(y + "", {
        parentClassName: "overflow-hidden text-ellipsis whitespace-nowrap"
      }),
      [a]
    ), f = t ? kt(y, n) : w, I = ee(), C = D(
      ($) => $.chat.currentUser
    ), [g, k] = H(!1), { unreadCount: N } = Os(e.unreadCount);
    _(() => {
      if (e.isMoving) {
        k(!0);
        const $ = setTimeout(() => {
          k(!1), I(St({ threadId: e.id }));
        }, 600);
        return () => clearTimeout($);
      }
    }, [e.isMoving, e.id, I]);
    const b = je(() => {
      r(e);
    }, [r, e]), p = Mt(e), F = !e.group && p.includes(ce.P2P), j = ((G = e.lastMessageVO) == null ? void 0 : G.ownerId) === (C == null ? void 0 : C.id) || ((E = (R = e.lastMessageVO) == null ? void 0 : R.participant) == null ? void 0 : E.id) === (C == null ? void 0 : C.id), P = ((U = e == null ? void 0 : e.callJoin) == null ? void 0 : U.id) && !h, L = F && j && !e.draft, W = e.mentioned && e.unreadCount > 0, O = L && e.partnerLastSeenMessageTime && ((z = e.lastMessageVO) == null ? void 0 : z.time) && e.partnerLastSeenMessageTime >= e.lastMessageVO.time;
    return /* @__PURE__ */ s(Dt, { children: /* @__PURE__ */ s(
      "div",
      {
        className: `rounded cursor-pointer ${o ? "bg-bgSecondary" : ""} ${g ? "thread-move-animation" : ""}`,
        children: /* @__PURE__ */ u(
          "div",
          {
            className: `${l ? "thread-item active-thread-item bg-bgActiveThread" : "thread-item"}`,
            children: [
              /* @__PURE__ */ s(
                "li",
                {
                  onClick: b,
                  className: "cursor-pointer h-[82px] p-2 hover:md:bg-hoverThread flex items-center justify-between",
                  children: /* @__PURE__ */ u("div", { className: "flex items-center w-full space-x-3 space-x-reverse", children: [
                    /* @__PURE__ */ u("div", { className: "relative", children: [
                      /* @__PURE__ */ s(
                        He,
                        {
                          size: "md",
                          firstName: e == null ? void 0 : e.title,
                          image: e == null ? void 0 : e.image,
                          inbox: (e == null ? void 0 : e.type) === De.SELF
                        }
                      ),
                      c && /* @__PURE__ */ s("div", { className: "absolute -right-01 -bottom-0 justify-center w-6 h-6 bg-accent rounded-full", children: /* @__PURE__ */ s(At, { className: "w-6 h-6" }) })
                    ] }),
                    /* @__PURE__ */ u("div", { className: "flex flex-col justify-center flex-1 gap-2 overflow-hidden", children: [
                      /* @__PURE__ */ s("div", { className: "flex items-center justify-between", children: /* @__PURE__ */ u("div", { className: "flex items-center text-sm font-bold truncate text-invertBlackWhite gap-x-1", children: [
                        /* @__PURE__ */ u(
                          "div",
                          {
                            className: `flex-1 ${l ? "text-accent" : "text-menuIconColor"}`,
                            children: [
                              p.includes(ce.Group) && /* @__PURE__ */ s(Lt, { size: 18 }),
                              p.includes(ce.Channel) && /* @__PURE__ */ s(Ot, { size: 18 })
                            ]
                          }
                        ),
                        /* @__PURE__ */ s("p", { children: f }),
                        Rt(e) && /* @__PURE__ */ s("span", { children: $t() })
                      ] }) }),
                      /* @__PURE__ */ s("div", { className: "flex items-center gap-1", children: /* @__PURE__ */ s("span", { className: "text-[12px] truncate text-secondary flex-1 flex items-center ", children: /* @__PURE__ */ s(
                        Ls,
                        {
                          thread: e,
                          isGroup: e.group,
                          IsActiveThread: l
                        }
                      ) }) })
                    ] }),
                    /* @__PURE__ */ u("div", { className: "flex flex-col items-end justify-end gap-2", children: [
                      P ? /* @__PURE__ */ s(
                        "button",
                        {
                          onClick: ($) => {
                            $.stopPropagation(), i && i(e);
                          },
                          className: "m-0  rounded-[5px] text-white  text-bold text-[10px] px-[5px] min-h-[23px]  bg-[#30d158] shadow-none",
                          children: "پیوستن به تماس"
                        }
                      ) : /* @__PURE__ */ u("div", { className: "flex items-center gap-1", children: [
                        L && /* @__PURE__ */ s("span", { className: "flex-shrink-0", children: O ? /* @__PURE__ */ s(
                          Ft,
                          {
                            className: "w-[18px] h-[18px]",
                            fill: "var(--color-accent)"
                          }
                        ) : /* @__PURE__ */ s(
                          Pt,
                          {
                            className: "w-[18px] h-[18px]",
                            fill: "var(--color-accent)"
                          }
                        ) }),
                        /* @__PURE__ */ s("span", { className: "text-[12px] text-[var(--light-text)] ", children: x })
                      ] }),
                      /* @__PURE__ */ u("div", { className: "flex items-center gap-1", children: [
                        (e == null ? void 0 : e.mute) && /* @__PURE__ */ s(
                          Vt,
                          {
                            stroke: "var(--color-secondary)",
                            fill: "var(--color-secondary)",
                            className: "ml-0 text-lg"
                          }
                        ),
                        (e == null ? void 0 : e.pin) && !(e != null && e.unreadCount) && /* @__PURE__ */ s(
                          jt,
                          {
                            stroke: "var(--color-secondary)",
                            fill: "var(--color-secondary)",
                            className: "ml-0 text-lg"
                          }
                        ),
                        W && /* @__PURE__ */ s("span", { className: "text-xs text-white rounded-full w-[24px] h-[24px] flex items-center justify-center bg-accent", children: "@" }),
                        e.unreadCount > 0 && /* @__PURE__ */ s(
                          "span",
                          {
                            className: `text-xs text-white rounded-full w-[24px] h-[24px] flex items-center justify-center ${e != null && e.mute ? "bg-gray-500" : "bg-accent"}`,
                            children: e.unreadCount > 999 ? "۹۹۹+" : /* @__PURE__ */ s(Et.div, { children: N })
                          }
                        ),
                        (e == null ? void 0 : e.closed) && /* @__PURE__ */ s(
                          Ut,
                          {
                            className: "ml-2 text-lg animate-fadeIn",
                            fill: "var(--color-secondary)"
                          }
                        )
                      ] })
                    ] })
                  ] })
                }
              ),
              /* @__PURE__ */ s(
                be,
                {
                  height: "h-[0.75px]",
                  bg: "bg-divider",
                  width: "w-[calc(100%-75px)]",
                  className: "relative right-[75px]"
                }
              )
            ]
          }
        )
      },
      e.id
    ) });
  }
);
var V = function() {
  return V = Object.assign || function(t) {
    for (var n, a = 1, r = arguments.length; a < r; a++) {
      n = arguments[a];
      for (var i in n) Object.prototype.hasOwnProperty.call(n, i) && (t[i] = n[i]);
    }
    return t;
  }, V.apply(this, arguments);
};
function $s(e, t) {
  var n = {};
  for (var a in e) Object.prototype.hasOwnProperty.call(e, a) && t.indexOf(a) < 0 && (n[a] = e[a]);
  if (e != null && typeof Object.getOwnPropertySymbols == "function")
    for (var r = 0, a = Object.getOwnPropertySymbols(e); r < a.length; r++)
      t.indexOf(a[r]) < 0 && Object.prototype.propertyIsEnumerable.call(e, a[r]) && (n[a[r]] = e[a[r]]);
  return n;
}
var Fs = function(e) {
  var t = e.animate, n = t === void 0 ? !0 : t, a = e.backgroundColor, r = a === void 0 ? "#f5f6f7" : a, i = e.backgroundOpacity, l = i === void 0 ? 1 : i, o = e.baseUrl, c = o === void 0 ? "" : o, h = e.children, x = e.foregroundColor, y = x === void 0 ? "#eee" : x, w = e.foregroundOpacity, f = w === void 0 ? 1 : w, I = e.gradientRatio, C = I === void 0 ? 2 : I, g = e.uniqueKey, k = e.rtl, N = k === void 0 ? !1 : k, b = e.speed, p = b === void 0 ? 1.2 : b, F = e.style, j = F === void 0 ? {} : F, P = e.title, L = P === void 0 ? "Loading..." : P, W = e.beforeMask, O = W === void 0 ? null : W, G = $s(e, ["animate", "backgroundColor", "backgroundOpacity", "baseUrl", "children", "foregroundColor", "foregroundOpacity", "gradientRatio", "uniqueKey", "rtl", "speed", "style", "title", "beforeMask"]), R = Ee();
  g && (R = g);
  var E = "".concat(R, "-diff"), U = "".concat(R, "-animated-diff"), z = "".concat(R, "-aria"), $ = N ? { transform: "scaleX(-1)" } : null, J = "".concat(p, "s"), K = "".concat(C * -1, " 0"), Q = "".concat(C, " 0");
  return T(
    "svg",
    V({ "aria-labelledby": z, role: "img", style: V(V({}, j), $) }, G),
    L ? T("title", { id: z }, L) : null,
    O && Ue(O) ? O : null,
    T("rect", { role: "presentation", x: "0", y: "0", width: "100%", height: "100%", clipPath: "url(".concat(c, "#").concat(E, ")"), style: { fill: "url(".concat(c, "#").concat(U, ")") } }),
    T(
      "defs",
      null,
      T("clipPath", { id: E }, h),
      T(
        "linearGradient",
        { id: U, gradientTransform: "translate(".concat(K, ")") },
        T("stop", { offset: "0%", stopColor: r, stopOpacity: l }),
        T("stop", { offset: "50%", stopColor: y, stopOpacity: f }),
        T("stop", { offset: "100%", stopColor: r, stopOpacity: l }),
        n && T("animateTransform", { attributeName: "gradientTransform", type: "translate", values: "".concat(K, "; 0 0; ").concat(Q), dur: J, repeatCount: "indefinite" })
      )
    )
  );
}, Re = function(e) {
  return e.children ? T(Fs, V({}, e)) : T(Ps, V({}, e));
}, Ps = function(e) {
  return T(
    Re,
    V({ viewBox: "0 0 476 124" }, e),
    T("rect", { x: "48", y: "8", width: "88", height: "6", rx: "3" }),
    T("rect", { x: "48", y: "26", width: "52", height: "6", rx: "3" }),
    T("rect", { x: "0", y: "56", width: "410", height: "6", rx: "3" }),
    T("rect", { x: "0", y: "72", width: "380", height: "6", rx: "3" }),
    T("rect", { x: "0", y: "88", width: "178", height: "6", rx: "3" }),
    T("circle", { cx: "20", cy: "20", r: "20" })
  );
};
function Vs() {
  const { theme: e } = we();
  return Array.from({ length: 15 }).map((t, n) => /* @__PURE__ */ u(
    Re,
    {
      className: "bg-bgColor",
      backgroundColor: e === "dark" ? "#292929" : "#EFEEF3",
      foregroundColor: "#8b8a8f",
      rtl: !0,
      speed: 2,
      viewBox: "0 0 380 84",
      children: [
        /* @__PURE__ */ s("rect", { x: "85", y: "31", rx: "3", ry: "3", width: "100", height: "10" }),
        /* @__PURE__ */ s("circle", { cx: "45", cy: "45", r: "30" }),
        /* @__PURE__ */ s("rect", { x: "85", y: "57", rx: "3", ry: "3", width: "30", height: "10" }),
        /* @__PURE__ */ s("rect", { x: "120", y: "57", rx: "3", ry: "3", width: "150", height: "10" })
      ]
    },
    n + ""
  ));
}
const js = ({
  archived: e = !1,
  thread: t,
  onSelectThread: n,
  // onArchiveThread,
  onUnArchiveThread: a,
  setOpenArchiveConfirm: r
}) => {
  const i = ee(), l = D((p) => p.threads.threads), o = De.SELF === t.type, h = l.filter((p) => !!p.pin).length >= zt && !t.pin, x = t.unreadCount > 0, y = t.closed === !0, w = t.mute === !0, f = t.pin === !0;
  if (y && e)
    return null;
  const I = () => {
    i(Gt({ threadId: t.id, mute: !w }));
  }, C = () => {
    i(Ht({ threadId: t.id, pin: !f })).unwrap().catch((p) => alert((p == null ? void 0 : p.message) || "خطا در پین کردن"));
  }, g = () => {
    var p;
    (p = t.lastMessageVO) != null && p.id && i(
      Wt({
        threadId: t.id,
        messageId: t.lastMessageVO.id
      })
    );
  }, k = () => {
    r == null || r(!0);
  }, b = (o ? [
    {
      title: "بازکردن گفتگو",
      action: () => n(t)
    },
    {
      title: f ? "برداشتن از بالا" : "چسباندن به بالا",
      action: C,
      hidden: h
    }
  ] : e ? [
    // Archived threads
    {
      title: m.readMessage,
      action: () => n(t),
      hidden: !x || y
    },
    {
      title: m.unArchive,
      action: () => a == null ? void 0 : a(t)
    }
  ] : y ? [
    // Closed threads (not archived)
    { title: "بازکردن گفتگو", action: () => n(t) },
    ...f ? [
      {
        title: "برداشتن از بالا",
        action: C,
        hidden: h
      }
    ] : []
  ] : [
    // Normal active threads
    { title: "بازکردن گفتگو", action: () => n(t) },
    {
      title: m.readMessage,
      action: g,
      hidden: !x
    },
    {
      title: w ? "برقراری اعلانات" : "قطع اعلانات",
      action: I
    },
    {
      title: f ? "برداشتن از بالا" : "چسباندن به بالا",
      action: C,
      hidden: h
    },
    { title: m.archive, action: k }
  ]).filter((p) => !p.hidden);
  return /* @__PURE__ */ s(Z, { children: /* @__PURE__ */ s(as, { children: /* @__PURE__ */ s(rs, { className: "bg-bgColor shadow-dropDown rounded-md min-w-[160px] text-right z-[101]", children: b.map((p, F) => /* @__PURE__ */ s(
    is,
    {
      className: "px-3 py-2 text-[14px] hover:text-accent rounded cursor-pointer text-text select-none outline-none",
      onSelect: p.action,
      children: p.title
    },
    F
  )) }) }) });
}, Es = ({
  archived: e = !1,
  isMenuOpen: t,
  thread: n,
  onSelectThread: a,
  onArchiveThread: r,
  onUnArchiveThread: i
}) => {
  const [l, o] = A.useState(!1);
  return n.closed === !0 && e ? null : /* @__PURE__ */ u(Z, { children: [
    t && /* @__PURE__ */ s(
      js,
      {
        thread: n,
        archived: e,
        onArchiveThread: r,
        onUnArchiveThread: i,
        onSelectThread: a,
        setOpenArchiveConfirm: o
      }
    ),
    /* @__PURE__ */ s(
      Te,
      {
        open: l,
        onOpenChange: o,
        title: m.archiveConfirm,
        description: m.archiveConfirmDescription,
        size: "sm",
        confirmText: m.archive,
        cancelText: m.cancel,
        onConfirm: () => {
          r == null || r(n), o(!1);
        },
        onCancel: () => o(!1)
      }
    )
  ] });
}, Us = () => {
  var Q;
  const e = ee(), { isMobile: t } = Se(), n = Me(), { showToast: a } = _t(), { threads: r, hasMore: i, loading: l, loadingFromDown: o, nextOffset: c } = D((d) => d.threads), h = ((Q = D((d) => d.threads.thread)) == null ? void 0 : Q.id) || 0, x = D((d) => d.call.callId), { openOrCreateThread: y } = Ye(), { searchResults: w, filters: f, showSearchInput: I } = D(
    (d) => d.filteredThreads
  );
  let g = f.showUnread || f.selectedDateRange ? r : r.filter((d) => !d.archiveThread);
  f.showUnread && (g = g.filter((d) => d.unread)), f.selectedDateRange && (g = g.filter(
    (d) => d.time >= f.selectedDateRange.startDate && d.time <= f.selectedDateRange.endDate
  ));
  const k = (d) => {
    const S = d.filter((M) => M.pin), v = d.filter((M) => !M.pin).sort((M, B) => B.time - M.time);
    return S.concat(v);
  }, N = q(
    () => k(g),
    [r, f]
  ), b = w.searchQuery.trim().length > 0, p = [];
  b && (p.push({ type: "header", text: m.threads }), w.threads.length > 0 ? w.threads.forEach(
    (d) => p.push({ type: "thread", data: d })
  ) : p.push({ type: "noResult", text: m.noResult }), p.push({ type: "header", text: m.contacts }), w.contacts.length > 0 ? w.contacts.forEach(
    (d) => p.push({ type: "contact", data: d })
  ) : p.push({ type: "noResult", text: m.noResult }));
  const F = N.map((d) => ({
    type: "thread",
    data: d
  })), j = b ? p : F, [P, L] = A.useState(null), W = Ne(), O = (d) => {
    n("/thread", {
      replace: !1
    }), e(Jt(!1)), e(qt(!1)), (d == null ? void 0 : d.id) !== h && (setTimeout(() => {
      e(Kt(d));
    }, 0), e(Qt("threadInfo")));
  }, G = (d) => {
    e(Zt({ thread: d }));
  }, R = (d) => pe(null, null, function* () {
    const S = d.userId || parseInt(d.id), v = r.find((M) => M.partner === S);
    v ? O(v) : yield y(d.linkedUser);
  });
  if (l.normal && c.normal === 0 && !b)
    return /* @__PURE__ */ s(Vs, {});
  const E = (d) => {
    var S, v, M, B;
    if (Ze(r, d.id)) {
      a(
        "امکان پیوستن به این تماس وجود ندارد, شما در تماس دیگری فعال هستید . ",
        "error",
        {
          containerId: "link-toaster-dark"
        }
      );
      return;
    }
    _e(d == null ? void 0 : d.callJoin) ? e(
      Xt({
        show: !0,
        callId: (v = (S = d == null ? void 0 : d.callJoin) == null ? void 0 : S.id) != null ? v : 1,
        group: d.group,
        threadId: d.id
      })
    ) : e(
      Yt({
        show: !0,
        callId: (B = (M = d == null ? void 0 : d.callJoin) == null ? void 0 : M.id) != null ? B : 1,
        group: d.group,
        threadId: d.id
      })
    );
  }, U = (d, S) => {
    if (S.type === "header")
      return /* @__PURE__ */ s(
        "div",
        {
          className: "px-4 py-2 text-xs text-center bg-bgSpacer text-textGrayColor",
          children: S.text
        },
        `header-${d}`
      );
    if (S.type === "thread") {
      const v = S.data, M = t ? h === (v == null ? void 0 : v.id) && W : h === (v == null ? void 0 : v.id);
      return /* @__PURE__ */ u(
        cs,
        {
          modal: !1,
          onOpenChange: (B) => {
            B ? L(v.id) : P === v.id && L(null);
          },
          children: [
            /* @__PURE__ */ s(os, { children: /* @__PURE__ */ s(
              Rs,
              {
                isSearching: b,
                searchQuery: w.searchQuery.trim(),
                title: v.title,
                onJoinToCall: E,
                isPinned: v.pin,
                onSelect: O,
                thread: v,
                activeCall: x,
                isActive: M,
                showContextTick: P === v.id
              }
            ) }),
            /* @__PURE__ */ s(
              Es,
              {
                isMenuOpen: P === v.id,
                onSelectThread: O,
                onArchiveThread: G,
                thread: v
              }
            )
          ]
        },
        v.id
      );
    } else if (S.type === "contact") {
      const v = S.data;
      return /* @__PURE__ */ s("div", { children: /* @__PURE__ */ s(Be, { contact: v, handleSelect: R }) }, `contact-${v.id}`);
    } else if (S.type === "noResult")
      return /* @__PURE__ */ s(
        "div",
        {
          className: "px-4 py-2 text-sm text-center text-gray-500",
          children: S.text
        },
        `noResult-${d}`
      );
    return null;
  }, z = () => {
    !b && i.normal && !o.normal && !f.showUnread && e(
      Bt({
        count: oe,
        offset: c.normal,
        threadName: ""
      })
    ), f.showUnread && !o.unread && !l.unread && !b && i.unread && $();
  };
  function $() {
    e(
      ke({
        count: oe,
        offset: c.unread
      })
    );
  }
  if (f.showUnread && l.unread)
    return /* @__PURE__ */ s("div", { className: "bg-bgColor text-center text-invertBlackWhite mt-3", children: /* @__PURE__ */ s("p", { children: "در حال جست و جو ..." }) });
  if (f.showUnread && j.length === 0)
    return /* @__PURE__ */ s("div", { className: "bg-bgColor text-center text-invertBlackWhite mt-3", children: /* @__PURE__ */ s("p", { children: "گفتگوی خوانده نشده پیدا نشد ." }) });
  if (w.isSearching)
    return /* @__PURE__ */ s("div", { className: "bg-bgColor", children: /* @__PURE__ */ s(We, {}) });
  let J = 60;
  I && (J += 47), (f.showUnread || f.selectedDateRange) && (J += 40);
  const K = f.showUnread ? o.unread : o.normal;
  return /* @__PURE__ */ s(
    "div",
    {
      className: "flex flex-col      ",
      style: { height: `calc(100% - ${J}px)` },
      children: /* @__PURE__ */ s(
        Ge,
        {
          components: {
            Footer: () => K && /* @__PURE__ */ s("div", { className: "py-2", children: /* @__PURE__ */ s(ye, { size: 5 }) })
          },
          onScroll: () => L(null),
          data: j,
          className: "scroll-container thin-scroll",
          overscan: 100,
          defaultItemHeight: 81.99,
          increaseViewportBy: { top: 0, bottom: 500 },
          endReached: z,
          style: {
            direction: "rtl"
          },
          totalCount: j.length,
          itemContent: U
        }
      )
    }
  );
}, zs = A.lazy(
  () => import("./HamburgerMenu-DfoRgV3L.js")
), Hs = A.lazy(() => import("./index-CTkNqo8y.js")), Ws = () => {
  const { handleToggle: e } = ve(), { pathname: t } = es(), n = Ne(), a = D(
    (r) => r.appConfig.AsideBanner
  );
  return /* @__PURE__ */ u(
    "aside",
    {
      id: "asideThread",
      className: `w-full z-chatThreadList ${n ? "hidden lg:block " : "lg:block"} sm:w-full lg:w-1/4 relative bg-bgColor overflow-y-hidden h-full shadow-md`,
      children: [
        /* @__PURE__ */ u(
          Je,
          {
            disabled: !1,
            onOutsideClick: (r) => {
              r.target.closest("[aria-expanded]") || e(!0);
            },
            children: [
              /* @__PURE__ */ s(Hs, {}),
              /* @__PURE__ */ s(zs, {})
            ]
          }
        ),
        /* @__PURE__ */ u("div", { className: `h-full ${t === "/folders" ? "hidden" : ""}`, children: [
          /* @__PURE__ */ s(ys, {}),
          a,
          /* @__PURE__ */ s(Us, {})
        ] }),
        /* @__PURE__ */ s(Ke, {})
      ]
    }
  );
}, _s = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null,
  default: Ws
}, Symbol.toStringTag, { value: "Module" }));
export {
  Vs as T,
  Rs as a,
  js as b,
  _s as i
};
