// SYSTEM PANEL //
[ROOT]
/
home
/
csender
/
legus.lawnet.me_backup_20250830-212545
/
assets
[ PARENT ]
EDIT :: ClientsManagement-Dhv4ZC-2.js
import{d as ge,r as n,c as h,g as fe,a as xe,o as be,b as i,e as f,f as e,T as ye,S as he,n as G,h as _e,i as k,t as c,u as p,j as A,w as j,v as N,k as we,l as Ce,F as z,m as J,A as I,p as ke,q as Ae,s as K,x as Me,y as De,z as d,_ as Ve}from"./index-BhhcJpm2.js";import{C as Ee}from"./ClientFormModal-CrBZzoXV.js";const Fe={class:"min-h-screen bg-[#F4F4F6]",dir:"rtl"},He={class:"flex pt-16"},Te={class:"px-6 py-4"},Le={class:"flex items-center justify-between mb-4"},je={class:"text-2xl font-bold text-[#1a1a1a]"},Se={key:0,class:"flex justify-center items-center p-8"},Be={key:1,class:"p-8 text-center"},$e={class:"text-red-500 mb-4"},Ne={class:"text-sm text-gray-600 mt-1"},ze={key:2,class:"p-6"},Ie={class:"bg-white rounded-lg shadow-sm border p-6 mb-4"},Pe={class:"flex items-center justify-between w-full",dir:"rtl"},Ue={class:"flex items-center gap-4"},Ze={class:"flex-1 flex justify-center"},Oe={class:"relative"},Re={class:"flex items-center gap-4"},qe={class:"flex items-center gap-2"},Qe={class:"bg-white rounded-lg shadow-sm border flex-1"},Ge={class:"overflow-x-auto"},Je={class:"w-full border-collapse border border-gray-200"},Ke={class:"px-4 py-3 text-sm text-[#54524F] border-r border-gray-200"},We={class:"px-4 py-3 border-r border-gray-200"},Xe={class:"flex items-center gap-2"},Ye={class:"text-sm text-[#DA7E13] font-medium"},et=["onClick"],tt={class:"px-4 py-3 border-r border-gray-200"},st={class:"flex items-center gap-2"},ot={class:"text-sm text-[#54524F]"},rt=["onClick"],lt={class:"px-4 py-3 text-sm text-[#54524F] border-r border-gray-200"},at={class:"px-4 py-3 text-sm text-[#54524F] border-r border-gray-200"},nt={class:"px-4 py-3 text-sm text-[#54524F] border-r border-gray-200"},it={class:"px-4 py-3 text-sm text-[#54524F] border-r border-gray-200"},dt={class:"px-4 py-3 border-r border-gray-200"},ut={class:"flex items-center gap-1 justify-end",dir:"rtl"},ct=["onClick"],vt=["onClick"],pt={key:0,class:"bg-white rounded-lg shadow-sm border p-12 text-center"},mt={key:1,class:"bg-white rounded-lg shadow-sm border p-4 mt-4"},gt={class:"flex items-center justify-center gap-2"},ft=["disabled"],xt={class:"flex items-center gap-1"},bt=["onClick"],yt={key:1,class:"px-2 text-gray-500"},ht=["disabled"],_t=ge({__name:"ClientsManagement",setup(wt){const W=(s,t)=>{let r;return(...o)=>{clearTimeout(r),r=setTimeout(()=>s.apply(null,o),t)}},_=n(!1),w=n(!1),M=n(""),D=n(!1),V=n(null),X=h(()=>fe()),Y=h(()=>xe()),E=n([]),m=n(""),x=n({client_type:"",status:""}),a=n(1),g=n(15),P=n(0),F=n(!1),b=n({show:!1,clientToDelete:null}),H=n({show:!1,message:""}),T=n({show:!1,message:""}),ee=h(()=>{let s=E.value;return m.value&&(s=s.filter(t=>{const r=y(t),o=B(t);return r.toLowerCase().includes(m.value.toLowerCase())||o.toLowerCase().includes(m.value.toLowerCase())||t.email.toLowerCase().includes(m.value.toLowerCase())||t.id.toString().includes(m.value)})),s}),U=h(()=>{const s=(a.value-1)*g.value,t=s+g.value;return ee.value.slice(s,t)}),L=h(()=>Math.ceil(P.value/g.value)),te=h(()=>{const s=L.value,t=a.value,r=[];if(s<=7)for(let o=1;o<=s;o++)r.push(o);else t<=4?r.push(1,2,3,4,5,"...",s):t>=s-3?r.push(1,"...",s-4,s-3,s-2,s-1,s):r.push(1,"...",t-1,t,t+1,"...",s);return r}),Z=()=>{_.value=!_.value},v=async()=>{w.value=!0,M.value="";try{const s=X.value,t={page:a.value,per_page:g.value,search:m.value||void 0,client_type:x.value.client_type||void 0,status:x.value.status||void 0};ke()||Ae()?s&&"officeId"in s&&(t.office_id=s.officeId):A()&&s&&"id"in s&&(t.client_id=s.id),Object.keys(t).forEach(o=>t[o]===void 0&&delete t[o]),console.log("Loading clients with filters:",t);const r=await K.getClients(t);if(r.success&&r.data)E.value=r.data,P.value=r.data.length,console.log(`Loaded ${r.data.length} clients for user role: ${Y.value}`);else throw new Error(r.message||"فشل في تحميل العملاء")}catch(s){M.value=s.message||"حدث خطأ في تحميل العملاء",console.error("Failed to load clients:",s)}finally{w.value=!1}},O=W(()=>{a.value=1,v()},500),S=()=>{a.value=1,v()},se=()=>{D.value=!1,V.value=null,F.value=!0},R=()=>{F.value=!1,D.value=!1,V.value=null},oe=s=>{D.value=!0,V.value=s,F.value=!0},re=s=>{b.value={show:!0,clientToDelete:s}},q=()=>{b.value={show:!1,clientToDelete:null}},le=()=>{H.value={show:!1,message:""}},ae=()=>{T.value={show:!1,message:""}},ne=async()=>{var t,r,o,C;if(!b.value.clientToDelete)return;const s=b.value.clientToDelete;q(),w.value=!0;try{console.log(`Attempting to delete client with ID: ${s.id}`);const l=await K.deleteClient(s.id);if(console.log("Delete response:",l),l.success){E.value=E.value.filter(me=>me.id!==s.id);const u=y(s),$=l.message||`تم حذف العميل "${u}" من النظام بنجاح. سيتم تحديث قائمة العملاء تلقائياً.`;H.value={show:!0,message:$},await v()}else{const u=l.message||"لم يتم حذف العميل. يرجى المحاولة مرة أخرى.";throw new Error(u)}}catch(l){console.error("Failed to delete client:",l);let u="";const $=y(s);((t=l.response)==null?void 0:t.status)===404?u="العميل غير موجود في النظام أو تم حذفه مسبقاً.":((r=l.response)==null?void 0:r.status)===403?u="ليس لديك صلاحية لحذف هذا العميل.":((o=l.response)==null?void 0:o.status)===400?u="لا يمكن حذف هذا العميل. قد يكون مرتبطاً ببيانات أخرى في النظام.":((C=l.response)==null?void 0:C.status)>=500?u="خطأ في الخادم. يرجى المحاولة لاحقاً أو الاتصال بالدعم الفني.":l.message?u=l.message:u=`حدث خطأ غير متوقع أثناء حذف العميل "${$}". يرجى المحاولة مرة أخرى.`,T.value={show:!0,message:u},await v()}finally{w.value=!1}},ie=()=>{R(),v()},de=s=>{console.error("Client operation error:",s)},y=s=>s?s.client_type==="individual"?s.name_ar||s.name_en||"غير محدد":s.client_type==="company"?s.trade_name_ar||"غير محدد":s.name_ar||s.name_en||s.trade_name_ar||"غير محدد":"غير محدد",B=s=>s?s.client_type==="individual"?s.name_en||"":s.client_type==="company"?s.trade_name_ar||"":s.name_en||"":"",ue=s=>s?s.city&&typeof s.city=="object"&&s.city.name_ar?s.city.name_ar:s.city_name_ar&&typeof s.city_name_ar=="string"?s.city_name_ar:"غير محدد":"غير محدد",Q=async s=>{try{await navigator.clipboard.writeText(s)}catch(t){console.error("Failed to copy text: ",t)}},ce=()=>{a.value>1&&(a.value--,v())},ve=()=>{a.value<L.value&&(a.value++,v())},pe=s=>{typeof s=="number"&&s!==a.value&&(a.value=s,v())};return be(()=>{v()}),(s,t)=>{const r=De("router-link");return d(),i("div",Fe,[f(ye,{sidebarCollapsed:_.value,onToggleSidebar:Z},null,8,["sidebarCollapsed"]),e("div",He,[f(he,{isCollapsed:_.value,onToggle:Z},null,8,["isCollapsed"]),e("div",{class:G(["flex-1 min-h-full transition-all duration-300",_.value?"mr-16":"mr-64"])},[e("div",Te,[e("div",Le,[e("h1",je,c(p(A)()?"عملائي":"إدارة العملاء"),1),p(A)()?k("",!0):(d(),i("button",{key:0,onClick:se,class:"flex items-center gap-3 px-6 py-3 bg-[#DA7E13] text-white rounded-lg hover:bg-[#DA7E13]/90 transition-colors text-base font-medium"},t[5]||(t[5]=[e("svg",{class:"w-4 h-4 fill-current",viewBox:"0 0 24 24"},[e("path",{d:"M19,13H13V19H11V13H5V11H11V5H13V11H19V13Z"})],-1),e("span",null,"إضافة عميل",-1)])))]),t[6]||(t[6]=_e('<nav class="flex items-center text-sm text-gray-600" dir="rtl" data-v-f5cc74de><span class="text-[#DA7E13]" data-v-f5cc74de>الرئيسية</span><span class="mx-2" data-v-f5cc74de>/</span><span class="text-[#DA7E13]" data-v-f5cc74de>إدارة العملاء</span><span class="mx-2" data-v-f5cc74de>/</span><span class="text-gray-400" data-v-f5cc74de>العملاء</span></nav>',1))]),w.value?(d(),i("div",Se,t[7]||(t[7]=[e("div",{class:"text-center"},[e("div",{class:"animate-spin rounded-full h-12 w-12 border-b-2 border-[#DA7E13] mx-auto"}),e("p",{class:"mt-2 text-gray-600"},"جاري تحميل العملاء...")],-1)]))):M.value?(d(),i("div",Be,[e("div",$e,[t[8]||(t[8]=e("svg",{class:"w-12 h-12 mx-auto mb-2",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})],-1)),t[9]||(t[9]=e("p",{class:"text-lg font-medium"},"خطأ في تحميل العملاء",-1)),e("p",Ne,c(M.value),1)]),e("button",{onClick:v,class:"px-4 py-2 bg-[#DA7E13] text-white rounded hover:bg-[#DA7E13]/90"}," إعادة المحاولة ")])):(d(),i("div",ze,[e("div",Ie,[e("div",Pe,[e("div",Ue,[t[12]||(t[12]=e("h2",{class:"text-lg font-semibold text-[#54524F] whitespace-nowrap"},"ملفات العملاء",-1)),j(e("select",{"onUpdate:modelValue":t[0]||(t[0]=o=>x.value.client_type=o),onChange:S,class:"px-4 py-2 border border-gray-300 rounded text-sm focus:ring-2 focus:ring-[#DA7E13] focus:border-[#DA7E13] bg-white min-w-[140px]"},t[10]||(t[10]=[e("option",{value:""},"جميع الأنواع",-1),e("option",{value:"individual"},"أفراد",-1),e("option",{value:"company"},"شركات",-1)]),544),[[N,x.value.client_type]]),j(e("select",{"onUpdate:modelValue":t[1]||(t[1]=o=>x.value.status=o),onChange:S,class:"px-4 py-2 border border-gray-300 rounded text-sm focus:ring-2 focus:ring-[#DA7E13] focus:border-[#DA7E13] bg-white min-w-[140px]"},t[11]||(t[11]=[e("option",{value:""},"جميع الحالات",-1),e("option",{value:"active"},"نشط",-1),e("option",{value:"inactive"},"غير نشط",-1)]),544),[[N,x.value.status]])]),e("div",Ze,[e("div",Oe,[j(e("input",{"onUpdate:modelValue":t[2]||(t[2]=o=>m.value=o),onInput:t[3]||(t[3]=(...o)=>p(O)&&p(O)(...o)),type:"text",placeholder:"بحث...",class:"w-80 px-4 py-2 pr-10 border border-gray-300 rounded text-right text-sm focus:ring-2 focus:ring-[#DA7E13] focus:border-[#DA7E13] bg-white"},null,544),[[we,m.value]]),t[13]||(t[13]=e("svg",{class:"absolute right-3 top-1/2 transform -translate-y-1/2 w-4 h-4 text-gray-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})],-1))])]),e("div",Re,[e("div",qe,[t[15]||(t[15]=e("span",{class:"text-sm text-[#54524F]"},"عرض",-1)),j(e("select",{"onUpdate:modelValue":t[4]||(t[4]=o=>g.value=o),onChange:S,class:"px-3 py-2 border border-gray-300 rounded text-sm focus:ring-2 focus:ring-[#DA7E13] focus:border-[#DA7E13] bg-white"},t[14]||(t[14]=[e("option",{value:"15"},"15",-1),e("option",{value:"10"},"10",-1),e("option",{value:"25"},"25",-1),e("option",{value:"50"},"50",-1)]),544),[[N,g.value]])]),t[16]||(t[16]=e("button",{class:"flex items-center gap-2 px-4 py-2 bg-transparent text-[#54524F] text-sm font-medium rounded-lg border border-gray-300 hover:bg-gray-50 transition-colors"},[e("svg",{class:"w-4 h-4 fill-[#DA7E13]",viewBox:"0 0 24 24"},[e("path",{d:"M5,20H19V18H5M19,9H15V3H9V9H5L12,16L19,9Z"})]),Ce(" تصدير ")],-1))])])]),e("div",Qe,[e("div",Ge,[e("table",Je,[t[22]||(t[22]=e("thead",{class:"bg-[#F8F9FA]"},[e("tr",{class:"text-right border-b border-gray-200"},[e("th",{class:"px-4 py-3 text-sm font-medium text-[#54524F] border-r border-gray-200"},"#"),e("th",{class:"px-4 py-3 text-sm font-medium text-[#54524F] border-r border-gray-200"},[e("div",{class:"flex items-center justify-start gap-1",dir:"rtl"},[e("span",null,"الاسم عربي"),e("svg",{class:"w-3 h-3 text-gray-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M8 9l4-4 4 4m0 6l-4 4-4-4"})])])]),e("th",{class:"px-4 py-3 text-sm font-medium text-[#54524F] border-r border-gray-200"},"الاسم انجليزي"),e("th",{class:"px-4 py-3 text-sm font-medium text-[#54524F] border-r border-gray-200"},"البريد الإلكتروني"),e("th",{class:"px-4 py-3 text-sm font-medium text-[#54524F] border-r border-gray-200"},"نوع العميل"),e("th",{class:"px-4 py-3 text-sm font-medium text-[#54524F] border-r border-gray-200"},"الهاتف"),e("th",{class:"px-4 py-3 text-sm font-medium text-[#54524F] border-r border-gray-200"},"المدينة"),e("th",{class:"px-4 py-3 text-sm font-medium text-[#54524F] border-r border-gray-200"},"خيارات")])],-1)),e("tbody",null,[(d(!0),i(z,null,J(U.value,(o,C)=>(d(),i("tr",{key:o.id,class:"hover:bg-gray-50 border-b border-gray-200 last:border-b"},[e("td",Ke,c(String((a.value-1)*g.value+C+1).padStart(2,"0")),1),e("td",We,[e("div",Xe,[e("span",Ye,c(y(o)),1),e("button",{class:"text-gray-400 hover:text-[#DA7E13] focus:outline-none focus:ring-0 active:outline-none",onClick:l=>Q(y(o))},t[17]||(t[17]=[e("svg",{class:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})],-1)]),8,et)])]),e("td",tt,[e("div",st,[e("span",ot,c(B(o)),1),e("button",{class:"text-gray-400 hover:text-[#DA7E13] focus:outline-none focus:ring-0 active:outline-none",onClick:l=>Q(B(o))},t[18]||(t[18]=[e("svg",{class:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})],-1)]),8,rt)])]),e("td",lt,c(o.email),1),e("td",at,c(o.client_type==="individual"?"فرد":"شركة"),1),e("td",nt,c(o.phone),1),e("td",it,c(ue(o)),1),e("td",dt,[e("div",ut,[f(r,{to:`/clients/${o.id}`,class:"p-1 text-[#DA7E13] hover:bg-orange-50 rounded",title:"عرض"},{default:Me(()=>t[19]||(t[19]=[e("svg",{class:"w-4 h-4",fill:"currentColor",viewBox:"0 0 24 24"},[e("path",{d:"M12,9A3,3 0 0,0 9,12A3,3 0 0,0 12,15A3,3 0 0,0 15,12A3,3 0 0,0 12,9M12,17A5,5 0 0,1 7,12A5,5 0 0,1 12,7A5,5 0 0,1 17,12A5,5 0 0,1 12,17M12,4.5C7,4.5 2.73,7.61 1,12C2.73,16.39 7,19.5 12,19.5C17,19.5 21.27,16.39 23,12C21.27,7.61 17,4.5 12,4.5Z"})],-1)])),_:2,__:[19]},1032,["to"]),p(A)()?k("",!0):(d(),i("button",{key:0,onClick:l=>oe(o.id),class:"p-1 text-blue-600 hover:bg-blue-50 rounded",title:"تعديل"},t[20]||(t[20]=[e("svg",{class:"w-4 h-4",fill:"currentColor",viewBox:"0 0 24 24"},[e("path",{d:"M20.71,7.04C21.1,6.65 21.1,6 20.71,5.63L18.37,3.29C18,2.9 17.35,2.9 16.96,3.29L15.12,5.12L18.87,8.87M3,17.25V21H6.75L17.81,9.93L14.06,6.18L3,17.25Z"})],-1)]),8,ct)),p(A)()?k("",!0):(d(),i("button",{key:1,onClick:l=>re(o),class:"p-1 text-red-600 hover:bg-red-50 rounded",title:"حذف"},t[21]||(t[21]=[e("svg",{class:"w-4 h-4",fill:"currentColor",viewBox:"0 0 24 24"},[e("path",{d:"M19,4H15.5L14.5,3H9.5L8.5,4H5V6H19M6,19A2,2 0 0,0 8,21H16A2,2 0 0,0 18,19V7H6V19Z"})],-1)]),8,vt))])])]))),128))])])])]),U.value.length===0?(d(),i("div",pt,t[23]||(t[23]=[e("svg",{class:"w-16 h-16 mx-auto mb-4 text-gray-300",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0zm6 3a2 2 0 11-4 0 2 2 0 014 0zM7 10a2 2 0 11-4 0 2 2 0 014 0z"})],-1),e("h3",{class:"text-lg font-medium text-gray-900 mb-2"},"لا توجد عملاء",-1),e("p",{class:"text-gray-600 mb-4"},"لا توجد عملاء مطابقين لمعايير البحث الخاصة بك",-1)]))):k("",!0),L.value>1?(d(),i("div",mt,[e("div",gt,[e("button",{onClick:ce,disabled:a.value===1,class:"px-3 py-1 border border-gray-300 rounded text-sm disabled:opacity-50 disabled:cursor-not-allowed hover:bg-gray-50"}," السابق ",8,ft),e("div",xt,[(d(!0),i(z,null,J(te.value,o=>(d(),i(z,{key:o},[typeof o=="number"?(d(),i("button",{key:0,onClick:C=>pe(o),class:G(["px-3 py-1 rounded text-sm",o===a.value?"bg-[#DA7E13] text-white":"border border-gray-300 hover:bg-gray-50"])},c(o),11,bt)):(d(),i("span",yt,c(o),1))],64))),128))]),e("button",{onClick:ve,disabled:a.value===L.value,class:"px-3 py-1 border border-gray-300 rounded text-sm disabled:opacity-50 disabled:cursor-not-allowed hover:bg-gray-50"}," التالي ",8,ht)])])):k("",!0)]))],2)]),f(Ee,{isVisible:F.value,clientId:V.value,mode:D.value?"edit":"add",onClose:R,onSuccess:ie,onError:de},null,8,["isVisible","clientId","mode"]),f(p(I),{isVisible:b.value.show,type:"warning",title:"تأكيد حذف العميل",message:`هل أنت متأكد من حذف العميل '${y(b.value.clientToDelete)}'؟ لا يمكن التراجع عن هذا الإجراء وسيتم حذف جميع البيانات المرتبطة بهذا العميل نهائياً.`,confirmText:"حذف",showCancel:!0,onClose:q,onConfirm:ne},null,8,["isVisible","message"]),f(p(I),{isVisible:H.value.show,type:"success",title:"تم حذف العميل بنجاح",message:H.value.message,confirmText:"حسناً",onClose:le},null,8,["isVisible","message"]),f(p(I),{isVisible:T.value.show,type:"error",title:"فشل في حذف العميل",message:T.value.message,confirmText:"حسناً",onClose:ae},null,8,["isVisible","message"])])}}}),At=Ve(_t,[["__scopeId","data-v-f5cc74de"]]);export{At as default};
SAVE
CANCEL