Files
machartaa_admin_dist/dist/assets/index-266c4e7d.js
T
2026-08-22 14:52:19 +03:30

2 lines
29 KiB
JavaScript

import{_ as Ue,v as fe,t as ge,a as Be}from"./AudienceSegmentPicker.vue_vue_type_script_setup_true_lang-433f382f.js";import{_ as me}from"./BasicModal.vue_vue_type_style_index_0_lang-20cc468f.js";import{u as te,_ as pe}from"./useBaseTable-1184a002.js";import{_ as Me}from"./button.vue_vue_type_style_index_0_lang-cbfd9667.js";import{g as Oe}from"./member-d49124ce.js";import{N as K,d as oe,g as u,h as $e,E as Ee,o as P,c as A,a,b as t,j as D,w as l,e as m,t as p,k as H,F as ve,n as Ne,J as ae,D as g,v as qe,O as Ve,r as Fe}from"./index-35c19078.js";import{t as ne}from"./useDataTime-35d3ce8c.js";import{M as ye,_ as Ke}from"./index-d1bea9c9.js";import{C as ce}from"./index-3e7c49ac.js";import{I as de,_ as Ie}from"./index-e2b66426.js";import{I as le}from"./Icon-0c226cc8.js";import{S as Re}from"./index-c135e3cd.js";import{B as Ce}from"./index-317dfb98.js";import{D as Se,_ as Te}from"./index-5d258eed.js";import{S as Pe,a as Ae}from"./index-0cfe3fb2.js";import{T as ie}from"./isSymbol-76912a30.js";import{_ as je}from"./BasicInput.vue_vue_type_style_index_0_lang-4f908c47.js";import{_ as ze,T as He}from"./index-0b82077f.js";import"./dayjs-5f515fbb.js";import"./updateLocale-674603f1.js";import"./shallowequal-336924ae.js";import"./_plugin-vue_export-helper-b8aa26f1.js";import"./vnode-bd016db8.js";import"./useState-0b0c0b26.js";import"./useMemo-141475be.js";import"./FormItemContext-c59740e7.js";import"./omit-fea2187f.js";import"./lodash-e3d7e6b8.js";import"./BaseSwitch.vue_vue_type_script_setup_true_lang-aa5cbf20.js";import"./index-9c958bd1.js";import"./Badge-5aec0f5b.js";import"./isNumeric-3f69e2aa.js";import"./index-597067d3.js";import"./index-81c6c557.js";import"./index-70f42a71.js";import"./DialogWrap-7ea92471.js";import"./pickAttrs-2a6a34d0.js";import"./styleChecker-5378d544.js";import"./index-53a07be2.js";import"./index-e39a0c4e.js";import"./css-aae66f86.js";import"./SearchOutlined-fd97bf7f.js";import"./toArray-f7bbf4fe.js";import"./isPlainObject-9fc066ac.js";import"./isMobile-e2e89480.js";import"./usePrice-bc935b83.js";import"./useRefs-d20fccdf.js";import"./_flatRest-ce9c6e5e.js";const xe=async e=>(await K.post("/admin/sms/preview",e)).data,Je=async e=>(await K.post("/admin/sms/test",e)).data,he=async e=>(await K.post("/admin/sms/campaigns/start",e)).data,Ge=async e=>{var v;const o=await K.get("/admin/sms/campaigns",{params:{page:e.page,limit:e.limit,search:e.search}}),b=e.page||1,S=e.limit||20,M=(b-1)*S;return{rows:(o.data||[]).map((x,k)=>({...x,index:M+k})),total:o.total??((v=o.data)==null?void 0:v.length)??0,query:{...e,total:o.total??0,page:b,limit:S}}},be=async(e,o)=>(await K.get(`/admin/sms/campaigns/${e}`,{params:o})).data,Qe=async e=>{const o=await K.get("/admin/sms/automations"),b=e.page||1,S=e.limit||20,M=(b-1)*S,v=o.data||[];return{rows:v.map((x,k)=>({...x,index:M+k})),total:o.total??v.length,query:{...e,total:o.total??v.length,page:b,limit:S}}},we=async(e,o)=>(await K.patch(`/admin/sms/automations/${e}`,o)).data,ke=async(e,o)=>(await K.get(`/admin/sms/automations/${e}/sends`,{params:o})).data,We=async(e,o)=>(await K.post(`/admin/sms/automations/${e}/test`,{phone:o})).data,Xe=[{title:"ردیف",dataIndex:"id",key:"id",filterable:!1,customRender:e=>e.index+1},{title:"نام",dataIndex:"first_name",key:"first_name",filterable:!0},{title:"نام خانوادگی",dataIndex:"last_name",key:"last_name",filterable:!0},{title:"شماره همراه",dataIndex:"phone",key:"phone",filterable:!0},{title:"زمان ثبت‌نام",dataIndex:"created_at",key:"created_at",type:"Date",filterable:!0,customRender:e=>e.record.created_at?ne(e.record.created_at):"-"}],Ye={class:"grid grid-cols-1 xl:grid-cols-3 gap-4 mb-4"},Ze={class:"xl:col-span-2 space-y-4"},et=a("div",{class:"mb-1 text-sm text-gray-600"},"متن پیامک *",-1),tt={class:"flex flex-wrap gap-4 items-center"},at={class:"flex flex-wrap gap-2"},nt={class:"bg-gray-50 rounded-lg p-4 border border-gray-200 space-y-2 text-sm"},st=a("div",{class:"font-semibold text-gray-700 mb-2"},"خلاصه ارسال",-1),lt={key:0},it={key:0,class:"text-amber-600 mt-1"},ot={key:1,class:"text-gray-500"},rt={key:2,class:"pt-2 border-t border-gray-200"},ut=a("div",{class:"font-medium mb-1"},"نمونه گیرندگان:",-1),ct={class:"space-y-1 text-xs text-gray-600"},dt={key:3,class:"pt-2 border-t border-gray-200"},mt=a("div",{class:"font-medium mb-1"},"آخرین کمپین:",-1),pt={class:"text-blue-600 mt-1"},vt={class:"border-t border-gray-200 pt-4"},_t=a("div",{class:"mb-2 text-sm text-gray-600"}," کاربران را فیلتر کنید و گیرندگان مورد نظر را انتخاب کنید. فقط کاربرانی که شماره موبایل دارند نمایش داده می‌شوند. ",-1),ft={class:"space-y-3"},gt=a("div",{class:"mb-1 text-sm text-gray-600"},"شماره موبایل",-1),yt=a("div",{class:"text-xs text-gray-500"}," متن پیامک از باکس اصلی استفاده می‌شود. ",-1),xt=oe({__name:"SendPanel",emits:["campaign-started"],setup(e,{emit:o}){const{TextArea:b}=de,[S,M]=te(),v=u(""),x=u(!0),k=u(!0),c=u(null),I=u(!1),f=u(!1),$=u(null),L=u(!1),T=u(""),V=u(!1),R=u([]),w=u({}),O=u({segments:[],inactiveDays:7,subscriberInactiveDays:3}),E=u(!1),N=u(""),G=$e(()=>({selectedRowKeys:R.value,onChange:i=>{R.value=i.map(String)},preserveSelectedRowKeys:!0})),Q=u({columns:Xe,api:async i=>{const n={...i,filters:[...i.filters||[],{field:"phone",op:"nn",value:!0,cr:"and",type:"switch",hidden:!0}]};return x.value&&n.filters.push({field:"first_name",op:"nn",value:!0,cr:"and",type:"switch",hidden:!0},{field:"last_name",op:"nn",value:!0,cr:"and",type:"switch",hidden:!0}),!n.sort&&!n.order&&(n.order="-created_at"),w.value=n,Oe(n)},defaultPageLimit:20,height:"45vh"});Ee(x,()=>{c.value=null,M()});function j(i){var n;return{message:v.value.trim(),appendAppName:k.value,registrationComplete:x.value,search:w.value.search||void 0,filters:(n=w.value.filters)==null?void 0:n.filter(s=>!s.hidden),sort:w.value.sort||void 0,order:w.value.order||void 0,mode:i,userIds:i==="selected"?R.value:void 0}}async function W(){var i,n;if(!v.value.trim()){g.warning("ابتدا متن پیامک را وارد کنید");return}I.value=!0;try{c.value=await xe(j("filtered"))}catch(s){g.error(((n=(i=s==null?void 0:s.response)==null?void 0:i.data)==null?void 0:n.error)||"خطا در پیش‌نمایش")}finally{I.value=!1}}async function X(){var i,n;if(!v.value.trim()){g.warning("متن پیامک الزامی است");return}if(!T.value.trim()){g.warning("شماره موبایل الزامی است");return}V.value=!0;try{await Je({...j("filtered"),phone:T.value.trim()}),g.success("پیامک تستی ارسال شد"),L.value=!1}catch(s){g.error(((n=(i=s==null?void 0:s.response)==null?void 0:i.data)==null?void 0:n.error)||"ارسال تستی ناموفق بود")}finally{V.value=!1}}async function z(i){if(!v.value.trim()){g.warning("متن پیامک الزامی است");return}if(i==="selected"&&!R.value.length){g.warning("حداقل یک کاربر انتخاب کنید");return}const n=i==="selected"?`آیا از ارسال پیامک به ${R.value.length} کاربر انتخاب‌شده مطمئن هستید؟`:"آیا از ارسال پیامک به همه کاربران فیلترشده مطمئن هستید؟";return new Promise(s=>{ye.confirm({title:"تأیید ارسال پیامک",content:n,okText:"بله، ارسال کن",cancelText:"انصراف",okType:"danger",centered:!0,onOk:async()=>{var r,y;f.value=!0,$.value=null;try{const d=await he(j(i));$.value=d,o("campaign-started",d.campaignId),g.success(`کمپین #${d.campaignId} با ${d.totalRecipients} گیرنده در پس‌زمینه ارسال می‌شود`)}catch(d){g.error(((y=(r=d==null?void 0:d.response)==null?void 0:r.data)==null?void 0:y.error)||"شروع کمپین ناموفق بود")}finally{f.value=!1,s()}},onCancel:()=>s()})})}function J(){return z("selected")}function Y(){return z("filtered")}async function Z(){var s,r;if(!v.value.trim()){g.warning("ابتدا متن پیامک را وارد کنید");return}const i={...O.value,includeUserIds:R.value},n=fe(i);if(n){g.warning(n);return}E.value=!0,N.value="";try{const y=ge(i),d=await xe({message:v.value.trim(),appendAppName:k.value,registrationComplete:x.value,mode:"segment",...y});c.value=d;const C=R.value.length>0?` (+ ${R.value.length.toLocaleString("fa-IR")} کاربر از جدول)`:"";N.value=d.cappedAt?`گیرندگان این دسته‌ها: ${d.totalRecipients.toLocaleString("fa-IR")} شماره${C} — در ارسال حداکثر ${d.cappedAt.toLocaleString("fa-IR")} نفر`:`گیرندگان این دسته‌ها: ${d.totalRecipients.toLocaleString("fa-IR")} شماره${C}`}catch(y){console.log(y),g.error(((r=(s=y==null?void 0:y.response)==null?void 0:s.data)==null?void 0:r.error)||"خطا در پیش‌نمایش")}finally{E.value=!1}}async function ee(){if(!v.value.trim()){g.warning("متن پیامک الزامی است");return}const i={...O.value,includeUserIds:R.value},n=fe(i);if(n){g.warning(n);return}const s=O.value.segments.length,r=R.value.length,y=r>0?`ارسال به ${s} دسته (OR) به‌علاوه ${r} کاربر انتخاب‌شده؟`:`ارسال به ${s} دسته مخاطب (اتحاد / OR)؟`;return new Promise(d=>{ye.confirm({title:"تأیید ارسال پیامک",content:y,okText:"بله، ارسال کن",cancelText:"انصراف",okType:"danger",centered:!0,onOk:async()=>{var C,_;f.value=!0,$.value=null;try{const q=ge(i),U=await he({message:v.value.trim(),appendAppName:k.value,registrationComplete:x.value,mode:"segment",...q});$.value=U,o("campaign-started",U.campaignId),g.success(`کمپین #${U.campaignId} با ${U.totalRecipients} گیرنده در پس‌زمینه ارسال می‌شود`)}catch(q){g.error(((_=(C=q==null?void 0:q.response)==null?void 0:C.data)==null?void 0:_.error)||"شروع کمپین ناموفق بود")}finally{f.value=!1,d()}},onCancel:()=>d()})})}return(i,n)=>{var d,C;const s=Me,r=pe,y=me;return P(),A("div",null,[a("div",Ye,[a("div",Ze,[a("div",null,[et,t(D(b),{value:v.value,"onUpdate:value":n[0]||(n[0]=_=>v.value=_),placeholder:"متن پیامک را وارد کنید...",rows:6,maxlength:1e3,"show-count":""},null,8,["value"])]),a("div",tt,[t(D(ce),{checked:x.value,"onUpdate:checked":n[1]||(n[1]=_=>x.value=_)},{default:l(()=>[m(" فقط کاربران با ثبت‌نام کامل (نام و نام خانوادگی) ")]),_:1},8,["checked"]),t(D(ce),{checked:k.value,"onUpdate:checked":n[2]||(n[2]=_=>k.value=_)},{default:l(()=>[m(" افزودن نام اپلیکیشن به انتهای پیام ")]),_:1},8,["checked"])]),a("div",at,[t(s,{loading:I.value,onClick:W},{default:l(()=>[m(" پیش‌نمایش گیرندگان ")]),_:1},8,["loading"]),t(s,{onClick:n[3]||(n[3]=_=>L.value=!0)},{default:l(()=>[m(" ارسال تست ")]),_:1}),t(s,{type:"primary",loading:f.value,disabled:!v.value.trim(),onClick:J},{default:l(()=>[m(" ارسال به انتخاب‌شده‌ها ("+p(R.value.length)+") ",1)]),_:1},8,["loading","disabled"]),t(s,{type:"primary",ghost:"",loading:f.value,disabled:!v.value.trim(),onClick:Y},{default:l(()=>[m(" ارسال به همه فیلترشده‌ها ")]),_:1},8,["loading","disabled"])]),t(Ue,{modelValue:O.value,"onUpdate:modelValue":n[4]||(n[4]=_=>O.value=_),"include-user-count":R.value.length,"preview-loading":E.value,sending:f.value,disabled:!v.value.trim(),"preview-text":N.value,onPreview:Z,onSend:ee},null,8,["modelValue","include-user-count","preview-loading","sending","disabled","preview-text"])]),a("div",nt,[st,c.value?(P(),A("div",lt,[a("div",null,[m("تعداد گیرنده: "),a("strong",null,p(c.value.totalRecipients),1)]),a("div",null,[m("شماره یکتا: "),a("strong",null,p(c.value.uniquePhones),1)]),a("div",null,[m("پارت پیامک (هر نفر): "),a("strong",null,p(c.value.smsPartsPerRecipient),1)]),a("div",null,[m("تخمین کل پارت: "),a("strong",null,p(c.value.estimatedTotalParts),1)]),c.value.cappedAt?(P(),A("div",it," حداکثر "+p(c.value.cappedAt)+" گیرنده در هر ارسال ",1)):H("",!0)])):(P(),A("div",ot," برای مشاهده تعداد گیرندگان، پیش‌نمایش بگیرید. ")),(C=(d=c.value)==null?void 0:d.samples)!=null&&C.length?(P(),A("div",rt,[ut,a("ul",ct,[(P(!0),A(ve,null,Ne(c.value.samples,_=>(P(),A("li",{key:_.id},p(_.first_name)+" "+p(_.last_name)+" — "+p(_.phone),1))),128))])])):H("",!0),$.value?(P(),A("div",dt,[mt,a("div",null,[m("کمپین: "),a("strong",null,"#"+p($.value.campaignId),1)]),a("div",null,[m("گیرندگان: "),a("strong",null,p($.value.totalRecipients),1)]),a("div",pt,p($.value.message),1)])):H("",!0)])]),a("div",vt,[_t,t(r,ae(Q.value,{"row-selection":G.value,onRegister:D(S)}),null,16,["row-selection","onRegister"])]),t(y,{visible:L.value,"onUpdate:visible":n[6]||(n[6]=_=>L.value=_),title:"ارسال پیامک تست",onOk:X,onCancel:n[7]||(n[7]=_=>L.value=!1),"confirm-loading":V.value},{default:l(()=>[a("div",ft,[a("div",null,[gt,t(D(de),{value:T.value,"onUpdate:value":n[5]||(n[5]=_=>T.value=_),placeholder:"مثال: 09123456789"},null,8,["value"])]),yt])]),_:1},8,["visible","confirm-loading"])])}}}),ht={pending:"در انتظار",sending:"در حال ارسال",completed:"تکمیل شده",failed:"ناموفق"},bt={selected:"انتخاب‌شده",filtered:"فیلترشده",segment:"دسته مخاطب"},wt=[{title:"ردیف",dataIndex:"id",key:"row_index",filterable:!1,customRender:e=>e.index+1},{title:"شناسه",dataIndex:"id",key:"id",filterable:!1},{title:"متن پیام",dataIndex:"message",key:"message",filterable:!1,customRender:e=>{const o=e.record.message||"";return o.length>60?`${o.slice(0,60)}...`:o}},{title:"گیرندگان",dataIndex:"total_recipients",key:"total_recipients",filterable:!1},{title:"پیشرفت",dataIndex:"sent_count",key:"progress",filterable:!1,customRender:e=>{const o=e.record;if(!o.total_recipients)return"-";const b=(o.sent_count||0)+(o.failed_count||0),S=Math.round(b/o.total_recipients*100);return`${b}/${o.total_recipients} (${S}%)`}},{title:"ناموفق",dataIndex:"failed_count",key:"failed_count",filterable:!1},{title:"نوع ارسال",dataIndex:"send_mode",key:"send_mode",filterable:!1,customRender:e=>bt[e.record.send_mode]||e.record.send_mode},{title:"وضعیت",dataIndex:"status",key:"status",filterable:!1,customRender:e=>ht[e.record.status]||e.record.status},{title:"تاریخ",dataIndex:"created_at",key:"created_at",filterable:!1,customRender:e=>e.record.created_at?ne(e.record.created_at):"-"},{title:"عملیات",dataIndex:"action",key:"action",slot:"action",filterable:!1,align:"center"}],kt={pending:"در انتظار",sent:"ارسال شده",failed:"ناموفق"},$t=[{title:"ردیف",dataIndex:"id",key:"row_index",filterable:!1,customRender:e=>e.index+1},{title:"نام",dataIndex:"first_name",key:"first_name",filterable:!1},{title:"نام خانوادگی",dataIndex:"last_name",key:"last_name",filterable:!1},{title:"شماره",dataIndex:"phone",key:"phone",filterable:!1},{title:"وضعیت",dataIndex:"status",key:"status",filterable:!1,customRender:e=>kt[e.record.status]||e.record.status},{title:"زمان ارسال",dataIndex:"sent_at",key:"sent_at",filterable:!1,customRender:e=>e.record.sent_at?ne(e.record.sent_at):"-"},{title:"خطا",dataIndex:"error_message",key:"error_message",filterable:!1,customRender:e=>e.record.error_message||"-"}],It={key:0,class:"mb-3 text-sm text-blue-600 flex items-center gap-2"},Rt=a("span",null,"یک یا چند کمپین در حال ارسال است — جدول هر ۵ ثانیه به‌روز می‌شود.",-1),Ct={class:"gap-2 flex justify-center"},St=a("span",null,"جزئیات کمپین",-1),Tt={class:"text-green-600"},Pt={class:"text-red-600"},At={key:0,class:"text-gray-500 mr-2"},Dt={class:"whitespace-pre-wrap text-sm"},Lt={class:"flex flex-wrap gap-2 items-center mb-3"},Ut=a("span",{class:"text-sm text-gray-600"},"فیلتر وضعیت گیرندگان:",-1),Bt=oe({__name:"CampaignsPanel",setup(e,{expose:o}){const[b,S]=te(),[M,v]=te(),x=u(!1),k=u(!1),c=u(null),I=u(null),f=u(),$=u(""),L=u(!1);let T=null;const V={pending:"در انتظار",sending:"در حال ارسال",completed:"تکمیل شده",failed:"ناموفق"},R={selected:"انتخاب‌شده",filtered:"فیلترشده",segment:"دسته مخاطب"},w=u({columns:wt,api:E,defaultPageLimit:20,height:"55vh"}),O=$e(()=>{var n;if(!((n=c.value)!=null&&n.campaign))return 0;const i=c.value.campaign;return Math.max(i.total_recipients-i.sent_count-i.failed_count,0)});async function E(i){const n=await Ge(i);return L.value=n.rows.some(s=>s.status==="sending"),n}const N=u({columns:$t,api:j,defaultPageLimit:20,height:"40vh",showOptionHeader:!1});function G(i){return V[i]||i}function se(i){return R[i]||i}function Q(i){return i?ne(i):"-"}async function j(i){if(!I.value)return{rows:[],total:0,query:{...i,total:0}};const n=await be(I.value,{page:i.page,limit:i.limit,status:f.value,search:$.value||i.search||void 0});c.value=n;const s=i.page||1,r=i.limit||20,y=(s-1)*r;return{rows:n.recipients.rows.map((d,C)=>({...d,index:y+C})),total:n.recipients.total,query:{...i,total:n.recipients.total,page:s,limit:r}}}async function W(i){k.value=!0;try{I.value=i,c.value=await be(i,{page:1,limit:20,status:f.value,search:$.value||void 0}),await v()}finally{k.value=!1}}function X(i){f.value=void 0,$.value="",x.value=!0,W(i.id)}function z(){x.value=!1,c.value=null,I.value=null}function J(){v()}function Y(){S()}function Z(){T||(T=setInterval(()=>{var i;S(),x.value&&I.value&&((i=c.value)==null?void 0:i.campaign.status)==="sending"&&v()},5e3))}function ee(){T&&(clearInterval(T),T=null)}return qe(()=>{Z()}),Ve(()=>{ee()}),o({reload:Y}),(i,n)=>{const s=Re,r=pe,y=Ce,d=Se,C=Te,_=Pe,q=Ae,U=Ie,re=me;return P(),A("div",null,[L.value?(P(),A("div",It,[t(s,{size:"small"}),Rt])):H("",!0),t(r,ae(w.value,{onRegister:D(b)}),{action:l(({record:B})=>[a("div",Ct,[t(D(ie),{class:"cursor-pointer"},{title:l(()=>[St]),default:l(()=>[t(le,{icon:"vuesax-linear:eye",color:"#1D4ED8",onClick:_e=>X(B)},null,8,["onClick"])]),_:2},1024)])]),_:1},16,["onRegister"]),t(re,{visible:x.value,"onUpdate:visible":n[2]||(n[2]=B=>x.value=B),title:"جزئیات کمپین پیامکی","custom-footer":"",width:"90%",onClose:z},{footer:l(()=>[t(y,{onClick:z},{default:l(()=>[m("بستن")]),_:1})]),default:l(()=>[t(s,{spinning:k.value},{default:l(()=>[c.value?(P(),A(ve,{key:0},[t(C,{bordered:"",column:2,size:"small",class:"mb-4"},{default:l(()=>[t(d,{label:"شناسه کمپین"},{default:l(()=>[m("#"+p(c.value.campaign.id),1)]),_:1}),t(d,{label:"وضعیت"},{default:l(()=>[m(p(G(c.value.campaign.status)),1)]),_:1}),t(d,{label:"تعداد گیرندگان"},{default:l(()=>[m(p(c.value.campaign.total_recipients),1)]),_:1}),t(d,{label:"موفق / ناموفق"},{default:l(()=>[a("span",Tt,p(c.value.campaign.sent_count),1),m(" / "),a("span",Pt,p(c.value.campaign.failed_count),1),c.value.campaign.status==="sending"?(P(),A("span",At," ("+p(O.value)+" در انتظار) ",1)):H("",!0)]),_:1}),t(d,{label:"نوع ارسال"},{default:l(()=>[m(p(se(c.value.campaign.send_mode)),1)]),_:1}),t(d,{label:"تاریخ ایجاد"},{default:l(()=>[m(p(Q(c.value.campaign.created_at)),1)]),_:1}),t(d,{label:"ایجادکننده",span:2},{default:l(()=>[m(p(c.value.campaign.created_by_admin_name||"-"),1)]),_:1}),t(d,{label:"متن پیام",span:2},{default:l(()=>[a("div",Dt,p(c.value.campaign.message),1)]),_:1})]),_:1}),a("div",Lt,[Ut,t(q,{value:f.value,"onUpdate:value":n[0]||(n[0]=B=>f.value=B),"allow-clear":"",placeholder:"همه",style:{width:"160px"},onChange:J},{default:l(()=>[t(_,{value:"sent"},{default:l(()=>[m("ارسال شده")]),_:1}),t(_,{value:"failed"},{default:l(()=>[m("ناموفق")]),_:1}),t(_,{value:"pending"},{default:l(()=>[m("در انتظار")]),_:1})]),_:1},8,["value"]),t(U,{value:$.value,"onUpdate:value":n[1]||(n[1]=B=>$.value=B),placeholder:"جستجو نام یا شماره",style:{width:"220px"},onSearch:J},null,8,["value"])]),t(r,ae(N.value,{onRegister:D(M)}),null,16,["onRegister"])],64)):H("",!0)]),_:1},8,["spinning"])]),_:1},8,["visible"])])}}}),Mt=[{title:"ردیف",dataIndex:"id",key:"row_index",filterable:!1,customRender:e=>e.index+1},{title:"نام",dataIndex:"name",key:"name",filterable:!1},{title:"کد",dataIndex:"code",key:"code",filterable:!1},{title:"متن پیام",dataIndex:"message",key:"message",filterable:!1,customRender:e=>{const o=e.record.message||"";return o.length>50?`${o.slice(0,50)}...`:o}},{title:"فعال",dataIndex:"is_active",key:"is_active",slot:"is_active",filterable:!1,align:"center"},{title:"ارسال‌شده",dataIndex:"sent_count",key:"sent_count",filterable:!1},{title:"ناموفق",dataIndex:"failed_count",key:"failed_count",filterable:!1},{title:"لغو/رد",dataIndex:"cancelled_count",key:"cancelled_count",filterable:!1},{title:"عملیات",dataIndex:"action",key:"action",slot:"action",filterable:!1,align:"center"}],Ot={pending:"در انتظار",sent:"ارسال شده",failed:"ناموفق",cancelled:"لغو شده",skipped:"رد شده"},Et=[{title:"ردیف",dataIndex:"id",key:"row_index",filterable:!1,customRender:e=>e.index+1},{title:"شماره",dataIndex:"phone",key:"phone",filterable:!1},{title:"وضعیت",dataIndex:"status",key:"status",filterable:!1,customRender:e=>Ot[e.record.status]||e.record.status},{title:"تاریخ برنامه‌ریزی",dataIndex:"scheduled_for",key:"scheduled_for",filterable:!1},{title:"زمان ارسال",dataIndex:"sent_at",key:"sent_at",filterable:!1,customRender:e=>e.record.sent_at?ne(e.record.sent_at):"-"},{title:"توضیح",dataIndex:"error_message",key:"error_message",filterable:!1,customRender:e=>e.record.error_message||"-"}],Nt=a("p",{class:"text-sm text-gray-500 mb-4"}," اتوماسیون‌های پیامکی کدوبلو. متن و فعال بودن را می‌توانید تغییر دهید؛ شرط ارسال در سیستم ثابت است. ",-1),qt={class:"gap-2 flex justify-center"},Vt=a("span",null,"ویرایش",-1),Ft=a("span",null,"آمار ارسال",-1),Kt=a("span",null,"ارسال تست",-1),jt={class:"space-y-4"},zt=a("div",{class:"mb-1 text-sm text-gray-600"},"نام",-1),Ht={class:"font-medium"},Jt=a("div",{class:"mb-1 text-sm text-gray-600"},"شرط ارسال",-1),Gt={class:"text-sm text-gray-700 whitespace-pre-wrap"},Qt=a("div",{class:"mb-1 text-sm text-gray-600"},"متن پیامک *",-1),Wt={class:"space-y-3"},Xt={class:"text-sm text-gray-600"},Yt={class:"text-green-600"},Zt={class:"text-red-600"},ea={class:"text-gray-500"},ta=a("span",{class:"text-xs text-gray-400 mr-2"},"(موفق / ناموفق / لغو)",-1),aa={class:"whitespace-pre-wrap text-sm"},na={class:"flex flex-wrap gap-2 items-center mb-3"},sa=a("span",{class:"text-sm text-gray-600"},"فیلتر وضعیت:",-1),la=oe({__name:"AutomationsPanel",setup(e,{expose:o}){const{TextArea:b}=de,[S,M]=te(),[v,x]=te(),k=u({columns:Mt,api:Qe,defaultPageLimit:20,height:"55vh",showOptionHeader:!1}),c=u(!1),I=u(null),f=Fe({message:"",is_active:!0}),$=u(!1),L=u(null),T=u(""),V=u(!1),R=u(!1),w=u(null),O=u(null),E=u(),N=u(""),G=u({columns:Et,api:Y,defaultPageLimit:20,height:"40vh",showOptionHeader:!1});async function se(s,r){if(s.is_active===r)return;const y=s.is_active;s.is_active=r;try{await we(s.id,{is_active:r}),g.success(r?"اتوماسیون فعال شد":"اتوماسیون غیرفعال شد")}catch{s.is_active=y,g.error("تغییر وضعیت ناموفق بود")}}function Q(s){I.value=s,f.message=s.message||"",f.is_active=s.is_active!==!1,c.value=!0}function j(){c.value=!1,I.value=null}async function W(){if(I.value){if(!f.message.trim()){g.error("متن پیامک الزامی است");return}try{await we(I.value.id,{message:f.message.trim(),is_active:f.is_active}),g.success("اتوماسیون ذخیره شد"),j(),await M()}catch{g.error("ذخیره ناموفق بود")}}}function X(s){L.value=s,T.value="",$.value=!0}function z(){$.value=!1,L.value=null,T.value=""}async function J(){if(!L.value)return;const s=T.value.trim();if(!s){g.error("شماره موبایل الزامی است");return}try{await We(L.value.id,s),g.success("پیامک تست ارسال شد"),z()}catch{g.error("ارسال تست ناموفق بود")}}async function Y(s){if(!O.value)return{rows:[],total:0,query:{...s,total:0}};const r=await ke(O.value,{page:s.page,limit:s.limit,status:E.value,search:N.value||s.search||void 0});w.value=r;const y=s.page||1,d=s.limit||20,C=(y-1)*d;return{rows:r.sends.rows.map((_,q)=>({..._,index:C+q})),total:r.sends.total,query:{...s,total:r.sends.total,page:y,limit:d}}}async function Z(s){R.value=!0;try{O.value=s,w.value=await ke(s,{page:1,limit:20,status:E.value,search:N.value||void 0}),await x()}finally{R.value=!1}}function ee(s){E.value=void 0,N.value="",V.value=!0,Z(s.id)}function i(){V.value=!1,w.value=null,O.value=null}function n(){x()}return o({reload:M}),(s,r)=>{const y=Ke,d=pe,C=me,_=je,q=Ce,U=Se,re=Te,B=Pe,_e=Ae,De=Ie,Le=Re;return P(),A("div",null,[Nt,t(d,ae(k.value,{onRegister:D(S)}),{is_active:l(({record:h})=>[t(y,{checked:h.is_active,onChange:F=>se(h,F)},null,8,["checked","onChange"])]),action:l(({record:h})=>[a("div",qt,[t(D(ie),{class:"cursor-pointer"},{title:l(()=>[Vt]),default:l(()=>[t(le,{icon:"vuesax-linear:edit",color:"#1D4ED8",onClick:F=>Q(h)},null,8,["onClick"])]),_:2},1024),t(D(ie),{class:"cursor-pointer"},{title:l(()=>[Ft]),default:l(()=>[t(le,{icon:"vuesax-linear:eye",color:"#059669",onClick:F=>ee(h)},null,8,["onClick"])]),_:2},1024),t(D(ie),{class:"cursor-pointer"},{title:l(()=>[Kt]),default:l(()=>[t(le,{icon:"vuesax-linear:sms",color:"#7C3AED",onClick:F=>X(h)},null,8,["onClick"])]),_:2},1024)])]),_:1},16,["onRegister"]),t(C,{visible:c.value,"onUpdate:visible":r[2]||(r[2]=h=>c.value=h),title:"ویرایش اتوماسیون",width:"640px",onOk:W,onCancel:j},{default:l(()=>{var h,F;return[a("div",jt,[a("div",null,[zt,a("div",Ht,p((h=I.value)==null?void 0:h.name),1)]),a("div",null,[Jt,a("div",Gt,p((F=I.value)==null?void 0:F.trigger_summary),1)]),a("div",null,[Qt,t(D(b),{value:f.message,"onUpdate:value":r[0]||(r[0]=ue=>f.message=ue),rows:5,placeholder:"متن پیامک"},null,8,["value"])]),a("div",null,[t(D(ce),{checked:f.is_active,"onUpdate:checked":r[1]||(r[1]=ue=>f.is_active=ue)},{default:l(()=>[m("فعال")]),_:1},8,["checked"])])])]}),_:1},8,["visible"]),t(C,{visible:$.value,"onUpdate:visible":r[4]||(r[4]=h=>$.value=h),title:"ارسال تست اتوماسیون",width:"480px",onOk:J,onCancel:z},{default:l(()=>{var h;return[a("div",Wt,[a("div",Xt," متن فعلی «"+p((h=L.value)==null?void 0:h.name)+"» به شماره زیر ارسال می‌شود. ",1),t(_,{value:T.value,"onUpdate:value":r[3]||(r[3]=F=>T.value=F),placeholder:"09xxxxxxxxx"},null,8,["value"])])]}),_:1},8,["visible"]),t(C,{visible:V.value,"onUpdate:visible":r[7]||(r[7]=h=>V.value=h),title:"آمار ارسال اتوماسیون","custom-footer":"",width:"90%",onClose:i},{footer:l(()=>[t(q,{onClick:i},{default:l(()=>[m("بستن")]),_:1})]),default:l(()=>[t(Le,{spinning:R.value},{default:l(()=>[w.value?(P(),A(ve,{key:0},[t(re,{bordered:"",column:2,size:"small",class:"mb-4"},{default:l(()=>[t(U,{label:"نام"},{default:l(()=>[m(p(w.value.automation.name),1)]),_:1}),t(U,{label:"کد"},{default:l(()=>[m(p(w.value.automation.code),1)]),_:1}),t(U,{label:"وضعیت"},{default:l(()=>[m(p(w.value.automation.is_active?"فعال":"غیرفعال"),1)]),_:1}),t(U,{label:"آمار کلی"},{default:l(()=>[a("span",Yt,p(w.value.automation.sent_count),1),m(" / "),a("span",Zt,p(w.value.automation.failed_count),1),m(" / "),a("span",ea,p(w.value.automation.cancelled_count),1),ta]),_:1}),t(U,{label:"شرط",span:2},{default:l(()=>[m(p(w.value.automation.trigger_summary),1)]),_:1}),t(U,{label:"متن پیام",span:2},{default:l(()=>[a("div",aa,p(w.value.automation.message),1)]),_:1})]),_:1}),a("div",na,[sa,t(_e,{value:E.value,"onUpdate:value":r[5]||(r[5]=h=>E.value=h),"allow-clear":"",placeholder:"همه",style:{width:"160px"},onChange:n},{default:l(()=>[t(B,{value:"sent"},{default:l(()=>[m("ارسال شده")]),_:1}),t(B,{value:"failed"},{default:l(()=>[m("ناموفق")]),_:1}),t(B,{value:"pending"},{default:l(()=>[m("در انتظار")]),_:1}),t(B,{value:"skipped"},{default:l(()=>[m("رد شده")]),_:1}),t(B,{value:"cancelled"},{default:l(()=>[m("لغو شده")]),_:1})]),_:1},8,["value"]),t(De,{value:N.value,"onUpdate:value":r[6]||(r[6]=h=>N.value=h),placeholder:"جستجو شماره",style:{width:"220px"},onSearch:n},null,8,["value"])]),t(d,ae(G.value,{onRegister:D(v)}),null,16,["onRegister"])],64)):H("",!0)]),_:1},8,["spinning"])]),_:1},8,["visible"])])}}}),ia=a("div",{class:"flex justify-between items-center mb-4"},[a("h2",null,"پنل پیامکی")],-1),tn=oe({__name:"index",setup(e){const o=u("send"),b=u(null),S=u(null);function M(){var v;o.value="campaigns",(v=b.value)==null||v.reload()}return(v,x)=>{const k=ze,c=He,I=Be;return P(),A("div",null,[t(I,null,{default:l(()=>[ia,t(c,{activeKey:o.value,"onUpdate:activeKey":x[0]||(x[0]=f=>o.value=f)},{default:l(()=>[t(k,{key:"send",tab:"ارسال پیامک"},{default:l(()=>[t(xt,{onCampaignStarted:M})]),_:1}),t(k,{key:"campaigns",tab:"کمپین‌های ارسالی"},{default:l(()=>[t(Bt,{ref_key:"campaignsPanelRef",ref:b},null,512)]),_:1}),t(k,{key:"automations",tab:"اتوماسیون‌ها"},{default:l(()=>[t(la,{ref_key:"automationsPanelRef",ref:S},null,512)]),_:1})]),_:1},8,["activeKey"])]),_:1})])}}});export{tn as default};