import{ah as N,o as V,a2 as C,b as n,c as i,d as t,q as j,t as l,F as B,C as M,p as D,ab as L,f as q,a,n as I}from"./vue-core-Di3IuVqe.js";import"./cjs-helpers-psZwOBky.js";const R="/logo_cmi.png",S="/logo_visa.png",$="/logo_mastercard.png",E={class:"min-h-screen bg-gradient-to-br from-blue-50 to-indigo-100 flex items-center justify-center p-4"},T={key:0,class:"text-center"},U={key:1,class:"bg-white rounded-2xl shadow-lg p-8 max-w-md w-full text-center"},A={class:"text-xl font-bold text-gray-800 mb-2"},O={class:"text-gray-600"},z={key:2,class:"bg-white rounded-2xl shadow-lg p-6 md:p-8 max-w-lg w-full"},G={class:"text-center mb-6"},H={class:"mt-2 text-gray-500"},J={class:"rounded-lg bg-gray-50 p-4 mb-6"},K={class:"flex items-center justify-between"},Q={class:"text-2xl font-bold text-blue-600"},W={key:0,class:"mb-6"},X={class:"border rounded-lg divide-y divide-gray-100 overflow-hidden"},Y={class:"font-medium text-gray-800"},Z={class:"text-gray-400 ml-2"},ee={class:"font-semibold text-red-600"},te=["disabled"],se={key:1,class:"text-red-600 text-sm text-center mt-3"},ae=["action"],ne=["name","value"],ce={__name:"PaiementPublic",setup(ie){const x=N().params.uuid,f=window.location.href.indexOf("localhost")!==-1?"http://localhost:8083/api":"https://api.omag.ma:7979/api",b=a(!0),p=a({}),v=a([]),g=a(null),u=a("Lien invalide"),d=a("pi pi-times-circle text-red-500"),r=a(!1),o=a(null),_=a(null),y=a(""),h=a({});function w(e){return e==null?"":new Intl.NumberFormat("fr-MA",{style:"currency",currency:"MAD"}).format(e)}function P(e){return e?new Date(e).toLocaleDateString("fr-FR"):""}function k(e,s){g.value=e,s==="paye"?(u.value="Déjà réglé",d.value="pi pi-check-circle text-green-500"):s==="expire"?(u.value="Lien expiré",d.value="pi pi-clock text-orange-500"):(u.value="Lien invalide",d.value="pi pi-times-circle text-red-500")}async function F(){r.value=!0,o.value=null;try{const{data:e}=await C.post(`${f}/paiements-en-ligne/payer/${x}`,{lang:"fr"});if(!e.success){o.value=e.message||"Impossible d'initier le paiement.",r.value=!1;return}y.value=e.gatewayUrl,h.value=e.params,await I(),_.value.submit()}catch(e){o.value=e.response?.data?.message||"Erreur lors de l'initiation du paiement.",r.value=!1}}return V(async()=>{try{const{data:e}=await C.get(`${f}/paiements-en-ligne/page/${x}`);if(!e.success){k(e.message,e.statut);return}p.value=e.paiement,v.value=e.factures||[]}catch(e){k(e.response?.data?.message||"Ce lien de paiement est invalide ou a expiré.")}finally{b.value=!1}}),(e,s)=>(n(),i("div",E,[b.value?(n(),i("div",T,[...s[0]||(s[0]=[t("i",{class:"pi pi-spin pi-spinner text-4xl text-blue-500"},null,-1),t("p",{class:"mt-4 text-gray-600"},"Chargement...",-1)])])):g.value?(n(),i("div",U,[t("i",{class:j([d.value,"text-5xl mb-4"])},null,2),t("h2",A,l(u.value),1),t("p",O,l(g.value),1)])):(n(),i("div",z,[t("div",G,[s[1]||(s[1]=t("i",{class:"pi pi-credit-card text-4xl text-blue-600 mb-3"},null,-1)),s[2]||(s[2]=t("h1",{class:"text-2xl font-bold text-gray-900"},"Règlement de vos factures",-1)),t("p",H,"Bonjour "+l(p.value.nom_client),1)]),t("div",J,[t("div",K,[s[3]||(s[3]=t("span",{class:"text-sm text-gray-500"},"Montant total à régler",-1)),t("span",Q,l(w(p.value.montant)),1)])]),v.value.length?(n(),i("div",W,[s[4]||(s[4]=t("h3",{class:"text-sm font-semibold text-gray-700 mb-2"},"Détail des factures impayées",-1)),t("div",X,[(n(!0),i(B,null,M(v.value,(c,m)=>(n(),i("div",{key:m,class:"flex items-center justify-between px-4 py-2 text-sm"},[t("div",null,[t("span",Y,"N° "+l(c.numero),1),t("span",Z,l(P(c.date)),1)]),t("span",ee,l(w(c.reste_a_payer)),1)]))),128))])])):D("",!0),s[5]||(s[5]=L('<div class="rounded-lg border border-blue-100 bg-blue-50 p-3 text-xs text-blue-700 mb-6"><div class="mb-2"><i class="pi pi-lock mr-1"></i> Paiement sécurisé par carte bancaire via la plateforme CMI. Vos données bancaires ne transitent jamais par nos serveurs. </div><div class="flex items-center justify-center gap-4"><img src="'+R+'" alt="CMI" class="h-6"><img src="'+S+'" alt="Visa" class="h-6"><img src="'+$+'" alt="MasterCard" class="h-6"></div></div>',1)),t("button",{class:"w-full bg-blue-600 hover:bg-blue-700 text-white font-semibold py-3 rounded-lg transition flex items-center justify-center gap-2 disabled:opacity-60",disabled:r.value,onClick:F},[t("i",{class:j(r.value?"pi pi-spin pi-spinner":"pi pi-credit-card")},null,2),q(" "+l(r.value?"Redirection...":"Payer maintenant"),1)],8,te),o.value?(n(),i("p",se,l(o.value),1)):D("",!0),t("form",{ref_key:"cmiForm",ref:_,action:y.value,method:"POST",style:{display:"none"}},[(n(!0),i(B,null,M(h.value,(c,m)=>(n(),i("input",{key:m,type:"hidden",name:m,value:c},null,8,ne))),128))],8,ae)]))]))}};export{ce as default};
