import{r as o,j as e,_ as a,s as L}from"./wp-i18n-shim-DUX0OV_V.js";import{B as h}from"./Button-BveKhP38.js";import{I as z}from"./input-Dw-69aYW.js";import{S as T,a as X,b as $,c as p,f as C}from"./select-BFNitOb0.js";import{a as V,s as q}from"./store-rDqSxbzb.js";import{D as j}from"./DollarCircle-CqTu8Ult.js";import{f as S}from"./priceFormatter-Dg4GlACg.js";import{L as _}from"./loader-circle-CcSu72zH.js";import{C as G}from"./circle-check-big-Bxgqw2u9.js";import{C as H}from"./Combination-BuKwnoTc.js";import{c as J,X as K}from"./utils-Bl0WAcve.js";/**
 * @license lucide-react v0.525.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const O=[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}]],Q=J("rotate-ccw",O);function ue({appointment:s,...A}){var k,v;const{module:N}=A,[f,g]=o.useState(!1),[U,W]=o.useState(!1),[l,b]=o.useState(""),[Y,Z]=o.useState(""),[F,y]=o.useState("paid"),[t,u]=o.useState(!1),{updateAppointmentPayment:P}=V(q),d=(k=s==null?void 0:s.payment)==null?void 0:k.status,i=parseFloat(((v=s==null?void 0:s.payment)==null?void 0:v.amount)||0)||0,x=()=>{var m,c;const r=parseFloat(((m=s==null?void 0:s.payment)==null?void 0:m.total_amount)||(s==null?void 0:s.price)||0)||0,n=parseFloat(((c=s==null?void 0:s.payment)==null?void 0:c.amount)||0)||0;return d==="partial_payment"?Math.max(0,r-n):r},M=async()=>{u(!0);try{const r="TXN_"+Date.now(),n=await P(s.id,{appointment:s,amount:parseFloat(l),status:F,transaction_id:r},N);b(""),y("paid"),g(!1)}catch(r){console.error("Payment failed:",r)}finally{u(!1)}},D=async()=>{var r,n,m;u(!0);try{const c=parseFloat(((r=s==null?void 0:s.customer)==null?void 0:r.price)||(s==null?void 0:s.price)||0)||0,B=parseFloat(((n=s==null?void 0:s.payment)==null?void 0:n.amount)||0)||0,I=parseFloat(((m=s==null?void 0:s.payment)==null?void 0:m.due_amount)||0)||0,ee=d==="partial_payment"?Math.max(0,c-B):c,E="TXN_"+Date.now();await P(s.id,{appointment:s,amount:I,status:"paid",transaction_id:E},N)}catch(c){console.error("Mark as paid failed:",c)}finally{u(!1)}},R=["pending","failed","partial_payment"].includes(d),w=["confirmed","completed"].includes(s==null?void 0:s.status)&&!t;return e.jsxs("div",{className:"space-y-3",children:[R&&e.jsx(e.Fragment,{children:f?e.jsxs("div",{className:"space-y-3 border p-4 rounded-lg bg-gray-50",children:[e.jsx("h4",{className:"font-medium text-title",children:a("Process Payment","radius-booking")}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(z,{type:"number",placeholder:a("Enter amount","radius-booking"),value:l,onChange:r=>b(r.target.value),disabled:t,min:"0",step:"1",className:`bg-white
                                        ${l&&parseFloat(l)>x()?" border-red-300 focus:border-red-500":""}
                                        `}),e.jsxs("div",{className:"flex justify-between text-xs",children:[e.jsx("span",{className:"text-title2",children:L(a("Max: $%s","radius-booking"),(x()||0).toFixed(2))}),l&&parseFloat(l)>x()&&e.jsx("span",{className:"text-red-500",children:a("Amount exceeds maximum","radius-booking")})]})]}),e.jsxs(T,{value:F,onValueChange:y,disabled:t,children:[e.jsx(X,{className:"bg-white",children:e.jsx($,{placeholder:a("Select status","radius-booking")})}),e.jsxs(p,{children:[e.jsx(C,{value:"paid",children:a("Paid","radius-booking")}),e.jsx(C,{value:"partial_payment",children:a("Partial Payment","radius-booking")})]})]}),e.jsxs("div",{className:"flex gap-2 flex-wrap",children:[e.jsxs(h,{onClick:M,className:"flex-1 bg-[#16803C] hover:bg-green-600 text-white font-medium py-2.5 gap-2",disabled:!l||parseFloat(l)<=0||parseFloat(l)>x()||t,children:[t?e.jsx(_,{className:"w-4 h-4 mr-2 animate-spin"}):e.jsx(j,{size:"14px",className:"text-white"}),t?a("Confirming...","radius-booking"):a("Confirm Payment","radius-booking")]}),e.jsx(h,{variant:"outline",className:"border border-red-700 text-red-700 hover:bg-red-700 hover:text-white",onClick:()=>{g(!1),b(""),y("paid")},disabled:t,children:a("Cancel","radius-booking")})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mb-4",children:[e.jsx("div",{className:"flex gap-2 mb-2",children:e.jsxs(h,{onClick:D,className:"flex-1 bg-[#16803C] hover:bg-green-600 text-white font-medium py-2.5 h-[46px] gap-1",disabled:!w,children:[t?e.jsx(_,{className:"w-4 h-4 mr-2 animate-spin"}):e.jsx(G,{className:"w-4 h-4 mr-2"}),t?a("Processing...","radius-booking"):a("Mark as Paid","radius-booking")]})}),e.jsx("div",{className:"flex gap-2",children:e.jsxs(h,{onClick:()=>g(!0),variant:"outline",className:"flex-1  bg-[#F5FAFF] border-[#BDCFFF] text-primary hover:bg-[#E4F1FF] hover-border-[#9CB7FF] font-medium py-2.5 h-[46px] gap-1",disabled:!w,children:[e.jsx(j,{size:"16px",className:"text-primary"}),a("Custom Payment","radius-booking")]})})]}),(s==null?void 0:s.status)!=="confirmed"&&e.jsx("p",{className:"text-xs text-title2 text-center",children:a("Payment can only be processed for confirmed appointments","radius-booking")})]})}),d==="paid"&&e.jsxs("div",{className:"flex items-center justify-between p-3 bg-green-50 text-green-700 rounded-lg border border-green-200 md:gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(H,{className:"w-5 h-5"}),e.jsx("span",{className:"font-medium md:text-sm",children:a("Payment Completed","radius-booking")})]}),i>0&&e.jsx("span",{className:"text-sm font-medium break-all",children:S(parseFloat(i).toFixed(2),s.currency)})]}),d==="failed"&&!f&&e.jsxs("div",{className:"flex items-center justify-center gap-2 p-3 bg-red-50 text-red-700 rounded-lg border border-red-200",children:[e.jsx(K,{className:"w-5 h-5"}),e.jsx("span",{className:"font-medium",children:a("Payment Failed","radius-booking")})]}),d==="partial_payment"&&!f&&e.jsxs("div",{className:"flex items-center justify-between p-3 bg-yellow-50 text-yellow-700 rounded-lg border border-yellow-300",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(j,{size:"16px"}),e.jsx("span",{className:"font-medium",children:a("Partially Paid","radius-booking")})]}),i>0&&e.jsx("span",{className:"text-sm font-medium",children:S(parseFloat(i).toFixed(2),s.currency)})]}),d==="refunded"&&e.jsxs("div",{className:"flex items-center justify-between p-3 bg-blue-50 text-primary rounded-lg border border-blue-200",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Q,{className:"w-5 h-5"}),e.jsx("span",{className:"font-medium",children:a("Refund Processed","radius-booking")})]}),i>0&&e.jsxs("span",{className:"text-sm font-medium",children:["$",i.toFixed(2)]})]})]})}export{ue as P};
//# sourceMappingURL=PaymentSection-Ds2_2QsE.js.map
