PageSourceSearch

https://shuryan-healthcare.netlify.app/assets/PrescriptionsPage-oly3Nmsd.js

js shuryan-healthcare.netlify.app collected 2026-10-03 11:24:42 UTC 62,209 bytes, 41 lines download raw bytes

1import{aa as J,ab as W,bo as E,r as d,j as e,a9 as H,a6 as $,x as O,aA as X,ag as D,bK as Z,_ as ee,aL as T,av as se,bz as Y,bL as te,bI as z,bn as L,bM as ae,au as le,aQ as re,q as B,n as ne,bN as V,bs as ie,bt as ce,aN as _,bO as oe,aK as de,aJ as q,X as G,T as K,D as xe,aM as me,A as he,N as be,bE as fe}from"./index-aQkVUlMC.js";import{P as ue}from"./PrescriptionDetailsModal-BlWbcUDm.js";import{p as pe}from"./payment.service-DSYw8qoj.js";import{f as je}from"./helpers-BjPMjhCy.js";import"./index-D-SuB-5T.js";import"./doctor.service-xNdIyfxJ.js";const ge=J(W(h=>({nearbyPharmacies:[],loading:!1,error:null,fetchNearbyPharmacies:async()=>{console.log("🏪 [PharmacyStore] Fetching nearby pharmacies..."),h({loading:!0,error:null});try{const n=await E.getNearbyPharmacies();console.log("✅ [PharmacyStore] Nearby pharmacies fetched:",n),console.log("✅ [PharmacyStore] Type check - is array:",Array.isArray(n));const s=Array.isArray(n)?n:[];return h({nearbyPharmacies:s,loading:!1,error:null}),{success:!0,data:s}}catch(n){console.error("❌ [PharmacyStore] Error fetching pharmacies:",n);const s=n.response?.data?.message||"فشل في جلب الصيدليات القريبة";return h({nearbyPharmacies:[],loading:!1,error:s}),{success:!1,error:s}}},clearPharmacies:()=>{console.log("🧹 [PharmacyStore] Clearing pharmacies data"),h({nearbyPharmacies:[],loading:!1,error:null})},sendPrescriptionToPharmacy:async(n,s)=>{console.log(`📤 [PharmacyStore] Sending prescription ${n} to pharmacy ${s}...`);try{const i=await E.sendPrescriptionToPharmacy(n,s);return console.log("✅ [PharmacyStore] Prescription sent successfully:",i),{success:!0,data:i}}catch(i){return console.error("❌ [PharmacyStore] Error sending prescription:",i),{success:!1,error:i.response?.data?.message||"فشل في إرسال الروشتة"}}},clearError:()=>{h({error:null})}}),{name:"pharmacy-store",partialize:h=>({nearbyPharmacies:h.nearbyPharmacies})})),Q=({autoFetch:h=!1}={})=>{const{nearbyPharmacies:n,loading:s,error:i,fetchNearbyPharmacies:o,sendPrescriptionToPharmacy:l,clearPharmacies:x,clearError:j}=ge();d.useEffect(()=>{h&&(console.log("🔄 [usePharmacy] Auto-fetching nearby pharmacies..."),o())},[h,o]),d.useEffect(()=>()=>{},[]);const g=n&&n.length>0;return{nearbyPharmacies:n,loading:s,error:i,hasPharmacies:g,isEmpty:!s&&!g,fetchNearbyPharmacies:o,sendPrescriptionToPharmacy:l,clearPharmacies:x,clearError:j}},Ne=({pharmacies:h=[],loading:n,onClose:s,onSelectPharmacy:i,prescription:o})=>{const[l,x]=d.useState(new Set),[j,g]=d.useState(null),[v,y]=d.useState(!1),{sendPrescriptionToPharmacy:F}=Q(),c=Array.isArray(h)?h:[],P=async a=>{if(!o?.id)return console.error("❌ No prescription ID provided"),{success:!1,pharmacyName:a.name,error:"لا يوجد معرف للروشتة"};g(a.id),console.log("📤 Sending prescription to pharmacy:",a.name,"Prescription ID:",o.id);try{const p=await F(o.id,a.id);if(!p.success){const b=p.error||"فشل في إرسال الروشتة";return console.error("❌ API returned error:",b),{success:!1,pharmacyName:a.name,error:b}}return x(b=>new Set([...b,a.id])),console.log("✅ Prescription sent successfully to:",a.name),{success:!0,pharmacyName:a.name}}catch(p){console.error("❌ Unexpected error sending prescription:",p);const b=p?.message||"حدث خطأ غير متوقع";return{success:!1,pharmacyName:a.name,error:b}}finally{g(null)}},M=async()=>{if(!o?.id){console.error("❌ No prescription ID provided"),alert("خطأ: لا يوجد معرف للروشتة");return}y(!0),console.log("📤 Sending prescription to all pharmacies");const a=[];
1for(const N of c)if(!l.has(N.id)){g(N.id);const C=await P(N);a.push(C),await new Promise(R=>setTimeout(R,300))}y(!1),g(null);const p=a.filter(N=>N.success).length,b=a.filter(N=>!N.success).length,A=a.filter(N=>!N.success);if(b===0&&p>0)alert(`✅ تم إرسال الروشتة بنجاح إلى جميع الصيدليات (${p})`);else if(p===0&&b>0){const N=A.map(C=>`- ${C.pharmacyName}: ${C.error}`).join(`
2`);alert(`❌ فشل إرسال الروشتة لجميع الصيدليات:
3
4${N}`)}else if(p>0&&b>0){const N=A.map(C=>`- ${C.pharmacyName}: ${C.error}`).join(`
5`);alert(`⚠️ نتائج متفاوتة:
6
7✅ تم الإرسال بنجاح: ${p}
8❌ فشل الإرسال: ${b}
9
10تفاصيل الأخطاء:
11${N}`)}else alert("لا توجد صيدليات للإرسال إليها")},k=a=>{console.log("📋 Viewing report from pharmacy:",a.name),i&&i(a)};return n?e.jsx("div",{className:"p-8",children:e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"inline-block w-16 h-16 border-4 border-teal-500 border-t-transparent rounded-full animate-spin mb-4"}),e.jsx("p",{className:"text-slate-600 font-semibold text-lg",children:"جاري البحث عن أقرب الصيدليات..."})]})})}):e.jsxs("div",{className:"p-8 space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-2xl font-black text-slate-800",children:"أقرب الصيدليات"}),e.jsx("p",{className:"text-slate-600 font-semibold mt-1",children:"اختر الصيدلية المناسبة لك"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[c.length>0&&l.size<c.length&&e.jsx("button",{onClick:M,disabled:v||j!==null,className:"px-5 py-2.5 bg-gradient-to-r from-teal-500 to-emerald-600 hover:from-teal-600 hover:to-emerald-700 text-white font-bold rounded-xl transition-all shadow-md hover:shadow-lg disabled:opacity-50 disabled:cursor-not-allowed flex items-center gap-2",children:v?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-4 h-4 border-2 border-white border-t-transparent rounded-full animate-spin"}),e.jsx("span",{children:"جاري الإرسال..."})]}):e.jsxs(e.Fragment,{children:[e.jsx(H,{className:"text-sm"}),e.jsxs("span",{children:["إرسال للجميع (",c.length-l.size,")"]})]})}),e.jsx("button",{onClick:s,className:"w-10 h-10 bg-slate-100 hover:bg-slate-200 rounded-full flex items-center justify-center transition-all",children:e.jsx($,{className:"text-slate-600"})})]})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:c.map((a,p)=>e.jsxs("div",{className:"bg-white border-2 border-slate-200 rounded-2xl p-5 hover:border-teal-400 hover:shadow-lg transition-all duration-200 cursor-pointer group",onClick:()=>i&&i(a),children:[e.jsxs("div",{className:"flex items-start justify-between mb-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-8 h-8 bg-gradient-to-br from-teal-500 to-emerald-600 rounded-lg flex items-center justify-center",children:e.jsxs("span",{className:"text-white font-black text-sm",children:["#",p+1]})}),l.has(a.id)&&e.jsxs("div",{className:"flex items-center gap-1 bg-green-100 px-2 py-1 rounded-lg",children:[e.jsx(O,{className:"text-green-600 text-xs"}),e.jsx("span",{className:"text-green-700 font-bold text-xs",children:"تم الإرسال"})]})]}),a.rating&&e.jsxs("div",{className:"flex items-center gap-1 bg-amber-50 px-2 py-1 rounded-lg",children:[e.jsx(X,{className:"text-amber-500 text-xs"}),e.jsx("span",{className:"text-amber-700 font-bold text-xs",children:a.rating})]})]}),e.jsx("div",{className:"flex justify-center mb-4",children:e.jsx("div",{className:"w-20 h-20 rounded-full overflow-hidden border-4 border-teal-100 group-hover:border-teal-300 transition-all",children:e.jsx("img",{src:a.profileImageUrl,alt:a.name,className:"w-full h-full object-cover",onError:b=>{b.target.src="https://via.placeholder.com/150/00b19f/ffffff?text=صيدلية"}})})}),e.jsx("h4",{className:"text-lg font-black text-slate-800 text-center mb-3 group-hover:text-teal-600 transition-colors",children:a.name}),e.jsxs("div",{className:"flex items-center justify-center gap-2 mb-3 bg-slate-50 rounded-lg py-2 px-3",children:[e.jsx(D,{className:"text-teal-600 text-sm"}),e.jsxs("span",{className:"text-slate-700 font-bold text-sm",children:[a.distanceInKm||a.distanceKm," كم"]})]}),e.jsx("div",{className:"mt-3 pt-3 border-t border-slate-200",children:a.offersDelivery||a.hasDelivery?e.jsxs("div",{className:"flex items-center justify-between bg-teal-50 rounded-lg py-2 px-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Z,{className:"text-teal-600 text-sm"}),e.jsx("span",{className:"text-teal-700 font-bold text-xs",children:"توصيل متاح"})]}),e.jsx("span",{className:"text-teal-700 font-black text-sm",children:a.deliveryFee===0?"مجاناً":`${a.deliveryFee} ج.م`})]}):e.jsxs("div",{className:"flex items-center justify-center gap-2 bg-slate-100 rounded-lg py-2 px-3",children:[e.jsx($,{className:"text-slate-500 text-xs"}),e.jsx("span",{className:"text-slate-600 font-bold text-xs",children:"لا يوجد توصيل"})]})}),a.phoneNumber&&e.jsx("div",{className:"mt-3 opacity-0 group-hover:opacity-100 transition-opacity",children:e.jsxs("div",{className:"flex items-center justify-center gap-2 text-slate-600",children:[e.jsx(ee,{className:"text-xs"}),e.jsx("span",{className:"text-xs font-semibold",children:a.phoneNumber})]})}),l.has(a.id)?e.jsxs("button",{onClick:b=>{b.stopPropagation(),k(a)},className:"w-full mt-4 px-4 py-2.5 bg-gradient-to-r from-blue-500 to-blue-600 hover:from-blue-600 hover:to-blue-700 text-white font-bold rounded-xl transition-all shadow-md hover:shadow-lg flex items-center justify-center gap-2",children:[e.jsx(T,{className:"text-sm"}),"عرض التقرير"]}):e.jsx("button",{onClick:b=>{b.stopPropagation(),P(a)},disabled:j===a.id,className:"w-full mt-4 px-4 py-2.5 bg-gradient-to-r from-teal-500 to-emerald-600 hover:from-teal-600 hover:to-emerald-700 text-white font-bold rounded-xl transition-all shadow-md hover:shadow-lg disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center gap-2",children:j===a.id?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-4 h-4 border-2 border-white border-t-transparent roun
11ded-full animate-spin"}),e.jsx("span",{children:"جاري الإرسال..."})]}):e.jsxs(e.Fragment,{children:[e.jsx(H,{className:"text-sm"}),"إرسال الروشتة"]})})]},a.id))}),c.length===0&&!n&&e.jsxs("div",{className:"text-center py-12",children:[e.jsx("div",{className:"w-24 h-24 bg-slate-100 rounded-2xl flex items-center justify-center mx-auto mb-4",children:e.jsx(D,{className:"text-4xl text-slate-400"})}),e.jsx("h3",{className:"text-xl font-bold text-slate-700 mb-2",children:"لا توجد صيدليات قريبة"}),e.jsx("p",{className:"text-slate-500",children:"لم نتمكن من العثور على صيدليات في منطقتك"})]})]})},ve={available:{label:"متوفر",color:"green",bgColor:"bg-green-50",borderColor:"border-green-200",textColor:"text-green-700",iconColor:"text-green-600"},unavailable:{label:"غير متوفر",color:"red",bgColor:"bg-red-50",borderColor:"border-red-200",textColor:"text-red-700",iconColor:"text-red-600"},has_alternative:{label:"بديل متوفر",color:"amber",bgColor:"bg-amber-50",borderColor:"border-amber-200",textColor:"text-amber-700",iconColor:"text-amber-600"}},ye=({isOpen:h,onClose:n,pharmacy:s,report:i})=>{if(!h)return null;const o=i&&i.status!=="pending";return e.jsxs("div",{className:"fixed inset-0 bg-black/60 backdrop-blur-sm flex items-center justify-center z-50 p-4 animate-fadeIn",children:[e.jsxs("div",{className:"bg-white rounded-3xl shadow-2xl max-w-3xl w-full overflow-hidden animate-slideUp max-h-[90vh] overflow-y-auto",children:[e.jsxs("div",{className:"relative bg-gradient-to-br from-blue-500 via-blue-600 to-indigo-600 p-8",children:[e.jsx("button",{onClick:n,className:"absolute top-4 left-4 w-10 h-10 bg-white/20 hover:bg-white/30 rounded-full flex items-center justify-center transition-all duration-200 hover:rotate-90",children:e.jsx($,{className:"text-white text-lg"})}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"w-16 h-16 rounded-full overflow-hidden border-4 border-white/30 flex-shrink-0",children:e.jsx("img",{src:s?.profileImageUrl,alt:s?.name,className:"w-full h-full object-cover",onError:l=>{l.target.src="https://via.placeholder.com/150/00b19f/ffffff?text=صيدلية"}})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-3xl font-black text-white mb-1",children:"تقرير الصيدلية"}),e.jsx("p",{className:"text-sm text-white/80 font-semibold",children:s?.name})]})]})]}),e.jsxs("div",{className:"p-8",children:[o?e.jsxs("div",{className:"space-y-6",children:[i.summary&&e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsxs("div",{className:"bg-green-50 rounded-xl p-4 border-2 border-green-200 text-center",children:[e.jsx("div",{className:"text-2xl font-black text-green-700",children:i.summary.availableItems}),e.jsx("div",{className:"text-xs font-semibold text-green-600 mt-1",children:"متوفر"})]}),e.jsxs("div",{className:"bg-amber-50 rounded-xl p-4 border-2 border-amber-200 text-center",children:[e.jsx("div",{className:"text-2xl font-black text-amber-700",children:i.summary.alternativeItems}),e.jsx("div",{className:"text-xs font-semibold text-amber-600 mt-1",children:"بديل متوفر"})]}),e.jsxs("div",{className:"bg-red-50 rounded-xl p-4 border-2 border-red-200 text-center",children:[e.jsx("div",{className:"text-2xl font-black text-red-700",children:i.summary.unavailableItems}),e.jsx("div",{className:"text-xs font-semibold text-red-600 mt-1",children:"غير متوفر"})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("h4",{className:"text-lg font-black text-slate-800 flex items-center gap-2",children:[e.jsx(Y,{className:"text-teal-600"}),"تفاصيل الأدوية"]}),i.medications&&i.medications.map(l=>{const x=ve[l.availability];return e.jsx("div",{className:`${x.bgColor} border-2 ${x.borderColor} rounded-xl p-4`,children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("h5",{className:"font-black text-slate-800",children:l.name}),e.jsx("span",{className:`px-2 py-1 ${x.bgColor} ${x.textColor} text-xs font-bold rounded-lg border ${x.borderColor}`,children:x.label})]}),l.availability==="has_alternative"&&e.jsxs("div",{className:"flex items-start gap-2 mt-2 bg-white/50 rounded-lg p-2",children:[e.jsx(te,{className:"text-amber-600 text-sm mt-1 flex-shrink-0"}),e.jsxs("div",{className:"text-xs",children:[e.jsxs("p",{className:"font-semibold text-slate-700",children:[e.jsx("span",{className:"text-amber-700 font-black",children:"البديل:"})," ",l.alternativeName]}),l.alternativeReason&&e.jsx("p",{className:"text-slate-600 mt-1",children:l.alternativeReason})]})]}),l.availability==="unavailable"&&l.reason&&e.jsxs("p",{className:"text-xs text-red-600 font-semibold mt-1",children:[e.jsx(z,{className:"inline mr-1"}),l.reason]})]}),e.jsx("div",{className:"text-left flex-shrink-0",children:l.unitPrice!==null?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"text-xs text-slate-600 font-semibold mb-1",children:[l.unit," × ",l.quantity]}),e.jsxs("div",{className:"text-sm font-bold text-slate-700",children:[l.unitPrice.toFixed(2)," ج.م / ",l.unit]}),e.jsxs("div",{className:"text-lg font-black text-teal-700 mt-1",children:[l.totalPrice.toFixed(2)," ج.م"]})]}):e.jsx("div",{className:"text-sm font-bold text-red-600",children:"-"})})]})},l.id)})]}),i.notes&&e.jsxs("div",{className:"bg-blue-50 rounded-xl p-4 border-2 border-blue-200",children:[e.jsx("h5",{className:"font-black text-blue-800 text-sm mb-2",children:"ملاحظات الصيدلية:"}),e.jsx("p",{className:"text-blue-700 text-sm font-semibold",children:i.notes})]}),i.summary&&e.jsxs("div",{className:"bg-gradient-to-br from-teal-50 to-emerald-50 rounded-2xl p-6 border-2 border-teal-200",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx(L,{className:"text-teal-600 text-xl"}),e.jsx("h4",{className:"text-lg font-black text-slate-800",children:"ملخص التكلفة"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"text-slate-700 font-semibold",children:"إجمالي الأدوية:"}),e.jsxs("span",{className:"text-slate-800 font-bold",children:[i.summary.subtotal.toFixed(2)," ج.م"]})]}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"text-slate-700 font-semibold",children:"رسوم التوصيل:"}),e.jsxs("span",{className:"text-slate-800 font-bold",children:[i.summary.deliveryFee.toFixed(2)," ج.م"]})]}),e.jsx("div",{className:"h-px bg-teal-300 my-2"}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"text-teal-800 font-black text-lg",children:"الإجمالي:"}),e.jsxs("span",{className:"text-teal-700 font-black text-2xl",children:[i.summary.total.toFixed(2)," ج.م"]})]})]}),e.jsx("button",{className:"w-full mt-4 px-6 py-3 bg-gradient-to-r from-teal-500 to-emerald-600 hover:from-teal-600 hover:to-emerald-700 text-white font-black rounded-xl transition-all shadow-md hover:shadow-lg",children:"تأكيد الطلب"})]})]}):e.jsxs("div",{className:"text-center py-12",children:[e.jsx("div",{className:"w-24 h-24 bg-amber-100 rounded-2xl flex items-center justify-center mx-auto mb-6",children:e.jsx(se,{className:"text-5xl text-amber-500 animate-pulse"})}),e.jsx("h3",{className:"text-2xl font-black text-slate-800 mb-3",children:"في انتظار الرد"}),e.jsx("p",{className:"text-slate-600 font-semibold text-lg mb-6",children:"لم ترد الصيدلية حتى الآن"}),e.jsx("p",{className:"text-slate-500 text-sm",children:"سيتم إشعارك فور استلام رد الصيدلية على الروشتة"}),e.jsx("div",{className:"mt-8 bg-blue-50 rounded-2xl p-6 border-2 border-blue-200",children:e.jsx("p",{className:"text-blue-700 font-semibold text-sm",children:"💡 عادةً ما تستغرق الصيدليات من 15-30 دقيقة للرد على الطلبات"})})]}),e.jsx("div",{className:"mt-8 pt-6 border-t border-slate-200",children:e.jsx("button",{onClick:n,className:"w-full px-6 py-4 bg-slate-100 hover:bg-slate-200 text-slate-700 font-bold rounded-xl transition-all",children:"إغلاق"})})]})]}),e.jsx("style",{jsx:!0,children:`
12        @keyframes fadeIn {
13          from { opacity: 0; }
14          to { opacity: 1; }
15        }
16        @keyframes slideUp {
17          from { transform: translateY(20px); opacity: 0; }
18          to { transform: translateY(0); opacity: 1; }
19        }
20        .animate-fadeIn {
21          animation: fadeIn 0.2s ease-out;
22        }
23        .animate-slideUp {
24          animation: slideUp 0.3s ease-out;
25        }
26      `})]})},we=({isOpen:h,onClose:n,prescription:s})=>{const[i,o]=d.useState(!1),[l,x]=d.useState(null),[j,g]=d.useState(!1),[v,y]=d.use
26State(null),[F,c]=d.useState(!1),[P,M]=d.useState([]),{nearbyPharmacies:k,loading:a,fetchNearbyPharmacies:p,clearError:b}=Q(),A=async()=>{try{const r=["order-1","order-2"],t=[];for(const w of r)try{const u=await E.getPharmacyResponse(w);u&&t.push({orderId:u.orderId,pharmacyId:u.orderId,pharmacyName:u.pharmacyName,pharmacyAddress:"",pharmacyPhone:u.pharmacyPhone,rating:4.5,hasReport:!0,reportStatus:"completed",totalAmount:u.totalAmount,deliveryAvailable:u.deliveryAvailable,deliveryFee:u.deliveryFee,responseTime:u.respondedAt,apiResponse:u})}catch{console.log(`No response found for order ${w}`)}return t}catch(r){return console.error("Error checking existing reports:",r),[]}},N=async()=>{console.log("🔍 Searching for nearby pharmacies for prescription:",s?.id);const r=await A();if(r.length>0){M(r),c(!0);return}b(),(await p()).success?o(!0):alert("حدث خطأ أثناء البحث عن الصيدليات. يرجى المحاولة مرة أخرى.")},C=async r=>{console.log("✅ Opening report for pharmacy:",r),x(r);const t={pharmacyName:r.name,medications:s?.medications||[],totalAmount:0,deliveryAvailable:!0,deliveryFee:10};y(t),g(!0)},R=()=>{o(!1),P.length>0&&c(!0)},f=()=>{g(!1),y(null),x(null)},m=async r=>{console.log("📋 Viewing report for pharmacy:",r.pharmacyName);try{if(r.apiResponse)y(r.apiResponse),x(r),g(!0);else{const t=await E.getPharmacyResponse(r.orderId);t?(y(t),x(r),g(!0)):alert("لا يمكن جلب تفاصيل التقرير في الوقت الحالي")}}catch(t){console.error("Error fetching pharmacy report:",t),alert("حدث خطأ أثناء جلب تفاصيل التقرير")}},I=()=>{c(!1),o(!1),M([]),x(null),y(null),g(!1)};return h?e.jsxs("div",{className:"fixed inset-0 bg-black/60 backdrop-blur-sm flex items-center justify-center z-50 p-4 animate-fadeIn",children:[e.jsxs("div",{className:"bg-white rounded-3xl shadow-2xl max-w-6xl w-full overflow-hidden animate-slideUp max-h-[90vh] overflow-y-auto",children:[e.jsxs("div",{className:"relative bg-gradient-to-br from-teal-500 via-teal-600 to-emerald-600 p-8",children:[e.jsx("button",{onClick:n,className:"absolute top-4 left-4 w-10 h-10 bg-white/20 hover:bg-white/30 rounded-full flex items-center justify-center transition-all duration-200 hover:rotate-90",children:e.jsx($,{className:"text-white text-lg"})}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"w-16 h-16 bg-white/20 backdrop-blur-sm rounded-2xl flex items-center justify-center flex-shrink-0",children:e.jsx(Y,{className:"text-4xl text-white"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-3xl font-black text-white mb-1",children:"طلب روشتة"}),e.jsxs("p",{className:"text-sm text-white/80 font-semibold",children:["رقم الروشتة: ",s?.prescriptionNumber||"N/A"]})]})]})]}),F?e.jsxs("div",{className:"p-8 space-y-6",children:[e.jsxs("div",{className:"text-center mb-6",children:[e.jsx("h3",{className:"text-2xl font-black text-slate-800 mb-2",children:"التقارير الواردة"}),e.jsxs("p",{className:"text-slate-600 font-semibold",children:["تم استلام ",P.length," تقرير من الصيدليات"]})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:P.map(r=>e.jsxs("div",{className:"bg-white border-2 border-slate-200 rounded-2xl p-6 hover:border-teal-300 hover:shadow-lg transition-all duration-200",children:[e.jsxs("div",{className:"flex items-start gap-3 mb-4",children:[e.jsx("div",{className:"w-12 h-12 bg-gradient-to-br from-teal-500 to-emerald-600 rounded-xl flex items-center justify-center flex-shrink-0",children:e.jsx(ae,{className:"text-white text-xl"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h4",{className:"font-black text-slate-800 text-lg mb-1",children:r.pharmacyName}),e.jsx("p",{className:"text-slate-500 text-sm",children:r.pharmacyAddress}),e.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[e.jsx("div",{className:"flex items-center gap-1",children:[...Array(5)].map((t,w)=>e.jsx(O,{className:`text-xs ${w<Math.floor(r.rating)?"text-amber-400":"text-slate-300"}`},w))}),e.jsx("span",{className:"text-xs text-slate-600 font-semibold",children:r.rating})]})]})]}),e.jsxs("div",{className:"space-y-3 mb-4",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"text-slate-600 font-semibold",children:"إجمالي المبلغ:"}),e.jsxs("span",{className:"font-black text-teal-600",children:[r.totalAmount," جÙ
26†ÙŠÙ‡"]})]}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"text-slate-600 font-semibold",children:"التوصيل:"}),e.jsx("span",{className:`font-semibold ${r.deliveryAvailable?"text-green-600":"text-red-600"}`,children:r.deliveryAvailable?`متاح (${r.deliveryFee} جنيه)`:"غير متاح"})]}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"text-slate-600 font-semibold",children:"وقت الرد:"}),e.jsx("span",{className:"text-slate-500 text-sm",children:new Date(r.responseTime).toLocaleTimeString("ar-EG",{hour:"2-digit",minute:"2-digit"})})]})]}),e.jsxs("button",{onClick:()=>m(r),className:"w-full px-4 py-3 bg-gradient-to-r from-teal-500 to-emerald-600 hover:from-teal-600 hover:to-emerald-700 text-white font-bold rounded-xl transition-all shadow-sm hover:shadow-md flex items-center justify-center gap-2",children:[e.jsx(T,{className:"text-sm"}),e.jsx("span",{children:"عرض التقرير"})]})]},r.pharmacyId))}),e.jsxs("div",{className:"flex items-center gap-3 pt-4",children:[e.jsxs("button",{onClick:I,className:"flex-1 px-6 py-4 bg-gradient-to-r from-emerald-500 to-teal-600 hover:from-emerald-600 hover:to-teal-700 text-white font-black rounded-xl transition-all shadow-lg hover:shadow-xl flex items-center justify-center gap-3",children:[e.jsx(le,{className:"text-xl"}),e.jsx("span",{children:"طلب جديد"})]}),e.jsx("button",{onClick:n,className:"px-6 py-4 bg-white hover:bg-slate-100 text-slate-700 font-bold rounded-xl border-2 border-slate-200 transition-all",children:"إغلاق"})]})]}):i?e.jsx(Ne,{pharmacies:k,loading:a,onClose:R,onSelectPharmacy:C,prescription:s}):e.jsxs("div",{className:"p-8 space-y-6",children:[e.jsx("div",{className:"bg-gradient-to-br from-teal-50 to-emerald-50 rounded-2xl p-6 border-2 border-teal-200",children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"w-12 h-12 bg-gradient-to-br from-teal-500 to-emerald-600 rounded-xl flex items-center justify-center flex-shrink-0",children:e.jsx(D,{className:"text-white text-xl"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h3",{className:"text-lg font-black text-slate-800 mb-2",children:"كيف يعمل النظام؟"}),e.jsxs("p",{className:"text-slate-600 leading-relaxed font-semibold",children:["سيقوم النظام بالبحث عن ",e.jsx("span",{className:"text-teal-600 font-black",children:"أقرب 3 صيدليات"})," من موقعك الحالي وإرسال الروشتة لهم للتأكد من توفر جميع الأدوية. ستتلقى ردودهم مع الأسعار والبدائل المتاحة لتختار الأنسب لك."]})]})]})}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-8 h-8 bg-teal-100 rounded-lg flex items-center justify-center flex-shrink-0",children:e.jsx(O,{className:"text-teal-600"})}),e.jsx("p",{className:"text-slate-700 font-semibold",children:"مقارنة الأسعار بين الصيدليات"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-8 h-8 bg-teal-100 rounded-lg flex items-center justify-center flex-shrink-0",children:e.jsx(O,{className:"text-teal-600"})}),e.jsx("p",{className:"text-slate-700 font-semibold",children:"معرفة البدائل المتاحة للأدوية"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-8 h-8 bg-teal-100 rounded-lg flex items-center justify-center flex-shrink-0",children:e.jsx(O,{className:"text-teal-600"})}),e.jsx("p",{className:"text-slate-700 font-semibold",children:"توصيل سريع لباب المنزل"})]})]}),e.jsxs("div",{className:"flex items-center gap-3 pt-4",children:[e.jsx("button",{onClick:N,disabled:a,className:"flex-1 px-6 py-4 bg-gradient-to-r from-teal-500 to-emerald-600 hover:from-teal-600 hover:to-emerald-700 text-white font-black rounded-xl transition-all shadow-lg hover:shadow-xl disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center gap-3",children:a?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-5 h-5 border-3 border-white border-t-transparent roun
26ded-full animate-spin"}),e.jsx("span",{children:"جاري البحث..."})]}):e.jsxs(e.Fragment,{children:[e.jsx(re,{className:"text-xl"}),e.jsx("span",{children:"ابحث الآن"})]})}),e.jsx("button",{onClick:n,className:"px-6 py-4 bg-white hover:bg-slate-100 text-slate-700 font-bold rounded-xl border-2 border-slate-200 transition-all",children:"إلغاء"})]})]})]}),e.jsx("style",{jsx:!0,children:`
27        @keyframes fadeIn {
28          from { opacity: 0; }
29          to { opacity: 1; }
30        }
31        @keyframes slideUp {
32          from { transform: translateY(20px); opacity: 0; }
33          to { transform: translateY(0); opacity: 1; }
34        }
35        .animate-fadeIn {
36          animation: fadeIn 0.2s ease-out;
37        }
38        .animate-slideUp {
39          animation: slideUp 0.3s ease-out;
40        }
41      `}),e.jsx(ye,{isOpen:j,onClose:f,pharmacy:l,report:v})]}):null},Pe=({isOpen:h,onClose:n,orderData:s,onPaymentConfirm:i})=>{const[o,l]=d.useState(""),[x,j]=d.useState(!1),[g,v]=d.useState(null),y=[{id:"card",name:"بطاقة ائتمان",icon:e.jsx(ie,{className:"text-3xl"}),description:"Visa • Mastercard • Amex",bgGradient:"from-blue-50 to-indigo-50",borderColor:"border-blue-300",iconBg:"bg-blue-500"},{id:"vodafone",name:"فودافون كاش",icon:e.jsx(ce,{className:"text-3xl"}),description:"ادفع من محفظتك الإلكترونية",bgGradient:"from-red-50 to-orange-50",borderColor:"border-red-300",iconBg:"bg-red-500"},{id:"cash",name:"كاش عند الاستلام",icon:e.jsx(L,{className:"text-3xl"}),description:"ادفع نقداً عند استلام الطلب",bgGradient:"from-green-50 to-emerald-50",borderColor:"border-green-300",iconBg:"bg-green-500"}],F=async()=>{if(!o){v("يرجى اختيار طريقة الدفع");return}j(!0),v(null);try{const c=s?.orderId;if(!c){v("لا يمكن تأكيد الطلب: رقم الطلب غير موجود"),j(!1);return}if(o==="cash"){console.log("💵 Cash on delivery selected for order:",c);const p=await E.confirmPharmacyOrder(c,{method:"cash",orderData:s});console.log("✅ Order confirmed for cash:",p),i({method:"cash",status:"confirmed"});return}const P=1,M=o==="vodafone"?1:0;console.log("💳 Initiating Paymob payment for pharmacy order:",c);const k=await pe.initiatePharmacyOrderPayment(c,P,M);console.log("💳 API Response:",JSON.stringify(k,null,2));const a=k?.data;if(a?.paymentUrl){console.log("🔗 Redirecting to Paymob:",a.paymentUrl),window.location.href=a.paymentUrl;return}console.error("❌ No paymentUrl in response:",k),v(k?.message||a?.message||"لم نتمكن من توليد رابط الدفع. يرجى المحاولة مرة أخرى."),j(!1)}catch(c){console.error("❌ Payment failed:",c);const P=c?.response?.data?.message;v(P||"حدث خطأ في عملية الدفع. يرجى المحاولة مرة أخرى."),j(!1)}};return h?e.jsx("div",{className:"fixed inset-0 bg-black/60 backdrop-blur-sm flex items-center justify-center z-50 p-4",dir:"rtl",children:e.jsxs("div",{className:"bg-white rounded-2xl shadow-2xl w-full max-w-2xl max-h-[90vh] overflow-hidden",children:[e.jsx("div",{className:"bg-gradient-to-r from-teal-500 to-emerald-600 p-6 relative",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-black text-white mb-2",children:"اختر طريقة الدفع"}),e.jsxs("p",{className:"text-teal-100 font-medium",children:["إجمالي المبلغ: ",s?.totalAmount||0," ج.م",s?.deliveryFee&&` + ${s.deliveryFee} ج.م رسوم توصيل`]})]}),e.jsx("button",{onClick:n,className:"w-10 h-10 bg-white/20 hover:bg-white/30 rounded-xl flex items-center justify-center transition-colors",children:e.jsx($,{className:"w-5 h-5 text-white"})})]})}),e.jsxs("div",{className:"p-6 max-h-[calc(90vh-200px)] overflow-y-auto",children:[g&&e.jsxs("div",{className:"mb-4 p-4 bg-red-50 border border-red-200 rounded-xl flex items-start gap-3",children:[e.jsx(B,{className:"text-red-500 mt-1 flex-shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-bold text-red-800 mb
41-1",children:"حدث خطأ"}),e.jsx("p",{className:"text-xs text-red-700",children:g})]})]}),e.jsxs("div",{className:"space-y-4 mb-6",children:[e.jsx("h3",{className:"text-lg font-bold text-slate-800 mb-4",children:"طرق الدفع المتاحة"}),y.map(c=>e.jsx("div",{onClick:()=>{l(c.id),v(null)},className:`p-4 rounded-xl border-2 cursor-pointer transition-all ${o===c.id?`${c.borderColor} bg-gradient-to-r ${c.bgGradient}`:"border-slate-200 hover:border-slate-300"}`,children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:`w-12 h-12 ${c.iconBg} rounded-xl flex items-center justify-center text-white`,children:c.icon}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h4",{className:"font-bold text-slate-800",children:c.name}),e.jsx("p",{className:"text-sm text-slate-600",children:c.description})]}),e.jsx("div",{className:`w-6 h-6 rounded-full border-2 ${o===c.id?"bg-teal-500 border-teal-500":"border-slate-300"}`,children:o===c.id&&e.jsx("div",{className:"w-full h-full rounded-full bg-white scale-50"})})]})},c.id))]}),(o==="card"||o==="vodafone")&&e.jsxs("div",{className:"bg-blue-50 border border-blue-200 rounded-xl p-5 mb-6 text-center",children:[e.jsx("div",{className:"bg-blue-100 w-14 h-14 mx-auto flex items-center justify-center rounded-full mb-3",children:e.jsx(ne,{className:"text-2xl text-blue-600"})}),e.jsx("h4",{className:"font-bold text-slate-800 mb-2",children:"الدفع الآمن باستخدام Paymob"}),e.jsx("p",{className:"text-sm text-slate-600",children:"سيتم توجيهك إلى بوابة الدفع الآمنة لإتمام العملية. جميع المعاملات مشفرة وآمنة 100%."})]}),o==="cash"&&e.jsx("div",{className:"bg-green-50 rounded-xl p-5 mb-6",children:e.jsxs("div",{className:"flex items-center gap-3 text-green-700",children:[e.jsx(L,{className:"text-2xl"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold",children:"سيتم الدفع نقداً عند استلام الطلب"}),e.jsx("p",{className:"text-sm",children:"تأكد من توفر المبلغ المطلوب عند التسليم"})]})]})})]}),e.jsxs("div",{className:"bg-slate-50 px-6 py-4 flex items-center justify-between",children:[e.jsx("button",{onClick:n,className:"px-6 py-3 bg-slate-500 text-white rounded-xl hover:bg-slate-600 transition-colors font-bold",children:"إلغاء"}),e.jsx("button",{onClick:F,disabled:!o||x,className:`px-8 py-3 rounded-xl font-bold flex items-center gap-2 transition-all ${!o||x?"bg-slate-300 text-slate-500 cursor-not-allowed":"bg-gradient-to-r from-teal-500 to-emerald-600 text-white hover:from-teal-600 hover:to-emerald-700"}`,children:x?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"w-5 h-5 border-2 border-white border-t-transparent rounded-full animate-spin"}),"جاري التحويل..."]}):e.jsxs(e.Fragment,{children:[e.jsx(V,{className:"w-5 h-5"}),o==="cash"?"تأكيد الطلب":"تأكيد والذهاب للدفع"]})})]})]})}):null},ke=({isOpen:h,onClose:n,prescription:s,onNewOrder:i})=>{const[o,l]=d.useState([]),[x,j]=d.useState(null),[g,v]=d.useState(!1),[y,F]=d.useState(null),[c,P]=d.useState(null),[M,k]=d.useState(!1),[a,p]=d.useState(!1),[b,A]=d.useState(null);d.useEffect(()=>{const f=async()=>{v(!0),F(null);try{console.log("📋 Fetching pharmacy reports for prescription:",s.id),console.log("📋 Full prescription object:",s);const m=await E.getPharmacyReports(s.id);if(console.log("✅ Raw API response:",m),console.log("✅ Response structure check:",{hasData:!!m,hasPrescriptionId:!!m?.prescriptionId,hasPharmacyResponses:!!m?.pharmacyResponses,pharmacyResponsesLength:m?.pharmacyResponses?.length||0,responseKeys:m?Object.keys(m):[]}),m&&m.prescriptionId){console.log("✅ Valid prescription pharmacy response found"),console.log("🔍 Raw pharmacyResponses:",m.pharmacyResponses),m.pharmacyResponses&&m.pharmacyResponses.length>0&&(console.log("🔍 First pharmacy response structure:",m.pharmacyResponses[0]),console.log("🔍 Available medications in first response:",m.pharmacyResponses[0]?.availableMedications),console.log("🔍 Alternative medications in first response:",m.pharmacyResponses[0]?.alternativeMedications));const I=m.pharmacyResponses?.map((r,t)=>{console.log(`🔍 Processing pharmacy response ${t+1}:`,r),console.log("🔍 Medications array:",r.medications);let w=[],u=[],U=[];return r.medications&&Array.isArray(r.medications)&&r.medications.forEach(S=>{console.log("🔍 Processing medication:",S),S.isAvailable&&S.availableQuantity>0?w.push({medicationName:S.medicationName,quantity:S.availableQuantity,unitPrice:S.unitPrice,isAvailable:!0}):!S.isAvailable&&S.alternativeOne?u.push({medicationName:S.alternativeOne.medicationName,unitPrice:S.alternativeOne.unitPrice,originalMedication:S.medicationName,quantity:1}):!S.isAvailable&&!S.alternativeOne&&U.push({medicationName:S.medicationName,isAvailable:!1})}
41),console.log(`🔍 Final medication counts for pharmacy ${t+1}:`,{available:w.length,alternative:u.length,unavailable:U.length}),{orderId:r.orderId,pharmacyId:r.pharmacyId,pharmacyName:r.pharmacyName,pharmacyPhone:r.pharmacyPhone,pharmacyAddress:r.pharmacyAddress,totalAmount:r.totalAmount,deliveryFee:r.deliveryFee,availableMedications:w,alternativeMedications:u,unavailableMedications:U,pharmacyNotes:r.pharmacyNotes,sentAt:r.sentAt,respondedAt:r.respondedAt,status:r.status||"responded"}})||[];console.log("📋 Converted reports array:",I),console.log("📋 First report medications check:",{available:I[0]?.availableMedications?.length||0,alternative:I[0]?.alternativeMedications?.length||0,unavailable:I[0]?.unavailableMedications?.length||0}),l(I),j({prescriptionId:m.prescriptionId,prescriptionNumber:m.prescriptionNumber,totalPharmacyResponses:m.totalPharmacyResponses})}else console.log("⚠️ No valid pharmacy response data found"),F("لا توجد تقارير متاحة لهذه الروشتة")}catch(m){console.error("❌ Error fetching pharmacy reports:",m),F("حدث خطأ في تحميل تقارير الصيدليات")}finally{v(!1)}};h&&s?.id&&f()},[h,s?.id]);const N=f=>{console.log("📋 Viewing detailed report for pharmacy:",f.pharmacyName),P(f),k(!0)},C=f=>{console.log("🛒 Opening payment modal for pharmacy:",f.pharmacyName),A(f),p(!0)},R=async f=>{try{console.log("💳 Payment confirmed:",f),p(!1),A(null),alert(`تم تأكيد الطلب من ${b.pharmacyName} بنجاح! سيتم التواصل معك قريباً.`),n()}catch(m){console.error("❌ Order confirmation failed:",m),alert("حدث خطأ في تأكيد الطلب. يرجى المحاولة مرة أخرى.")}};return h?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 bg-black/60 backdrop-blur-sm flex items-center justify-center z-50 p-4",dir:"rtl",children:e.jsxs("div",{className:"bg-white rounded-2xl shadow-2xl w-full max-w-4xl max-h-[90vh] overflow-hidden",children:[e.jsx("div",{className:"bg-gradient-to-r from-teal-500 to-emerald-600 p-6 text-white",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"w-12 h-12 bg-white/20 rounded-xl flex items-center justify-center",children:e.jsx(T,{className:"w-6 h-6"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-black",children:"تقارير الصيدليات"}),e.jsxs("p",{className:"text-teal-100 font-medium",children:["روشتة رقم: ",x?.prescriptionNumber||s?.prescriptionNumber||"غير محدد"]})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("button",{onClick:()=>{n(),i?i(s):window.location.href="/patient/prescriptions"},className:"px-4 py-2 bg-white/20 hover:bg-white/30 rounded-xl flex items-center gap-2 transition-colors font-bold text-sm",children:[e.jsx(V,{className:"w-4 h-4"}),e.jsx("span",{children:"طلب جديد"})]}),e.jsx("button",{onClick:n,className:"w-10 h-10 bg-white/20 hover:bg-white/30 rounded-xl flex items-center justify-center transition-colors",children:e.jsx($,{className:"w-5 h-5"})})]})]})}),e.jsx("div",{className:"p-6 max-h-[calc(90vh-200px)] overflow-y-auto",children:g?e.jsx("div",{className:"flex items-center justify-center py-20",children:e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"w-16 h-16 border-4 border-teal-200 border-t-teal-600 rounded-full animate-spin mx-auto mb-4"}),e.jsx("p",{className:"text-slate-600 font-medium",children:"جاري تحميل التقارير..."})]})}):y?e.jsxs("div",{className:"text-center py-20",children:[e.jsx("div",{className:"w-24 h-24 bg-red-100 rounded-full flex items-center justify-center mx-auto mb-4",children:e.jsx(B,{className:"text-red-500 text-4xl"})}),e.jsx("h3",{className:"text-xl font-bold text-slate-800 mb-2",children:"حدث خطأ"}),e.jsx("p",{className:"text-slate-600 font-medium mb-4",children:y}),e.jsx("button",{onClick:()=>window.location.reload(),className:"px-6 py-2.5 bg-gradient-to-r from-teal-500 to-emerald-600 text-white rounded-xl hover:from-teal-600 hover:to-emerald-700 transition-all font-bold text-sm shadow-lg",children:"إعادة المحاولة"})]}):o.length===0?e.jsxs("div",{className:"text-center py-20",children:[e.jsx("div",{className:"w-24 h-24 bg-slate-100 rounded-full flex items-center justify-center mx-auto mb-4",children:e.jsx(T,{className:"text-slate-400 text-4xl"})}),e.jsx("h3",{className:"text-xl font-bold text-slate-800 mb-2",children:"لا توجد تقارير"}),e.jsx("p",{className:"text-slate-600 font-medium",children:"لم ترد أي صيدلية على هذه الروشتة بعد"})]}):e.jsx("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:o.map((f,m)=>e.jsxs("div",{className:"bg-white rounded-2xl border-2 border-slate-200 hover:border-teal-400 transition-all shadow-sm hover:shadow-lg p-6",children:[e.jsx("div",{className:"flex items-center justify-between mb-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-12 h-12 bg-gradient-to-br from-emerald-500 to-teal-600 rounded-xl flex items-center justify-center text-white font-black text-lg",children:m+1}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-black text-slate-800",children:f.pharmacyName}),e.jsxs("div",{className:"flex items-center gap-2 text-sm text-slate-600",children:[e.jsx(D,{className:"text-teal-500"}),e.jsx("span",{children:f.pharmacyAddress})]})]})]})}),e.jsx("div",{className:"bg-gradient-to-r from-slate-50 to-slate-100/50 rounded-xl p-4 mb-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold text-slate-600",children:"إجمالي السعر"}),e.jsxs("p",{className:"text-2xl font-black text-slate-800",children:[f.totalAmount," ج.م"]})]}),f.deliveryFee>0&&e.jsxs("div",{className:"text-left",children:[e.jsx("p",{className:"text-sm font-semibold text-slate-600",children:"رسوم التوصيل"}),e.jsxs("p",{className:"text-lg font-bold text-emerald-600",children:[f.deliveryFee," ج.م"]})]})]})}),e.jsxs("div",{className:"space-y-2 mb-4",children:[e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsx("span",{className:"text-slate-600",children:"الأدوية المتوفرة:"}),e.jsx("span",{className:"font-bold text-green-600",children:f.availableMedications?.length||0})]}),e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsx("span",{className:"text-slate-600",children:"البدائل المقترحة:"}),e.jsx("span",{className:"font-bold text-blue-600",children:f.alternativeMedications?.length||0})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("button",{onClick:()=>N(f),className:"flex-1 px-4 py-2.5 bg-gradient-to-r from-slate-500 to-slate-600 text-white rounded-xl hover:from-slate-600 hover:to-slate-700 transition-all font-bold text-sm shadow-md hover:shadow-lg flex items-center justify-center gap-2",children:[e.jsx(_,{className:"w-4 h-4"}),"عرض التفاصيل"]}),e.jsxs("button",{onClick:()=>C(f),className:"flex-1 px-4 py-2.5 bg-gradient-to-r from-teal-500 to-emerald-600 text-white rounded-xl hover:from-teal-600 hover:to-emerald-700 transition-all font-bold text-sm shadow-md hover:shadow-lg flex items-center justify-center gap-2",children:[e.jsx(V,{className:"w-4 h-4"}),"اطلب الآن"]})]})]},f.orderId||m))})})]})}),M&&c&&e.jsx(Ce,{isOpen:M,onClose:()=>k(!1),report:c,onOrderNow:()=>{k(!1),C(c)}}),e.jsx(Pe,{isOpen:a,onClose:()=>p(!1),orderData:b,onPaymentConfirm:R})]}):null},Ce=({isOpen:h,onClose:n,report:s,onOrderNow:i})=>{if(!h||!s)return null;const o=l=>new Date(l).toLocaleDateString("ar-EG",{day:"numeric",month:"long",year:"numeric",hour:"2-digit",minute:"2-digit"});return e.jsx("div",{className:"fixed inset-0 bg-black/60 backdrop-blur-sm flex items-center justify-center z-50 p-4",dir:"rtl",children:e.jsxs("div",{className:"bg-white rounded-2xl shadow-2xl w-full max-w-4xl max-h-[90vh] overflow-hidden",children:[e.jsx("div",{className:"bg-gradient-to-r from-emerald-500 to-teal-600 p-6 text-white",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"w-12 h-12 bg-white/20 rounded-xl flex items-center justify-center",children:e.jsx(T,{className:"w-6 h-6"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-black",children:s.pharmacyName}),e.jsx("p",{className:"text-emerald-100 font-medium",children:"تفاصيل العرض والأدوية"})]})]}),e.jsx("button",{onClick:n,className:"w-10 h-10 bg-white/20 hover:bg-white/30 rounded-xl flex items-center justify-center transition-colors",children:e.jsx($,{className:"w-5 h-5"})})]})}
41),e.jsxs("div",{className:"p-6 max-h-[calc(90vh-200px)] overflow-y-auto",children:[e.jsxs("div",{className:"bg-slate-50 rounded-xl p-4 mb-6",children:[e.jsx("h3",{className:"text-lg font-black text-slate-800 mb-3",children:"معلومات الصيدلية"}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(D,{className:"text-teal-500"}),e.jsx("span",{className:"text-sm font-semibold text-slate-700",children:s.pharmacyAddress})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(oe,{className:"text-teal-500"}),e.jsx("span",{className:"text-sm font-semibold text-slate-700",children:s.pharmacyPhone})]})]})]}),e.jsxs("div",{className:"bg-gradient-to-r from-emerald-50 to-teal-50 rounded-xl p-4 mb-6",children:[e.jsx("h3",{className:"text-lg font-black text-slate-800 mb-3",children:"تفاصيل السعر"}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold text-slate-600",children:"إجمالي الأدوية"}),e.jsxs("p",{className:"text-2xl font-black text-slate-800",children:[s.totalAmount," ج.م"]})]}),s.deliveryFee>0&&e.jsxs("div",{className:"text-left",children:[e.jsx("p",{className:"text-sm font-semibold text-slate-600",children:"رسوم التوصيل"}),e.jsxs("p",{className:"text-xl font-bold text-emerald-600",children:[s.deliveryFee," ج.م"]})]}),e.jsxs("div",{className:"text-left",children:[e.jsx("p",{className:"text-sm font-semibold text-slate-600",children:"المجموع الكلي"}),e.jsxs("p",{className:"text-2xl font-black text-emerald-600",children:[s.totalAmount+(s.deliveryFee||0)," ج.م"]})]})]})]}),s.availableMedications&&s.availableMedications.length>0&&e.jsxs("div",{className:"mb-6",children:[e.jsxs("h3",{className:"text-lg font-black text-slate-800 mb-4 flex items-center gap-2",children:[e.jsx(O,{className:"text-green-500"}),"الأدوية المتوفرة (",s.availableMedications.length,")"]}),e.jsx("div",{className:"space-y-3",children:s.availableMedications.map((l,x)=>e.jsx("div",{className:"bg-green-50 rounded-xl p-4 border border-green-200",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"font-bold text-slate-800",children:l.medicationName}),e.jsx("p",{className:"text-sm text-green-600 font-semibold",children:"متوفر"})]}),e.jsxs("div",{className:"text-left",children:[e.jsxs("p",{className:"text-lg font-black text-green-600",children:[l.unitPrice," ج.م"]}),e.jsxs("p",{className:"text-sm text-slate-600",children:["الكمية: ",l.quantity]})]})]})},x))})]}),s.alternativeMedications&&s.alternativeMedications.length>0&&e.jsxs("div",{className:"mb-6",children:[e.jsxs("h3",{className:"text-lg font-black text-slate-800 mb-4 flex items-center gap-2",children:[e.jsx(B,{className:"text-amber-500"}),"البدائل المقترحة (",s.alternativeMedications.length,")"]}),e.jsx("div",{className:"space-y-3",children:s.alternativeMedications.map((l,x)=>e.jsxs("div",{className:"bg-amber-50 rounded-xl p-4 border-2 border-amber-300",children:[e.jsx("div",{className:"mb-3 pb-3 border-b border-amber-200",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(z,{className:"text-red-500 text-sm"}),e.jsx("span",{className:"text-sm text-slate-600 font-semibold",children:"غير متوفر:"}),e.jsx("span",{className:"text-sm text-slate-800 font-bold",children:l.originalMedication})]})}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(O,{className:"text-amber-500 text-sm"}),e.jsx("span",{className:"text-xs text-amber-700 font-semibold",children:"البديل المقترح:"})]}),e.jsx("h4",{className:"font-black text-slate-800 text-lg",children:l.medicationName})]}),e.jsxs("div",{className:"text-left",children:[e.jsxs("p",{className:"text-lg font-black text-amber-600",children:[l.unitPrice," ج.م"]}),e.jsxs("p",{className:"text-sm text-slate-600",children:["الكمية: ",l.quantity]})]})]})]},x))})]}),s.unavailableMedications&&s.unavailableMedications.length>0&&e.jsxs("div",{className:"mb-6",children:[e.jsxs("h3",{className:"text-lg font-black text-slate-800 mb-4 flex items-center gap-2",children:[e.jsx(z,{className:"text-red-500"}),"الأدوية غير المتوفرة (",s.unavailableMedications.length,")"]}),e.jsx("div",{className:"space-y-3",children:s.unavailableMedications.map((l,x)=>e.jsx("div",{className:"bg-red-50 rounded-xl p-4 border border-red-200",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"font-bold text-slate-800",children:l.medicationName}),e.jsx("p",{className:"text-sm text-red-600 font-semibold",children:"غير متوفر ولا يوجد بديل"})]}),e.jsx("div",{className:"text-left",children:e.jsx("span",{className:"text-sm font-bold text-red-600 bg-red-100 px-3 py-1.5 rounded-full",children:"غير متوفر"})})]})},x))})]}),s.pharmacyNotes&&e.jsxs("div",{className:"bg-yellow-50 rounded-xl p-4 mb-6",children:[e.jsx("h3",{className:"text-lg font-black text-slate-800 mb-2",children:"ملاحظات الصيدلية"}),e.jsx("p",{className:"text-slate-700",children:s.pharmacyNotes})]}),e.jsx("div",{className:"bg-slate-50 rounded-xl p-4 text-sm text-slate-600",children:e.jsx("div",{className:"grid grid-cols-2 gap-4",children:e.jsxs("div",{children:[e.jsx("span",{className:"font-semibold",children:"تاريخ الرد: "}),o(s.respondedAt)]})})})]}),e.jsx("div",{className:"bg-slate-50 p-6 border-t",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("button",{onClick:n,className:"px-6 py-3 bg-slate-500 text-white rounded-xl hover:bg-slate-600 transition-colors font-bold",children:"إغلاق"}),e.jsxs("button",{onClick:()=>i(s),className:"px-8 py-3 bg-gradient-to-r from-teal-500 to-emerald-600 text-white rounded-xl hover:from-teal-600 hover:to-emerald-700 transition-all font-bold flex items-center gap-2",children:[e.jsx(V,{className:"w-5 h-5"}),"تأكيد الطلب الآن"]})]})})]})})},Oe=()=>{const{user:h}
41=de(),[n,s]=d.useState([]),[i,o]=d.useState(!0),[l,x]=d.useState(null),[j,g]=d.useState(null),[v,y]=d.useState(!1),[F,c]=d.useState(!1),[P,M]=d.useState(null),[k,a]=d.useState(!1),[p,b]=d.useState(null),A=async()=>{o(!0),x(null);try{console.log("💊 Fetching prescriptions for patient:",h?.id);const t=await E.getMyPrescriptions();console.log("✅ Prescriptions response:",t);const w=t.map(u=>({...u,consultationType:u.appointmentType==="regular"?"كشف جديد":"إعادة كشف",patientId:h?.id}));console.log("📊 Prescription statuses:",w.map(u=>({id:u.id,prescriptionNumber:u.prescriptionNumber,status:u.status,statusName:u.statusName,statusText:I(u.status),hasReports:u.status===5}))),s(w),o(!1)}catch(t){console.error("❌ Error fetching prescriptions:",t),x("حدث خطأ في تحميل الروشتات"),o(!1)}};d.useEffect(()=>{h?.id&&A()},[h?.id]);const N=t=>{console.log("👁️ Viewing prescription:",t),g(t),y(!0)},C=t=>{console.log("🛒 Ordering prescription:",t),M(t),c(!0)},R=t=>{console.log("📋 Viewing reports for prescription:",t),b(t),a(!0)},f=t=>(console.log("🔍 Checking prescription status:",{id:t.id,status:t.status,statusName:t.statusName,hasReports:t.status===5}),t.status===5),m=t=>{if(!t)return"غير محدد";try{return je(t)}catch{return t}},I=t=>({1:"نشطة",2:"ملغية",3:"تم صرفها",4:"منتهية الصلاحية",5:"تم الرد عليها"})[t]||"غير محدد",r=t=>({1:"text-blue-600 bg-blue-50",2:"text-red-600 bg-red-50",3:"text-green-600 bg-green-50",4:"text-gray-600 bg-gray-50",5:"text-emerald-600 bg-emerald-50"})[t]||"text-gray-600 bg-gray-50";return e.jsxs("div",{className:"min-h-screen bg-gradient-to-br from-slate-50 via-teal-50/30 to-emerald-50/30",dir:"rtl",children:[e.jsxs("div",{className:"max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8",children:[e.jsxs("div",{className:"bg-gradient-to-r from-teal-500 to-emerald-600 rounded-2xl p-8 mb-8 relative overflow-hidden",children:[e.jsx("div",{className:"absolute inset-0 opacity-10",children:e.jsx("div",{className:"absolute inset-0",style:{backgroundImage:`url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='1'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E")`}})}),e.jsx("div",{className:"absolute top-0 right-0 w-64 h-64 bg-white/10 rounded-full -mr-32 -mt-32"}),e.jsx("div",{className:"absolute bottom-0 left-0 w-48 h-48 bg-emerald-400/20 rounded-full -ml-24 -mb-24"}),e.jsxs("div",{className:"relative",children:[e.jsxs("div",{className:"flex items-center gap-4 mb-4",children:[e.jsx("div",{className:"w-16 h-16 bg-white/20 backdrop-blur-sm rounded-2xl flex items-center justify-center shadow-lg",children:e.jsx(q,{className:"text-white text-3xl"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-4xl font-black text-white mb-2",children:"الروشتات الطبية"}),e.jsx("p",{className:"text-white/90 text-lg font-medium",children:"جميع الروشتات الخاصة بك من كل الأطباء"})]})]}),!i&&!l&&e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4 mt-6",children:[e.jsx("div",{className:"bg-white/20 backdrop-blur-sm rounded-xl p-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 bg-white/30 rounded-lg flex items-center justify-center",children:e.jsx(q,{className:"text-white"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold text-white/80",children:"إجمالي الروشتات"}),e.jsx("p",{className:"text-2xl font-black text-white",children:n.length})]})]})}),e.jsx("div",{className:"bg-white/20 backdrop-blur-sm rounded-xl p-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 bg-white/30 rounded-lg flex items-center justify-center",children:e.jsx(G,{className:"text-white"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold text-white/80",children:"عدد الأطباء"}),e.jsx("p",{className:"text-2xl font-black text-white",children:new Set(n.map(t=>t.doctorId)).size})]})]})}),e.jsx("div",{className:"bg-white/20 backdrop-blur-sm rounded-xl p-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 bg-white/30 rounded-lg flex items-center justify-center",children:e.jsx(K,{className:"text-white"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold text-white/80",children:"آخر روشتة"}),e.jsx("p",{className:"text-sm font-bold text-white",children:n.length>0?m(n[0].createdAt):"-"})]})]})})]})]})]}),e.jsx("div",{className:"bg-white rounded-2xl shadow-lg p-6",children:i?e.jsx("div",{className:"flex items-center justify-center py-20",children:e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"w-16 h-16 border-4 border-teal-200 border-t-teal-600 rounded-full animate-spin mx-auto mb-4"}),e.jsx("p",{className:"text-slate-600 font-medium",children:"جاري تحميل الروشتات..."})]})}):l?e.jsxs("div",{className:"text-center py-20",children:[e.jsx("div",{className:"w-24 h-24 bg-red-100 rounded-full flex items-center justify-center mx-auto mb-4",children:e.jsx(xe,{className:"text-red-500 text-4xl"})}),e.jsx("h3",{className:"text-xl font-bold text-slate-800 mb-2",children:"حدث خطأ"}),e.jsx("p",{className:"text-slate-600 font-medium mb-4",children:l}),e.jsx("button",{onClick:A,className:"px-6 py-2.5 bg-gradient-to-r from-teal-500 to-emerald-600 text-white rounded-xl hover:from-teal-600 hover:to-emerald-700 transition-all font-bold text-sm shadow-lg",children:"إعادة المحاولة"})]}):n.length===0?e.jsxs("div",{className:"text-center py-20",children:[e.jsx("div",{className:"w-24 h-24 bg-slate-100 rounded-full flex items-center justify-center mx-auto mb-4",children:e.jsx(T,{className:"text-slate-400 text-4xl"})}),e.jsx("h3",{className:"text-xl font-bold text-slate-800 mb-2",children:"لا توجد روشتات"}),e.jsx("p",{className:"text-slate-600 font-medium",children:"لم يتم إنشاء أي روشتات لك بعد"})]}):e.jsx("div",{className:"space-y-4",children:n.map((t,w)=>e.jsx("div",{className:"bg-white rounded-2xl border-2 border-slate-200 hover:border-teal-400 transition-all shadow-sm hover:shadow-lg p-6",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"w-14 h-14 bg-gradient-to-br from-teal-500 to-emerald-600 rounded-xl flex items-center justify-center text-white font-black text-lg flex-shrink-0",children:w+1}),e.jsxs("div",{className:"flex-1 grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(me,{className:"text-teal-600 text-sm"}),e.jsx("span",{className:"text-xs font-semibold text-teal-700",children:"رقم الروشتة:"}),e.jsx("span",{className:"text-sm font-black text-slate-900",children:t.prescriptionNumber})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(G,{className:"text-teal-600 text-sm"}),e.jsx("span",{className:"text-xs font-semibold text-teal-700",children:"الطبيب:"}),e.jsx("span",{className:"text-sm font-bold text-slate-900",children:t.doctorName})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(K,{className:"text-teal-600 text-sm"}),e.jsx("span",{className:"text-xs font-semibold text-teal-700",children:"تاريخ الإنشاء:"}),e.jsx("span",{className:"text-sm font-bold text-slate-700",children:m(t.createdAt)})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(he,{className:"text-teal-600 text-sm"}),e.jsx("span",{className:"text-xs font-semibold text-teal-700",children:"الحالة:"}),e.jsx("span",{className:`text-xs font-bold px-2 py-1 rounded-full ${r(t.status)}`,children:I(t.status)})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(be,{className:"text-teal-600 text-sm"}),e.jsx("span",{className:"text-xs font-semibold text-teal-700",children:"التخصص:"}),e.jsx("span",{className:"text-sm font-bold text-slate-700",children:t.doctorSpecialty})]})]})]}),e.jsxs("div",{className:"flex flex-col items-end gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2 bg-teal-50 px-3 py-1.5 rounded-lg border border-teal-200",children:[e.jsx(fe,{className:"text-teal-600 text-xs"}),e.jsx("span",{className:"text-xs font-bold text-teal-700",children:t.consultationType})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:()=>N(t),className:"px-4 py-2.5 bg-gradient-to-r from-slate-500 to-slate-600 text-white rounded-xl hover:from-slate-600 hover:to-slate-700 transition-all font-bold text-sm shadow-md hover:shadow-lg flex items-center gap-2 whitespace-nowrap",children:[e.jsx(_,{className:"w-4 h-4"}),"عرض الروشتة"]}),(t.status===1||t.status===5)&&(f(t)?e.jsxs("button",{onClick:()=>R(t),className:"px-4 py-2.5 bg-gradient-to-r from-emerald-500 to-teal-600 text-white rounded-xl hover:from-emerald-600 hover:to-teal-700 transition-all font-bold text-sm shadow-md hover:shadow-lg flex items-center gap-2 whitespace-nowrap",children:[e.jsx(T,{className:"w-4 h-4"}),"التقارير"]}):t.status===1?e.jsxs("button",{onClick:()=>C(t),className:"px-4 py-2.5 bg-gradient-to-r from-teal-500 to-emerald-600 text-white rounded-xl hover:from-teal-600 hover:to-emerald-700 transition-all font-bold text-sm shadow-md hover:shadow-lg flex items-center gap-2 whitespace-nowrap",children:[e.jsx(V,{className:"w-4 h-4"}),"اطلب الآن"]}):null)]})]})]})},t.id))})})]}),j&&e.jsx(ue,{isOpen:v,onClose:()=>{y(!1),g(null)},prescriptionId:j.id,patientId:j.patientId,doctorId:j.doctorId,doctorName:j.doctorName,doctorSpecialty:j.doctorSpecialty}),e.jsx(we,{isOpen:F,onClose:()=>{c(!1),M(null)},prescription:P}),e.jsx(ke,{isOpen:k,onClose:()=>{a(!1),b(null)},prescription:p,onNewOrder:t=>{a(!1),M(t),c(!0)}})]})};export{Oe as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.