var F = Object.defineProperty, T = Object.defineProperties;
var W = Object.getOwnPropertyDescriptors;
var g = Object.getOwnPropertySymbols;
var E = Object.prototype.hasOwnProperty, L = Object.prototype.propertyIsEnumerable;
var v = (r, t, e) => t in r ? F(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e, k = (r, t) => {
  for (var e in t || (t = {}))
    E.call(t, e) && v(r, e, t[e]);
  if (g)
    for (var e of g(t))
      L.call(t, e) && v(r, e, t[e]);
  return r;
}, y = (r, t) => T(r, W(t));
var w = (r, t, e) => new Promise((x, o) => {
  var n = (l) => {
    try {
      i(e.next(l));
    } catch (m) {
      o(m);
    }
  }, u = (l) => {
    try {
      i(e.throw(l));
    } catch (m) {
      o(m);
    }
  }, i = (l) => l.done ? x(l.value) : Promise.resolve(l.value).then(n, u);
  i((e = e.apply(r, t)).next());
});
import { jsx as s, jsxs as d } from "react/jsx-runtime";
import { useState as p, useEffect as M } from "react";
import { g as j, e as A, eI as S, eh as V } from "./main-CxoAwMiG.js";
import { b as G } from "./helpers-DcTymofH.js";
const q = ({ open: r, setOpen: t, init: e, onComplete: x }) => {
  const o = e || {
    firstName: "",
    lastName: "",
    username: ""
  }, [n, u] = p(o), i = j(), [l, m] = p(!1), { openOrCreateThread: C } = G(), [I, h] = p(""), N = (c) => {
    const { name: a, value: f } = c.target;
    u((B) => y(k({}, B), { [a]: f }));
  };
  function b() {
    t(!1), h(""), u(o);
  }
  M(() => {
    r || u(o);
  }, [r, i, e]);
  function U(c) {
    return c.username.trim() ? c.firstName.trim() ? "" : "نام اجباری است" : "نام کاربری یا موبایل اجباری است";
  }
  return /* @__PURE__ */ s("div", { children: /* @__PURE__ */ s(
    A,
    {
      disableAutoFocus: !0,
      open: r,
      onOpenChange: () => {
        t(!r), h("");
      },
      title: "اضافه کردن مخاطب جدید",
      closable: !1,
      size: "xs",
      errorText: I || void 0,
      onConfirm: () => w(null, null, function* () {
        var c;
        if (!n.firstName.trim() || !n.username.trim()) {
          const a = U(n);
          h(a);
          return;
        }
        m(!0), h("");
        try {
          const a = yield i(
            S({
              firstName: n.firstName,
              addBy: n.username,
              lastName: n.lastName
            })
          ).unwrap();
          if (m(!1), a.hasError || !a.linkedUser) {
            h((c = a.errorMessage) != null ? c : "کاربر یافت نشد");
            return;
          }
          if (b(), x) {
            x(a);
            return;
          }
          const f = a.id;
          if (!f)
            return;
          i(
            V({
              new_data: {
                coreUserId: a.linkedUser.coreUserId,
                contactFirstName: a.firstName,
                contactId: f,
                contactLastName: a.lastName,
                image: a.linkedUser.image
              }
            })
          ), yield C({
            coreUserId: a.linkedUser.coreUserId,
            username: a.linkedUser.username,
            contactId: f,
            participantInfo: {
              firstName: a.firstName,
              lastName: a.lastName,
              image: a.linkedUser.image
            }
          });
        } catch (a) {
          m(!1);
        }
      }),
      onCancel: () => b(),
      confirmText: l ? "در حال اضافه کردن..." : "اضافه کردن",
      cancelText: "انصراف",
      children: /* @__PURE__ */ s("div", { className: "mt-5", children: /* @__PURE__ */ s("form", { className: "h-full", noValidate: !0, children: /* @__PURE__ */ s("div", { className: "flex flex-1 h-full flex-col items-between justify-between", children: /* @__PURE__ */ d("div", { className: "gap-4", children: [
        /* @__PURE__ */ d("div", { className: "mb-10", children: [
          /* @__PURE__ */ d(
            "label",
            {
              className: "mb-2 mr-1 flex items-center gap-1 text-xs font-medium",
              htmlFor: "firstName",
              children: [
                /* @__PURE__ */ s("span", { className: "text-invertBlackWhite text-xs", children: "نام" }),
                /* @__PURE__ */ s("span", { className: "text-textGrayColor text-xs", children: "( اجباری )" })
              ]
            }
          ),
          /* @__PURE__ */ s(
            "input",
            {
              maxLength: 15,
              placeholder: "نام",
              id: "firstName",
              name: "firstName",
              value: n.firstName,
              onChange: N,
              disabled: l,
              className: "w-full outline-none px-3 py-[14px] bg-bgInput text-invertBlackWhite disabled:opacity-50 disabled:cursor-not-allowed"
            }
          )
        ] }),
        /* @__PURE__ */ d("div", { className: "mb-10", children: [
          /* @__PURE__ */ s(
            "label",
            {
              className: "mb-2 mr-1 flex text-invertBlackWhite text-xs",
              htmlFor: "lastName",
              children: /* @__PURE__ */ s("span", { children: "نام خانوادگی" })
            }
          ),
          /* @__PURE__ */ s(
            "input",
            {
              maxLength: 15,
              placeholder: "نام خانوادگی",
              id: "lastName",
              name: "lastName",
              value: n.lastName,
              onChange: N,
              disabled: l,
              className: "w-full px-3 outline-none py-[14px] bg-bgInput text-invertBlackWhite disabled:opacity-50 disabled:cursor-not-allowed"
            }
          )
        ] }),
        /* @__PURE__ */ d("div", { className: `${e != null && e.username ? "hidden" : "block"} mb-10`, children: [
          /* @__PURE__ */ d(
            "label",
            {
              className: "mb-2 mr-1 flex items-center gap-1 text-invertBlackWhite text-xs",
              htmlFor: "username",
              children: [
                /* @__PURE__ */ s("span", { children: "شماره موبایل یا نام کاربری " }),
                /* @__PURE__ */ s("span", { className: "text-textGrayColor text-xs", children: "( اجباری )" })
              ]
            }
          ),
          /* @__PURE__ */ s(
            "input",
            {
              placeholder: "شماره موبایل یا نام کاربری ",
              id: "username",
              name: "username",
              value: n.username,
              maxLength: 40,
              onChange: N,
              disabled: l,
              className: "w-full px-3 outline-none py-[14px] bg-bgInput text-invertBlackWhite disabled:opacity-50 disabled:cursor-not-allowed"
            }
          )
        ] })
      ] }) }) }) })
    }
  ) });
};
export {
  q as A
};
