(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[931],{8451:function(e,s,t){Promise.resolve().then(t.bind(t,5180))},5180:function(e,s,t){"use strict";t.r(s),t.d(s,{default:function(){return el}});var l=t(7437),a=t(2265),r=t(7732),n=t(9992),d=t(981),o=t(1178),i=t(3883),c=t(2095),x=t(3922),m=t(6325);function b(e){let{activeTab:s,setActiveTab:t,overdueCount:b=0,dueTodayCount:h=0,onOpenNewLead:p,onNewLead:u,onExportExcel:g,onImportExcel:j,onImportSuccess:f}=e,N=a.useRef(null),[v,y]=a.useState(!1),w=async e=>{var s;let t=null===(s=e.target.files)||void 0===s?void 0:s[0];if(!t)return;let l=new FormData;l.append("file",t),y(!0);try{let e=await fetch("/api/import",{method:"POST",body:l});if(e.ok)alert("فایل اکسل با موفقیت وارد و لیدها ثبت شدند."),f&&f();else{let s=await e.json();alert("خطا در ایمپورت اکسل: "+(s.error||"فرمت نامعتبر"))}}catch(e){alert("خطا در آپلود فایل: "+e.message)}finally{y(!1),e.target&&(e.target.value="")}},k=[{id:"dashboard",label:"داشبورد مدیریتی",icon:r.Z},{id:"today",label:"وظایف امروز",icon:n.Z,badge:h,isAlert:b>0},{id:"pipeline",label:"پایپ‌لاین فروش",icon:d.Z},{id:"onboarding",label:"آنبوردینگ مشتریان",icon:o.Z},{id:"settings",label:"تنظیمات و قوانین",icon:i.Z}];return(0,l.jsx)("header",{className:"sticky top-0 z-40 bg-white/95 backdrop-blur-md border-b border-slate-200/80 shadow-xs",children:(0,l.jsxs)("div",{className:"max-w-7xl mx-auto px-4 sm:px-6 lg:px-8",children:[(0,l.jsxs)("div",{className:"flex items-center justify-between h-16 gap-4",children:[(0,l.jsxs)("div",{className:"flex items-center gap-3.5 shrink-0",children:[(0,l.jsx)("div",{className:"w-10 h-10 rounded-xl bg-gradient-to-br from-sky-600 via-sky-700 to-indigo-800 flex items-center justify-center text-white font-extrabold text-xl shadow-sm shadow-sky-500/20 ring-1 ring-sky-500/30",children:"E"}),(0,l.jsxs)("div",{children:[(0,l.jsxs)("div",{className:"flex items-center gap-2",children:[(0,l.jsxs)("span",{className:"font-extrabold text-base sm:text-lg text-slate-900 tracking-tight",children:["اکیپا ",(0,l.jsx)("span",{className:"text-sky-600",children:"CRM"})]}),(0,l.jsxs)("span",{className:"inline-flex items-center gap-1 text-[10px] font-bold bg-sky-50 text-sky-700 px-2 py-0.5 rounded-full border border-sky-200/70",children:[(0,l.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-emerald-500 animate-pulse"}),"اتاق‌های فرار"]})]}),(0,l.jsx)("p",{className:"text-[11px] text-slate-500 hidden sm:flex items-center gap-1 font-medium",children:"سیستم جذب، فروش و آنبوردینگ"})]})]}),(0,l.jsx)("nav",{className:"hidden md:flex items-center bg-slate-100/80 p-1 rounded-xl border border-slate-200/60",children:k.map(e=>{let a=e.icon,r=s===e.id;return(0,l.jsxs)("button",{onClick:()=>t(e.id),className:"flex items-center gap-2 px-3 py-1.5 rounded-lg text-xs font-semibold transition-all duration-150 cursor-pointer ".concat(r?"bg-white text-sky-700 shadow-xs font-bold":"text-slate-600 hover:text-slate-900 hover:bg-white/60"),children:[(0,l.jsx)(a,{className:"w-3.5 h-3.5 ".concat(r?"text-sky-600":"text-slate-500")}),(0,l.jsx)("span",{children:e.label}),void 0!==e.badge&&e.badge>0&&(0,l.jsx)("span",{className:"text-[10px] font-bold px-1.5 py-0.2 rounded-full tabular-nums text-white ".concat(e.isAlert?"bg-rose-500 shadow-xs shadow-rose-500/30":"bg-amber-500"),children:e.badge})]},e.id)})}),(0,l.jsxs)("div",{className:"flex items-center gap-2 shrink-0",children:[(0,l.jsx)("input",{type:"file",ref:N,onChange:w,accept:".xlsx,.xls",className:"hidden"}),(0,l.jsxs)("button",{onClick:g,title:"دریافت فایل اکسل لیدها",className:"hidden sm:inline-flex items-center gap-1.5 px-3 py-1.5 text-xs font-semibold text-slate-700 bg-white hover:bg-slate-50 border border-slate-200 rounded-lg shadow-xs hover:border-slate-300 transition-all cursor-pointer",children:[(0,l.jsx)(c.Z,{className:"w-3.5 h-3.5 text-emerald-600"}),(0,l.jsx)("span",{children:"خروجی اکسل"})]}),(0,l.jsxs)("button",{onClick:()=>{N.current?N.current.click():j&&j()},disabled:v,title:"بارگذاری فایل اکسل",className:"hidden sm:inline-flex items-center gap-1.5 px-3 py-1.5 text-xs font-semibold text-slate-700 bg-white hover:bg-slate-50 border border-slate-200 rounded-lg shadow-xs hover:border-slate-300 transition-all cursor-pointer",children:[(0,l.jsx)(x.Z,{className:"w-3.5 h-3.5 text-indigo-600"}),(0,l.jsx)("span",{children:v?"در حال ورود...":"ورودی اکسل"})]}),(0,l.jsxs)("button",{onClick:p||u||(()=>{}),className:"inline-flex items-center gap-1.5 px-3.5 py-1.5 text-xs font-bold text-white bg-sky-600 hover:bg-sky-700 active:bg-sky-800 rounded-lg shadow-xs shadow-sky-600/20 hover:shadow-sm transition-all cursor-pointer",children:[(0,l.jsx)(m.Z,{className:"w-4 h-4 stroke-[2.5]"}),(0,l.jsx)("span",{children:"ثبت لید جدید"})]})]})]}),(0,l.jsx)("div",{className:"flex md:hidden items-center justify-between py-2 border-t border-slate-100 overflow-x-auto gap-2",children:k.map(e=>{let a=e.icon,r=s===e.id;return(0,l.jsxs)("button",{onClick:()=>t(e.id),className:"flex items-center gap-1 px-2.5 py-1.5 rounded-lg text-xs font-semibold whitespace-nowrap cursor-pointer transition-all ".concat(r?"bg-sky-50 text-sky-700 border border-sky-200":"text-slate-600 hover:bg-slate-100"),children:[(0,l.jsx)(a,{className:"w-3.5 h-3.5"}),(0,l.jsx)("span",{children:e.label}),void 0!==e.badge&&e.badge>0&&(0,l.jsx)("span",{className:"text-[10px] font-bold px-1 rounded-full bg-rose-500 text-white tabular-nums",children:e.badge})]},e.id)})})]})})}var h=t(1338),p=t(1996),u=t(7403),g=t(512),j=t(1192),f=t(6562),N=t(2076),v=t(7182),y=t(6754),w=t(3550),k=t(677);function C(e){let{stats:s={},funnel:t=[],topObjections:a=[],recentActivities:r=[],onSelectLead:d,onGoToTodayTasks:o,onNavigateTab:i}=e,c=(null==s?void 0:s.stats)||s||{},x=(null==t?void 0:t.length)?t:(null==s?void 0:s.funnel)||[],m=(null==a?void 0:a.length)?a:(null==s?void 0:s.topObjections)||[],b=(null==r?void 0:r.length)?r:(null==s?void 0:s.recentActivities)||[],C=o||(()=>i&&i("today")),S=[{title:"کل سرنخ‌های ثبت‌شده",value:(c.totalLeads||0).toLocaleString("fa-IR"),desc:"مجموعه‌های اتاق فرار در سامانه",icon:h.Z,color:"text-indigo-600",bgColor:"bg-indigo-50/80 ring-1 ring-indigo-500/20",border:"border-slate-200/80"},{title:"لیدهای داغ و اولویت بالا",value:(c.warmLeads||0).toLocaleString("fa-IR"),desc:"".concat(Math.round((c.warmLeads||0)/(c.totalLeads||1)*100),"% از کل فرصت‌ها"),icon:p.Z,color:"text-rose-600",bgColor:"bg-rose-50/80 ring-1 ring-rose-500/20",border:"border-slate-200/80"},{title:"پیگیری‌های معوق و امروز",value:(c.dueTodayCount||0).toLocaleString("fa-IR"),desc:"".concat(c.overdueCount||0," مورد نیازمند تماس فوری"),icon:u.Z,color:(c.overdueCount||0)>0?"text-amber-600":"text-emerald-600",bgColor:(c.overdueCount||0)>0?"bg-amber-50/80 ring-1 ring-amber-500/20":"bg-emerald-50/80 ring-1 ring-emerald-500/20",border:(c.overdueCount||0)>0?"border-amber-200":"border-slate-200/80",action:C},{title:"نرخ تبدیل نهایی (Won)",value:"".concat(c.conversionRate||0,"٪"),desc:"".concat(c.closedWonCount||0," قرارداد موفق اکیپا"),icon:g.Z,color:"text-emerald-600",bgColor:"bg-emerald-50/80 ring-1 ring-emerald-500/20",border:"border-slate-200/80"}];return(0,l.jsxs)("div",{className:"space-y-6",children:[(0,l.jsx)("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4",children:S.map((e,s)=>{let t=e.icon;return(0,l.jsx)("div",{onClick:e.action,className:"bg-white p-5 rounded-2xl border ".concat(e.border," shadow-xs hover:shadow-md transition-all duration-200 group ").concat(e.action?"cursor-pointer":""),children:(0,l.jsxs)("div",{className:"flex items-start justify-between",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("p",{className:"text-xs font-bold text-slate-500 mb-1",children:e.title}),(0,l.jsx)("h3",{className:"text-2xl font-black text-slate-900 tabular-nums tracking-tight",children:e.value}),(0,l.jsx)("p",{className:"text-[11px] font-medium text-slate-500 mt-1",children:e.desc})]}),(0,l.jsx)("div",{className:"p-3 rounded-xl ".concat(e.bgColor," transition-transform group-hover:scale-105 duration-200"),children:(0,l.jsx)(t,{className:"w-5 h-5 ".concat(e.color)})})]})},s)})}),(0,l.jsxs)("div",{className:"bg-gradient-to-r from-slate-900 via-sky-950 to-indigo-950 text-white rounded-2xl p-6 shadow-sm border border-slate-800 relative overflow-hidden",children:[(0,l.jsx)("div",{className:"absolute top-0 right-0 -mt-10 -mr-10 w-48 h-48 bg-sky-500/10 rounded-full blur-3xl pointer-events-none"}),(0,l.jsxs)("div",{className:"relative z-10 flex flex-col md:flex-row items-start md:items-center justify-between gap-4",children:[(0,l.jsxs)("div",{className:"space-y-1.5",children:[(0,l.jsxs)("div",{className:"inline-flex items-center gap-1.5 text-[10px] font-bold uppercase tracking-wider text-sky-300 bg-sky-900/60 border border-sky-700/50 px-2.5 py-0.5 rounded-full",children:[(0,l.jsx)(j.Z,{className:"w-3 h-3 text-sky-400"}),"عملکرد رشد و فروش اتاق‌های فرار در اکیپا"]}),(0,l.jsxs)("h3",{className:"text-lg sm:text-xl font-black text-white",children:["گردش مالی جذب‌شده: ",(0,l.jsx)("span",{className:"tabular-nums font-mono-num",children:(c.totalSalesAll||0).toLocaleString("fa-IR")})," تومان"]}),(0,l.jsxs)("p",{className:"text-xs text-slate-300",children:["فروش ماه گذشته مجموعه‌های عضو اکیپا:"," ",(0,l.jsxs)("strong",{className:"text-emerald-400 font-bold tabular-nums",children:[(c.totalSalesLastMonth||0).toLocaleString("fa-IR")," تومان"]})]})]}),(0,l.jsx)("div",{className:"flex items-center gap-3 shrink-0",children:(0,l.jsxs)("button",{onClick:C,className:"bg-white hover:bg-slate-50 text-slate-900 px-4 py-2 rounded-xl text-xs font-bold shadow-xs transition-all flex items-center gap-1.5 cursor-pointer active:scale-98",children:[(0,l.jsx)(n.Z,{className:"w-4 h-4 text-sky-600"}),(0,l.jsxs)("span",{children:["مشاهده کارتابل امروز (",c.dueTodayCount||0,")"]}),(0,l.jsx)(f.Z,{className:"w-3.5 h-3.5 text-slate-400"})]})})]})]}),(0,l.jsxs)("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-6",children:[(0,l.jsxs)("div",{className:"lg:col-span-2 bg-white rounded-2xl border border-slate-200/80 p-6 shadow-xs",children:[(0,l.jsxs)("div",{className:"flex items-center justify-between mb-5",children:[(0,l.jsxs)("div",{children:[(0,l.jsxs)("div",{className:"flex items-center gap-2",children:[(0,l.jsx)(N.Z,{className:"w-4 h-4 text-sky-600"}),(0,l.jsx)("h3",{className:"text-sm font-bold text-slate-900",children:"قیف فروش و مراحل پایپ‌لاین"})]}),(0,l.jsx)("p",{className:"text-[11px] text-slate-500 mt-0.5",children:"توزیع لیدها در مراحل ۷ گانه تا جذب و لوپ دوره‌ای"})]}),(0,l.jsxs)("span",{className:"text-xs font-bold text-slate-500 bg-slate-100 px-2.5 py-1 rounded-full tabular-nums",children:["مجموع: ",c.totalLeads||0]})]}),(0,l.jsx)("div",{className:"space-y-3.5",children:x.map((e,s)=>{let t="bg-sky-500",a="bg-sky-50 text-sky-700 border-sky-200";return e.stage.includes("موفق")?(t="bg-emerald-500",a="bg-emerald-50 text-emerald-700 border-emerald-200"):e.stage.includes("ناموفق")||e.stage.includes("بایگانی")?(t="bg-slate-400",a="bg-slate-50 text-slate-700 border-slate-200"):(e.stage.includes("گرم")||e.stage.includes("مذاکره"))&&(t="bg-rose-500",a="bg-rose-50 text-rose-700 border-rose-200"),(0,l.jsxs)("div",{className:"space-y-1.5 group",children:[(0,l.jsxs)("div",{className:"flex justify-between items-center text-xs",children:[(0,l.jsx)("span",{className:"font-bold text-slate-700",children:e.stage}),(0,l.jsxs)("div",{className:"flex items-center gap-2",children:[(0,l.jsxs)("span",{className:"text-[10px] font-bold px-2 py-0.5 rounded-full border tabular-nums ".concat(a),children:[e.count," مجموعه"]}),(0,l.jsxs)("span",{className:"text-slate-400 font-semibold tabular-nums w-8 text-left",children:[e.percentage,"%"]})]})]}),(0,l.jsx)("div",{className:"w-full bg-slate-100 rounded-full h-2 overflow-hidden",children:(0,l.jsx)("div",{className:"h-2 rounded-full transition-all duration-500 ".concat(t),style:{width:"".concat(Math.max(e.percentage,e.count>0?6:0),"%")}})})]},s)})})]}),(0,l.jsxs)("div",{className:"space-y-6",children:[(0,l.jsxs)("div",{className:"bg-white rounded-2xl border border-slate-200/80 p-6 shadow-xs",children:[(0,l.jsxs)("h3",{className:"text-sm font-bold text-slate-900 mb-4 flex items-center gap-2",children:[(0,l.jsx)(p.Z,{className:"w-4 h-4 text-rose-500"}),"وضعیت دمای لیدها (Lead Temperature)"]}),(0,l.jsxs)("div",{className:"space-y-2.5",children:[(0,l.jsxs)("div",{className:"flex items-center justify-between p-3 rounded-xl bg-rose-50/70 border border-rose-200/60",children:[(0,l.jsxs)("div",{className:"flex items-center gap-2.5",children:[(0,l.jsx)("span",{className:"w-2.5 h-2.5 rounded-full bg-rose-500 animate-pulse"}),(0,l.jsx)("span",{className:"text-xs font-bold text-rose-950",children:"لیدهای داغ و گرم"})]}),(0,l.jsx)("span",{className:"text-sm font-black text-rose-700 tabular-nums",children:c.warmLeads||0})]}),(0,l.jsxs)("div",{className:"flex items-center justify-between p-3 rounded-xl bg-amber-50/70 border border-amber-200/60",children:[(0,l.jsxs)("div",{className:"flex items-center gap-2.5",children:[(0,l.jsx)("span",{className:"w-2.5 h-2.5 rounded-full bg-amber-500"}),(0,l.jsx)("span",{className:"text-xs font-bold text-amber-950",children:"خنثی / در حال بررسی"})]}),(0,l.jsx)("span",{className:"text-sm font-black text-amber-700 tabular-nums",children:c.neutralLeads||0})]}),(0,l.jsxs)("div",{className:"flex items-center justify-between p-3 rounded-xl bg-slate-50/70 border border-slate-200/60",children:[(0,l.jsxs)("div",{className:"flex items-center gap-2.5",children:[(0,l.jsx)("span",{className:"w-2.5 h-2.5 rounded-full bg-slate-400"}),(0,l.jsx)("span",{className:"text-xs font-bold text-slate-800",children:"سرد / کم‌تعامل"})]}),(0,l.jsx)("span",{className:"text-sm font-black text-slate-700 tabular-nums",children:c.coldLeads||0})]})]})]}),(0,l.jsxs)("div",{className:"bg-white rounded-2xl border border-slate-200/80 p-6 shadow-xs",children:[(0,l.jsx)("div",{className:"flex items-center justify-between mb-3",children:(0,l.jsxs)("h3",{className:"text-sm font-bold text-slate-900 flex items-center gap-2",children:[(0,l.jsx)(v.Z,{className:"w-4 h-4 text-amber-500"}),"اعتراضات پرتکرار مدیران"]})}),0===m.length?(0,l.jsx)("p",{className:"text-xs text-slate-400 py-3 text-center",children:"هیچ اعتراضی در تماس‌ها ثبت نشده است."}):(0,l.jsx)("div",{className:"space-y-2",children:m.slice(0,4).map((e,s)=>(0,l.jsxs)("div",{className:"flex items-center justify-between text-xs p-2.5 rounded-xl bg-slate-50 border border-slate-100 hover:border-slate-200 transition-all",children:[(0,l.jsx)("span",{className:"font-semibold text-slate-700 truncate max-w-[180px]",children:e.name}),(0,l.jsxs)("span",{className:"font-bold text-[10px] bg-slate-200 text-slate-800 px-2 py-0.5 rounded-full tabular-nums",children:[e.count," مورد"]})]},s))})]})]})]}),(0,l.jsxs)("div",{className:"bg-white rounded-2xl border border-slate-200/80 p-6 shadow-xs",children:[(0,l.jsxs)("h3",{className:"text-sm font-bold text-slate-900 mb-4 flex items-center gap-2",children:[(0,l.jsx)(u.Z,{className:"w-4 h-4 text-indigo-500"}),"آخرین فعالیت‌ها و لاگ تعاملات ثبت‌شده"]}),0===b.length?(0,l.jsx)("p",{className:"text-xs text-slate-400 text-center py-6",children:"هنوز فعالیتی ثبت نشده است."}):(0,l.jsx)("div",{className:"divide-y divide-slate-100",children:b.map(e=>{let s=y.Z,t="text-sky-600 bg-sky-50 border-sky-200/60";return"call"===e.type?(s=w.Z,t="text-emerald-600 bg-emerald-50 border-emerald-200/60"):"stage_change"===e.type?(s=k.Z,t="text-purple-600 bg-purple-50 border-purple-200/60"):"sms"===e.type&&(s=y.Z,t="text-indigo-600 bg-indigo-50 border-indigo-200/60"),(0,l.jsxs)("div",{className:"py-3.5 flex items-start justify-between gap-3 text-xs first:pt-0 last:pb-0",children:[(0,l.jsxs)("div",{className:"flex items-start gap-3",children:[(0,l.jsx)("div",{className:"p-2 rounded-xl ".concat(t," border shrink-0 mt-0.5"),children:(0,l.jsx)(s,{className:"w-4 h-4"})}),(0,l.jsxs)("div",{children:[e.lead&&(0,l.jsx)("button",{onClick:()=>d&&d(e.lead.id),className:"font-bold text-sky-700 hover:text-sky-800 inline-block mb-0.5 cursor-pointer",children:e.lead.name}),(0,l.jsx)("p",{className:"text-slate-600 leading-relaxed whitespace-pre-line",children:e.content})]})]}),(0,l.jsx)("span",{className:"text-[11px] font-medium text-slate-400 shrink-0 tabular-nums",children:new Date(e.createdAt).toLocaleDateString("fa-IR")})]},e.id)})})]})]})}var S=t(9150),Z=t(776),T=t(9001);let P=[{currentStage:"ارتباط اولیه",nextStage:"ارسال پرپوزال",delayDays:0,channel:"پیامک",action:"ارسال پرپوزال اکیپا",smsTag:"خوش آمدگویی"},{currentStage:"ارسال پرپوزال",nextStage:"پیگیری سرد ۱",delayDays:1,channel:"پیامک",action:"پیامک راه‌حل اکیپا برای نقطه درد + دعوت به اقدام",smsTag:"خوش آمدگویی"},{currentStage:"مشاهده پرپوزال",nextStage:"پیگیری گرم ۱",delayDays:2,channel:"تماس",action:"رفع ابهام + پیشنهاد دو هفته‌ی رایگان اکیپا",smsTag:"اطلاع از آپدیت‌ها"},{currentStage:"پیگیری سرد ۱",nextStage:"پیگیری گرم ۱",delayDays:2,channel:"تماس",action:"پیگیری سوالات، مشاهده‌ی اطلاعات ارسالی، پیشنهاد دو هفته‌ی رایگان",smsTag:"اطلاع از آپدیت‌ها"},{currentStage:"پیگیری گرم ۱",nextStage:"پیگیری سرد ۲",delayDays:3,channel:"پیامک",action:"ارسال آمار موفقیت اکیپا و آمار لاین مجموعه با لینک",smsTag:"آمار موفقیت‌های اکیپا"},{currentStage:"پیگیری سرد ۲",nextStage:"پیگیری گرم ۲",delayDays:3,channel:"تماس",action:"جویا شدن علت عدم همکاری و رفع موانع اتصال",smsTag:"آمار موفقیت‌های اکیپا"},{currentStage:"پیگیری گرم ۲",nextStage:"لوپ پیامکی",delayDays:10,channel:"پیامک",action:"ورود به لوپ پیامکی خودکار اکیپا",smsTag:"آمار موفقیت‌های اکیپا"},{currentStage:"لوپ پیامکی",nextStage:"لوپ پیامکی",delayDays:10,channel:"پیامک",action:"پیامک لوپ دوره‌ای (ارسال آمار و نکات افزایش رزرو)",smsTag:"طبق جدول لوپ"}],_=["ارتباط اولیه","ارسال پرپوزال","مشاهده پرپوزال","پیگیری سرد ۱","پیگیری گرم ۱","پیگیری سرد ۲","پیگیری گرم ۲","لوپ پیامکی","بسته شد / موفق","بایگانی / ناموفق"].map(e=>({stage:e,name:e})),A=[{objection:"درصدی کار نمی‌کنیم / کمیسیون بالاست",rebuttal:"اکیپا کمیسیون را از افزایش فروش سانس‌های خالی پوشش می‌دهد؛ دو هفته اول بدون هیچ ریسک و هزینه‌ای تست کنید.",action:"ارسال ماشین‌حساب سودآوری اکیپا"},{objection:"خودمون سایت داریم و فروش کافیه",rebuttal:"سایت شما مخاطب ثابت شماست؛ اکیپا مسافران و کاربران جدید کشف‌نشده را به سانس‌های خالی وسط هفته شما می‌آورد.",action:"ارسال نمونه کیس‌استادی افزایش ۳۰٪ رزروهای خالی"},{objection:"نیاز به هماهنگی با شریک دارم",rebuttal:"کاملاً درسته؛ پرپوزال خلاصه تک‌صفحه‌ای اختصاصی برای ارائه به شریک برایتان ارسال شد، کی برای جلسه مشترک مناسب است؟",action:"تنظیم جلسه آنلاین ۵ دقیقه‌ای با شرکا"},{objection:"وقت پر کردن سانس و کار با پنل رو نداریم",rebuttal:"مدیریت و همگام‌سازی سانس‌ها از طریق وب‌هوک و پشتیبانی اکیپا کاملاً اتوماتیک انجام می‌شود، صفر بار کاری برای پرسنل شما.",action:"توضیح سیستم سینک خودکار سانس‌ها"}];function L(e){if(!e)return{overdue:!1,days:0};let s=new Date(e),t=new Date;s.setHours(0,0,0,0),t.setHours(0,0,0,0);let l=Math.floor((t.getTime()-s.getTime())/864e5);return{overdue:l>0,days:l>0?l:0}}function D(e){let{leads:s,onSelectLead:t,onAdvanceLead:r,onRefresh:n}=e,[d,o]=(0,a.useState)("kanban"),[i,c]=(0,a.useState)(""),[x,m]=(0,a.useState)("all"),[b,h]=(0,a.useState)("all"),[p,u]=(0,a.useState)("all"),g=s.filter(e=>{let s=e.name.toLowerCase().includes(i.toLowerCase())||e.ownerName.toLowerCase().includes(i.toLowerCase())||e.ownerPhone.includes(i)||e.city&&e.city.includes(i),t="all"===x||e.city===x,l="all"===b||e.temperature===b,a="all"===p||e.stage===p;return s&&t&&l&&a}),j=Array.from(new Set(s.map(e=>e.city).filter(Boolean))),N=async(e,s)=>{e.stopPropagation(),r?await r(s):await fetch("/api/leads/".concat(s,"/advance"),{method:"POST"}),n()};return(0,l.jsxs)("div",{className:"space-y-4",children:[(0,l.jsxs)("div",{className:"bg-white p-4 rounded-2xl border border-slate-200 shadow-sm flex flex-col md:flex-row items-center justify-between gap-3",children:[(0,l.jsxs)("div",{className:"flex flex-wrap items-center gap-2.5 w-full md:w-auto",children:[(0,l.jsxs)("div",{className:"relative w-full sm:w-64",children:[(0,l.jsx)(S.Z,{className:"w-4 h-4 text-slate-400 absolute right-3 top-2.5"}),(0,l.jsx)("input",{type:"text",placeholder:"جستجوی نام مجموعه، مدیر، شماره...",value:i,onChange:e=>c(e.target.value),className:"w-full pl-3 pr-9 py-1.5 text-xs border border-slate-300 rounded-xl focus:ring-2 focus:ring-sky-500"})]}),(0,l.jsxs)("select",{value:x,onChange:e=>m(e.target.value),className:"border border-slate-300 rounded-xl px-2.5 py-1.5 text-xs text-slate-700 focus:ring-2 focus:ring-sky-500",children:[(0,l.jsx)("option",{value:"all",children:"همه شهرها"}),j.map(e=>(0,l.jsx)("option",{value:e,children:e},e))]}),(0,l.jsxs)("select",{value:b,onChange:e=>h(e.target.value),className:"border border-slate-300 rounded-xl px-2.5 py-1.5 text-xs text-slate-700 focus:ring-2 focus:ring-sky-500",children:[(0,l.jsx)("option",{value:"all",children:"همه دماها"}),(0,l.jsx)("option",{value:"گرم",children:"فقط لیدهای گرم"}),(0,l.jsx)("option",{value:"خنثی",children:"فقط لیدهای خنثی"}),(0,l.jsx)("option",{value:"سرد",children:"فقط لیدهای سرد"})]}),"table"===d&&(0,l.jsxs)("select",{value:p,onChange:e=>u(e.target.value),className:"border border-slate-300 rounded-xl px-2.5 py-1.5 text-xs text-slate-700 focus:ring-2 focus:ring-sky-500",children:[(0,l.jsx)("option",{value:"all",children:"همه مراحل پایپ‌لاین"}),_.map(e=>{let s="string"==typeof e?e:e.stage;return(0,l.jsx)("option",{value:s,children:s},s)})]})]}),(0,l.jsxs)("div",{className:"flex items-center gap-1 bg-slate-100 p-1 rounded-xl self-end md:self-auto",children:[(0,l.jsxs)("button",{onClick:()=>o("kanban"),className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-bold transition-all ".concat("kanban"===d?"bg-white text-slate-900 shadow-sm":"text-slate-600 hover:text-slate-900"),children:[(0,l.jsx)(Z.Z,{className:"w-3.5 h-3.5"}),(0,l.jsx)("span",{children:"کانبان"})]}),(0,l.jsxs)("button",{onClick:()=>o("table"),className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-bold transition-all ".concat("table"===d?"bg-white text-slate-900 shadow-sm":"text-slate-600 hover:text-slate-900"),children:[(0,l.jsx)(T.Z,{className:"w-3.5 h-3.5"}),(0,l.jsx)("span",{children:"جدول"})]})]})]}),"kanban"===d&&(0,l.jsx)("div",{className:"flex gap-4 overflow-x-auto pb-6 pt-1",children:_.map(e=>{let s="string"==typeof e?e:e.stage,a=g.filter(e=>e.stage===s),r="bg-slate-100 text-slate-800";return"ارتباط اولیه"===s&&(r="bg-sky-100 text-sky-900"),s.includes("پرپوزال")&&(r="bg-blue-100 text-blue-900"),s.includes("گرم")&&(r="bg-rose-100 text-rose-900"),s.includes("سرد")&&(r="bg-slate-200 text-slate-800"),"لوپ پیامکی"===s&&(r="bg-indigo-100 text-indigo-900"),"بسته شد / موفق"===s&&(r="bg-emerald-100 text-emerald-900"),"بایگانی / ناموفق"===s&&(r="bg-gray-200 text-gray-700"),(0,l.jsxs)("div",{className:"w-72 shrink-0 bg-slate-50/70 rounded-2xl border border-slate-200 p-3 flex flex-col max-h-[calc(100vh-220px)]",children:[(0,l.jsxs)("div",{className:"p-2.5 rounded-xl ".concat(r," flex items-center justify-between mb-3 shadow-sm"),children:[(0,l.jsx)("h4",{className:"font-bold text-xs",children:s}),(0,l.jsx)("span",{className:"text-xs font-extrabold bg-white/70 px-2 py-0.5 rounded-full",children:a.length})]}),(0,l.jsx)("div",{className:"space-y-2.5 overflow-y-auto flex-1 pr-0.5 pl-0.5",children:0===a.length?(0,l.jsx)("div",{className:"text-center py-8 text-[11px] text-slate-400",children:"موردی در این مرحله نیست"}):a.map(e=>{let a=e.nextFollowupAt&&L(new Date(e.nextFollowupAt));return(0,l.jsxs)("div",{onClick:()=>t(e.id),className:"bg-white p-3.5 rounded-xl border border-slate-200 hover:border-sky-300 shadow-sm hover:shadow transition-all cursor-pointer space-y-2.5",children:[(0,l.jsxs)("div",{className:"flex items-start justify-between",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("h5",{className:"font-bold text-slate-900 text-xs",children:e.name}),(0,l.jsxs)("p",{className:"text-[11px] text-slate-500 mt-0.5",children:[e.city," ",e.district?"• ".concat(e.district):""]})]}),(0,l.jsx)("span",{className:"text-[10px] font-bold px-1.5 py-0.5 rounded ".concat("گرم"===e.temperature?"bg-rose-100 text-rose-700":"خنثی"===e.temperature?"bg-amber-100 text-amber-700":"bg-slate-100 text-slate-600"),children:e.temperature})]}),e.rooms&&e.rooms.length>0&&(0,l.jsx)("div",{className:"flex flex-wrap gap-1",children:e.rooms.map(e=>(0,l.jsx)("span",{className:"text-[10px] bg-slate-100 text-slate-600 px-1.5 py-0.2 rounded",children:e.title},e.id))}),(0,l.jsxs)("div",{className:"text-[11px] bg-slate-50 p-2 rounded-lg text-slate-600 space-y-1",children:[(0,l.jsxs)("div",{className:"flex items-center justify-between",children:[(0,l.jsxs)("span",{className:"font-semibold",children:["اقدام: ",e.nextChannel]}),a&&(0,l.jsx)("span",{className:"text-[9px] font-bold bg-rose-500 text-white px-1 py-0.2 rounded",children:"تاخیر"})]}),(0,l.jsx)("p",{className:"text-[10px] text-slate-500 line-clamp-1",children:e.nextAction})]}),(0,l.jsxs)("div",{className:"flex items-center justify-between pt-1",children:[(0,l.jsxs)("span",{className:"text-[10px] text-slate-400",children:["مدیر: ",e.ownerName]}),"بسته شد / موفق"!==s&&"بایگانی / ناموفق"!==s&&(0,l.jsxs)("button",{onClick:s=>N(s,e.id),title:"مرحله بعد",className:"flex items-center gap-1 text-[10px] font-bold bg-sky-50 hover:bg-sky-100 text-sky-700 px-2 py-1 rounded-md border border-sky-200 transition-colors",children:[(0,l.jsx)("span",{children:"مرحله بعد"}),(0,l.jsx)(f.Z,{className:"w-3 h-3"})]})]})]},e.id)})})]},s)})}),"table"===d&&(0,l.jsx)("div",{className:"bg-white rounded-2xl border border-slate-200 shadow-sm overflow-hidden",children:(0,l.jsx)("div",{className:"overflow-x-auto",children:(0,l.jsxs)("table",{className:"w-full text-right text-xs",children:[(0,l.jsx)("thead",{className:"bg-slate-50 text-slate-700 border-b border-slate-200 font-bold",children:(0,l.jsxs)("tr",{children:[(0,l.jsx)("th",{className:"py-3 px-4",children:"نام مجموعه"}),(0,l.jsx)("th",{className:"py-3 px-4",children:"شهر و منطقه"}),(0,l.jsx)("th",{className:"py-3 px-4",children:"مدیر و شماره"}),(0,l.jsx)("th",{className:"py-3 px-4",children:"مرحله فعلی"}),(0,l.jsx)("th",{className:"py-3 px-4",children:"دما"}),(0,l.jsx)("th",{className:"py-3 px-4",children:"اقدام و کانال بعدی"}),(0,l.jsx)("th",{className:"py-3 px-4",children:"تاریخ پیگیری"}),(0,l.jsx)("th",{className:"py-3 px-4 text-center",children:"عملیات"})]})}),(0,l.jsx)("tbody",{className:"divide-y divide-slate-100",children:0===g.length?(0,l.jsx)("tr",{children:(0,l.jsx)("td",{colSpan:8,className:"py-8 text-center text-slate-400",children:"هیچ موردی با فیلترهای انتخابی یافت نشد."})}):g.map(e=>{let s=e.nextFollowupAt&&L(new Date(e.nextFollowupAt));return(0,l.jsxs)("tr",{onClick:()=>t(e.id),className:"hover:bg-slate-50/80 cursor-pointer transition-colors",children:[(0,l.jsxs)("td",{className:"py-3 px-4 font-bold text-slate-900",children:[e.name,e.rooms&&(0,l.jsx)("span",{className:"text-[10px] text-slate-400 block font-normal",children:e.rooms.map(e=>e.title).join("، ")})]}),(0,l.jsxs)("td",{className:"py-3 px-4 text-slate-600",children:[e.city," ",e.district?"(".concat(e.district,")"):""]}),(0,l.jsxs)("td",{className:"py-3 px-4 text-slate-600",children:[(0,l.jsx)("span",{className:"font-semibold text-slate-800",children:e.ownerName}),(0,l.jsx)("span",{className:"block text-[11px] text-slate-400",children:e.ownerPhone})]}),(0,l.jsx)("td",{className:"py-3 px-4",children:(0,l.jsx)("span",{className:"bg-slate-100 text-slate-800 px-2 py-0.5 rounded-full font-medium",children:e.stage})}),(0,l.jsx)("td",{className:"py-3 px-4",children:(0,l.jsxs)("span",{className:"px-2 py-0.5 rounded-full font-bold text-[10px] ".concat("گرم"===e.temperature?"bg-rose-100 text-rose-700":"خنثی"===e.temperature?"bg-amber-100 text-amber-700":"bg-slate-100 text-slate-600"),children:[e.temperature," (",e.temperatureScore,")"]})}),(0,l.jsxs)("td",{className:"py-3 px-4 text-slate-700",children:[(0,l.jsxs)("span",{className:"font-semibold",children:[e.nextChannel,": "]}),(0,l.jsx)("span",{className:"text-slate-500",children:e.nextAction})]}),(0,l.jsx)("td",{className:"py-3 px-4 text-slate-600",children:e.nextFollowupAt?(0,l.jsxs)("span",{className:s?"text-rose-600 font-bold":"",children:[new Date(e.nextFollowupAt).toLocaleDateString("fa-IR"),s&&" (تاخیر)"]}):"—"}),(0,l.jsx)("td",{className:"py-3 px-4 text-center",children:(0,l.jsx)("button",{onClick:s=>N(s,e.id),className:"bg-sky-50 hover:bg-sky-100 text-sky-700 px-2.5 py-1 rounded-lg text-xs font-bold border border-sky-200 transition-colors",children:"مرحله بعد"})})]},e.id)})})]})})})]})}var O=t(1746),I=t(498),M=t(9811),R=t(4754),F=t(2850);t(257);let E={welcome_proposal:{title:"ارسال پرپوزال و خوش‌آمدگویی",template:"سلام {owner_name} عزیز، پرپوزال همکاری اختصاصی مجموعه {lead_name} با پلتفرم اکیپا آماده شد. برای افزایش رزرو سانس‌های وسط هفته می‌توانید از لینک زیر مشاهده کنید: https://ekipa.ir/p/{lead_id}\nتیم فروش اکیپا"},pain_solution:{title:"راه‌حل نقطه درد و آفر تست رایگان",template:"سلام {owner_name} گرامی، پیرو صحبت‌مون اکیپا دقیقاً برای پر کردن سانس‌های خالی {lead_name} راه‌اندازی شده است. ۲ هفته اول تست کاملاً رایگان و بدون ریسک است. برای فعال‌سازی کافیست عدد ۱ را ارسال کنید."},case_study:{title:"ارسال آمار موفقیت و کیس‌استادی",template:"سلام {owner_name} عزیز، ماه گذشته اسکیپ‌روم‌های همکار اکیپا میانگین ۳۸ رزرو جدید در سانس‌های کم‌مخاطب ثبت کردند. مشاهده آمار: https://ekipa.ir/stats\nاکیپا - همراه رشد اتاق فرار شما"},loop_nudge:{title:"پیامک دوره‌ای لوپ پیگیری",template:"{owner_name} عزیز سلام، راهنمای جدید اکیپا برای افزایش رزروهای آخر هفته {lead_name} منتشر شد: https://ekipa.ir/blog/tips\nمشتاق همکاری با مجموعه شما هستیم."}};function J(e){var s;let{tasks:t,data:r,onSendSms:d,onAdvanceLead:o,onToggleOnboardingTask:i,onSelectLead:c,onRefresh:x}=e,m=r||t||{summary:{totalDueToday:0,overdueCount:0,smsCount:0,callCount:0,onboardingCount:0},smsTasks:[],callTasks:[],onboardingTasks:[]},[b,h]=(0,a.useState)("sms"),[p,u]=(0,a.useState)([]),[g,j]=(0,a.useState)("welcome_proposal"),[f,N]=(0,a.useState)(""),[v,C]=(0,a.useState)(!1),[S,Z]=(0,a.useState)({}),T=e=>{p.includes(e)?u(p.filter(s=>s!==e)):u([...p,e])},P=async()=>{if(0!==p.length){C(!0);try{d?await d({leadIds:p,templateKey:g,customMessage:f||void 0}):await fetch("/api/sms/send",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({leadIds:p,templateKey:g,message:f||void 0})}),u([]),N(""),x()}finally{C(!1)}}},_=async e=>{C(!0);try{d?await d({leadId:e.id,templateKey:g,customMessage:f||void 0}):await fetch("/api/sms/send",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({leadId:e.id,templateKey:g,message:f||void 0})}),x()}finally{C(!1)}},A=async e=>{await o(e)&&x()};return(0,l.jsxs)("div",{className:"space-y-6",children:[(0,l.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-3 bg-white p-3 rounded-2xl border border-slate-200 shadow-sm",children:[(0,l.jsxs)("div",{className:"flex items-center gap-2",children:[(0,l.jsxs)("button",{onClick:()=>h("sms"),className:"flex items-center gap-2 px-4 py-2 rounded-xl text-xs font-bold transition-all ".concat("sms"===b?"bg-indigo-600 text-white shadow-sm":"text-slate-600 hover:bg-slate-100"),children:[(0,l.jsx)(y.Z,{className:"w-4 h-4"}),(0,l.jsxs)("span",{children:["پیامک‌های امروز (",(m.smsTasks||[]).length,")"]})]}),(0,l.jsxs)("button",{onClick:()=>h("call"),className:"flex items-center gap-2 px-4 py-2 rounded-xl text-xs font-bold transition-all ".concat("call"===b?"bg-emerald-600 text-white shadow-sm":"text-slate-600 hover:bg-slate-100"),children:[(0,l.jsx)(w.Z,{className:"w-4 h-4"}),(0,l.jsxs)("span",{children:["تماس‌های تلفنی امروز (",(m.callTasks||[]).length,")"]})]}),(0,l.jsxs)("button",{onClick:()=>h("onboarding"),className:"flex items-center gap-2 px-4 py-2 rounded-xl text-xs font-bold transition-all ".concat("onboarding"===b?"bg-amber-600 text-white shadow-sm":"text-slate-600 hover:bg-slate-100"),children:[(0,l.jsx)(n.Z,{className:"w-4 h-4"}),(0,l.jsxs)("span",{children:["تسک‌های آنبوردینگ (",(m.onboardingTasks||[]).length,")"]})]})]}),((null===(s=m.summary)||void 0===s?void 0:s.overdueCount)||0)>0&&(0,l.jsxs)("div",{className:"flex items-center gap-1.5 text-xs text-rose-700 bg-rose-50 px-3 py-1.5 rounded-lg border border-rose-200",children:[(0,l.jsx)(O.Z,{className:"w-4 h-4"}),(0,l.jsxs)("span",{children:[m.summary.overdueCount," پیگیری معوق و دارای تاخیر"]})]})]}),"sms"===b&&(0,l.jsxs)("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-6",children:[(0,l.jsxs)("div",{className:"lg:col-span-2 bg-white rounded-2xl border border-slate-200 p-6 shadow-sm space-y-4",children:[(0,l.jsxs)("div",{className:"flex items-center justify-between",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("h3",{className:"text-base font-bold text-slate-900",children:"لیست پیامک‌های زمان‌بندی‌شده"}),(0,l.jsx)("p",{className:"text-xs text-slate-500",children:"مجموعه‌هایی که کانال پیگیری امروز آنها پیامک تعیین شده است"})]}),(0,l.jsx)("button",{onClick:()=>{p.length===(m.smsTasks||[]).length?u([]):u((m.smsTasks||[]).map(e=>e.id))},className:"text-xs font-semibold text-indigo-600 hover:text-indigo-800",children:p.length===(m.smsTasks||[]).length?"لغو انتخاب همه":"انتخاب همه"})]}),0===(m.smsTasks||[]).length?(0,l.jsxs)("div",{className:"text-center py-10",children:[(0,l.jsx)(k.Z,{className:"w-10 h-10 text-emerald-500 mx-auto mb-2"}),(0,l.jsx)("p",{className:"text-sm font-semibold text-slate-700",children:"هیچ پیامکی برای امروز زمان‌بندی نشده است."}),(0,l.jsx)("p",{className:"text-xs text-slate-400 mt-1",children:"تمام پیگیری‌های پیامکی به‌موقع انجام شده‌اند."})]}):(0,l.jsx)("div",{className:"space-y-3",children:(m.smsTasks||[]).map(e=>{let s=p.includes(e.id);return(0,l.jsxs)("div",{className:"py-3.5 flex items-center justify-between gap-3 text-xs transition-colors rounded-xl px-2.5 ".concat(s?"bg-indigo-50/60":"hover:bg-slate-50"),children:[(0,l.jsxs)("div",{className:"flex items-center gap-3",children:[(0,l.jsx)("input",{type:"checkbox",checked:s,onChange:()=>T(e.id),className:"w-4 h-4 text-indigo-600 rounded border-slate-300 focus:ring-indigo-500"}),(0,l.jsxs)("div",{children:[(0,l.jsxs)("div",{className:"flex items-center gap-2",children:[(0,l.jsx)("button",{onClick:()=>c(e.id),className:"font-bold text-slate-900 hover:text-indigo-600 text-sm",children:e.name}),(0,l.jsx)("span",{className:"text-[11px] bg-slate-100 text-slate-700 px-2 py-0.5 rounded",children:e.city}),e.isOverdue&&(0,l.jsx)("span",{className:"text-[10px] font-bold bg-rose-100 text-rose-700 px-1.5 py-0.2 rounded",children:"تاخیر"})]}),(0,l.jsxs)("p",{className:"text-slate-500 mt-0.5",children:["مدیر: ",e.ownerName," (",e.ownerPhone,") • مرحله: ",e.stage]}),(0,l.jsxs)("p",{className:"text-indigo-700 font-medium mt-0.5",children:["اقدام: ",e.nextAction]})]})]}),(0,l.jsx)("div",{className:"flex items-center gap-2 shrink-0",children:(0,l.jsxs)("button",{onClick:()=>_(e),disabled:v,className:"flex items-center gap-1 bg-indigo-600 hover:bg-indigo-700 text-white px-3 py-1.5 rounded-lg text-xs font-semibold shadow-sm transition-all",children:[(0,l.jsx)(I.Z,{className:"w-3.5 h-3.5"}),(0,l.jsx)("span",{children:"ارسال"})]})})]},e.id)})})]}),(0,l.jsxs)("div",{className:"bg-white rounded-2xl border border-slate-200 p-6 shadow-sm space-y-4",children:[(0,l.jsx)("h3",{className:"text-base font-bold text-slate-900",children:"ارسال گروهی و تنظیم قالب پیامک"}),(0,l.jsxs)("p",{className:"text-xs text-slate-500",children:[p.length," مخاطب انتخاب شده است."]}),(0,l.jsxs)("div",{className:"space-y-3 text-xs",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block font-semibold text-slate-700 mb-1",children:"قالب پیامک اکیپا:"}),(0,l.jsxs)("select",{value:g,onChange:e=>j(e.target.value),className:"w-full border border-slate-300 rounded-xl px-3 py-2 text-xs focus:ring-2 focus:ring-indigo-500",children:[(0,l.jsx)("option",{value:"welcome_proposal",children:"خوش‌آمدگویی و پرپوزال اختصاصی"}),(0,l.jsx)("option",{value:"pain_point_solution",children:"راه‌حل نقطه درد سانس‌های خالی"}),(0,l.jsx)("option",{value:"success_stats",children:"آمار موفقیت و افزایش فروش اکیپا"}),(0,l.jsx)("option",{value:"loop_weekly",children:"پیگیری دوره‌ای و نکته مارکتینگ"})]})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block font-semibold text-slate-700 mb-1",children:"پیش‌نمایش متن پیامک:"}),(0,l.jsx)("div",{className:"p-3 bg-slate-50 rounded-xl border border-slate-200 text-slate-700 text-xs leading-relaxed whitespace-pre-line",children:"object"==typeof E[g]?E[g].template:E[g]||"متن پیش‌فرض"})]}),(0,l.jsxs)("div",{children:[(0,l.jsxs)("label",{className:"block font-semibold text-slate-700 mb-1",children:["یا متن دلخواه (با متغیرهای ","{lead_name}"," و ","{owner_name}","):"]}),(0,l.jsx)("textarea",{value:f,onChange:e=>N(e.target.value),placeholder:"در صورت تمایل متن اختصاصی خود را وارد کنید...",rows:3,className:"w-full border border-slate-300 rounded-xl p-2.5 text-xs focus:ring-2 focus:ring-indigo-500"})]}),(0,l.jsxs)("button",{onClick:P,disabled:v||0===p.length,className:"w-full py-2.5 bg-indigo-600 hover:bg-indigo-700 disabled:bg-slate-300 text-white rounded-xl text-xs font-bold shadow transition-all flex items-center justify-center gap-2",children:[(0,l.jsx)(I.Z,{className:"w-4 h-4"}),(0,l.jsxs)("span",{children:["ارسال گروهی به ",p.length," مجموعه منتخب"]})]})]})]})]}),"call"===b&&(0,l.jsxs)("div",{className:"bg-white rounded-2xl border border-slate-200 p-6 shadow-sm space-y-4",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("h3",{className:"text-base font-bold text-slate-900",children:"لیست تماس‌های تلفنی امروز"}),(0,l.jsx)("p",{className:"text-xs text-slate-500",children:"اتاق‌های فراری که طبق برنامه پیگیری تلفنی دارند همراه با پیشنهاد راه‌حل اعتراض"})]}),0===(m.callTasks||[]).length?(0,l.jsxs)("div",{className:"text-center py-10",children:[(0,l.jsx)(k.Z,{className:"w-10 h-10 text-emerald-500 mx-auto mb-2"}),(0,l.jsx)("p",{className:"text-sm font-semibold text-slate-700",children:"هیچ تماس معوقی برای امروز وجود ندارد."})]}):(0,l.jsx)("div",{className:"space-y-4",children:(m.callTasks||[]).map(e=>(0,l.jsxs)("div",{className:"p-5 rounded-2xl border border-slate-200 bg-slate-50/50 hover:bg-white hover:border-emerald-300 transition-all space-y-3",children:[(0,l.jsxs)("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-2",children:[(0,l.jsxs)("div",{children:[(0,l.jsxs)("div",{className:"flex items-center gap-2",children:[(0,l.jsx)("button",{onClick:()=>c(e.id),className:"font-black text-slate-900 hover:text-emerald-700 text-base",children:e.name}),(0,l.jsxs)("span",{className:"text-xs bg-slate-200 text-slate-800 px-2 py-0.5 rounded-full",children:[e.city," ",e.district?"(".concat(e.district,")"):""]}),(0,l.jsxs)("span",{className:"text-xs font-bold px-2 py-0.5 rounded-full ".concat("گرم"===e.temperature?"bg-rose-100 text-rose-700":"خنثی"===e.temperature?"bg-amber-100 text-amber-700":"bg-slate-200 text-slate-700"),children:["دمای ",e.temperature," (",e.temperatureScore,")"]}),e.isOverdue&&(0,l.jsx)("span",{className:"text-xs font-bold bg-rose-500 text-white px-2 py-0.5 rounded-full",children:"تاخیر در پیگیری"})]}),(0,l.jsxs)("p",{className:"text-xs text-slate-500 mt-1",children:["مدیر مجموعه: ",(0,l.jsx)("strong",{children:e.ownerName})," • مرحله: ",(0,l.jsx)("strong",{children:e.stage})]})]}),(0,l.jsxs)("div",{className:"flex items-center gap-2",children:[(0,l.jsxs)("a",{href:"tel:".concat(e.ownerPhone),className:"flex items-center gap-1.5 bg-emerald-600 hover:bg-emerald-700 text-white px-4 py-2 rounded-xl text-xs font-bold shadow-sm transition-all",children:[(0,l.jsx)(M.Z,{className:"w-3.5 h-3.5"}),(0,l.jsxs)("span",{children:["تماس (",e.ownerPhone,")"]})]}),(0,l.jsxs)("button",{onClick:()=>A(e.id),className:"flex items-center gap-1.5 bg-sky-600 hover:bg-sky-700 text-white px-3.5 py-2 rounded-xl text-xs font-bold shadow-sm transition-all",children:[(0,l.jsx)(R.Z,{className:"w-3.5 h-3.5"}),(0,l.jsx)("span",{children:"ثبت تماس و مرحله بعد"})]})]})]}),e.suggestedResponse&&(0,l.jsxs)("div",{className:"bg-amber-50/80 border border-amber-200 rounded-xl p-3 text-xs space-y-1",children:[(0,l.jsxs)("div",{className:"flex items-center gap-1.5 font-bold text-amber-900",children:[(0,l.jsx)(F.Z,{className:"w-4 h-4 text-amber-600"}),(0,l.jsxs)("span",{children:['پاسخ پیشنهادی اکیپا به اعتراض: "',e.objection,'"']})]}),(0,l.jsx)("p",{className:"text-amber-800 leading-relaxed",children:e.suggestedResponse}),e.suggestedKeyPoint&&(0,l.jsxs)("p",{className:"text-[11px] text-amber-700 font-semibold",children:["نکته کلیدی: ",e.suggestedKeyPoint]})]}),(0,l.jsxs)("div",{className:"text-xs text-slate-600 bg-white p-2.5 rounded-xl border border-slate-100 flex items-center justify-between",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("span",{className:"font-semibold text-slate-700",children:"اقدام مقرر: "}),(0,l.jsx)("span",{children:e.nextAction})]}),(0,l.jsx)("button",{onClick:()=>c(e.id),className:"text-sky-600 font-bold hover:underline",children:"مشاهده شناسنامه و ثبت جزئیات"})]})]},e.id))})]}),"onboarding"===b&&(0,l.jsxs)("div",{className:"bg-white rounded-2xl border border-slate-200 p-6 shadow-sm space-y-4",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("h3",{className:"text-base font-bold text-slate-900",children:"چک‌لیست آنبوردینگ مجموعه‌های تازه جذب‌شده"}),(0,l.jsx)("p",{className:"text-xs text-slate-500",children:"تسک‌های ۴ هفته ابتدایی برای تضمین اولین فروش و اتصال به تقویم اکیپا"})]}),0===(m.onboardingTasks||[]).length?(0,l.jsxs)("div",{className:"text-center py-10",children:[(0,l.jsx)(k.Z,{className:"w-10 h-10 text-emerald-500 mx-auto mb-2"}),(0,l.jsx)("p",{className:"text-sm font-semibold text-slate-700",children:"هیچ تسک آنبوردینگ معوقی وجود ندارد."})]}):(0,l.jsx)("div",{className:"divide-y divide-slate-100",children:(m.onboardingTasks||[]).map(e=>(0,l.jsxs)("div",{className:"py-3 flex items-center justify-between gap-3 text-xs",children:[(0,l.jsxs)("div",{className:"flex items-center gap-3",children:[(0,l.jsx)("input",{type:"checkbox",checked:!!e.doneAt,onChange:s=>{let t=s.target.checked;i?i(e.leadId,e.id,t).then(x):fetch("/api/leads/".concat(e.leadId,"/onboarding"),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({taskId:e.id,done:t})}).then(x)},className:"w-4 h-4 text-emerald-600 rounded border-slate-300 focus:ring-emerald-500"}),(0,l.jsxs)("div",{children:[(0,l.jsx)("p",{className:"font-bold text-slate-900 text-sm",children:e.title}),(0,l.jsxs)("p",{className:"text-slate-500 mt-0.5",children:["مجموعه:"," ",(0,l.jsx)("button",{onClick:()=>c(e.leadId),className:"text-sky-700 font-bold hover:underline",children:e.lead.name})," ","• هفته ",e.week," • مدیر: ",e.lead.ownerName," (",e.lead.ownerPhone,")"]})]})]}),(0,l.jsxs)("span",{className:"text-[11px] font-semibold bg-amber-100 text-amber-800 px-2 py-0.5 rounded-full",children:["هفته ",e.week]})]},e.id))})]})]})}var H=t(8470);function z(e){let{leads:s,onRefresh:t,onSelectLead:r}=e,[n,d]=(0,a.useState)(null),[i,c]=(0,a.useState)("all"),x=s.filter(e=>"بسته شد / موفق"===e.stage||e.onboardingTasks&&e.onboardingTasks.length>0),m=x.filter(e=>"graduated"===i?e.clubMember:"in_progress"!==i||!e.clubMember),b=async(e,s,l)=>{d(s);try{(await fetch("/api/leads/".concat(e,"/onboarding"),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({taskId:s,completed:!l})})).ok&&t()}catch(e){console.error(e)}finally{d(null)}},h=async(e,s)=>{try{(await fetch("/api/leads/".concat(e,"/onboarding"),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({clubMember:!s})})).ok&&t()}catch(e){console.error(e)}};return(0,l.jsxs)("div",{className:"space-y-6",children:[(0,l.jsxs)("div",{className:"bg-gradient-to-r from-emerald-600 to-teal-700 rounded-2xl p-6 text-white shadow-lg flex flex-col md:flex-row items-start md:items-center justify-between gap-4",children:[(0,l.jsxs)("div",{children:[(0,l.jsxs)("div",{className:"flex items-center gap-2 mb-2",children:[(0,l.jsx)(o.Z,{className:"w-7 h-7 text-emerald-200"}),(0,l.jsx)("h2",{className:"text-xl font-bold",children:"فرآیند ۴ هفته‌ای آنبوردینگ اکیپا"})]}),(0,l.jsx)("p",{className:"text-emerald-100 text-sm max-w-2xl leading-relaxed",children:"مجموعه‌هایی که به عنوان شریک جذب شده‌اند وارد دوره ۴ هفته‌ای استقرار می‌شوند. تکمیل تمام وظایف این ۴ هفته موجب ارتقای مجموعه به سطح \xabعضو باشگاه اکیپا\xbb و آغاز دوره‌های تمدید وفاداری می‌شود."})]}),(0,l.jsxs)("div",{className:"flex items-center gap-3",children:[(0,l.jsxs)("div",{className:"bg-white/10 backdrop-blur-md px-4 py-2 rounded-xl text-center border border-white/20",children:[(0,l.jsx)("span",{className:"text-xs text-emerald-200 block",children:"در حال آنبوردینگ"}),(0,l.jsx)("span",{className:"text-2xl font-bold",children:x.filter(e=>!e.clubMember).length})]}),(0,l.jsxs)("div",{className:"bg-white/10 backdrop-blur-md px-4 py-2 rounded-xl text-center border border-white/20",children:[(0,l.jsx)("span",{className:"text-xs text-emerald-200 block",children:"اعضای باشگاه اکیپا"}),(0,l.jsx)("span",{className:"text-2xl font-bold",children:x.filter(e=>e.clubMember).length})]})]})]}),(0,l.jsx)("div",{className:"flex items-center justify-between bg-white p-2 rounded-xl border border-slate-200",children:(0,l.jsxs)("div",{className:"flex gap-2",children:[(0,l.jsxs)("button",{onClick:()=>c("all"),className:"px-4 py-2 rounded-lg text-sm font-medium transition-colors ".concat("all"===i?"bg-slate-900 text-white":"text-slate-600 hover:bg-slate-100"),children:["همه مجموعه‌ها (",x.length,")"]}),(0,l.jsxs)("button",{onClick:()=>c("in_progress"),className:"px-4 py-2 rounded-lg text-sm font-medium transition-colors ".concat("in_progress"===i?"bg-emerald-600 text-white":"text-slate-600 hover:bg-slate-100"),children:["در حال استقرار (",x.filter(e=>!e.clubMember).length,")"]}),(0,l.jsxs)("button",{onClick:()=>c("graduated"),className:"px-4 py-2 rounded-lg text-sm font-medium transition-colors ".concat("graduated"===i?"bg-amber-600 text-white":"text-slate-600 hover:bg-slate-100"),children:["اعضای باشگاه اکیپا (",x.filter(e=>e.clubMember).length,")"]})]})}),0===m.length?(0,l.jsxs)("div",{className:"bg-white rounded-2xl border border-slate-200 p-12 text-center text-slate-500",children:[(0,l.jsx)(o.Z,{className:"w-12 h-12 text-slate-300 mx-auto mb-3"}),(0,l.jsx)("p",{className:"font-medium text-slate-700",children:"هیچ مجموعه‌ای در این بخش یافت نشد."}),(0,l.jsx)("p",{className:"text-sm text-slate-400 mt-1",children:"با بستن موفق معامله‌ها در پایپ‌لاین، مجموعه‌ها به طور خودکار به این بخش منتقل می‌شوند."})]}):(0,l.jsx)("div",{className:"grid grid-cols-1 gap-6",children:m.map(e=>{let s=e.onboardingTasks||[],t=s.filter(e=>e.completed).length,a=s.length||6,d=a>0?Math.round(t/a*100):0;return(0,l.jsxs)("div",{className:"bg-white rounded-2xl border border-slate-200 overflow-hidden shadow-sm hover:shadow-md transition-shadow",children:[(0,l.jsxs)("div",{className:"p-5 border-b border-slate-100 flex flex-col md:flex-row md:items-center justify-between gap-4 bg-slate-50/50",children:[(0,l.jsxs)("div",{className:"flex items-center gap-3",children:[(0,l.jsx)("div",{className:"w-12 h-12 rounded-xl bg-emerald-100 text-emerald-700 font-bold flex items-center justify-center text-lg",children:e.name.substring(0,2)}),(0,l.jsxs)("div",{children:[(0,l.jsxs)("div",{className:"flex items-center gap-2",children:[(0,l.jsx)("button",{onClick:()=>r(e),className:"font-bold text-slate-900 hover:text-emerald-700 text-lg transition-colors",children:e.name}),e.clubMember&&(0,l.jsxs)("span",{className:"inline-flex items-center gap-1 px-2.5 py-0.5 rounded-full text-xs font-semibold bg-amber-100 text-amber-800 border border-amber-300",children:[(0,l.jsx)(g.Z,{className:"w-3.5 h-3.5 text-amber-600"}),"عضو باشگاه اکیپا"]})]}),(0,l.jsxs)("div",{className:"flex items-center gap-3 text-xs text-slate-500 mt-1",children:[(0,l.jsxs)("span",{children:[e.city," ",e.district?"(".concat(e.district,")"):""]}),(0,l.jsx)("span",{children:"•"}),(0,l.jsxs)("span",{children:["مدیر: ",e.managerName||"نامشخص"]}),(0,l.jsx)("span",{children:"•"}),(0,l.jsx)("span",{dir:"ltr",children:e.phone})]})]})]}),(0,l.jsxs)("div",{className:"flex items-center gap-4",children:[(0,l.jsxs)("div",{className:"w-44 text-left",children:[(0,l.jsxs)("div",{className:"flex justify-between text-xs text-slate-500 mb-1",children:[(0,l.jsx)("span",{children:"پیشرفت استقرار"}),(0,l.jsxs)("span",{className:"font-semibold text-slate-800",children:[d,"%"]})]}),(0,l.jsx)("div",{className:"w-full bg-slate-200 h-2 rounded-full overflow-hidden",children:(0,l.jsx)("div",{className:"h-full rounded-full transition-all duration-500 ".concat(100===d?"bg-emerald-500":"bg-teal-500"),style:{width:"".concat(d,"%")}})})]}),(0,l.jsx)("button",{onClick:()=>h(e.id,e.clubMember),className:"px-3 py-1.5 rounded-lg text-xs font-medium border transition-colors ".concat(e.clubMember?"border-amber-300 bg-amber-50 text-amber-800 hover:bg-amber-100":"border-slate-300 bg-white text-slate-700 hover:bg-slate-50"),children:e.clubMember?"خروج از باشگاه":"ارتقا به باشگاه اکیپا"})]})]}),(0,l.jsx)("div",{className:"p-5 grid grid-cols-1 md:grid-cols-4 gap-4",children:[1,2,3,4].map(t=>{let a=s.filter(e=>e.week===t),r=a.length>0&&a.every(e=>e.completed);return(0,l.jsxs)("div",{className:"rounded-xl p-3 border ".concat(r?"bg-emerald-50/60 border-emerald-200":e.onboardingWeek===t?"bg-amber-50/60 border-amber-300 ring-2 ring-amber-400/20":"bg-slate-50/60 border-slate-200"),children:[(0,l.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,l.jsx)("span",{className:"text-xs font-bold text-slate-800",children:1===t?"هفته ۱: راه‌اندازی و پروفایل":2===t?"هفته ۲: سانس‌های آزمایشی":3===t?"هفته ۳: اولین کمپین جذب":"هفته ۴: تثبیت و ارزیابی"}),r?(0,l.jsx)(k.Z,{className:"w-4 h-4 text-emerald-600"}):e.onboardingWeek===t?(0,l.jsx)("span",{className:"text-[10px] bg-amber-200 text-amber-800 px-1.5 py-0.5 rounded font-medium",children:"جاری"}):(0,l.jsx)(H.Z,{className:"w-3.5 h-3.5 text-slate-400"})]}),(0,l.jsx)("div",{className:"space-y-1.5",children:0===a.length?(0,l.jsx)("p",{className:"text-xs text-slate-400 italic",children:"بدون وظیفه تعریف‌شده"}):a.map(s=>(0,l.jsxs)("button",{disabled:n===s.id,onClick:()=>b(e.id,s.id,s.completed),className:"w-full text-right p-2 rounded-lg text-xs flex items-start gap-2 transition-all ".concat(s.completed?"bg-emerald-100/70 text-emerald-900 line-through opacity-80":"bg-white border border-slate-200 text-slate-700 hover:border-emerald-400 hover:bg-emerald-50/30"),children:[(0,l.jsx)("span",{className:"w-4 h-4 rounded border flex items-center justify-center mt-0.5 shrink-0 ".concat(s.completed?"bg-emerald-600 border-emerald-600 text-white":"border-slate-300 bg-white"),children:s.completed&&(0,l.jsx)(R.Z,{className:"w-3 h-3 stroke-[3]"})}),(0,l.jsx)("span",{className:"leading-tight",children:s.title})]},s.id))})]},t)})})]},e.id)})})]})}var K=t(6534),W=t(1451),q=t(1340),B=t(6339),Q=t(9623),G=t(5972);function U(e){let{leadCount:s,stats:t,onRefresh:r}=e,[n,d]=(0,a.useState)("automation"),[o,c]=(0,a.useState)(""),[x,m]=(0,a.useState)("mock"),[b,h]=(0,a.useState)(!1);return(0,l.jsxs)("div",{className:"space-y-6",children:[(0,l.jsxs)("div",{className:"bg-white rounded-2xl border border-slate-200 p-6 flex flex-col md:flex-row md:items-center justify-between gap-4",children:[(0,l.jsxs)("div",{children:[(0,l.jsxs)("div",{className:"flex items-center gap-2 mb-1",children:[(0,l.jsx)(i.Z,{className:"w-6 h-6 text-slate-700"}),(0,l.jsx)("h2",{className:"text-xl font-bold text-slate-900",children:"تنظیمات و زیرساخت اتوماسیون"})]}),(0,l.jsx)("p",{className:"text-sm text-slate-500",children:"پیکربندی قوانین خودکار پایپ‌لاین، موتور پیامک، کتابچه اعتراضات و دیتابیس محلی پایدار SQLite"})]}),b&&(0,l.jsxs)("div",{className:"flex items-center gap-2 text-emerald-700 bg-emerald-50 px-4 py-2 rounded-xl border border-emerald-200 text-sm",children:[(0,l.jsx)(k.Z,{className:"w-4 h-4"}),(0,l.jsx)("span",{children:"تنظیمات با موفقیت ذخیره شد"})]})]}),(0,l.jsxs)("div",{className:"flex gap-2 border-b border-slate-200 pb-2",children:[(0,l.jsxs)("button",{onClick:()=>d("automation"),className:"flex items-center gap-2 px-4 py-2.5 rounded-xl text-sm font-medium transition-colors ".concat("automation"===n?"bg-slate-900 text-white":"text-slate-600 hover:bg-slate-100"),children:[(0,l.jsx)(K.Z,{className:"w-4 h-4"}),"قوانین مراحل و تاخیرها"]}),(0,l.jsxs)("button",{onClick:()=>d("objections"),className:"flex items-center gap-2 px-4 py-2.5 rounded-xl text-sm font-medium transition-colors ".concat("objections"===n?"bg-slate-900 text-white":"text-slate-600 hover:bg-slate-100"),children:[(0,l.jsx)(W.Z,{className:"w-4 h-4"}),"کتابچه پاسخ به اعتراضات"]}),(0,l.jsxs)("button",{onClick:()=>d("sms"),className:"flex items-center gap-2 px-4 py-2.5 rounded-xl text-sm font-medium transition-colors ".concat("sms"===n?"bg-slate-900 text-white":"text-slate-600 hover:bg-slate-100"),children:[(0,l.jsx)(y.Z,{className:"w-4 h-4"}),"قالب‌های پیامک و اتصال n8n"]}),(0,l.jsxs)("button",{onClick:()=>d("database"),className:"flex items-center gap-2 px-4 py-2.5 rounded-xl text-sm font-medium transition-colors ".concat("database"===n?"bg-slate-900 text-white":"text-slate-600 hover:bg-slate-100"),children:[(0,l.jsx)(q.Z,{className:"w-4 h-4"}),"پایگاه داده محلی SQLite"]})]}),"automation"===n&&(0,l.jsxs)("div",{className:"bg-white rounded-2xl border border-slate-200 overflow-hidden",children:[(0,l.jsxs)("div",{className:"p-5 border-b border-slate-100 bg-slate-50 flex items-center justify-between",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("h3",{className:"font-bold text-slate-800",children:"جدول قوانین اتوماسیون پایپ‌لاین"}),(0,l.jsx)("p",{className:"text-xs text-slate-500 mt-0.5",children:"سیستم با ثبت هر اقدام، مرحله بعدی، کانال ارتباطی و فاصله زمانی مناسب را بر اساس این ماتریس محاسبه می‌کند."})]}),(0,l.jsx)("span",{className:"text-xs font-semibold px-2.5 py-1 bg-teal-100 text-teal-800 rounded-lg",children:"۱۰ مرحله استاندارد"})]}),(0,l.jsx)("div",{className:"overflow-x-auto",children:(0,l.jsxs)("table",{className:"w-full text-right text-xs",children:[(0,l.jsx)("thead",{className:"bg-slate-100/70 text-slate-600 font-semibold border-b border-slate-200",children:(0,l.jsxs)("tr",{children:[(0,l.jsx)("th",{className:"p-3.5",children:"مرحله"}),(0,l.jsx)("th",{className:"p-3.5",children:"اقدام بعدی خودکار"}),(0,l.jsx)("th",{className:"p-3.5",children:"کانال پیگیری"}),(0,l.jsx)("th",{className:"p-3.5",children:"فاصله زمانی (روز)"}),(0,l.jsx)("th",{className:"p-3.5",children:"برچسب پیامک پیش‌فرض"})]})}),(0,l.jsx)("tbody",{className:"divide-y divide-slate-100",children:P.map((e,s)=>(0,l.jsxs)("tr",{className:"hover:bg-slate-50/50",children:[(0,l.jsx)("td",{className:"p-3.5 font-bold text-slate-900",children:e.currentStage}),(0,l.jsx)("td",{className:"p-3.5 text-slate-700",children:e.action}),(0,l.jsx)("td",{className:"p-3.5",children:(0,l.jsx)("span",{className:"px-2 py-0.5 rounded-full text-[11px] font-semibold ".concat("پیامک"===e.channel?"bg-blue-100 text-blue-800":"bg-emerald-100 text-emerald-800"),children:e.channel})}),(0,l.jsx)("td",{className:"p-3.5 text-slate-800 font-mono",children:0===e.delayDays?"همان روز":"".concat(e.delayDays," روز")}),(0,l.jsx)("td",{className:"p-3.5",children:e.smsTag?(0,l.jsx)("span",{className:"px-2 py-0.5 rounded bg-slate-100 text-slate-700 font-mono text-[11px]",children:e.smsTag}):(0,l.jsx)("span",{className:"text-slate-400",children:"—"})})]},s))})]})})]}),"objections"===n&&(0,l.jsxs)("div",{className:"space-y-4",children:[(0,l.jsxs)("div",{className:"bg-amber-50 border border-amber-200 rounded-2xl p-5 text-amber-900 flex items-start gap-3",children:[(0,l.jsx)(v.Z,{className:"w-5 h-5 text-amber-600 shrink-0 mt-0.5"}),(0,l.jsxs)("div",{children:[(0,l.jsx)("h4",{className:"font-bold text-sm",children:"پلی‌بوک پاسخ به اعتراضات صاحبان اتاق فرار"}),(0,l.jsx)("p",{className:"text-xs text-amber-800 mt-1 leading-relaxed",children:"این راهنما در تماس‌های تلفنی و ثبت لاگ فعالیت برای هر لید به عنوان دستیار هوشمند نمایش داده می‌شود تا تیم فروش سریع‌ترین و بهترین پاسخ اقناعی را ارائه دهد."})]})]}),(0,l.jsx)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:Object.entries(A).map((e,s)=>{let[t,a]=e;return(0,l.jsxs)("div",{className:"bg-white rounded-2xl border border-slate-200 p-5 shadow-sm space-y-3",children:[(0,l.jsxs)("div",{className:"flex items-center justify-between",children:[(0,l.jsx)("span",{className:"font-bold text-sm text-slate-900 bg-slate-100 px-3 py-1 rounded-xl",children:t}),(0,l.jsx)("span",{className:"text-xs text-rose-600 bg-rose-50 px-2 py-0.5 rounded-md font-medium",children:"اعتراض متداول"})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("span",{className:"text-[11px] font-bold text-slate-500 block mb-1",children:"زاویه دید مشتری:"}),(0,l.jsxs)("p",{className:"text-xs text-slate-600 bg-slate-50 p-2.5 rounded-xl border border-slate-100 leading-relaxed",children:["\xab",a.objection||a.angle,"\xbb"]})]}),(0,l.jsxs)("div",{children:[(0,l.jsxs)("span",{className:"text-[11px] font-bold text-emerald-700 block mb-1 flex items-center gap-1",children:[(0,l.jsx)(j.Z,{className:"w-3.5 h-3.5"}),"پاسخ پیشنهادی اکیپا:"]}),(0,l.jsx)("p",{className:"text-xs text-emerald-900 bg-emerald-50/80 p-3 rounded-xl border border-emerald-200 leading-relaxed font-medium",children:a.rebuttal||a.pitch})]})]},s)})})]}),"sms"===n&&(0,l.jsxs)("div",{className:"space-y-6",children:[(0,l.jsxs)("div",{className:"bg-white rounded-2xl border border-slate-200 p-6 space-y-4",children:[(0,l.jsxs)("h3",{className:"font-bold text-slate-900 flex items-center gap-2",children:[(0,l.jsx)(y.Z,{className:"w-5 h-5 text-indigo-600"}),"تنظیمات وب‌هوک n8n و شبیه‌ساز پیامک"]}),(0,l.jsx)("p",{className:"text-xs text-slate-500",children:"در حال حاضر سامانه پیامک در وضعیت خودکفا (Mock) عمل می‌کند و کلیه رویدادهای ارسالی در جدول تاریخچه دیتابیس ثبت می‌شوند. در صورت اتصال وب‌هوک n8n، پیامک‌ها به سرویس کاوه‌نگار یا فراز انتقال می‌یابند."}),(0,l.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4 pt-2",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"text-xs font-semibold text-slate-700 block mb-1.5",children:"حالت ارسال پیامک"}),(0,l.jsxs)("div",{className:"flex gap-2",children:[(0,l.jsx)("button",{onClick:()=>m("mock"),className:"flex-1 py-2 px-3 rounded-xl text-xs font-semibold border transition-colors ".concat("mock"===x?"bg-emerald-600 text-white border-emerald-600":"bg-white text-slate-600 border-slate-300"),children:"شبیه‌ساز داخلی (Mock / بدون وابستگی)"}),(0,l.jsx)("button",{onClick:()=>m("live"),className:"flex-1 py-2 px-3 rounded-xl text-xs font-semibold border transition-colors ".concat("live"===x?"bg-indigo-600 text-white border-indigo-600":"bg-white text-slate-600 border-slate-300"),children:"اتصال زنده به n8n Webhook"})]})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"text-xs font-semibold text-slate-700 block mb-1.5",children:"آدرس وب‌هوک n8n (اختیاری)"}),(0,l.jsx)("input",{type:"text",placeholder:"https://n8n.domain.com/webhook/crm-sms",value:o,onChange:e=>c(e.target.value),dir:"ltr",className:"w-full text-xs font-mono px-3 py-2 rounded-xl border border-slate-300 focus:outline-none focus:ring-2 focus:ring-indigo-500"})]})]}),(0,l.jsx)("div",{className:"pt-2 flex justify-end",children:(0,l.jsxs)("button",{onClick:()=>{h(!0),setTimeout(()=>h(!1),3e3)},className:"flex items-center gap-1.5 px-4 py-2 bg-slate-900 text-white text-xs font-semibold rounded-xl hover:bg-slate-800 transition-colors",children:[(0,l.jsx)(B.Z,{className:"w-3.5 h-3.5"}),"ذخیره تنظیمات وب‌هوک"]})})]}),(0,l.jsxs)("div",{className:"bg-white rounded-2xl border border-slate-200 p-6 space-y-4",children:[(0,l.jsx)("h3",{className:"font-bold text-slate-900",children:"قالب‌های فعال پیامک اکیپا"}),(0,l.jsx)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:Object.entries(E).map(e=>{let[s,t]=e;return(0,l.jsxs)("div",{className:"border border-slate-200 rounded-xl p-4 bg-slate-50/50 space-y-2",children:[(0,l.jsxs)("div",{className:"flex items-center justify-between",children:[(0,l.jsx)("span",{className:"font-mono text-xs font-bold bg-indigo-50 text-indigo-700 px-2 py-0.5 rounded",children:s}),(0,l.jsx)("span",{className:"text-[11px] text-slate-400",children:"قالب خودکار"})]}),(0,l.jsx)("p",{className:"text-xs text-slate-700 leading-relaxed font-mono whitespace-pre-line bg-white p-2.5 rounded-lg border border-slate-100",children:"string"==typeof t?t:t.template})]},s)})})]})]}),"database"===n&&(0,l.jsxs)("div",{className:"bg-white rounded-2xl border border-slate-200 p-6 space-y-6",children:[(0,l.jsxs)("div",{className:"flex items-center gap-3",children:[(0,l.jsx)("div",{className:"w-12 h-12 rounded-2xl bg-indigo-50 flex items-center justify-center text-indigo-600",children:(0,l.jsx)(Q.Z,{className:"w-6 h-6"})}),(0,l.jsxs)("div",{children:[(0,l.jsx)("h3",{className:"font-bold text-slate-900 text-base",children:"پایگاه داده محلی SQLite (مستقل و پایدار)"}),(0,l.jsx)("p",{className:"text-xs text-slate-500",children:"تمام اطلاعات، اتاق‌ها، فعالیت‌ها و وظایف آنبوردینگ در دیسک محلی ذخیره می‌شوند."})]})]}),(0,l.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[(0,l.jsxs)("div",{className:"bg-slate-50 rounded-xl p-4 border border-slate-200",children:[(0,l.jsx)("span",{className:"text-xs text-slate-500 block mb-1",children:"مسیر فایل دیتابیس"}),(0,l.jsx)("span",{className:"font-mono text-xs font-bold text-slate-800 break-all",dir:"ltr",children:"/workspace/personal/crm/prisma/crm.db"})]}),(0,l.jsxs)("div",{className:"bg-slate-50 rounded-xl p-4 border border-slate-200",children:[(0,l.jsx)("span",{className:"text-xs text-slate-500 block mb-1",children:"تعداد لیدهای فعال"}),(0,l.jsxs)("span",{className:"text-xl font-bold text-slate-800",children:[s," مجموعه"]})]}),(0,l.jsxs)("div",{className:"bg-slate-50 rounded-xl p-4 border border-slate-200",children:[(0,l.jsx)("span",{className:"text-xs text-slate-500 block mb-1",children:"سیستم نگهداری و ORM"}),(0,l.jsx)("span",{className:"text-sm font-bold text-emerald-700",children:"Prisma Client v5.22 (بدون نیاز به شبکه)"})]})]}),(0,l.jsxs)("div",{className:"border-t border-slate-100 pt-4 flex items-center justify-between text-xs text-slate-500",children:[(0,l.jsxs)("span",{children:["برای پشتیبان‌گیری، کپی کردن فایل ",(0,l.jsx)("code",{className:"font-mono bg-slate-100 px-1 py-0.5 rounded",children:"crm.db"})," یا گرفتن خروجی اکسل از نوار بالا کافی است."]}),(0,l.jsxs)("button",{onClick:r,className:"flex items-center gap-1 text-slate-700 hover:text-slate-900 font-semibold",children:[(0,l.jsx)(G.Z,{className:"w-3.5 h-3.5"}),"بروزرسانی وضعیت دیتابیس"]})]})]})]})}var V=t(8399),X=t(4891),Y=t(6865),$=t(6064),ee=t(8079);function es(e){var s,t;let{lead:r,isOpen:n,onClose:d,onRefresh:o}=e;if(!n||!r)return null;let[i,c]=(0,a.useState)("info"),[x,b]=(0,a.useState)({...r}),[h,u]=(0,a.useState)(!1),[g,f]=(0,a.useState)(!1),[N,v]=(0,a.useState)(""),[w,k]=(0,a.useState)(!1),[C,S]=(0,a.useState)(""),[Z,T]=(0,a.useState)(""),[P,L]=(0,a.useState)(6),[D,O]=(0,a.useState)(25e4),[M,R]=(0,a.useState)("تماس تلفنی"),[F,E]=(0,a.useState)(""),[J,H]=(0,a.useState)(!1),z=async()=>{u(!0);try{let e={...x,ownerName:x.ownerName||x.managerName,ownerPhone:x.ownerPhone||x.phone,nextAction:x.nextAction||x.nextActionNote,nextChannel:x.nextChannel||x.nextFollowupChannel,painPoint:x.painPoint||x.biggestPain,aspiration:x.aspiration||x.coreDesire,ekipaHook:x.ekipaHook||x.hookForEkipa};(await fetch("/api/leads/".concat(r.id),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})).ok&&(o(),alert("اطلاعات با موفقیت ذخیره شد."))}catch(e){console.error(e)}finally{u(!1)}},K=async()=>{f(!0);try{(await fetch("/api/leads/".concat(r.id,"/advance"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({notes:"ارتقای مرحله از پروفایل لید"})})).ok&&(o(),d())}catch(e){console.error(e)}finally{f(!1)}},W=async()=>{if(!N.trim()){alert("لطفاً ابتدا یادداشت مکالمه را وارد کنید.");return}k(!0),S("");try{let e=await fetch("/api/ai/extract",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({leadId:r.id,text:N})}),s=await e.json();if(s.success&&s.extracted){let e=s.extracted;b(s=>({...s,salesChannels:e.salesChannels?e.salesChannels.join(", "):s.salesChannels,deadSlots:e.deadSlots||s.deadSlots,biggestPain:e.biggestPain||s.biggestPain,coreDesire:e.coreDesire||s.coreDesire,hookForEkipa:e.hookForEkipa||s.hookForEkipa,objectionStatus:e.objectionStatus||s.objectionStatus,smsTag:e.suggestedSmsTag||s.smsTag})),S("اطلاعات با هوش مصنوعی استخراج و فرم بروزرسانی شد.")}}catch(e){console.error(e)}finally{k(!1)}},q=async e=>{if(e.preventDefault(),F.trim()){H(!0);try{(await fetch("/api/leads/".concat(r.id,"/activities"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:M,notes:F})})).ok&&(E(""),o())}catch(e){console.error(e)}finally{H(!1)}}},Q=e=>{let s=x.rooms||[];b({...x,rooms:s.filter((s,t)=>t!==e)})};return(0,l.jsx)("div",{className:"fixed inset-0 z-50 bg-slate-900/60 backdrop-blur-sm flex items-center justify-center p-3 md:p-6 overflow-y-auto",children:(0,l.jsxs)("div",{className:"bg-white rounded-3xl shadow-2xl border border-slate-200 w-full max-w-4xl max-h-[90vh] flex flex-col overflow-hidden animate-in fade-in zoom-in-95 duration-150",children:[(0,l.jsxs)("div",{className:"p-6 border-b border-slate-200 flex flex-col md:flex-row md:items-center justify-between gap-4 bg-slate-50",children:[(0,l.jsxs)("div",{className:"flex items-start gap-4",children:[(0,l.jsx)("div",{className:"w-14 h-14 rounded-2xl bg-teal-600 text-white font-bold text-xl flex items-center justify-center shrink-0 shadow-md",children:r.name.substring(0,2)}),(0,l.jsxs)("div",{children:[(0,l.jsxs)("div",{className:"flex items-center gap-2",children:[(0,l.jsx)("h2",{className:"text-xl font-bold text-slate-900",children:r.name}),(0,l.jsxs)("span",{className:"px-3 py-0.5 rounded-full text-xs font-bold border ".concat("گرم"===r.temperature?"bg-rose-50 text-rose-700 border-rose-200":"خنثی"===r.temperature?"bg-amber-50 text-amber-700 border-amber-200":"bg-blue-50 text-blue-700 border-blue-200"),children:[(0,l.jsx)(p.Z,{className:"w-3.5 h-3.5 inline ml-1"}),r.temperature," (",r.temperatureScore," امتیاز)"]})]}),(0,l.jsxs)("div",{className:"flex items-center gap-3 text-xs text-slate-500 mt-1",children:[(0,l.jsxs)("span",{children:[r.city," ",r.district?"(".concat(r.district,")"):""]}),(0,l.jsx)("span",{children:"•"}),(0,l.jsx)("span",{className:"font-semibold text-slate-700",children:r.stage}),(0,l.jsx)("span",{children:"•"}),(0,l.jsx)("span",{dir:"ltr",children:r.phone})]})]})]}),(0,l.jsxs)("div",{className:"flex items-center gap-2",children:[(0,l.jsxs)("button",{onClick:K,disabled:g,className:"flex items-center gap-1.5 px-4 py-2.5 rounded-xl bg-teal-600 hover:bg-teal-700 text-white text-xs font-bold shadow-md transition-all active:scale-95",children:[(0,l.jsx)(V.Z,{className:"w-4 h-4"}),(0,l.jsx)("span",{children:"انجام شد، برو مرحله‌ی بعد"})]}),(0,l.jsx)("button",{onClick:d,className:"p-2.5 rounded-xl text-slate-400 hover:text-slate-700 hover:bg-slate-200/60 transition-colors",children:(0,l.jsx)(X.Z,{className:"w-5 h-5"})})]})]}),(0,l.jsxs)("div",{className:"flex border-b border-slate-200 px-6 gap-6 bg-white text-sm font-semibold",children:[(0,l.jsxs)("button",{onClick:()=>c("info"),className:"py-3.5 border-b-2 transition-colors flex items-center gap-2 ".concat("info"===i?"border-teal-600 text-teal-700":"border-transparent text-slate-500 hover:text-slate-800"),children:[(0,l.jsx)(Y.Z,{className:"w-4 h-4"}),"مشخصات، پایپ‌لاین و اتاق‌ها"]}),(0,l.jsxs)("button",{onClick:()=>c("ai"),className:"py-3.5 border-b-2 transition-colors flex items-center gap-2 ".concat("ai"===i?"border-teal-600 text-teal-700":"border-transparent text-slate-500 hover:text-slate-800"),children:[(0,l.jsx)(j.Z,{className:"w-4 h-4 text-purple-600"}),"تحلیل هوشمند و پر کردن با AI"]}),(0,l.jsxs)("button",{onClick:()=>c("activities"),className:"py-3.5 border-b-2 transition-colors flex items-center gap-2 ".concat("activities"===i?"border-teal-600 text-teal-700":"border-transparent text-slate-500 hover:text-slate-800"),children:[(0,l.jsx)($.Z,{className:"w-4 h-4"}),"تاریخچه تعاملات (",(null===(s=r.activities)||void 0===s?void 0:s.length)||0,")"]})]}),(0,l.jsxs)("div",{className:"p-6 overflow-y-auto space-y-6 flex-1 bg-slate-50/30",children:["info"===i&&(0,l.jsxs)("div",{className:"space-y-6",children:[(0,l.jsxs)("div",{className:"bg-white p-5 rounded-2xl border border-slate-200 shadow-sm space-y-4",children:[(0,l.jsx)("h3",{className:"font-bold text-sm text-slate-900 border-b border-slate-100 pb-2",children:"اطلاعات تماس و مدیریت"}),(0,l.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"text-xs font-semibold text-slate-600 block mb-1",children:"نام مدیر"}),(0,l.jsx)("input",{type:"text",value:x.managerName||"",onChange:e=>b({...x,managerName:e.target.value}),className:"w-full text-xs px-3 py-2 rounded-xl border border-slate-300 focus:ring-2 focus:ring-teal-500"})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"text-xs font-semibold text-slate-600 block mb-1",children:"شماره تماس"}),(0,l.jsx)("input",{type:"text",dir:"ltr",value:x.phone||"",onChange:e=>b({...x,phone:e.target.value}),className:"w-full text-xs px-3 py-2 rounded-xl border border-slate-300 focus:ring-2 focus:ring-teal-500"})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"text-xs font-semibold text-slate-600 block mb-1",children:"شهر"}),(0,l.jsx)("input",{type:"text",value:x.city||"",onChange:e=>b({...x,city:e.target.value}),className:"w-full text-xs px-3 py-2 rounded-xl border border-slate-300 focus:ring-2 focus:ring-teal-500"})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"text-xs font-semibold text-slate-600 block mb-1",children:"منطقه / محله"}),(0,l.jsx)("input",{type:"text",value:x.district||"",onChange:e=>b({...x,district:e.target.value}),className:"w-full text-xs px-3 py-2 rounded-xl border border-slate-300 focus:ring-2 focus:ring-teal-500"})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"text-xs font-semibold text-slate-600 block mb-1",children:"آیدی اینستاگرام"}),(0,l.jsx)("input",{type:"text",dir:"ltr",value:x.instagram||"",onChange:e=>b({...x,instagram:e.target.value}),placeholder:"@escaperoom",className:"w-full text-xs px-3 py-2 rounded-xl border border-slate-300 focus:ring-2 focus:ring-teal-500"})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"text-xs font-semibold text-slate-600 block mb-1",children:"وب‌سایت / پلتفرم رزرو"}),(0,l.jsx)("input",{type:"text",dir:"ltr",value:x.website||"",onChange:e=>b({...x,website:e.target.value}),className:"w-full text-xs px-3 py-2 rounded-xl border border-slate-300 focus:ring-2 focus:ring-teal-500"})]})]})]}),(0,l.jsxs)("div",{className:"bg-white p-5 rounded-2xl border border-slate-200 shadow-sm space-y-4",children:[(0,l.jsx)("h3",{className:"font-bold text-sm text-slate-900 border-b border-slate-100 pb-2",children:"وضعیت پایپ‌لاین و پیگیری"}),(0,l.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"text-xs font-semibold text-slate-600 block mb-1",children:"مرحله فعلی"}),(0,l.jsx)("select",{value:x.stage||"",onChange:e=>b({...x,stage:e.target.value}),className:"w-full text-xs px-3 py-2 rounded-xl border border-slate-300 focus:ring-2 focus:ring-teal-500 font-semibold",children:_.map((e,s)=>(0,l.jsx)("option",{value:e.stage,children:e.stage},s))})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"text-xs font-semibold text-slate-600 block mb-1",children:"کانال پیگیری بعدی"}),(0,l.jsxs)("select",{value:x.nextFollowupChannel||"تلفنی",onChange:e=>b({...x,nextFollowupChannel:e.target.value}),className:"w-full text-xs px-3 py-2 rounded-xl border border-slate-300 focus:ring-2 focus:ring-teal-500",children:[(0,l.jsx)("option",{value:"تلفنی",children:"تلفنی"}),(0,l.jsx)("option",{value:"پیامک",children:"پیامک"}),(0,l.jsx)("option",{value:"حضوری",children:"حضوری"}),(0,l.jsx)("option",{value:"انجام شد",children:"انجام شد"})]})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"text-xs font-semibold text-slate-600 block mb-1",children:"دور لوپ پیگیری"}),(0,l.jsx)("input",{type:"number",value:x.loopIndex||0,onChange:e=>b({...x,loopIndex:Number(e.target.value)}),className:"w-full text-xs px-3 py-2 rounded-xl border border-slate-300 focus:ring-2 focus:ring-teal-500"})]}),(0,l.jsxs)("div",{className:"md:col-span-3",children:[(0,l.jsx)("label",{className:"text-xs font-semibold text-slate-600 block mb-1",children:"اقدام بعدی یا خلاصه یادداشت"}),(0,l.jsx)("input",{type:"text",value:x.nextActionNote||"",onChange:e=>b({...x,nextActionNote:e.target.value}),className:"w-full text-xs px-3 py-2 rounded-xl border border-slate-300 focus:ring-2 focus:ring-teal-500"})]})]})]}),(0,l.jsxs)("div",{className:"bg-white p-5 rounded-2xl border border-slate-200 shadow-sm space-y-4",children:[(0,l.jsxs)("h3",{className:"font-bold text-sm text-slate-900 border-b border-slate-100 pb-2",children:["اتاق‌های فرار مجموعه (",(null===(t=x.rooms)||void 0===t?void 0:t.length)||0," اتاق)"]}),(0,l.jsx)("div",{className:"space-y-2",children:(x.rooms||[]).map((e,s)=>(0,l.jsxs)("div",{className:"flex items-center justify-between p-3 rounded-xl bg-slate-50 border border-slate-200 text-xs",children:[(0,l.jsxs)("div",{className:"flex items-center gap-3",children:[(0,l.jsx)("span",{className:"w-6 h-6 rounded-lg bg-teal-100 text-teal-800 font-bold flex items-center justify-center",children:s+1}),(0,l.jsx)("span",{className:"font-bold text-slate-800 text-sm",children:e.name}),(0,l.jsxs)("span",{className:"text-slate-500",children:["ظرفیت: ",e.capacity||6," نفر"]}),(0,l.jsxs)("span",{className:"text-slate-500",children:["قیمت هر نفر: ",(e.pricePerPerson||25e4).toLocaleString("fa-IR")," تومان"]})]}),(0,l.jsx)("button",{onClick:()=>Q(s),className:"text-rose-500 hover:text-rose-700 p-1 rounded-lg",children:(0,l.jsx)(ee.Z,{className:"w-4 h-4"})})]},s))}),(0,l.jsxs)("div",{className:"pt-2 border-t border-slate-100 flex flex-wrap items-center gap-2",children:[(0,l.jsx)("input",{type:"text",placeholder:"نام اتاق فرار جدید",value:Z,onChange:e=>T(e.target.value),className:"text-xs px-3 py-2 rounded-xl border border-slate-300 focus:ring-2 focus:ring-teal-500 flex-1"}),(0,l.jsx)("input",{type:"number",placeholder:"ظرفیت",value:P,onChange:e=>L(Number(e.target.value)),className:"text-xs px-3 py-2 rounded-xl border border-slate-300 focus:ring-2 focus:ring-teal-500 w-20"}),(0,l.jsx)("input",{type:"number",placeholder:"قیمت هر نفر",value:D,onChange:e=>O(Number(e.target.value)),className:"text-xs px-3 py-2 rounded-xl border border-slate-300 focus:ring-2 focus:ring-teal-500 w-32"}),(0,l.jsxs)("button",{onClick:()=>{if(!Z.trim())return;let e=x.rooms||[];b({...x,rooms:[...e,{name:Z.trim(),capacity:Number(P)||6,pricePerPerson:Number(D)||25e4}]}),T("")},className:"flex items-center gap-1 px-3 py-2 bg-slate-800 hover:bg-slate-900 text-white rounded-xl text-xs font-semibold",children:[(0,l.jsx)(m.Z,{className:"w-4 h-4"}),"افزودن اتاق"]})]})]}),(0,l.jsx)("div",{className:"flex justify-end",children:(0,l.jsxs)("button",{onClick:z,disabled:h,className:"flex items-center gap-2 px-6 py-2.5 bg-teal-600 hover:bg-teal-700 text-white rounded-xl text-xs font-bold shadow transition-all",children:[(0,l.jsx)(B.Z,{className:"w-4 h-4"}),(0,l.jsx)("span",{children:h?"در حال ذخیره...":"ذخیره تغییرات"})]})})]}),"ai"===i&&(0,l.jsxs)("div",{className:"space-y-6",children:[(0,l.jsxs)("div",{className:"bg-purple-50/70 border border-purple-200 rounded-2xl p-5 space-y-3",children:[(0,l.jsxs)("div",{className:"flex items-center gap-2 text-purple-900 font-bold text-sm",children:[(0,l.jsx)(j.Z,{className:"w-5 h-5 text-purple-600"}),(0,l.jsx)("span",{children:"استخراج خودکار اطلاعات لید از متن تماس (AI)"})]}),(0,l.jsx)("p",{className:"text-xs text-purple-800 leading-relaxed",children:"متن خلاصه مکالمه یا یادداشت صوتی تبدیل‌شده به متن را در کادر زیر وارد کنید و دکمه را بزنید؛ سیستم هوشمند فیلدهای سانس‌های خالی، خواست قلبی، چالش‌ها و اعتراض مشتری را خودکار استخراج می‌کند."}),(0,l.jsx)("textarea",{rows:3,value:N,onChange:e=>v(e.target.value),placeholder:"مثال: با آقای باقری صحبت شد. گفتن وسط هفته‌ها سانس‌های ۲ تا ۶ بعدازظهر کاملاً خالیه. از کارمزد پلتفرم‌های دیگه ناراضین و دنبال فروش بیشتر آخر هفته نیستن بلکه وسط هفته براشون مهمه...",className:"w-full text-xs p-3 rounded-xl border border-purple-300 focus:ring-2 focus:ring-purple-500 bg-white"}),(0,l.jsxs)("div",{className:"flex items-center justify-between",children:[(0,l.jsxs)("button",{onClick:W,disabled:w,className:"flex items-center gap-2 px-5 py-2.5 bg-purple-600 hover:bg-purple-700 text-white text-xs font-bold rounded-xl shadow-md transition-all active:scale-95",children:[(0,l.jsx)(j.Z,{className:"w-4 h-4"}),(0,l.jsx)("span",{children:w?"در حال پردازش هوش مصنوعی...":"✨ پر کردن خودکار با AI"})]}),C&&(0,l.jsx)("span",{className:"text-xs text-emerald-700 font-bold bg-emerald-100 px-3 py-1 rounded-lg",children:C})]})]}),(0,l.jsxs)("div",{className:"bg-white p-5 rounded-2xl border border-slate-200 space-y-4",children:[(0,l.jsx)("h3",{className:"font-bold text-sm text-slate-900 border-b border-slate-100 pb-2",children:"بینش‌های استخراج‌شده و قلاب اکیپا"}),(0,l.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"text-xs font-semibold text-slate-600 block mb-1",children:"سانس‌های مرده و خالی"}),(0,l.jsx)("input",{type:"text",value:x.deadSlots||"",onChange:e=>b({...x,deadSlots:e.target.value}),placeholder:"مثال: شنبه تا سه‌شنبه ۱۲ تا ۱۸",className:"w-full text-xs px-3 py-2 rounded-xl border border-slate-300 focus:ring-2 focus:ring-teal-500"})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"text-xs font-semibold text-slate-600 block mb-1",children:"کانال‌های فروش فعلی"}),(0,l.jsx)("input",{type:"text",value:x.salesChannels||"",onChange:e=>b({...x,salesChannels:e.target.value}),placeholder:"مثال: تلفنی، اینستاگرام، تایم فور فان",className:"w-full text-xs px-3 py-2 rounded-xl border border-slate-300 focus:ring-2 focus:ring-teal-500"})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"text-xs font-semibold text-slate-600 block mb-1",children:"بزرگ‌ترین درد و چالش"}),(0,l.jsx)("input",{type:"text",value:x.biggestPain||"",onChange:e=>b({...x,biggestPain:e.target.value}),placeholder:"مثال: کنسلی‌های لحظه آخری و نبود مشتری وسط هفته",className:"w-full text-xs px-3 py-2 rounded-xl border border-slate-300 focus:ring-2 focus:ring-teal-500"})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"text-xs font-semibold text-slate-600 block mb-1",children:"خواست و هدف قلبی مدیر"}),(0,l.jsx)("input",{type:"text",value:x.coreDesire||"",onChange:e=>b({...x,coreDesire:e.target.value}),placeholder:"مثال: پر شدن سانس‌های خالی بدون هزینه اولیه سنگین",className:"w-full text-xs px-3 py-2 rounded-xl border border-slate-300 focus:ring-2 focus:ring-teal-500"})]}),(0,l.jsxs)("div",{className:"md:col-span-2",children:[(0,l.jsx)("label",{className:"text-xs font-semibold text-teal-800 block mb-1",children:"قلاب اختصاصی اکیپا برای این مجموعه (Hook)"}),(0,l.jsx)("input",{type:"text",value:x.hookForEkipa||"",onChange:e=>b({...x,hookForEkipa:e.target.value}),placeholder:"مثال: پر کردن تضمینی سانس‌های بعدازظهر بدون کارمزد ثابت",className:"w-full text-xs px-3 py-2 rounded-xl border border-teal-300 bg-teal-50/50 focus:ring-2 focus:ring-teal-500 font-semibold"})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"text-xs font-semibold text-slate-600 block mb-1",children:"نوع اعتراض مطرح‌شده"}),(0,l.jsxs)("select",{value:x.objectionStatus||"",onChange:e=>b({...x,objectionStatus:e.target.value}),className:"w-full text-xs px-3 py-2 rounded-xl border border-slate-300 focus:ring-2 focus:ring-teal-500",children:[(0,l.jsx)("option",{value:"",children:"بدون اعتراض خاص"}),Object.keys(A).map(e=>(0,l.jsx)("option",{value:e,children:e},e))]})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"text-xs font-semibold text-slate-600 block mb-1",children:"قالب پیامک پیشنهادی"}),(0,l.jsx)("input",{type:"text",value:x.smsTag||"",onChange:e=>b({...x,smsTag:e.target.value}),placeholder:"sms_proposal_welcome",className:"w-full text-xs px-3 py-2 rounded-xl border border-slate-300 focus:ring-2 focus:ring-teal-500 font-mono"})]})]}),(0,l.jsx)("div",{className:"pt-2 flex justify-end",children:(0,l.jsxs)("button",{onClick:z,disabled:h,className:"flex items-center gap-2 px-6 py-2.5 bg-purple-600 hover:bg-purple-700 text-white rounded-xl text-xs font-bold shadow transition-all",children:[(0,l.jsx)(B.Z,{className:"w-4 h-4"}),(0,l.jsx)("span",{children:h?"در حال ذخیره...":"ذخیره بینش‌های AI"})]})})]})]}),"activities"===i&&(0,l.jsxs)("div",{className:"space-y-6",children:[(0,l.jsxs)("form",{onSubmit:q,className:"bg-white p-5 rounded-2xl border border-slate-200 space-y-3",children:[(0,l.jsx)("h3",{className:"font-bold text-sm text-slate-900",children:"ثبت تعامل یا تماس جدید"}),(0,l.jsx)("div",{className:"flex gap-2",children:["تماس تلفنی","ارسال پیامک","جلسه حضوری","پیگیری واتساپ"].map(e=>(0,l.jsx)("button",{type:"button",onClick:()=>R(e),className:"px-3 py-1.5 rounded-lg text-xs font-medium border transition-colors ".concat(M===e?"bg-slate-900 text-white border-slate-900":"bg-white text-slate-600 border-slate-200"),children:e},e))}),(0,l.jsx)("textarea",{rows:2,value:F,onChange:e=>E(e.target.value),placeholder:"نتیجه مکالمه یا بازخورد لید را یادداشت کنید...",className:"w-full text-xs p-3 rounded-xl border border-slate-300 focus:ring-2 focus:ring-teal-500"}),(0,l.jsx)("div",{className:"flex justify-end",children:(0,l.jsxs)("button",{type:"submit",disabled:J,className:"flex items-center gap-1.5 px-4 py-2 bg-teal-600 hover:bg-teal-700 text-white rounded-xl text-xs font-bold transition-all",children:[(0,l.jsx)(I.Z,{className:"w-3.5 h-3.5"}),(0,l.jsx)("span",{children:"ثبت در تاریخچه"})]})})]}),(0,l.jsx)("div",{className:"space-y-3",children:0===(r.activities||[]).length?(0,l.jsx)("p",{className:"text-center text-xs text-slate-400 py-6",children:"هیچ تعاملی ثبت نشده است."}):(r.activities||[]).map(e=>(0,l.jsxs)("div",{className:"bg-white p-4 rounded-xl border border-slate-200 flex items-start gap-3 text-xs",children:[(0,l.jsx)("div",{className:"w-8 h-8 rounded-lg bg-teal-50 text-teal-700 flex items-center justify-center shrink-0",children:(0,l.jsx)(y.Z,{className:"w-4 h-4"})}),(0,l.jsxs)("div",{className:"flex-1",children:[(0,l.jsxs)("div",{className:"flex items-center justify-between",children:[(0,l.jsx)("span",{className:"font-bold text-slate-800",children:e.type}),(0,l.jsx)("span",{className:"text-[11px] text-slate-400 font-mono",dir:"ltr",children:new Date(e.createdAt).toLocaleString("fa-IR")})]}),e.notes&&(0,l.jsx)("p",{className:"text-slate-600 mt-1 leading-relaxed bg-slate-50 p-2 rounded-lg",children:e.notes}),e.performedBy&&(0,l.jsxs)("span",{className:"text-[10px] text-slate-400 block mt-1",children:["ثبت توسط: ",e.performedBy]})]})]},e.id))})]})]})]})})}function et(e){let{isOpen:s,onClose:t,onSuccess:r}=e;if(!s)return null;let[n,d]=(0,a.useState)(""),[o,i]=(0,a.useState)("تهران"),[c,x]=(0,a.useState)(""),[b,h]=(0,a.useState)(""),[p,u]=(0,a.useState)(""),[g,j]=(0,a.useState)(""),[f,N]=(0,a.useState)(""),[v,y]=(0,a.useState)("ارتباط اولیه"),[w,k]=(0,a.useState)(15e6),[C,S]=(0,a.useState)(""),[Z,T]=(0,a.useState)(!1),[P,A]=(0,a.useState)(""),L=async e=>{if(e.preventDefault(),!n.trim()||!p.trim()||!o.trim()){A("نام مجموعه، شهر و شماره تماس الزامی هستند.");return}T(!0),A("");try{let e=await fetch("/api/leads",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:n.trim(),city:o.trim(),district:c.trim()||null,ownerName:b.trim()||"مدیر مجموعه",ownerPhone:p.trim(),managerName:b.trim()||null,phone:p.trim(),stage:v,rooms:C.trim()?[{title:C.trim(),minPlayers:4,maxPlayers:8,ticketPrice:25e4}]:[]})});if(!e.ok){let s=await e.json();throw Error(s.error||"خطا در ثبت لید")}r(),t()}catch(e){A(e.message||"خطا در برقراری ارتباط")}finally{T(!1)}};return(0,l.jsx)("div",{className:"fixed inset-0 z-50 bg-slate-900/60 backdrop-blur-sm flex items-center justify-center p-4 overflow-y-auto",children:(0,l.jsxs)("div",{className:"bg-white rounded-3xl shadow-2xl border border-slate-200 w-full max-w-xl overflow-hidden animate-in fade-in zoom-in-95 duration-150",children:[(0,l.jsxs)("div",{className:"p-6 border-b border-slate-100 flex items-center justify-between bg-slate-50",children:[(0,l.jsxs)("div",{className:"flex items-center gap-3",children:[(0,l.jsx)("div",{className:"w-10 h-10 rounded-xl bg-teal-600 text-white flex items-center justify-center",children:(0,l.jsx)(Y.Z,{className:"w-5 h-5"})}),(0,l.jsxs)("div",{children:[(0,l.jsx)("h2",{className:"text-base font-bold text-slate-900",children:"افزودن مجموعه اتاق فرار جدید"}),(0,l.jsx)("p",{className:"text-xs text-slate-500",children:"ثبت لید جدید در پایپ‌لاین فروش اکیپا"})]})]}),(0,l.jsx)("button",{onClick:t,className:"p-2 text-slate-400 hover:text-slate-700 hover:bg-slate-200/50 rounded-xl transition-colors",children:(0,l.jsx)(X.Z,{className:"w-5 h-5"})})]}),(0,l.jsxs)("form",{onSubmit:L,className:"p-6 space-y-4",children:[P&&(0,l.jsx)("div",{className:"p-3 rounded-xl bg-rose-50 border border-rose-200 text-rose-700 text-xs font-semibold",children:P}),(0,l.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[(0,l.jsxs)("div",{className:"md:col-span-2",children:[(0,l.jsxs)("label",{className:"text-xs font-semibold text-slate-700 block mb-1",children:["نام مجموعه / اتاق فرار ",(0,l.jsx)("span",{className:"text-rose-500",children:"*"})]}),(0,l.jsx)("input",{type:"text",required:!0,value:n,onChange:e=>d(e.target.value),placeholder:"مثال: اتاق فرار طاعون سیاه",className:"w-full text-xs px-3 py-2.5 rounded-xl border border-slate-300 focus:ring-2 focus:ring-teal-500"})]}),(0,l.jsxs)("div",{children:[(0,l.jsxs)("label",{className:"text-xs font-semibold text-slate-700 block mb-1",children:["شهر ",(0,l.jsx)("span",{className:"text-rose-500",children:"*"})]}),(0,l.jsx)("input",{type:"text",required:!0,value:o,onChange:e=>i(e.target.value),placeholder:"تهران / کرج / اصفهان ...",className:"w-full text-xs px-3 py-2.5 rounded-xl border border-slate-300 focus:ring-2 focus:ring-teal-500"})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"text-xs font-semibold text-slate-700 block mb-1",children:"منطقه / محله"}),(0,l.jsx)("input",{type:"text",value:c,onChange:e=>x(e.target.value),placeholder:"مثال: سعادت‌آباد، فردیس",className:"w-full text-xs px-3 py-2.5 rounded-xl border border-slate-300 focus:ring-2 focus:ring-teal-500"})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"text-xs font-semibold text-slate-700 block mb-1",children:"نام مدیر یا مسئول"}),(0,l.jsx)("input",{type:"text",value:b,onChange:e=>h(e.target.value),placeholder:"مثال: احسان رضایی",className:"w-full text-xs px-3 py-2.5 rounded-xl border border-slate-300 focus:ring-2 focus:ring-teal-500"})]}),(0,l.jsxs)("div",{children:[(0,l.jsxs)("label",{className:"text-xs font-semibold text-slate-700 block mb-1",children:["شماره تماس ",(0,l.jsx)("span",{className:"text-rose-500",children:"*"})]}),(0,l.jsx)("input",{type:"text",required:!0,dir:"ltr",value:p,onChange:e=>u(e.target.value),placeholder:"09123456789",className:"w-full text-xs px-3 py-2.5 rounded-xl border border-slate-300 focus:ring-2 focus:ring-teal-500"})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"text-xs font-semibold text-slate-700 block mb-1",children:"آیدی اینستاگرام"}),(0,l.jsx)("input",{type:"text",dir:"ltr",value:g,onChange:e=>j(e.target.value),placeholder:"@escaperoom_ir",className:"w-full text-xs px-3 py-2.5 rounded-xl border border-slate-300 focus:ring-2 focus:ring-teal-500"})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"text-xs font-semibold text-slate-700 block mb-1",children:"وب‌سایت / پلتفرم رزرو"}),(0,l.jsx)("input",{type:"text",dir:"ltr",value:f,onChange:e=>N(e.target.value),placeholder:"https://t4f.ir/...",className:"w-full text-xs px-3 py-2.5 rounded-xl border border-slate-300 focus:ring-2 focus:ring-teal-500"})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"text-xs font-semibold text-slate-700 block mb-1",children:"مرحله ورود به پایپ‌لاین"}),(0,l.jsx)("select",{value:v,onChange:e=>y(e.target.value),className:"w-full text-xs px-3 py-2.5 rounded-xl border border-slate-300 focus:ring-2 focus:ring-teal-500 font-semibold",children:_.map((e,s)=>(0,l.jsx)("option",{value:e.stage,children:e.stage},s))})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"text-xs font-semibold text-slate-700 block mb-1",children:"ارزش بالقوه قرارداد (تومان)"}),(0,l.jsx)("input",{type:"number",value:w,onChange:e=>k(Number(e.target.value)),className:"w-full text-xs px-3 py-2.5 rounded-xl border border-slate-300 focus:ring-2 focus:ring-teal-500"})]}),(0,l.jsxs)("div",{className:"md:col-span-2",children:[(0,l.jsx)("label",{className:"text-xs font-semibold text-slate-700 block mb-1",children:"نام اولین اتاق فعال مجموعه (اختیاری)"}),(0,l.jsx)("input",{type:"text",value:C,onChange:e=>S(e.target.value),placeholder:"مثال: اتاق جن‌گیر (۶ نفره - ۲۵۰,۰۰۰ تومان)",className:"w-full text-xs px-3 py-2.5 rounded-xl border border-slate-300 focus:ring-2 focus:ring-teal-500"})]})]}),(0,l.jsxs)("div",{className:"pt-4 border-t border-slate-100 flex items-center justify-end gap-3",children:[(0,l.jsx)("button",{type:"button",onClick:t,className:"px-4 py-2 text-xs font-semibold text-slate-600 hover:bg-slate-100 rounded-xl transition-colors",children:"انصراف"}),(0,l.jsxs)("button",{type:"submit",disabled:Z,className:"flex items-center gap-1.5 px-6 py-2.5 bg-teal-600 hover:bg-teal-700 text-white text-xs font-bold rounded-xl shadow transition-all active:scale-95",children:[(0,l.jsx)(m.Z,{className:"w-4 h-4"}),(0,l.jsx)("span",{children:Z?"در حال ثبت...":"ثبت مجموعه در CRM"})]})]})]})]})})}function el(){let[e,s]=(0,a.useState)("dashboard"),[t,r]=(0,a.useState)(!0),[n,d]=(0,a.useState)(null),[o,i]=(0,a.useState)([]),[c,x]=(0,a.useState)(null),[m,h]=(0,a.useState)(null),[p,u]=(0,a.useState)(!1),[g,j]=(0,a.useState)(!1),f=async()=>{try{let[e,s,t]=await Promise.all([fetch("/api/dashboard/stats"),fetch("/api/leads"),fetch("/api/tasks/today")]);e.ok&&d(await e.json()),s.ok&&i(await s.json()),t.ok&&x(await t.json())}catch(e){console.error("Error fetching CRM data:",e)}finally{r(!1)}};(0,a.useEffect)(()=>{f()},[]);let N=async e=>{try{let s=await fetch("/api/leads/".concat(e.id));if(s.ok){let e=await s.json();h(e)}else h(e)}catch(s){h(e)}u(!0)};return(0,l.jsxs)("div",{className:"min-h-screen bg-slate-50 flex flex-col font-sans selection:bg-teal-100 selection:text-teal-900",children:[(0,l.jsx)(b,{activeTab:e,setActiveTab:s,onNewLead:()=>j(!0),onExportExcel:()=>{window.open("/api/export","_blank")},onImportSuccess:f}),(0,l.jsx)("main",{className:"flex-1 max-w-7xl w-full mx-auto p-4 md:p-6 pb-16",children:t?(0,l.jsxs)("div",{className:"flex flex-col items-center justify-center py-32 space-y-4",children:[(0,l.jsx)("div",{className:"w-12 h-12 border-4 border-teal-600 border-t-transparent rounded-full animate-spin"}),(0,l.jsx)("p",{className:"text-sm font-semibold text-slate-500",children:"در حال بارگذاری اطلاعات CRM اکیپا..."})]}):(0,l.jsxs)(l.Fragment,{children:["dashboard"===e&&(0,l.jsx)(C,{stats:n,onSelectLead:N,onNavigateTab:e=>s(e)}),"pipeline"===e&&(0,l.jsx)(D,{leads:o,onSelectLead:N,onRefresh:f}),"today"===e&&(0,l.jsx)(J,{data:c,onSelectLead:N,onRefresh:f}),"onboarding"===e&&(0,l.jsx)(z,{leads:o,onSelectLead:N,onRefresh:f}),"settings"===e&&(0,l.jsx)(U,{stats:n,onRefresh:f})]})}),(0,l.jsx)(es,{lead:m,isOpen:p,onClose:()=>{u(!1),h(null)},onRefresh:f}),(0,l.jsx)(et,{isOpen:g,onClose:()=>j(!1),onSuccess:f})]})}}},function(e){e.O(0,[865,971,117,744],function(){return e(e.s=8451)}),_N_E=e.O()}]);