@fundly.ai/payment-sdk 1.0.4 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +84 -1
- package/dist/embed/index.d.ts +33 -0
- package/dist/embed/index.d.ts.map +1 -0
- package/dist/embed/types.d.ts +105 -0
- package/dist/embed/types.d.ts.map +1 -0
- package/dist/embed.css +1 -0
- package/dist/embed.js +739 -0
- package/dist/index.js +1 -1
- package/dist/index.mjs +6 -6
- package/dist/payment-sdk.css +1 -1
- package/dist/sdk/index.d.ts.map +1 -1
- package/package.json +12 -4
package/dist/index.js
CHANGED
|
@@ -662,4 +662,4 @@ Fundly Team`;await Lt.shareString(ge)}};return t.jsxs(Di,{open:h,onClose:X,child
|
|
|
662
662
|
.animate-spin-slow {
|
|
663
663
|
animation: spin-slow 2s linear infinite;
|
|
664
664
|
}
|
|
665
|
-
`})]}),kA=({size:h=24,color:o="currentColor",className:f,style:C})=>t.jsx("svg",{width:h,height:h,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:f,style:C,"aria-hidden":"true",children:t.jsx("path",{d:"M22 16.92V19.92C22.0011 20.1985 21.9441 20.4742 21.8325 20.7293C21.7209 20.9845 21.5573 21.2136 21.3521 21.4019C21.1468 21.5901 20.9046 21.7335 20.6407 21.8227C20.3769 21.9119 20.0974 21.9451 19.82 21.92C16.7428 21.5856 13.787 20.5341 11.19 18.85C8.77382 17.3147 6.72533 15.2662 5.18999 12.85C3.49997 10.2412 2.44824 7.27099 2.11999 4.18C2.095 3.90347 2.12787 3.62476 2.21649 3.36162C2.30512 3.09849 2.44756 2.85669 2.63476 2.65162C2.82196 2.44655 3.0498 2.28271 3.30379 2.17052C3.55777 2.05833 3.83233 2.00026 4.10999 2H7.10999C7.5953 1.99522 8.06579 2.16708 8.43376 2.48353C8.80173 2.79999 9.04207 3.23945 9.10999 3.72C9.23662 4.68007 9.47144 5.62273 9.80999 6.53C9.94454 6.88792 9.97366 7.27691 9.89384 7.65088C9.81401 8.02485 9.62892 8.36811 9.35999 8.64L8.08999 9.91C9.51355 12.4135 11.5864 14.4864 14.09 15.91L15.36 14.64C15.6319 14.3711 15.9751 14.186 16.3491 14.1062C16.7231 14.0263 17.1121 14.0555 17.47 14.19C18.3773 14.5286 19.3199 14.7634 20.28 14.89C20.7658 14.9585 21.2094 15.2032 21.5265 15.5775C21.8437 15.9518 22.0122 16.4296 22 16.92Z",stroke:o,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}),FA=({size:h=24,color:o="currentColor",className:f,style:C})=>t.jsxs("svg",{width:h,height:h,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:f,style:C,"aria-hidden":"true",children:[t.jsx("path",{d:"M4 4H20C21.1 4 22 4.9 22 6V18C22 19.1 21.1 20 20 20H4C2.9 20 2 19.1 2 18V6C2 4.9 2.9 4 4 4Z",stroke:o,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),t.jsx("path",{d:"M22 6L12 13L2 6",stroke:o,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]}),Nr={PHONE:"+91-9892422528",EMAIL:"connect@fundly.ai"},Bi={FUNDLY_PAY:"FUNDLY_PAY",DYNAMIC_QR:"DYNAMIC_QR",PAYMENT_LINK:"PAYMENT_LINK",CASH:"CASH",CHEQUE:"CHEQUE",UPI:"UPI",NETBANKING:"NETBANKING"},zs={FUNDLY_CUSTOMER_APP:"FUNDLY_CUSTOMER_APP",FUNDLY_COLLECT_APP:"FUNDLY_COLLECT_APP"},PA=({open:h,onClose:o})=>{const f=C=>{navigator.clipboard.writeText(C)};return t.jsx(Di,{open:h,onClose:o,children:t.jsxs("div",{className:"w-full flex flex-col px-8 py-4 space-y-4 mt-2 mb-12",children:[t.jsx("div",{className:"w-full flex items-center justify-end",children:t.jsx("img",{src:me.closingCross,className:"w-4 h-4 cursor-pointer",onClick:o,alt:"Close"})}),t.jsx("img",{src:me.customerSup,className:"w-14 h-14",alt:"Support"}),t.jsxs("div",{className:"flex space-x-6 items-center",children:[t.jsx(kA,{size:24,color:"#16558B"}),t.jsx("span",{className:"font-semibold",children:Nr.PHONE}),t.jsx("img",{src:me.copy,className:"w-5 h-5 cursor-pointer",onClick:()=>f(Nr.PHONE),alt:"Copy"})]}),t.jsxs("div",{className:"flex space-x-6 items-center",children:[t.jsx(FA,{size:24,color:"#16558B"}),t.jsx("span",{className:"font-semibold",children:Nr.EMAIL}),t.jsx("img",{src:me.copy,className:"w-5 h-5 cursor-pointer",onClick:()=>f(Nr.EMAIL),alt:"Copy"})]})]})})},TA=({open:h,onClose:o,onConfirm:f})=>t.jsxs(Ai,{open:h,onClose:o,children:[t.jsx(_i,{children:t.jsx("div",{className:"w-full flex justify-end",children:t.jsx("img",{src:me.closingCross,className:"w-4 h-4 cursor-pointer",onClick:o,alt:"Close"})})}),t.jsx(xi,{children:t.jsxs("div",{style:{fontFamily:"Poppins"},className:"w-full flex flex-col justify-center items-center",children:[t.jsx("img",{src:me.paymentLeave,className:"w-18 h-18",alt:"Leave"}),t.jsx("span",{className:"text-[18px] text-wrap font-bold text-center",children:"Leave this page?"}),t.jsx("span",{className:"text-[14px] text-wrap font-semibold text-center text-[#6D6D6D]",children:"Any unsaved payment details will be lost."})]})}),t.jsx(Ni,{children:t.jsxs("div",{style:{fontFamily:"Poppins"},className:"w-full flex justify-between px-3 mb-3 gap-3",children:[t.jsx("button",{className:"flex-1 w-[96px] h-[48px] border-2 border-gray-400 text-gray-400 rounded-xl",onClick:f,children:"Yes, Leave"}),t.jsx("button",{className:"flex-1 w-[96px] h-[48px] bg-[#16558B] text-white rounded-xl",onClick:o,children:"No"})]})})]}),zA=()=>{const{partnerCredentials:h}=ci(),[o,f]=D.useState(null),[C,a]=D.useState(!1),[F,k]=D.useState(null);return{login:D.useCallback(async()=>{a(!0),k(null);try{if(!h)throw new Error("Partner credentials not provided");const T={loginType:"PARTNER",username:h.username,password:h.password},Q=await xA(T);if(Q?.accessToken){const z=Q.accessToken;return Do(z),f(z),z}throw new Error("No access token received")}catch(T){const Q=T instanceof Error?T:new Error("Login failed");throw k(Q),Q}finally{a(!1)}},[h]),token:o,isLoading:C,error:F}},RA=h=>{const{setChemistId:o,setLeadId:f,setDistributorIdnum:C,setTypeOfApp:a,setPaymentInvoice:F,setPayableValue:k,setInvoices:P,setPaymentType:T,setSalesmanId:Q,distributorIdnum:z,chemistId:J,leadId:$}=ci(),Z=D.useRef(!1);D.useEffect(()=>{const X=oe=>{if(typeof oe.data!="object"||oe.data===null||oe.source!==window||oe.data?.source==="react-devtools-content-script"||oe.source!==window||oe.data?.source?.includes("react-devtools")||oe.origin!==window.origin)return;const{source:Ce,distributorId:ve,chemistId:ie,paymentType:xe,payableAmount:Se,invoices:ce,paymentInvoice:je,salesmanId:Ee}=oe.data;ve&&C(ve),ie&&o(ie),Ce&&a(Ce),Array.isArray(je)&&F(je),Se&&k(Se),Array.isArray(ce)&&P(ce),xe&&T(xe),Ee&&Q(Ee),Z.current||(h(),Z.current=!0)},H=J&&J.trim()!=="",q=$&&$.trim()!=="";return z&&(H||q)&&!Z.current&&(h(),Z.current=!0),window.addEventListener("message",X),()=>window.removeEventListener("message",X)},[h,o,f,C,a,F,k,P,T,Q,z,J,$])},QA=h=>{const{distributorIdnum:o,typeOfApp:f,chemistId:C,leadId:a,payableValue:F,salesmanId:k,paymentType:P,setDistributorName:T,setChemistName:Q,setPayerMobileNumber:z,setSalesmanPhoneNumber:J,setTenureMappings:$,setFiCode:Z,setDrawdownRepaymentOption:X,setCreditLimitData:H}=ci(),[q,oe]=D.useState([]),[Ce,ve]=D.useState(null),[ie,xe]=D.useState(null),[Se,ce]=D.useState(null),[je,Ee]=D.useState(null),[De,Te]=D.useState(!0);return D.useEffect(()=>{h&&(async()=>{const ye={distributorBusinessId:o,source:f,...C&&C.trim()!==""&&{chemistBusinessId:C},...a&&a.trim()!==""&&{leadId:a},payableAmount:F,...k&&{salesmanId:k},...P&&{collectType:P}};try{const _=await pA(ye);ve(_.bankDetails),_.bankDetails&&(T(_.bankDetails.distributorName||""),Q(_.bankDetails.chemistName||""),z(_.bankDetails.mobileNumber||""),J(_.bankDetails.salesmanPhoneNumber||""));const de=_.paymentOption.find(Be=>Be.name==="FUNDLY_PAY");de?.details?.tenureMappings&&$(de.details.tenureMappings),xe(de?.details?.maxEligibleLimit??null),ce(de?.details?.minEligibleLimit??null),Ee(de?.reason??null),de?.details?.fiCode&&Z(de.details.fiCode),de?.details?.drawdownRepaymentOption&&X(de.details.drawdownRepaymentOption);const re=_.paymentOption.filter(Be=>Be.isActive).map(Be=>Be.name);if(oe(re),de?.isActive&&_.bankDetails?.chemistBusinessId)try{const Be=await fA(_.bankDetails.chemistBusinessId);H(Be)}catch(Be){console.warn("Credit limit filter API failed:",Be),H(null)}Te(!1)}catch{Te(!1)}})()},[h]),{paymentOptions:q,bankDetails:Ce,maxEligibleLimit:ie,minEligibleLimit:Se,fundlyPayReason:je,loading:De}};function Gl(){const[h,o]=D.useState({activeDrawer:null,paymentData:null}),f=D.useCallback(P=>{o({activeDrawer:P,paymentData:null})},[]),C=D.useCallback(()=>{o({activeDrawer:null,paymentData:null})},[]),a=D.useCallback(P=>{o({activeDrawer:"SUCCESS",paymentData:P||null})},[]),F=D.useCallback(P=>{o({activeDrawer:"FAILURE",paymentData:P||null})},[]),k=D.useCallback(P=>h.activeDrawer===P,[h.activeDrawer]);return{activeDrawer:h.activeDrawer,paymentData:h.paymentData,openPaymentDrawer:f,closeDrawer:C,isDrawerOpen:k,handlePaymentSuccess:a,handlePaymentFailure:F,showFundlyPayDrawer:k("FUNDLY_PAY"),showUpiDrawer:k("UPI"),showDynamicQrDrawer:k("DYNAMIC_QR"),showStaticQrDrawer:k("STATIC_QR"),showPaymentLinkDrawer:k("PAYMENT_LINK"),showNetbankingDrawer:k("NETBANKING"),showCashDrawer:k("CASH"),showChequeDrawer:k("CHEQUE"),showSuccessDrawer:k("SUCCESS"),showFailureDrawer:k("FAILURE")}}const UA=({onPaymentCollected:h,onPaymentFailed:o})=>{const[f,C]=D.useState(!1),[a,F]=D.useState(!1),[k,P]=D.useState(!1),[T,Q]=D.useState(null),{paymentData:z,openPaymentDrawer:J,closeDrawer:$,handlePaymentSuccess:Z,handlePaymentFailure:X,showFundlyPayDrawer:H,showUpiDrawer:q,showDynamicQrDrawer:oe,showStaticQrDrawer:Ce,showPaymentLinkDrawer:ve,showNetbankingDrawer:ie,showCashDrawer:xe,showChequeDrawer:Se,showSuccessDrawer:ce,showFailureDrawer:je}=Gl(),[Ee,De]=D.useState(!1),[Te,W]=D.useState(-1),[ye,_]=D.useState(null),[de,re]=D.useState([]),[Be,dt]=D.useState(null),[ge,he]=D.useState(null),Me=D.useRef(!1),{distributorName:pe,distributorIdnum:fe,payableValue:Ie,typeOfApp:le,transactionId:pt,showResultOnly:Bt,successButtonText:Le,failureButtonText:Qe,creditLimitData:Fe,paymentType:Pe,paymentInvoice:ot,chemistId:We,leadId:ze,salesmanId:Ue,payerMobileNumber:qe,scanId:_e,viewId:At,sessionId:ut,erpId:Ge}=ci(),mt=D.useMemo(()=>({type:"collection",distributorId:fe||"",chemistId:We||void 0,leadId:ze||void 0,invoices:ot||[],paymentType:Pe||"INVOICE_COLLECT",salesmanId:Ue||void 0,payerMobileNumber:qe||void 0}),[fe,We,ze,ot,Pe,Ue,qe]),{login:at,token:Ye,error:gt}=zA(),ft=D.useCallback(async()=>{try{await at(),Q(null)}catch(V){const we=V instanceof Error?V.message:"Authentication failed. Please try again later.";Q(we)}},[at]);RA(ft);const{paymentOptions:Ae,bankDetails:ue,maxEligibleLimit:Je,minEligibleLimit:$e,fundlyPayReason:nt,loading:Re}=QA(Ye);D.useEffect(()=>{if(!Bt&&!pt){const V=new URLSearchParams(window.location.search);if((V.has("orderId")||V.has("transactionId"))&&!Ye){const Ve=new URL(window.location.href);Ve.searchParams.delete("orderId"),Ve.searchParams.delete("transactionId"),window.history.replaceState({},"",Ve.toString())}}},[Bt,Ye,pt]),D.useEffect(()=>{if(T||gt){const V=setTimeout(async()=>{await Lt.navigateHome()},1e4);return()=>clearTimeout(V)}},[T,gt]),D.useEffect(()=>{const V=new URLSearchParams(window.location.search);(V.get("orderId")||V.get("transactionId"))&&Ye&&!Bt&&J("UPI")},[Ye,Bt,J]),D.useEffect(()=>{!Bt||!pt||!Ye||!ce&&!je&&!q&&J("UPI")},[Bt,pt,Ye,ce,je,q,J]),D.useEffect(()=>{if(Bt||Re||!Ye||Me.current||Ae.length===0)return;Me.current=!0;const V=()=>{const Yt=navigator.userAgent.toLowerCase();return Yt.includes("android")?"android":Yt.includes("iphone")||Yt.includes("ipad")||Yt.includes("ipod")?"ios":"web"},we=()=>Ue&&Ue>0?"salesman":ze&&ze.trim()!==""?"guest":"retailer",Ve=()=>le===zs.FUNDLY_COLLECT_APP?"collect_app":le===zs.FUNDLY_CUSTOMER_APP?"customer_app":le==="FUNDLY_QR_WEB"?"web":"external_app",Xe=()=>le===zs.FUNDLY_COLLECT_APP?"collect_app":le===zs.FUNDLY_CUSTOMER_APP?"customer_app":null,rt=()=>le==="FUNDLY_QR_WEB"?"invoice_qr":Pe==="INVOICE_COLLECT"?"invoice_pay_page":Pe==="DIRECT_COLLECT"?"direct_pay_page":"invoice_qr",qt=ot?.map(Yt=>Yt.invoiceId?.toString()||Yt.invoiceNumber?.toString()).filter(Boolean)||null,es=ut||`sdk_session_${Date.now()}_${Math.random().toString(36).substring(2,11)}`,hi={scan_id:_e||null,view_id:At||null,invoice_id:qt,supplier_id:fe?.toString()||"",erp_id:Ge||null,business_id:We||null,salesman_id:Ue?.toString()||null,user_type:we(),session_id:es,scan_channel:Xe(),scan_origin:Pe==="INVOICE_COLLECT"?"invoice":null,device_type:V(),payment_type:Pe==="INVOICE_COLLECT"?"invoice_pay":"direct_pay",payment_sdk_entry_point:rt(),payment_options:Ae,default_payment_option:null,payment_amount:Number(Ie)||0,is_payment_enabled:Ae.length>0,status:"success",failure_reason:null,error_code:null,error_description:null,failure_stage:null,sdk_version:"2.11.0-beta.8",app_context:Ve(),app_version:"2.11.0-beta.8",mobile_number:qe||null};ai.trackPaymentSDKLaunched(hi)},[Re,Ye,Bt,Ae,fe,We,ze,Ue,Ie,Pe,ot,le,_e,At,ut,Ge]);const tt=async()=>{C(!1),await Lt.navigateHome()},et=V=>{if(!V?.productRules||!Array.isArray(V.productRules))return{tenureMappings:[],repaymentOption:null,disbursementAccount:null};const we=Pe==="INVOICE_COLLECT"?"YES":"NO",Xe=V.productRules.find(rt=>rt.isInvoiceRequired===we&&rt.disbursementAccount==="SUPPLIER")||V.productRules[0];return{tenureMappings:Xe?.tenureMappings||[],repaymentOption:Xe?.repaymentOption||null,disbursementAccount:Xe?.disbursementAccount||null}};return T||gt?t.jsx("div",{style:{fontFamily:"Poppins"},className:"relative w-full h-screen flex items-center justify-center px-4 bg-[#F8FCFF]",children:t.jsxs("div",{className:"w-full max-w-md bg-white border border-red-100 rounded-2xl p-8 text-center shadow-lg",children:[t.jsx("div",{className:"w-16 h-16 mx-auto mb-4 bg-red-50 rounded-full flex items-center justify-center",children:t.jsx("svg",{className:"w-8 h-8 text-red-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})})}),t.jsx("h3",{className:"text-[20px] font-semibold text-gray-800 mb-3",children:"Authentication Failed"}),t.jsx("p",{className:"text-[14px] text-gray-600 mb-4",children:T||gt?.message||"We're unable to authenticate your session at the moment. Please try again later."}),t.jsx("p",{className:"text-[12px] text-gray-500",children:"This window will close automatically in a few seconds..."})]})}):Re?t.jsx(OA,{}):Bt?t.jsxs("div",{style:{fontFamily:"Poppins"},className:"relative w-full h-screen flex items-center justify-center bg-[#F8FCFF]",children:[t.jsx(bo,{open:ce,onClose:()=>{$(),h&&z&&h(z)},paymentData:z,buttonText:Le}),t.jsx(jo,{open:je,onClose:()=>{$(),o&&z&&o(z)},paymentData:z,buttonText:Qe}),t.jsx(Ll,{open:q,onClose:()=>$(),onPaymentCollected:V=>{Z(V)},onPaymentFailed:V=>{X(V)}})]}):t.jsxs("div",{style:{fontFamily:"Poppins"},className:"relative w-full h-screen pt-10 flex flex-col px-4 bg-[#F8FCFF]",children:[t.jsx("div",{className:"w-full h-10 flex items-center space-x-3",children:t.jsx("img",{src:me.backButton,alt:"Back",className:"w-4 h-4 cursor-pointer",onClick:()=>C(!0)})}),t.jsxs("div",{className:"w-full items-center text-center justify-between flex ",children:[t.jsx("h1",{className:"font-medium text-[20px] text-[#222222]",children:"Payment Options"}),t.jsxs("label",{className:"flex items-center text-[14px] cursor-pointer",onClick:()=>P(!0),children:[t.jsx("img",{src:me.QuestionMark,className:"w-4 h-4 mr-1"}),"Get Help"]})]}),t.jsx("div",{className:"flex-1 overflow-y-auto mb-12 mt-2",children:le==="FUNDLY_CUSTOMER_APP"&&!ue?t.jsx("div",{className:"w-full h-full flex items-center justify-center",children:t.jsxs("div",{className:"w-full max-w-md bg-white border border-gray-200 rounded-2xl p-8 text-center shadow-sm",children:[t.jsx("div",{className:"w-16 h-16 mx-auto mb-4 bg-gray-100 rounded-full flex items-center justify-center",children:t.jsx("svg",{className:"w-8 h-8 text-gray-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})})}),t.jsx("h3",{className:"text-[18px] font-semibold text-gray-800 mb-2",children:"Bank Details Not Available"}),t.jsx("p",{className:"text-[14px] text-gray-500",children:"We couldn't find bank details for this distributor. Please contact support for assistance."})]})}):t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"w-full border border-gray-100 bg-white rounded-xl p-4 mt-6 flex flex-col space-y-2",children:[t.jsxs("div",{className:"flex justify-between items-start",children:[t.jsxs("div",{className:"flex flex-col flex-1",children:[t.jsx("h4",{className:"text-[12px] font-normal text-gray-400",children:"Collect For"}),t.jsx("label",{className:"font-semibold text-[16px] text-[#222222]",children:pe})]}),t.jsxs("div",{className:"flex flex-col items-end flex-shrink-0",children:[t.jsx("h4",{className:"text-[12px] font-normal text-gray-400 text-right",children:"Collection Amount"}),t.jsxs("label",{className:"font-semibold text-[16px] text-[#222222]",children:["₹",xt(Ie)]})]})]}),(le==="FUNDLY_CUSTOMER_APP"||le==="FUNDLY_QR_WEB")&&ue&&t.jsxs("div",{className:"w-full mt-2",children:[t.jsxs("label",{className:"cursor-pointer select-none text-[#16558B] font-medium text-[12px]",onClick:()=>F(V=>!V),children:["Bank Details ",a?"▲":"▼"]}),a&&t.jsxs("div",{className:"w-full flex flex-col space-y-3 mt-2",children:[t.jsxs("div",{className:"flex flex-col ",children:[t.jsx("h4",{className:"text-[12px] font-normal text-gray-400",children:"Account Holder Name"}),t.jsx("label",{className:"text-[14px] font-medium text-[#222222]",children:ue.accountName})]}),t.jsxs("div",{className:"flex justify-between",children:[t.jsxs("div",{className:"flex flex-col space-y-1",children:[t.jsx("h4",{className:"text-[12px] font-normal text-gray-400",children:"Account Number"}),t.jsx("label",{className:"text-[14px] font-medium text-[#222222]",children:ue.accountNumber})]}),t.jsxs("div",{className:"flex flex-col space-y-1",children:[t.jsx("h4",{className:"text-[12px] font-normal text-gray-400",children:"IFSC Code"}),t.jsx("label",{className:"text-[14px] font-medium text-[#222222]",children:ue.ifsc})]})]})]})]})]}),Ae.includes(Bi.FUNDLY_PAY)&&(()=>{const V=Number(Ie??0),we=$e??1e3,Ve=Je??null;let Xe=null,rt=!1;V<we?(Xe=`Fundly Pay not available below ₹${we.toLocaleString("en-IN")} payment.`,rt=!0):Ve!==null&&V>Ve?(Xe=`Max Eligible Amount: ₹${xt(Ve)}`,rt=!0):nt&&(Xe=nt,rt=!0);let qt=[],es=0;Fe?.subLimits&&Array.isArray(Fe.subLimits)&&(qt=Fe.subLimits.filter(Pt=>Pt.expired===!1),qt.sort((Pt,di)=>{const js=Pt.maxEligibleAmount||Pt.availableLimit||0;return(di.maxEligibleAmount||di.availableLimit||0)-js}),qt.length>0&&(es=Math.max(...qt.map(Pt=>Pt.maxEligibleAmount||Pt.availableLimit||0))));const hi=qt.length>1,Yt=qt.length===1,Bn=qt.length===0;return t.jsxs("div",{className:"w-full flex flex-col mt-6",children:[t.jsx("h2",{className:"text-[16px] font-semibold",children:"Preferred Payment"}),t.jsxs("div",{className:"w-full flex flex-col mt-2",children:[t.jsxs("div",{className:`w-full border border-gray-100 ${rt?"bg-[#efefef]":"bg-white"} ${Xe||hi&&Ee||Yt?"rounded-t-xl":"rounded-xl"} ${rt?"":"cursor-pointer hover:shadow-2xs"} p-4 flex items-center justify-between`,onClick:()=>{if(!rt)if(hi)De(!Ee);else if(Yt){W(0),_(qt[0].fiCode);const Pt=et(qt[0]);re(Pt.tenureMappings),dt(Pt.repaymentOption),he(Pt.disbursementAccount),J("FUNDLY_PAY")}else J("FUNDLY_PAY")},children:[t.jsxs("div",{className:"flex items-center space-x-2",children:[t.jsx("img",{src:me.logo,className:"w-[32px] h-[32px]"}),t.jsx("label",{className:"text-[14px] font-medium cursor-pointer",children:"Fundly Pay"}),t.jsxs("div",{className:"flex items-center bg-[#34A877] py-1 px-3 rounded-4xl",children:[t.jsx("img",{src:me.primary,className:"w-3 h-3"}),t.jsx("label",{className:"text-[10px] font-medium text-white",children:"1 Click Payment"})]})]}),t.jsxs("div",{className:"flex items-center space-x-2",children:[!rt&&hi&&t.jsx("svg",{className:`w-5 h-5 text-[#16558B] transition-transform duration-200 ${Ee?"rotate-180":""}`,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"3",d:"M19 9l-7 7-7-7"})}),!rt&&!hi&&t.jsx("img",{src:me.cardOpener,className:"w-4 h-4"})]})]}),!rt&&Yt&&t.jsx("div",{className:"w-full bg-[#E6F7EF] flex p-2 text-[#34A877] rounded-b-xl border-x border-b border-gray-100",children:t.jsxs("label",{className:"text-[10px] font-medium",children:["Max Eligible Amount:"," ",t.jsxs("span",{className:"font-bold",children:["₹",xt(qt[0].maxEligibleAmount||qt[0].availableLimit||0)]})]})}),!rt&&hi&&!Ee&&t.jsx("div",{className:"w-[95%] m-auto bg-[#E6F7EF] flex p-2 text-[#34A877] rounded-b-xl border-x border-b border-gray-100",children:t.jsxs("label",{className:"text-[10px] font-medium",children:["Max Eligible Amount:"," ",t.jsxs("span",{className:"font-bold",children:["₹",xt(es)]})]})}),!rt&&hi&&Ee&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"w-full bg-white border-x border-gray-100 rounded-b-xl px-3 pt-3 pb-2 flex flex-col space-y-2.5",children:qt.map((Pt,di)=>{const js=Pt.maxEligibleAmount||Pt.availableLimit||0,pi=js<V;return t.jsx("button",{type:"button",disabled:pi,className:`w-full text-left focus:outline-none transition-all duration-150 ${pi?"cursor-not-allowed opacity-50":Te===di?"bg-[#EBF4FA]":"bg-white hover:border-[#16558B] cursor-pointer"}`,style:{fontFamily:"Poppins",paddingTop:"10px",paddingLeft:"10px",paddingBottom:"10px",paddingRight:"16px",borderRadius:"8px",borderWidth:"0.87px",borderStyle:"solid",borderColor:pi?"#E0E0E0":Te===di?"#C5DBED":"#E8EEF3",height:"35px",display:"flex",alignItems:"center"},onClick:()=>{if(!pi){W(di),_(Pt.fiCode);const Ms=et(Pt);re(Ms.tenureMappings),dt(Ms.repaymentOption),he(Ms.disbursementAccount),De(!1),J("FUNDLY_PAY")}},children:t.jsxs("div",{className:"flex justify-between items-center w-full",style:{lineHeight:"24px"},children:[t.jsx("span",{className:`font-medium ${pi?"text-gray-400":"text-[#16558B]"}`,style:{fontSize:"12px",letterSpacing:"0px",textTransform:"capitalize"},children:Pt.fiCode?.toLowerCase()}),t.jsxs("span",{className:`text-[12px] font-semibold ${pi?"text-gray-400":"text-[#000000]"}`,style:{letterSpacing:"0px",lineHeight:"100%"},children:["₹ ",xt(js)]})]})},di)})}),t.jsx("div",{className:"w-[95%] m-auto bg-[#E6F7EF] flex p-2 text-[#34A877] rounded-b-xl border-x border-b border-gray-100",children:t.jsxs("label",{style:{fontFamily:"Poppins"},children:[t.jsxs("span",{className:"text-[10px] font-medium",children:["Max Eligible Amount:"," "]}),t.jsxs("span",{className:"font-bold text-[10px]",children:["₹",xt(es)]})]})})]}),Xe&&Bn&&t.jsx("div",{className:"w-full bg-red-50 flex p-2 text-red-700 rounded-b-xl border-x border-b border-gray-100",children:t.jsx("label",{className:"text-[11px] ml-2",children:Xe})}),!Xe&&Bn&&Ve!==null&&t.jsx("div",{className:"w-full bg-green-50 flex p-2 text-green-700 rounded-b-xl border-x border-b border-gray-100",children:t.jsxs("label",{className:"text-[11px] ml-2",children:["Max Eligible Amount:"," ",t.jsxs("span",{className:"font-medium",children:["₹",xt(Ve)]})]})})]})]})})(),Ae.includes(Bi.UPI)&&t.jsxs("div",{className:"w-full mt-6 flex flex-col space-y-2",children:[t.jsxs("div",{className:"flex items-center space-x-2",children:[t.jsx("img",{src:me.upi,className:"h-[20px]",alt:"UPI Logo"}),t.jsx("h2",{className:"text-[16px] font-semibold",children:"Pay by UPI"})]}),t.jsxs("div",{className:"w-full border border-gray-100 bg-white hover:shadow-2xs cursor-pointer rounded-xl p-4 flex items-center justify-between",onClick:()=>J("UPI"),children:[t.jsxs("div",{className:"flex items-center space-x-2",children:[t.jsx("img",{src:me.upiIcon,className:"w-[32px] h-[32px]",alt:"UPI"}),t.jsx("label",{className:"text-[14px] font-medium text-[#222222]",children:"UPI"}),t.jsx("div",{className:"flex items-center bg-green-50 rounded-4xl py-1 px-2",children:t.jsx("label",{className:"text-[10px] text-green-700 font-medium",children:"₹ 0 charges"})})]}),t.jsx("img",{src:me.cardOpener,className:"w-4 h-4"})]})]}),Ae.includes(Bi.NETBANKING)&&t.jsxs("div",{className:"w-full mt-6 flex flex-col space-y-2",children:[t.jsx("h2",{className:"text-[16px] font-semibold",children:"Netbanking"}),t.jsxs("div",{className:"w-full border border-gray-100 bg-white hover:shadow-2xs cursor-pointer rounded-xl p-4 flex items-center justify-between",onClick:()=>J("NETBANKING"),children:[t.jsxs("div",{className:"flex items-center space-x-2",children:[t.jsx("img",{src:me.scanqrIcon,className:"w-[32px] h-[32px]"}),t.jsx("label",{className:"text-[14px] font-medium text-[#222222]",children:"Netbanking"})]}),t.jsx("img",{src:me.cardOpener,className:"w-4 h-4"})]})]}),Ae.includes(Bi.DYNAMIC_QR)&&!(le===zs.FUNDLY_CUSTOMER_APP&&Ae.includes(Bi.PAYMENT_LINK))&&t.jsxs("div",{className:"w-full mt-6 flex flex-col space-y-2",children:[t.jsx("h2",{className:"text-[16px] font-semibold",children:"Online Payment Options"}),t.jsxs("div",{className:"w-full border border-gray-100 bg-white hover:shadow-2xs cursor-pointer rounded-xl p-4 flex items-center justify-between",onClick:()=>J("DYNAMIC_QR"),children:[t.jsxs("div",{className:"flex items-center space-x-2",children:[t.jsx("img",{src:me.generateqrIcon,className:"w-[32px] h-[32px]"}),t.jsx("label",{className:"text-[14px] font-medium",children:"Generate QR"}),t.jsx("div",{className:"flex items-center bg-green-50 rounded-4xl py-1 px-2",children:t.jsx("label",{className:"text-[10px] text-green-700 font-medium",children:"₹ 0 charges"})})]}),t.jsx("img",{src:me.cardOpener,className:"w-4 h-4"})]}),Ae.includes(Bi.PAYMENT_LINK)&&le===zs.FUNDLY_COLLECT_APP&&t.jsxs("div",{className:"w-full border border-gray-100 bg-white hover:shadow-2xs cursor-pointer rounded-xl p-4 mt-2 flex items-center justify-between",onClick:()=>J("PAYMENT_LINK"),children:[t.jsxs("div",{className:"flex items-center space-x-2",children:[t.jsx("img",{src:me.paymentlinkIcon,className:"w-[32px] h-[32px]"}),t.jsx("label",{className:"text-[14px] font-medium",children:"Payment Link"}),t.jsx("div",{className:"flex items-center bg-green-50 rounded-4xl py-1 px-2",children:t.jsx("label",{className:"text-[10px] text-green-700 font-medium",children:"₹ 0 charges"})})]}),t.jsx("img",{src:me.cardOpener,className:"w-4 h-4"})]})]}),(Ae.includes(Bi.CASH)||Ae.includes(Bi.CHEQUE))&&t.jsxs("div",{className:"w-full mt-6 flex flex-col space-y-2",children:[t.jsx("h2",{className:"text-[16px] font-semibold",children:"More Payment Options"}),Ae.includes(Bi.CASH)&&t.jsxs("div",{className:"w-full border border-gray-100 bg-white hover:shadow-2xs cursor-pointer rounded-xl p-4 flex items-center justify-between",onClick:()=>J("CASH"),children:[t.jsxs("div",{className:"flex items-center space-x-2",children:[t.jsx("img",{src:me.cashIcon,className:"w-[32px] h-[32px]"}),t.jsx("label",{className:"text-[14px] font-medium text-[#222222]",children:"Cash"})]}),t.jsx("img",{src:me.cardOpener,className:"w-4 h-4"})]}),Ae.includes(Bi.CHEQUE)&&t.jsxs("div",{className:"w-full bg-white border border-gray-100 hover:shadow-2xs cursor-pointer rounded-xl p-4 mt-2 flex items-center justify-between",onClick:()=>J("CHEQUE"),children:[t.jsxs("div",{className:"flex items-center space-x-2",children:[t.jsx("img",{src:me.chequeIcon,className:"w-[32px] h-[32px]"}),t.jsx("label",{className:"text-[14px] font-medium text-[#222222]",children:"Cheque"})]}),t.jsx("img",{src:me.cardOpener,className:"w-4 h-4"})]})]})]})}),t.jsx(jA,{open:Ce,onClose:async()=>{$(),await Lt.navigateHome()},onPaymentCollected:V=>{Z(V)}}),t.jsx(Ll,{open:q,onClose:async()=>{$(),await Lt.navigateHome()},onPaymentCollected:V=>{Z(V)},onPaymentFailed:V=>{X(V)}}),t.jsx(BA,{open:ie,onClose:async()=>{$(),await Lt.navigateHome()},onPaymentCollected:V=>{Z(V)},onPaymentFailed:V=>{X(V)}}),t.jsx(ql,{open:xe,metadata:mt,onClose:async()=>{$(),await Lt.navigateHome()},onPaymentCollected:V=>{Z(V)}}),t.jsx(Vl,{open:Se,metadata:mt,onClose:async()=>{$(),await Lt.navigateHome()},onPaymentCollected:V=>{Z(V)}}),t.jsx(DA,{open:H,onClose:()=>{$()},onPaymentCollected:V=>{Z(V)},selectedLenderIdx:Te,selectedLenderFiCode:ye,selectedLenderTenureMappings:de,selectedLenderRepaymentOption:Be,selectedLenderDisbursementAccount:ge}),t.jsx(SA,{open:ve,onClose:async()=>{$(),await Lt.navigateHome()},onPaymentCollected:()=>{Z()}}),t.jsx(LA,{open:oe,onClose:async()=>{$(),await Lt.navigateHome()},onPaymentCollected:V=>{Z(V)},onPaymentFailed:V=>{X(V)}}),t.jsx(bo,{open:ce,onClose:()=>$(),paymentData:z,buttonText:Le}),t.jsx(jo,{open:je,onClose:()=>$(),paymentData:z,buttonText:Qe}),t.jsx(TA,{open:f,onClose:()=>C(!1),onConfirm:tt}),t.jsx(PA,{open:k,onClose:()=>P(!1)})]})},Kl=D.createContext(void 0);function Zl({children:h,initialValues:o}){Or(o?.environment??"production");const[f,C]=D.useState(o?.partnerCredentials||null),[a,F]=D.useState(o?.businessId||null),[k,P]=D.useState(o?.businessName||null),[T,Q]=D.useState(null),[z,J]=D.useState([]),[$,Z]=D.useState([]),[X,H]=D.useState([]),[q,oe]=D.useState(0),[Ce,ve]=D.useState("FULL"),[ie,xe]=D.useState(null),[Se,ce]=D.useState(o?.onPaymentComplete?()=>o.onPaymentComplete:void 0),[je,Ee]=D.useState(o?.onNavigateHome?()=>o.onNavigateHome:void 0),[De,Te]=D.useState(o?.sessionId||null),[W,ye]=D.useState(o?.erpId||null);D.useEffect(()=>{const de=Fr(),re=Pr();de&&ai.configure({enabled:!0,clevertap:{accountId:de,region:re}})},[]);const _={partnerCredentials:f,setPartnerCredentials:C,businessId:a,setBusinessId:F,businessName:k,setBusinessName:P,selectedLender:T,setSelectedLender:Q,lenderList:z,setLenderList:J,selectedLoans:$,setSelectedLoans:Z,loanList:X,setLoanList:H,totalAmount:q,setTotalAmount:oe,repaymentType:Ce,setRepaymentType:ve,redirectionUrl:ie,setRedirectionUrl:xe,onPaymentComplete:Se,setOnPaymentComplete:ce,onNavigateHome:je,setOnNavigateHome:Ee,sessionId:De,setSessionId:Te,erpId:W,setErpId:ye};return t.jsx(Kl.Provider,{value:_,children:h})}function Ln(){const h=D.useContext(Kl);if(!h)throw new Error("useRepaymentContext must be used within a RepaymentProvider");return h}const Nn={availableLimit:6e4,totalLimit:98e3,outstandingBalance:38e3},JA=({onSelectLender:h,onNavigateBack:o})=>{const{businessId:f,setLenderList:C}=Ln(),[a,F]=D.useState([]),[k,P]=D.useState(!0),[T,Q]=D.useState(null);D.useEffect(()=>{f&&z()},[f]);const z=async()=>{if(!f){Q("Business ID is required"),P(!1);return}try{P(!0),Q(null);const Z=await CA(f);F(Z),C(Z)}catch(Z){console.error("Error loading lenders:",Z);const X=Z?.response?.data?.errorMessage||Z?.response?.data?.message||Z?.message||"Failed to load lenders. Please try again.";Q(X)}finally{P(!1)}},J=Z=>new Date(Z).toLocaleDateString("en-IN",{day:"numeric",month:"short",year:"numeric"}),$=Nn.availableLimit/Nn.totalLimit*100;return k?t.jsx("div",{className:"flex items-center justify-center min-h-screen bg-gray-50",children:t.jsxs("div",{className:"text-center",children:[t.jsx("div",{className:"animate-spin rounded-full h-12 w-12 border-b-2 border-blue-600 mx-auto"}),t.jsx("p",{className:"mt-4 text-gray-600",children:"Loading lenders..."})]})}):T?t.jsxs("div",{className:"min-h-screen bg-gray-50",children:[t.jsx("div",{className:"bg-white border-b border-gray-200 sticky top-0 z-10",children:t.jsxs("div",{className:"flex items-center px-4 py-4",children:[t.jsx("button",{onClick:o,className:"mr-4 p-2 hover:bg-gray-100 rounded-full transition-colors",children:t.jsx("img",{src:me.backButton,alt:"Back",className:"w-6 h-6"})}),t.jsx("h1",{className:"text-xl font-semibold text-gray-900",children:"Fundly Pay"})]})}),t.jsx("div",{className:"flex items-center justify-center min-h-[calc(100vh-80px)] px-4",children:t.jsxs("div",{className:"text-center max-w-md",children:[t.jsx("div",{className:"w-20 h-20 mx-auto mb-4 bg-red-100 rounded-full flex items-center justify-center",children:t.jsx("svg",{className:"w-10 h-10 text-red-600",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})})}),t.jsx("h2",{className:"text-xl font-semibold text-gray-900 mb-2",children:"Error Loading Lenders"}),t.jsx("p",{className:"text-gray-600 mb-6",children:T}),t.jsx("button",{onClick:z,className:"bg-blue-600 hover:bg-blue-700 text-white font-semibold py-3 px-6 rounded-xl transition-colors",children:"Try Again"})]})})]}):t.jsxs("div",{className:"min-h-screen bg-gray-50 pb-24",children:[t.jsx("div",{className:"bg-white border-b border-gray-200 sticky top-0 z-10",children:t.jsxs("div",{className:"flex items-center px-4 py-4",children:[t.jsx("button",{onClick:o,className:"mr-4 p-2 hover:bg-gray-100 rounded-full transition-colors",children:t.jsx("img",{src:me.backButton,alt:"Back",className:"w-6 h-6"})}),t.jsx("h1",{className:"text-xl font-semibold text-gray-900",children:"Fundly Pay"})]})}),t.jsxs("div",{className:"px-4 py-6 space-y-4",children:[t.jsxs("div",{className:"bg-gradient-to-br from-blue-50 to-blue-100 rounded-2xl p-6 shadow-sm relative overflow-visible",children:[t.jsxs("div",{className:"relative z-10 pr-24",children:[t.jsx("p",{className:"text-sm text-gray-700 mb-2",children:"Your Available Limit"}),t.jsxs("div",{className:"flex items-baseline space-x-2 mb-4",children:[t.jsx("span",{className:"text-3xl font-bold text-blue-900",children:xt(Nn.availableLimit)}),t.jsxs("span",{className:"text-lg text-gray-600",children:["/ ",xt(Nn.totalLimit)]})]}),t.jsx("div",{className:"w-full bg-gray-300 rounded-full h-2 mb-4",children:t.jsx("div",{className:"bg-blue-600 h-2 rounded-full transition-all duration-500",style:{width:`${$}%`}})}),t.jsxs("div",{children:[t.jsx("p",{className:"text-sm text-gray-700 mb-1",children:"Outstanding Balance"}),t.jsx("p",{className:"text-2xl font-bold text-red-600",children:xt(Nn.outstandingBalance)})]})]}),t.jsx("div",{className:"absolute right-3 bottom-3 border-2 border-dashed border-blue-400 rounded-lg p-1.5 bg-white/70 shadow-sm",children:t.jsx("img",{src:me.billy13,alt:"Credit",className:"w-20 h-20 object-contain"})})]}),t.jsx("div",{className:"space-y-3",children:a.map(Z=>t.jsx("button",{onClick:()=>h(Z),className:"w-full bg-white rounded-xl p-5 shadow-sm hover:shadow-md transition-all active:scale-98 border border-gray-100",children:t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsxs("div",{className:"flex-1 text-left",children:[t.jsx("h3",{className:"text-lg font-semibold text-gray-900 mb-1",children:Z.lenderName}),t.jsxs("p",{className:"text-sm text-gray-500",children:["Upcoming Due: ",J(Z.nextDueDate)]})]}),t.jsxs("div",{className:"flex-shrink-0 ml-4 text-right",children:[t.jsx("p",{className:"text-xl font-bold text-gray-900",children:xt(Z.outstandingAmount)}),t.jsxs("p",{className:"text-xs text-gray-500 mt-1",children:[Z.loanCount," ",Z.loanCount===1?"loan":"loans"]})]})]})},Z.lenderId))}),a.length===0&&!k&&t.jsxs("div",{className:"text-center py-12",children:[t.jsx("div",{className:"text-gray-400 mb-4",children:t.jsx("svg",{className:"w-20 h-20 mx-auto",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})})}),t.jsx("p",{className:"text-gray-600 font-medium",children:"No loans found"}),t.jsx("p",{className:"text-sm text-gray-500 mt-2",children:"You don't have any active loans at the moment"})]})]}),t.jsx("div",{className:"fixed bottom-8 left-0 right-0 flex justify-end px-4 pointer-events-none",children:t.jsxs("button",{onClick:()=>{console.log("Navigate to transaction history")},className:"bg-blue-600 hover:bg-blue-700 text-white font-semibold py-3.5 px-8 rounded-full transition-colors shadow-lg hover:shadow-xl active:scale-95 flex items-center gap-3 pointer-events-auto",children:[t.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})}),"Transaction"]})})]})},HA=({onNavigateBack:h,onSelectLoans:o,onViewLoanDetails:f})=>{const{businessId:C,selectedLender:a,setLoanList:F}=Ln(),[k,P]=D.useState([]),[T,Q]=D.useState(new Set),[z,J]=D.useState(!0),[$,Z]=D.useState(null),[X,H]=D.useState("");D.useEffect(()=>{C&&a&&q()},[C,a]);const q=async()=>{if(!C||!a){Z("Business ID and lender are required"),J(!1);return}try{J(!0),Z(null);const ie=await yA(C,a.lenderId);P(ie),F(ie)}catch(ie){console.error("Error loading loans:",ie);const xe=ie?.response?.data?.errorMessage||ie?.response?.data?.message||ie?.message||"Failed to load loans. Please try again.";Z(xe)}finally{J(!1)}},oe=ie=>new Date(ie).toLocaleDateString("en-IN",{day:"numeric",month:"short",year:"numeric"}),Ce=ie=>{const xe=new Set(T);xe.has(ie)?xe.delete(ie):xe.add(ie),Q(xe);const Se=k.filter(ce=>xe.has(ce.loanId)).reduce((ce,je)=>ce+je.outstandingAmount,0);H(Se.toFixed(2))},ve=()=>{const ie=k.filter(xe=>T.has(xe.loanId));o(ie)};return z?t.jsx("div",{className:"flex items-center justify-center min-h-screen bg-gray-50",children:t.jsxs("div",{className:"text-center",children:[t.jsx("div",{className:"animate-spin rounded-full h-12 w-12 border-b-2 border-blue-600 mx-auto"}),t.jsx("p",{className:"mt-4 text-gray-600",children:"Loading loans..."})]})}):$?t.jsxs("div",{className:"min-h-screen bg-gray-50",children:[t.jsx("div",{className:"bg-white border-b border-gray-200 sticky top-0 z-10",children:t.jsxs("div",{className:"flex items-center px-4 py-4",children:[t.jsx("button",{onClick:h,className:"mr-4 p-2 hover:bg-gray-100 rounded-full transition-colors",children:t.jsx("img",{src:me.backButton,alt:"Back",className:"w-6 h-6"})}),t.jsx("h1",{className:"text-xl font-semibold text-gray-900",children:a?.lenderName||"Loans"})]})}),t.jsx("div",{className:"flex items-center justify-center min-h-[calc(100vh-80px)] px-4",children:t.jsxs("div",{className:"text-center max-w-md",children:[t.jsx("div",{className:"w-20 h-20 mx-auto mb-4 bg-red-100 rounded-full flex items-center justify-center",children:t.jsx("svg",{className:"w-10 h-10 text-red-600",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})})}),t.jsx("h2",{className:"text-xl font-semibold text-gray-900 mb-2",children:"Error Loading Loans"}),t.jsx("p",{className:"text-gray-600 mb-6",children:$}),t.jsx("button",{onClick:q,className:"bg-blue-600 hover:bg-blue-700 text-white font-semibold py-3 px-6 rounded-xl transition-colors",children:"Try Again"})]})})]}):t.jsxs("div",{className:"min-h-screen bg-gray-50 pb-24",children:[t.jsx("div",{className:"bg-white border-b border-gray-200 sticky top-0 z-10",children:t.jsxs("div",{className:"flex items-center px-4 py-4",children:[t.jsx("button",{onClick:h,className:"mr-4 p-2 hover:bg-gray-100 rounded-full transition-colors",children:t.jsx("img",{src:me.backButton,alt:"Back",className:"w-6 h-6"})}),t.jsx("h1",{className:"text-xl font-semibold text-gray-900",children:a?.lenderName||"Loans"})]})}),t.jsxs("div",{className:"px-4 py-6 space-y-3",children:[k.map(ie=>{const xe=T.has(ie.loanId);return t.jsx("div",{className:`bg-white rounded-xl shadow-sm border transition-all ${xe?"border-blue-500 ring-2 ring-blue-100":"border-gray-100 hover:border-gray-300"}`,children:t.jsx("div",{className:"p-5",children:t.jsxs("div",{className:"flex items-start",children:[t.jsx("button",{onClick:()=>Ce(ie.loanId),className:"flex-shrink-0 mr-4 mt-1",children:t.jsx("div",{className:`w-6 h-6 rounded border-2 flex items-center justify-center transition-colors ${xe?"bg-blue-600 border-blue-600":"border-gray-300 bg-white"}`,children:xe&&t.jsx("svg",{className:"w-4 h-4 text-white",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:3,d:"M5 13l4 4L19 7"})})})}),t.jsx("div",{className:"flex-1",children:t.jsxs("button",{onClick:()=>f(ie),className:"w-full text-left",children:[t.jsx("h3",{className:"text-lg font-semibold text-blue-600 underline mb-1",children:ie.loanNumber}),t.jsxs("p",{className:"text-sm text-gray-500",children:["Due: ",oe(ie.dueDate)]})]})}),t.jsx("div",{className:"flex-shrink-0 ml-4 text-right",children:t.jsx("p",{className:"text-xl font-bold text-gray-900",children:xt(ie.outstandingAmount)})})]})})},ie.loanId)}),k.length===0&&!z&&t.jsxs("div",{className:"text-center py-12",children:[t.jsx("div",{className:"text-gray-400 mb-4",children:t.jsx("svg",{className:"w-20 h-20 mx-auto",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})})}),t.jsx("p",{className:"text-gray-600 font-medium",children:"No loans found"}),t.jsx("p",{className:"text-sm text-gray-500 mt-2",children:"This lender doesn't have any active loans"})]})]}),T.size>0&&t.jsx("div",{className:"fixed bottom-0 left-0 right-0 bg-white border-t border-gray-200 p-4 shadow-lg",children:t.jsx("div",{className:"max-w-md mx-auto",children:t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsxs("div",{className:"flex-1",children:[t.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Custom Amount"}),t.jsxs("div",{className:"relative",children:[t.jsx("span",{className:"absolute left-4 top-1/2 -translate-y-1/2 text-gray-500 text-lg",children:"₹"}),t.jsx("input",{type:"text",inputMode:"decimal",value:X,onChange:ie=>{const xe=ie.target.value.replace(/[^0-9.]/g,"");H(xe)},className:"w-full pl-8 pr-4 py-4 text-lg font-semibold border-2 border-gray-300 rounded-xl focus:outline-none focus:border-blue-500 transition-colors",placeholder:"0.00"})]})]}),t.jsx("div",{className:"flex-shrink-0 pt-7",children:t.jsx("button",{onClick:ve,disabled:!X||parseFloat(X)<=0,className:"bg-blue-600 hover:bg-blue-700 disabled:bg-gray-300 disabled:cursor-not-allowed text-white font-semibold py-4 px-8 rounded-xl transition-colors shadow-md active:scale-98 whitespace-nowrap",children:"Pay now"})})]})})})]})},WA=({loan:h,onNavigateBack:o})=>{const{businessId:f}=Ln(),[C,a]=D.useState(!1),[F,k]=D.useState([]),[P,T]=D.useState(null);D.useEffect(()=>{(async()=>{if(h.loanType==="BULLET"&&f)try{const J=await vA(h.loanId,f);k(J)}catch(J){console.error("Error loading partial payments:",J),k([])}})()},[h.loanId,h.loanType,f]),D.useEffect(()=>{(async()=>{try{const J=await bA(h.loanId);T(J)}catch(J){console.error("Error loading payment details:",J),T(null)}})()},[h.loanId]);const Q=z=>new Date(z).toLocaleDateString("en-IN",{day:"numeric",month:"short",year:"numeric"});return t.jsxs("div",{className:"min-h-screen bg-gray-50",children:[t.jsx("div",{className:"bg-white border-b border-gray-200 sticky top-0 z-10",children:t.jsxs("div",{className:"flex items-center justify-between px-4 py-4",children:[t.jsxs("div",{className:"flex items-center flex-1",children:[t.jsx("button",{onClick:o,className:"mr-4 p-2 hover:bg-gray-100 rounded-full transition-colors",children:t.jsx("img",{src:me.backButton,alt:"Back",className:"w-6 h-6"})}),t.jsx("h1",{className:"text-xl font-semibold text-gray-900",children:h.loanNumber})]}),t.jsxs("button",{className:"flex items-center space-x-2 px-4 py-2 text-blue-600 hover:bg-blue-50 rounded-lg transition-colors",children:[t.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8.228 9c.549-1.165 2.03-2 3.772-2 2.21 0 4 1.343 4 3 0 1.4-1.278 2.575-3.006 2.907-.542.104-.994.54-.994 1.093m0 3h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),t.jsx("span",{className:"text-sm font-medium",children:"Get Help"})]})]})}),t.jsxs("div",{className:"px-4 py-6 space-y-6",children:[t.jsxs("div",{className:"bg-white rounded-2xl p-6 shadow-sm border border-gray-100",children:[t.jsxs("div",{className:"flex items-center space-x-3 mb-6",children:[t.jsx("div",{className:"w-12 h-12 bg-blue-100 rounded-full flex items-center justify-center",children:t.jsx("svg",{className:"w-6 h-6 text-blue-600",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8c-1.657 0-3 .895-3 2s1.343 2 3 2 3 .895 3 2-1.343 2-3 2m0-8c1.11 0 2.08.402 2.599 1M12 8V7m0 1v8m0 0v1m0-1c-1.11 0-2.08-.402-2.599-1M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})})}),t.jsx("h2",{className:"text-lg font-semibold text-gray-900",children:"Loan Details"})]}),t.jsxs("div",{className:"grid grid-cols-2 gap-4 mb-6",children:[t.jsxs("div",{children:[t.jsx("p",{className:"text-sm text-gray-600 mb-1",children:"Disbursed"}),t.jsx("p",{className:"text-xl font-bold text-gray-900",children:xt(h.disbursedAmount)})]}),t.jsxs("div",{children:[t.jsx("p",{className:"text-sm text-gray-600 mb-1",children:"Current O/S"}),t.jsx("p",{className:"text-xl font-bold text-blue-600",children:xt(h.outstandingAmount)})]})]}),t.jsxs("div",{className:"grid grid-cols-3 gap-4 mb-6",children:[t.jsxs("div",{children:[t.jsx("p",{className:"text-sm text-gray-600 mb-1",children:"Principal"}),t.jsx("p",{className:"text-lg font-semibold text-gray-900",children:xt(h.principalOutstanding)})]}),t.jsxs("div",{children:[t.jsx("p",{className:"text-sm text-gray-600 mb-1",children:"Interest"}),t.jsx("p",{className:"text-lg font-semibold text-gray-900",children:xt(h.interestOutstanding)})]}),t.jsxs("div",{children:[t.jsx("p",{className:"text-sm text-gray-600 mb-1",children:"Charges"}),t.jsx("p",{className:"text-lg font-semibold text-gray-900",children:xt(h.chargesOutstanding)})]})]}),t.jsxs("div",{className:"border-t border-gray-200 pt-4",children:[t.jsxs("div",{className:"grid grid-cols-2 gap-4 mb-4",children:[t.jsxs("div",{children:[t.jsx("p",{className:"text-sm text-gray-600 mb-1",children:"Tenure"}),t.jsxs("p",{className:"text-base font-semibold text-gray-900",children:[h.tenure," ",h.tenureUnit==="DAYS"?"Days":"Months"]})]}),t.jsxs("div",{children:[t.jsx("p",{className:"text-sm text-gray-600 mb-1",children:"Due on"}),t.jsx("p",{className:"text-base font-semibold text-gray-900",children:Q(h.dueDate)})]})]}),t.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[t.jsxs("div",{children:[t.jsx("p",{className:"text-sm text-gray-600 mb-1",children:"Lender"}),t.jsx("p",{className:"text-base font-semibold text-gray-900",children:h.lenderName})]}),t.jsxs("div",{children:[t.jsx("p",{className:"text-sm text-gray-600 mb-1",children:"UTR No"}),t.jsx("p",{className:"text-base font-semibold text-gray-900",children:h.utrNumber})]})]})]})]}),P&&t.jsxs("div",{className:"bg-white rounded-2xl p-6 shadow-sm border border-gray-100",children:[t.jsx("h2",{className:"text-lg font-semibold text-gray-900 mb-4",children:"Supplier Details"}),t.jsxs("div",{className:"space-y-4",children:[t.jsxs("div",{className:"flex justify-between items-center",children:[t.jsx("p",{className:"text-sm text-gray-600",children:"Supplier Name"}),t.jsx("p",{className:"text-base font-semibold text-gray-900",children:P.supplierName})]}),t.jsxs("div",{className:"flex justify-between items-center",children:[t.jsx("p",{className:"text-sm text-gray-600",children:"Supplier ID"}),t.jsx("p",{className:"text-base font-semibold text-gray-900",children:P.supplierId})]})]})]}),P&&P.invoices.length>0&&t.jsxs("div",{className:"bg-white rounded-2xl p-6 shadow-sm border border-gray-100",children:[t.jsx("h2",{className:"text-lg font-semibold text-gray-900 mb-4",children:"Invoice Details"}),t.jsx("div",{className:"overflow-x-auto",children:t.jsxs("table",{className:"w-full",children:[t.jsx("thead",{children:t.jsxs("tr",{className:"bg-gray-100 text-left",children:[t.jsx("th",{className:"px-4 py-3 text-sm font-semibold text-gray-700 rounded-tl-lg",children:"Invoice No."}),t.jsx("th",{className:"px-4 py-3 text-sm font-semibold text-gray-700 text-right",children:"OS Amt"}),t.jsx("th",{className:"px-4 py-3 text-sm font-semibold text-gray-700 text-right rounded-tr-lg",children:"Paid Amt"})]})}),t.jsx("tbody",{className:"divide-y divide-gray-200",children:P.invoices.map((z,J)=>t.jsxs("tr",{children:[t.jsx("td",{className:"px-4 py-3 text-sm text-gray-900",children:z.invoiceNo}),t.jsx("td",{className:"px-4 py-3 text-sm text-gray-900 text-right",children:xt(z.osAmount)}),t.jsx("td",{className:"px-4 py-3 text-sm text-gray-900 text-right",children:xt(z.paidAmount)})]},J))})]})})]}),t.jsxs("div",{className:"bg-white rounded-2xl shadow-sm border border-gray-100 overflow-hidden",children:[t.jsxs("button",{onClick:()=>a(!C),className:"w-full p-6 flex items-center justify-between hover:bg-gray-50 transition-colors",children:[t.jsxs("div",{className:"flex items-center space-x-3",children:[t.jsx("div",{className:"w-12 h-12 bg-blue-100 rounded-full flex items-center justify-center",children:t.jsx("svg",{className:"w-6 h-6 text-blue-600",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"})})}),t.jsx("h2",{className:"text-lg font-semibold text-gray-900",children:"Partial Payment History"})]}),t.jsx("svg",{className:`w-6 h-6 text-gray-400 transition-transform ${C?"rotate-180":""}`,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),C&&t.jsxs("div",{className:"px-6 pb-6 space-y-4",children:[F.map((z,J)=>t.jsxs("div",{className:"bg-gray-50 rounded-lg p-4",children:[t.jsxs("div",{className:"flex justify-between items-start mb-3",children:[t.jsxs("div",{children:[t.jsx("p",{className:"text-sm text-gray-600",children:"Payment Date"}),t.jsx("p",{className:"text-base font-semibold text-gray-900",children:Q(z.paymentDate)})]}),t.jsxs("div",{className:"text-right",children:[t.jsx("p",{className:"text-sm text-gray-600",children:"Amount"}),t.jsx("p",{className:"text-lg font-bold text-blue-600",children:xt(z.amount)})]})]}),t.jsxs("div",{className:"grid grid-cols-3 gap-4 text-sm",children:[t.jsxs("div",{children:[t.jsx("p",{className:"text-gray-600",children:"Principal"}),t.jsx("p",{className:"font-semibold text-gray-900",children:xt(z.principalPaid)})]}),t.jsxs("div",{children:[t.jsx("p",{className:"text-gray-600",children:"Interest"}),t.jsx("p",{className:"font-semibold text-gray-900",children:xt(z.interestPaid)})]}),t.jsxs("div",{children:[t.jsx("p",{className:"text-gray-600",children:"Charges"}),t.jsx("p",{className:"font-semibold text-gray-900",children:xt(z.chargesPaid)})]})]}),t.jsx("div",{className:"mt-2 pt-2 border-t border-gray-200",children:t.jsxs("p",{className:"text-xs text-gray-500",children:["TXN ID: ",z.transactionId]})})]},J)),F.length===0&&t.jsx("p",{className:"text-center text-gray-500 py-4",children:"No partial payments made yet"})]})]})]})]})},XA=({selectedLoans:h,onNavigateBack:o,onPaymentComplete:f})=>{const{selectedLender:C,businessId:a}=Ln(),{paymentData:F,openPaymentDrawer:k,closeDrawer:P,handlePaymentSuccess:T,showCashDrawer:Q,showChequeDrawer:z,showSuccessDrawer:J,showFailureDrawer:$}=Gl(),Z=D.useMemo(()=>h.reduce((oe,Ce)=>oe+Ce.outstandingAmount,0),[h]),X=D.useMemo(()=>({type:"repayment",businessId:a||"",lenderId:C?.lenderId||"",lenderName:C?.lenderName||"",loanIds:h.map(oe=>oe.loanId),amount:Z,repaymentType:"FULL"}),[a,C,h,Z]),H=()=>{P(),f&&F?.transactionId&&f(F.transactionId)},q=[{id:"CASH",name:"Cash",icon:me.cashIcon,available:!0},{id:"CHEQUE",name:"Cheque",icon:me.chequeIcon,available:!0},{id:"UPI",name:"UPI",icon:me.upiIcon,available:!1},{id:"NETBANKING",name:"Netbanking",icon:me.Gateway,available:!1}];return t.jsxs("div",{className:"min-h-screen bg-gray-50",children:[t.jsx("div",{className:"bg-white border-b border-gray-200 sticky top-0 z-10",children:t.jsxs("div",{className:"flex items-center px-4 py-4",children:[t.jsx("button",{onClick:o,className:"mr-4 p-2 hover:bg-gray-100 rounded-full transition-colors",children:t.jsx("img",{src:me.backButton,alt:"Back",className:"w-6 h-6"})}),t.jsx("h1",{className:"text-xl font-semibold text-gray-900",children:"Repayment"})]})}),t.jsxs("div",{className:"px-4 py-6 space-y-6",children:[t.jsxs("div",{className:"bg-gradient-to-br from-blue-50 to-blue-100 rounded-2xl p-6 shadow-sm",children:[t.jsxs("div",{className:"mb-4",children:[t.jsx("p",{className:"text-sm text-gray-700 mb-1",children:"Lender"}),t.jsx("p",{className:"text-xl font-bold text-gray-900",children:C?.lenderName})]}),t.jsxs("div",{className:"bg-white/60 backdrop-blur rounded-xl p-4 mb-4",children:[t.jsx("p",{className:"text-sm text-gray-700 mb-1",children:"Selected Loans"}),t.jsxs("p",{className:"text-lg font-semibold text-gray-900",children:[h.length," ",h.length===1?"loan":"loans"]}),t.jsx("div",{className:"mt-2 space-y-1 max-h-32 overflow-y-auto",children:h.map(oe=>t.jsxs("p",{className:"text-xs text-gray-600",children:[oe.loanNumber," - ",xt(oe.outstandingAmount)]},oe.loanId))})]}),t.jsxs("div",{className:"bg-white rounded-xl p-4",children:[t.jsx("p",{className:"text-sm text-gray-700 mb-2",children:"Total Amount to Pay"}),t.jsx("p",{className:"text-3xl font-bold text-blue-600",children:xt(Z)})]})]}),t.jsxs("div",{children:[t.jsx("h2",{className:"text-lg font-semibold text-gray-900 mb-4",children:"Select Payment Method"}),t.jsx("div",{className:"grid grid-cols-2 gap-3",children:q.map(oe=>t.jsxs("button",{onClick:()=>oe.available&&k(oe.id),disabled:!oe.available,className:`bg-white rounded-xl p-5 shadow-sm transition-all border border-gray-100 flex flex-col items-center ${oe.available?"hover:shadow-md active:scale-95":"opacity-50 cursor-not-allowed"}`,children:[t.jsx("div",{className:"w-12 h-12 mb-3",children:t.jsx("img",{src:oe.icon,alt:oe.name,className:"w-full h-full object-contain"})}),t.jsx("p",{className:"text-sm font-semibold text-gray-900",children:oe.name}),!oe.available&&t.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"Coming soon"})]},oe.id))})]})]}),t.jsx(ql,{open:Q,metadata:X,onClose:P,onPaymentCollected:T}),t.jsx(Vl,{open:z,metadata:X,onClose:P,onPaymentCollected:T}),t.jsx(bo,{open:J,onClose:H,paymentData:F,buttonText:"Done"}),t.jsx(jo,{open:$,onClose:P,paymentData:F,buttonText:"Try Again"})]})},qA=({onNavigateHome:h,onPaymentComplete:o})=>{const{setSelectedLender:f,setSelectedLoans:C}=Ln(),[a,F]=D.useState("lenderList"),[k,P]=D.useState([]),[T,Q]=D.useState(null),z=oe=>{f(oe),F("loanList")},J=()=>{F("lenderList"),f(null)},$=oe=>{P(oe),C(oe),F("payment")},Z=oe=>{console.log("Payment completed:",oe),o&&o(oe),F("lenderList"),f(null),P([])},X=()=>{F("loanList")},H=oe=>{Q(oe),F("loanDetails")},q=()=>{F("loanList"),Q(null)};switch(a){case"lenderList":return t.jsx(JA,{onSelectLender:z,onNavigateBack:h});case"loanList":return t.jsx(HA,{onNavigateBack:J,onSelectLoans:$,onViewLoanDetails:H});case"loanDetails":return T?t.jsx(WA,{loan:T,onNavigateBack:q}):(F("loanList"),null);case"payment":return t.jsx(XA,{selectedLoans:k,onNavigateBack:X,onPaymentComplete:Z});default:return null}},_l=D.createContext(void 0);function $l({children:h,initialValues:o}){Or(o?.environment??"production");const[f,C]=D.useState(o?.partnerCredentials||null),[a,F]=D.useState(o?.businessId||null),[k,P]=D.useState(o?.businessName||null),[T,Q]=D.useState([]),[z,J]=D.useState(null),[$,Z]=D.useState(o?.filters||null),[X,H]=D.useState(o?.defaultTab||"all"),[q,oe]=D.useState(1),[Ce,ve]=D.useState(!0),[ie,xe]=D.useState(!1),[Se,ce]=D.useState(o?.onNavigateHome?()=>o.onNavigateHome:void 0),[je,Ee]=D.useState(o?.sessionId||null),[De,Te]=D.useState(o?.erpId||null);D.useEffect(()=>{const ye=Fr(),_=Pr();ye&&ai.configure({enabled:!0,clevertap:{accountId:ye,region:_}})},[]);const W={partnerCredentials:f,setPartnerCredentials:C,businessId:a,setBusinessId:F,businessName:k,setBusinessName:P,transactions:T,setTransactions:Q,selectedTransaction:z,setSelectedTransaction:J,filter:$,setFilter:Z,activeTab:X,setActiveTab:H,currentPage:q,setCurrentPage:oe,hasMore:Ce,setHasMore:ve,isLoading:ie,setIsLoading:xe,onNavigateHome:Se,setOnNavigateHome:ce,sessionId:je,setSessionId:Ee,erpId:De,setErpId:Te};return t.jsx(_l.Provider,{value:W,children:h})}function YA(){const h=D.useContext(_l);if(!h)throw new Error("useTransactionContext must be used within a TransactionProvider");return h}const VA=({onNavigateBack:h,onViewTransaction:o})=>{const{businessId:f}=YA(),[C,a]=D.useState([]),[F,k]=D.useState(!0),[P,T]=D.useState(null),[Q,z]=D.useState("all"),[J,$]=D.useState(""),[Z,X]=D.useState("all"),[H,q]=D.useState(1),[oe,Ce]=D.useState(!1),[ve,ie]=D.useState(0);D.useEffect(()=>{f&&xe()},[f,Q,Z,H]);const xe=async()=>{if(!f){T("Business ID is required"),k(!1);return}try{k(!0),T(null);const ye=await IA({businessId:f,filter:{type:Q,status:Z,searchQuery:J||void 0},page:H,limit:20});a(ye.transactions),ie(ye.totalCount),Ce(ye.hasMore)}catch(W){console.error("Error loading transactions:",W);const ye=W?.response?.data?.errorMessage||W?.response?.data?.message||W?.message||"Failed to load transactions. Please try again.";T(ye)}finally{k(!1)}},Se=()=>{q(1),xe()},ce=W=>{z(W),q(1)},je=W=>{X(W),q(1)},Ee=W=>new Date(W).toLocaleDateString("en-IN",{day:"numeric",month:"short",year:"numeric",hour:"2-digit",minute:"2-digit"}),De=W=>{switch(W.toUpperCase()){case"SUCCESS":return"bg-green-100 text-green-700";case"PENDING":return"bg-yellow-100 text-yellow-700";case"FAILED":return"bg-red-100 text-red-700";default:return"bg-gray-100 text-gray-700"}},Te=W=>{switch(W){case"LOAN_REPAYMENT":return"Loan Repayment";case"SUPPLIER_PAYMENT":return"Supplier Payment";default:return W}};return F&&H===1?t.jsx("div",{className:"flex items-center justify-center min-h-screen bg-gray-50",children:t.jsxs("div",{className:"text-center",children:[t.jsx("div",{className:"animate-spin rounded-full h-12 w-12 border-b-2 border-blue-600 mx-auto"}),t.jsx("p",{className:"mt-4 text-gray-600",children:"Loading transactions..."})]})}):P?t.jsxs("div",{className:"min-h-screen bg-gray-50",children:[t.jsx("div",{className:"bg-white border-b border-gray-200 sticky top-0 z-10",children:t.jsxs("div",{className:"flex items-center px-4 py-4",children:[t.jsx("button",{onClick:h,className:"mr-4 p-2 hover:bg-gray-100 rounded-full transition-colors",children:t.jsx("img",{src:me.backButton,alt:"Back",className:"w-6 h-6"})}),t.jsx("h1",{className:"text-xl font-semibold text-gray-900",children:"Transaction History"})]})}),t.jsx("div",{className:"flex items-center justify-center min-h-[calc(100vh-80px)] px-4",children:t.jsxs("div",{className:"text-center max-w-md",children:[t.jsx("div",{className:"w-20 h-20 mx-auto mb-4 bg-red-100 rounded-full flex items-center justify-center",children:t.jsx("svg",{className:"w-10 h-10 text-red-600",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})})}),t.jsx("h2",{className:"text-xl font-semibold text-gray-900 mb-2",children:"Error Loading Transactions"}),t.jsx("p",{className:"text-gray-600 mb-6",children:P}),t.jsx("button",{onClick:xe,className:"bg-blue-600 hover:bg-blue-700 text-white font-semibold py-3 px-6 rounded-xl transition-colors",children:"Try Again"})]})})]}):t.jsxs("div",{className:"min-h-screen bg-gray-50 pb-24",children:[t.jsxs("div",{className:"bg-white border-b border-gray-200 sticky top-0 z-20",children:[t.jsxs("div",{className:"flex items-center px-4 py-4",children:[t.jsx("button",{onClick:h,className:"mr-4 p-2 hover:bg-gray-100 rounded-full transition-colors",children:t.jsx("img",{src:me.backButton,alt:"Back",className:"w-6 h-6"})}),t.jsx("h1",{className:"text-xl font-semibold text-gray-900",children:"Transaction History"})]}),t.jsxs("div",{className:"flex border-t border-gray-200",children:[t.jsx("button",{onClick:()=>ce("all"),className:`flex-1 py-3 text-sm font-medium transition-colors ${Q==="all"?"text-blue-600 border-b-2 border-blue-600":"text-gray-600 hover:text-gray-900"}`,children:"All"}),t.jsx("button",{onClick:()=>ce("fundly"),className:`flex-1 py-3 text-sm font-medium transition-colors ${Q==="fundly"?"text-blue-600 border-b-2 border-blue-600":"text-gray-600 hover:text-gray-900"}`,children:"Fundly"}),t.jsx("button",{onClick:()=>ce("distributor"),className:`flex-1 py-3 text-sm font-medium transition-colors ${Q==="distributor"?"text-blue-600 border-b-2 border-blue-600":"text-gray-600 hover:text-gray-900"}`,children:"Distributor"})]})]}),t.jsxs("div",{className:"bg-white border-b border-gray-200 p-4 space-y-3",children:[t.jsxs("div",{className:"flex space-x-2",children:[t.jsxs("div",{className:"flex-1 relative",children:[t.jsx("input",{type:"text",placeholder:"Search by transaction ID, lender, supplier...",value:J,onChange:W=>$(W.target.value),onKeyPress:W=>W.key==="Enter"&&Se(),className:"w-full pl-10 pr-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500"}),t.jsx("svg",{className:"absolute left-3 top-2.5 w-5 h-5 text-gray-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})})]}),t.jsx("button",{onClick:Se,className:"px-6 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors",children:"Search"})]}),t.jsx("div",{className:"flex space-x-2 overflow-x-auto pb-2",children:["all","success","pending","failed"].map(W=>t.jsx("button",{onClick:()=>je(W),className:`px-4 py-2 rounded-full text-sm font-medium whitespace-nowrap transition-colors ${Z===W?"bg-blue-600 text-white":"bg-gray-100 text-gray-700 hover:bg-gray-200"}`,children:W.charAt(0).toUpperCase()+W.slice(1)},W))})]}),t.jsx("div",{className:"px-4 py-6 space-y-3",children:C.length===0&&!F?t.jsxs("div",{className:"text-center py-12",children:[t.jsx("div",{className:"text-gray-400 mb-4",children:t.jsx("svg",{className:"w-20 h-20 mx-auto",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})})}),t.jsx("p",{className:"text-gray-600 font-medium",children:"No transactions found"}),t.jsx("p",{className:"text-sm text-gray-500 mt-2",children:J?"Try adjusting your search or filters":"Your transaction history will appear here"})]}):t.jsxs(t.Fragment,{children:[C.map(W=>t.jsxs("button",{onClick:()=>o(W),className:"w-full bg-white rounded-xl p-4 shadow-sm hover:shadow-md transition-all border border-gray-100 text-left",children:[t.jsxs("div",{className:"flex items-start justify-between mb-2",children:[t.jsxs("div",{className:"flex-1",children:[t.jsx("h3",{className:"text-base font-semibold text-gray-900 mb-1",children:W.lenderName||W.supplierName||"N/A"}),t.jsx("p",{className:"text-xs text-gray-500",children:Ee(W.date)})]}),t.jsxs("div",{className:"text-right",children:[t.jsx("p",{className:"text-lg font-bold text-gray-900",children:xt(W.amount)}),t.jsx("span",{className:`inline-block px-2 py-1 rounded-full text-xs font-medium mt-1 ${De(W.status)}`,children:W.status})]})]}),t.jsxs("div",{className:"flex items-center justify-between text-sm",children:[t.jsx("span",{className:"text-gray-600",children:Te(W.transactionType)}),t.jsx("span",{className:"text-gray-600",children:W.paymentMode})]}),t.jsxs("div",{className:"mt-2 text-xs text-gray-500",children:["TXN ID: ",W.transactionId]})]},W.transactionId)),oe&&t.jsx("div",{className:"flex justify-center pt-4",children:t.jsx("button",{onClick:()=>q(H+1),disabled:F,className:"px-6 py-3 bg-blue-600 text-white rounded-xl hover:bg-blue-700 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:F?"Loading...":"Load More"})}),t.jsxs("div",{className:"text-center text-sm text-gray-500 pt-4",children:["Showing ",C.length," of ",ve," transactions"]})]})})]})},GA=({transaction:h,onNavigateBack:o})=>{const[f,C]=D.useState(!1),a=T=>new Date(T).toLocaleDateString("en-IN",{day:"numeric",month:"short",year:"numeric",hour:"2-digit",minute:"2-digit"}),F=T=>{switch(T.toUpperCase()){case"SUCCESS":return"bg-green-100 text-green-700";case"PENDING":return"bg-yellow-100 text-yellow-700";case"FAILED":return"bg-red-100 text-red-700";default:return"bg-gray-100 text-gray-700"}},k=h.transactionType==="LOAN_REPAYMENT",P=h.transactionType==="SUPPLIER_PAYMENT";return t.jsxs("div",{className:"min-h-screen bg-gray-50",children:[t.jsx("div",{className:"bg-white border-b border-gray-200 sticky top-0 z-10",children:t.jsxs("div",{className:"flex items-center px-4 py-4",children:[t.jsx("button",{onClick:o,className:"mr-4 p-2 hover:bg-gray-100 rounded-full transition-colors",children:t.jsx("img",{src:me.backButton,alt:"Back",className:"w-6 h-6"})}),t.jsx("h1",{className:"text-xl font-semibold text-gray-900",children:"Transaction Details"})]})}),t.jsxs("div",{className:"px-4 py-6 space-y-4",children:[t.jsxs("div",{className:`rounded-2xl p-6 shadow-sm ${h.status==="SUCCESS"?"bg-gradient-to-br from-green-50 to-green-100":h.status==="PENDING"?"bg-gradient-to-br from-yellow-50 to-yellow-100":"bg-gradient-to-br from-red-50 to-red-100"}`,children:[t.jsx("div",{className:"flex items-center justify-center mb-4",children:t.jsx("div",{className:`w-16 h-16 rounded-full flex items-center justify-center ${h.status==="SUCCESS"?"bg-green-200":h.status==="PENDING"?"bg-yellow-200":"bg-red-200"}`,children:t.jsx("svg",{className:`w-8 h-8 ${h.status==="SUCCESS"?"text-green-600":h.status==="PENDING"?"text-yellow-600":"text-red-600"}`,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:h.status==="SUCCESS"?t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"}):h.status==="PENDING"?t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"}):t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})}),t.jsxs("div",{className:"text-center",children:[t.jsx("p",{className:"text-4xl font-bold text-gray-900 mb-2",children:xt(h.amount)}),t.jsx("span",{className:`inline-block px-4 py-2 rounded-full text-sm font-semibold ${F(h.status)}`,children:h.status})]})]}),t.jsxs("div",{className:"bg-white rounded-2xl p-6 shadow-sm border border-gray-100",children:[t.jsx("h2",{className:"text-lg font-semibold text-gray-900 mb-4",children:"Transaction Information"}),t.jsxs("div",{className:"space-y-3",children:[t.jsxs("div",{className:"flex justify-between items-center pb-3 border-b border-gray-100",children:[t.jsx("span",{className:"text-sm text-gray-600",children:"Transaction ID"}),t.jsx("span",{className:"text-sm font-semibold text-gray-900",children:h.transactionId})]}),t.jsxs("div",{className:"flex justify-between items-center pb-3 border-b border-gray-100",children:[t.jsx("span",{className:"text-sm text-gray-600",children:"Date & Time"}),t.jsx("span",{className:"text-sm font-semibold text-gray-900",children:a(h.date)})]}),t.jsxs("div",{className:"flex justify-between items-center pb-3 border-b border-gray-100",children:[t.jsx("span",{className:"text-sm text-gray-600",children:"Payment Mode"}),t.jsx("span",{className:"text-sm font-semibold text-gray-900",children:h.paymentMode})]}),h.paymentChannel&&t.jsxs("div",{className:"flex justify-between items-center pb-3 border-b border-gray-100",children:[t.jsx("span",{className:"text-sm text-gray-600",children:"Payment Channel"}),t.jsx("span",{className:"text-sm font-semibold text-gray-900",children:h.paymentChannel})]})]})]}),k&&t.jsxs("div",{className:"bg-white rounded-2xl p-6 shadow-sm border border-gray-100",children:[t.jsx("h2",{className:"text-lg font-semibold text-gray-900 mb-4",children:"Loan Repayment Details"}),t.jsxs("div",{className:"space-y-3",children:[t.jsxs("div",{className:"flex justify-between items-center pb-3 border-b border-gray-100",children:[t.jsx("span",{className:"text-sm text-gray-600",children:"Lender Name"}),t.jsx("span",{className:"text-sm font-semibold text-gray-900",children:h.lenderName})]}),t.jsxs("div",{className:"pb-3 border-b border-gray-100",children:[t.jsx("span",{className:"text-sm text-gray-600 block mb-2",children:"Loan IDs"}),t.jsx("div",{className:"space-y-1",children:h.loanIds?.map(T=>t.jsx("div",{className:"text-sm font-semibold text-gray-900 bg-gray-50 rounded px-3 py-2",children:T},T))})]})]})]}),P&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"bg-white rounded-2xl p-6 shadow-sm border border-gray-100",children:[t.jsx("h2",{className:"text-lg font-semibold text-gray-900 mb-4",children:"Supplier Details"}),t.jsx("div",{className:"space-y-3",children:t.jsxs("div",{className:"flex justify-between items-center pb-3 border-b border-gray-100",children:[t.jsx("span",{className:"text-sm text-gray-600",children:"Supplier Name"}),t.jsx("span",{className:"text-sm font-semibold text-gray-900",children:h.supplierName})]})})]}),h.invoiceDetails&&t.jsxs("div",{className:"bg-white rounded-2xl shadow-sm border border-gray-100 overflow-hidden",children:[t.jsxs("button",{onClick:()=>C(!f),className:"w-full p-6 flex items-center justify-between hover:bg-gray-50 transition-colors",children:[t.jsxs("div",{className:"flex items-center space-x-3",children:[t.jsx("div",{className:"w-12 h-12 bg-blue-100 rounded-full flex items-center justify-center",children:t.jsx("svg",{className:"w-6 h-6 text-blue-600",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})})}),t.jsx("h2",{className:"text-lg font-semibold text-gray-900",children:"Invoice Details"})]}),t.jsx("svg",{className:`w-6 h-6 text-gray-400 transition-transform ${f?"rotate-180":""}`,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),f&&t.jsx("div",{className:"px-6 pb-6",children:t.jsx("div",{className:"overflow-x-auto",children:t.jsxs("table",{className:"w-full",children:[t.jsx("thead",{children:t.jsxs("tr",{className:"bg-gray-100 text-left",children:[t.jsx("th",{className:"px-4 py-3 text-sm font-semibold text-gray-700 rounded-tl-lg",children:"Invoice No."}),t.jsx("th",{className:"px-4 py-3 text-sm font-semibold text-gray-700 text-right",children:"Paid Amount"}),t.jsx("th",{className:"px-4 py-3 text-sm font-semibold text-gray-700 text-right rounded-tr-lg",children:"Status"})]})}),t.jsx("tbody",{className:"divide-y divide-gray-200",children:h.invoiceDetails.map((T,Q)=>t.jsxs("tr",{children:[t.jsx("td",{className:"px-4 py-3 text-sm text-gray-900",children:T.invoiceNumber}),t.jsx("td",{className:"px-4 py-3 text-sm text-gray-900 text-right",children:xt(T.paidAmount)}),t.jsx("td",{className:"px-4 py-3 text-sm text-right",children:t.jsx("span",{className:`inline-block px-2 py-1 rounded-full text-xs font-medium ${T.status==="FULLY_PAID"?"bg-green-100 text-green-700":"bg-yellow-100 text-yellow-700"}`,children:T.status||"PAID"})})]},Q))})]})})})]})]}),t.jsx("div",{className:"pt-4",children:t.jsxs("button",{className:"w-full flex items-center justify-center space-x-2 px-4 py-3 text-blue-600 hover:bg-blue-50 rounded-xl transition-colors border border-blue-200",children:[t.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8.228 9c.549-1.165 2.03-2 3.772-2 2.21 0 4 1.343 4 3 0 1.4-1.278 2.575-3.006 2.907-.542.104-.994.54-.994 1.093m0 3h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),t.jsx("span",{className:"text-sm font-medium",children:"Need Help with this Transaction?"})]})})]})]})},KA=({onNavigateHome:h})=>{const[o,f]=D.useState("list"),[C,a]=D.useState(null),F=P=>{a(P),f("details")},k=()=>{f("list"),a(null)};switch(o){case"list":return t.jsx(VA,{onNavigateBack:h,onViewTransaction:F});case"details":return C?t.jsx(GA,{transaction:C,onNavigateBack:k}):(f("list"),null);default:return null}};function e0({config:h,onPaymentCollected:o,onPaymentFailed:f}){return t.jsx(Hl,{initialValues:h,children:t.jsx(UA,{onPaymentCollected:o,onPaymentFailed:f})})}const ZA=e0;function _A({config:h,onPaymentComplete:o,onNavigateHome:f}){const C=()=>{f?f():console.warn("RepaymentFlow: onNavigateHome callback not provided")};return t.jsx(Zl,{initialValues:{...h,onPaymentComplete:o,onNavigateHome:C},children:t.jsx(qA,{onNavigateHome:C,onPaymentComplete:o})})}function $A({config:h,onNavigateHome:o}){const f=()=>{o?o():console.warn("TransactionHistory: onNavigateHome callback not provided")};return t.jsx($l,{initialValues:{...h,onNavigateHome:f},children:t.jsx(KA,{onNavigateHome:f})})}exports.CleverTapProvider=Fl;exports.CollectionFlow=ZA;exports.PaymentOptionPage=e0;exports.PaymentProvider=Hl;exports.RepaymentFlow=_A;exports.RepaymentProvider=Zl;exports.TransactionHistory=$A;exports.TransactionProvider=$l;exports.analyticsService=ai;exports.getAccessToken=it;exports.sdkConfig=Lt;exports.setAccessToken=Do;
|
|
665
|
+
`})]}),kA=({size:h=24,color:o="currentColor",className:f,style:C})=>t.jsx("svg",{width:h,height:h,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:f,style:C,"aria-hidden":"true",children:t.jsx("path",{d:"M22 16.92V19.92C22.0011 20.1985 21.9441 20.4742 21.8325 20.7293C21.7209 20.9845 21.5573 21.2136 21.3521 21.4019C21.1468 21.5901 20.9046 21.7335 20.6407 21.8227C20.3769 21.9119 20.0974 21.9451 19.82 21.92C16.7428 21.5856 13.787 20.5341 11.19 18.85C8.77382 17.3147 6.72533 15.2662 5.18999 12.85C3.49997 10.2412 2.44824 7.27099 2.11999 4.18C2.095 3.90347 2.12787 3.62476 2.21649 3.36162C2.30512 3.09849 2.44756 2.85669 2.63476 2.65162C2.82196 2.44655 3.0498 2.28271 3.30379 2.17052C3.55777 2.05833 3.83233 2.00026 4.10999 2H7.10999C7.5953 1.99522 8.06579 2.16708 8.43376 2.48353C8.80173 2.79999 9.04207 3.23945 9.10999 3.72C9.23662 4.68007 9.47144 5.62273 9.80999 6.53C9.94454 6.88792 9.97366 7.27691 9.89384 7.65088C9.81401 8.02485 9.62892 8.36811 9.35999 8.64L8.08999 9.91C9.51355 12.4135 11.5864 14.4864 14.09 15.91L15.36 14.64C15.6319 14.3711 15.9751 14.186 16.3491 14.1062C16.7231 14.0263 17.1121 14.0555 17.47 14.19C18.3773 14.5286 19.3199 14.7634 20.28 14.89C20.7658 14.9585 21.2094 15.2032 21.5265 15.5775C21.8437 15.9518 22.0122 16.4296 22 16.92Z",stroke:o,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}),FA=({size:h=24,color:o="currentColor",className:f,style:C})=>t.jsxs("svg",{width:h,height:h,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:f,style:C,"aria-hidden":"true",children:[t.jsx("path",{d:"M4 4H20C21.1 4 22 4.9 22 6V18C22 19.1 21.1 20 20 20H4C2.9 20 2 19.1 2 18V6C2 4.9 2.9 4 4 4Z",stroke:o,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),t.jsx("path",{d:"M22 6L12 13L2 6",stroke:o,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]}),Nr={PHONE:"+91-9892422528",EMAIL:"connect@fundly.ai"},Bi={FUNDLY_PAY:"FUNDLY_PAY",DYNAMIC_QR:"DYNAMIC_QR",PAYMENT_LINK:"PAYMENT_LINK",CASH:"CASH",CHEQUE:"CHEQUE",UPI:"UPI",NETBANKING:"NETBANKING"},zs={FUNDLY_CUSTOMER_APP:"FUNDLY_CUSTOMER_APP",FUNDLY_COLLECT_APP:"FUNDLY_COLLECT_APP"},PA=({open:h,onClose:o})=>{const f=C=>{navigator.clipboard.writeText(C)};return t.jsx(Di,{open:h,onClose:o,children:t.jsxs("div",{className:"w-full flex flex-col px-8 py-4 space-y-4 mt-2 mb-12",children:[t.jsx("div",{className:"w-full flex items-center justify-end",children:t.jsx("img",{src:me.closingCross,className:"w-4 h-4 cursor-pointer",onClick:o,alt:"Close"})}),t.jsx("img",{src:me.customerSup,className:"w-14 h-14",alt:"Support"}),t.jsxs("div",{className:"flex space-x-6 items-center",children:[t.jsx(kA,{size:24,color:"#16558B"}),t.jsx("span",{className:"font-semibold",children:Nr.PHONE}),t.jsx("img",{src:me.copy,className:"w-5 h-5 cursor-pointer",onClick:()=>f(Nr.PHONE),alt:"Copy"})]}),t.jsxs("div",{className:"flex space-x-6 items-center",children:[t.jsx(FA,{size:24,color:"#16558B"}),t.jsx("span",{className:"font-semibold",children:Nr.EMAIL}),t.jsx("img",{src:me.copy,className:"w-5 h-5 cursor-pointer",onClick:()=>f(Nr.EMAIL),alt:"Copy"})]})]})})},TA=({open:h,onClose:o,onConfirm:f})=>t.jsxs(Ai,{open:h,onClose:o,children:[t.jsx(_i,{children:t.jsx("div",{className:"w-full flex justify-end",children:t.jsx("img",{src:me.closingCross,className:"w-4 h-4 cursor-pointer",onClick:o,alt:"Close"})})}),t.jsx(xi,{children:t.jsxs("div",{style:{fontFamily:"Poppins"},className:"w-full flex flex-col justify-center items-center",children:[t.jsx("img",{src:me.paymentLeave,className:"w-18 h-18",alt:"Leave"}),t.jsx("span",{className:"text-[18px] text-wrap font-bold text-center",children:"Leave this page?"}),t.jsx("span",{className:"text-[14px] text-wrap font-semibold text-center text-[#6D6D6D]",children:"Any unsaved payment details will be lost."})]})}),t.jsx(Ni,{children:t.jsxs("div",{style:{fontFamily:"Poppins"},className:"w-full flex justify-between px-3 mb-3 gap-3",children:[t.jsx("button",{className:"flex-1 w-[96px] h-[48px] border-2 border-gray-400 text-gray-400 rounded-xl",onClick:f,children:"Yes, Leave"}),t.jsx("button",{className:"flex-1 w-[96px] h-[48px] bg-[#16558B] text-white rounded-xl",onClick:o,children:"No"})]})})]}),zA=()=>{const{partnerCredentials:h}=ci(),[o,f]=D.useState(null),[C,a]=D.useState(!1),[F,k]=D.useState(null);return{login:D.useCallback(async()=>{a(!0),k(null);try{if(!h)throw new Error("Partner credentials not provided");const T={loginType:"PARTNER",username:h.username,password:h.password},Q=await xA(T);if(Q?.accessToken){const z=Q.accessToken;return Do(z),f(z),z}throw new Error("No access token received")}catch(T){const Q=T instanceof Error?T:new Error("Login failed");throw k(Q),Q}finally{a(!1)}},[h]),token:o,isLoading:C,error:F}},RA=h=>{const{setChemistId:o,setLeadId:f,setDistributorIdnum:C,setTypeOfApp:a,setPaymentInvoice:F,setPayableValue:k,setInvoices:P,setPaymentType:T,setSalesmanId:Q,distributorIdnum:z,chemistId:J,leadId:$}=ci(),Z=D.useRef(!1);D.useEffect(()=>{const X=oe=>{if(typeof oe.data!="object"||oe.data===null||oe.source!==window||oe.data?.source==="react-devtools-content-script"||oe.source!==window||oe.data?.source?.includes("react-devtools")||oe.origin!==window.origin)return;const{source:Ce,distributorId:ve,chemistId:ie,paymentType:xe,payableAmount:Se,invoices:ce,paymentInvoice:je,salesmanId:Ee}=oe.data;ve&&C(ve),ie&&o(ie),Ce&&a(Ce),Array.isArray(je)&&F(je),Se&&k(Se),Array.isArray(ce)&&P(ce),xe&&T(xe),Ee&&Q(Ee),Z.current||(h(),Z.current=!0)},H=J&&J.trim()!=="",q=$&&$.trim()!=="";return z&&(H||q)&&!Z.current&&(h(),Z.current=!0),window.addEventListener("message",X),()=>window.removeEventListener("message",X)},[h,o,f,C,a,F,k,P,T,Q,z,J,$])},QA=h=>{const{distributorIdnum:o,typeOfApp:f,chemistId:C,leadId:a,payableValue:F,salesmanId:k,paymentType:P,setDistributorName:T,setChemistName:Q,setPayerMobileNumber:z,setSalesmanPhoneNumber:J,setTenureMappings:$,setFiCode:Z,setDrawdownRepaymentOption:X,setCreditLimitData:H}=ci(),[q,oe]=D.useState([]),[Ce,ve]=D.useState(null),[ie,xe]=D.useState(null),[Se,ce]=D.useState(null),[je,Ee]=D.useState(null),[De,Te]=D.useState(!0);return D.useEffect(()=>{h&&(async()=>{const ye={distributorBusinessId:o,source:f,...C&&C.trim()!==""&&{chemistBusinessId:C},...a&&a.trim()!==""&&{leadId:a},payableAmount:F,...k&&{salesmanId:k},...P&&{collectType:P}};try{const _=await pA(ye);ve(_.bankDetails),_.bankDetails&&(T(_.bankDetails.distributorName||""),Q(_.bankDetails.chemistName||""),z(_.bankDetails.mobileNumber||""),J(_.bankDetails.salesmanPhoneNumber||""));const de=_.paymentOption.find(Be=>Be.name==="FUNDLY_PAY");de?.details?.tenureMappings&&$(de.details.tenureMappings),xe(de?.details?.maxEligibleLimit??null),ce(de?.details?.minEligibleLimit??null),Ee(de?.reason??null),de?.details?.fiCode&&Z(de.details.fiCode),de?.details?.drawdownRepaymentOption&&X(de.details.drawdownRepaymentOption);const re=_.paymentOption.filter(Be=>Be.isActive).map(Be=>Be.name);if(oe(re),de?.isActive&&_.bankDetails?.chemistBusinessId)try{const Be=await fA(_.bankDetails.chemistBusinessId);H(Be)}catch(Be){console.warn("Credit limit filter API failed:",Be),H(null)}Te(!1)}catch{Te(!1)}})()},[h]),{paymentOptions:q,bankDetails:Ce,maxEligibleLimit:ie,minEligibleLimit:Se,fundlyPayReason:je,loading:De}};function Gl(){const[h,o]=D.useState({activeDrawer:null,paymentData:null}),f=D.useCallback(P=>{o({activeDrawer:P,paymentData:null})},[]),C=D.useCallback(()=>{o({activeDrawer:null,paymentData:null})},[]),a=D.useCallback(P=>{o({activeDrawer:"SUCCESS",paymentData:P||null})},[]),F=D.useCallback(P=>{o({activeDrawer:"FAILURE",paymentData:P||null})},[]),k=D.useCallback(P=>h.activeDrawer===P,[h.activeDrawer]);return{activeDrawer:h.activeDrawer,paymentData:h.paymentData,openPaymentDrawer:f,closeDrawer:C,isDrawerOpen:k,handlePaymentSuccess:a,handlePaymentFailure:F,showFundlyPayDrawer:k("FUNDLY_PAY"),showUpiDrawer:k("UPI"),showDynamicQrDrawer:k("DYNAMIC_QR"),showStaticQrDrawer:k("STATIC_QR"),showPaymentLinkDrawer:k("PAYMENT_LINK"),showNetbankingDrawer:k("NETBANKING"),showCashDrawer:k("CASH"),showChequeDrawer:k("CHEQUE"),showSuccessDrawer:k("SUCCESS"),showFailureDrawer:k("FAILURE")}}const UA=({onPaymentCollected:h,onPaymentFailed:o})=>{const[f,C]=D.useState(!1),[a,F]=D.useState(!1),[k,P]=D.useState(!1),[T,Q]=D.useState(null),{paymentData:z,openPaymentDrawer:J,closeDrawer:$,handlePaymentSuccess:Z,handlePaymentFailure:X,showFundlyPayDrawer:H,showUpiDrawer:q,showDynamicQrDrawer:oe,showStaticQrDrawer:Ce,showPaymentLinkDrawer:ve,showNetbankingDrawer:ie,showCashDrawer:xe,showChequeDrawer:Se,showSuccessDrawer:ce,showFailureDrawer:je}=Gl(),[Ee,De]=D.useState(!1),[Te,W]=D.useState(-1),[ye,_]=D.useState(null),[de,re]=D.useState([]),[Be,dt]=D.useState(null),[ge,he]=D.useState(null),Me=D.useRef(!1),{distributorName:pe,distributorIdnum:fe,payableValue:Ie,typeOfApp:le,transactionId:pt,showResultOnly:Bt,successButtonText:Le,failureButtonText:Qe,creditLimitData:Fe,paymentType:Pe,paymentInvoice:ot,chemistId:We,leadId:ze,salesmanId:Ue,payerMobileNumber:qe,scanId:_e,viewId:At,sessionId:ut,erpId:Ge}=ci(),mt=D.useMemo(()=>({type:"collection",distributorId:fe||"",chemistId:We||void 0,leadId:ze||void 0,invoices:ot||[],paymentType:Pe||"INVOICE_COLLECT",salesmanId:Ue||void 0,payerMobileNumber:qe||void 0}),[fe,We,ze,ot,Pe,Ue,qe]),{login:at,token:Ye,error:gt}=zA(),ft=D.useCallback(async()=>{try{await at(),Q(null)}catch(V){const we=V instanceof Error?V.message:"Authentication failed. Please try again later.";Q(we)}},[at]);RA(ft);const{paymentOptions:Ae,bankDetails:ue,maxEligibleLimit:Je,minEligibleLimit:$e,fundlyPayReason:nt,loading:Re}=QA(Ye);D.useEffect(()=>{if(!Bt&&!pt){const V=new URLSearchParams(window.location.search);if((V.has("orderId")||V.has("transactionId"))&&!Ye){const Ve=new URL(window.location.href);Ve.searchParams.delete("orderId"),Ve.searchParams.delete("transactionId"),window.history.replaceState({},"",Ve.toString())}}},[Bt,Ye,pt]),D.useEffect(()=>{if(T||gt){const V=setTimeout(async()=>{await Lt.navigateHome()},1e4);return()=>clearTimeout(V)}},[T,gt]),D.useEffect(()=>{const V=new URLSearchParams(window.location.search);(V.get("orderId")||V.get("transactionId"))&&Ye&&!Bt&&J("UPI")},[Ye,Bt,J]),D.useEffect(()=>{!Bt||!pt||!Ye||!ce&&!je&&!q&&J("UPI")},[Bt,pt,Ye,ce,je,q,J]),D.useEffect(()=>{if(Bt||Re||!Ye||Me.current||Ae.length===0)return;Me.current=!0;const V=()=>{const Yt=navigator.userAgent.toLowerCase();return Yt.includes("android")?"android":Yt.includes("iphone")||Yt.includes("ipad")||Yt.includes("ipod")?"ios":"web"},we=()=>Ue&&Ue>0?"salesman":ze&&ze.trim()!==""?"guest":"retailer",Ve=()=>le===zs.FUNDLY_COLLECT_APP?"collect_app":le===zs.FUNDLY_CUSTOMER_APP?"customer_app":le==="FUNDLY_QR_WEB"?"web":"external_app",Xe=()=>le===zs.FUNDLY_COLLECT_APP?"collect_app":le===zs.FUNDLY_CUSTOMER_APP?"customer_app":null,rt=()=>le==="FUNDLY_QR_WEB"?"invoice_qr":Pe==="INVOICE_COLLECT"?"invoice_pay_page":Pe==="DIRECT_COLLECT"?"direct_pay_page":"invoice_qr",qt=ot?.map(Yt=>Yt.invoiceId?.toString()||Yt.invoiceNumber?.toString()).filter(Boolean)||null,es=ut||`sdk_session_${Date.now()}_${Math.random().toString(36).substring(2,11)}`,hi={scan_id:_e||null,view_id:At||null,invoice_id:qt,supplier_id:fe?.toString()||"",erp_id:Ge||null,business_id:We||null,salesman_id:Ue?.toString()||null,user_type:we(),session_id:es,scan_channel:Xe(),scan_origin:Pe==="INVOICE_COLLECT"?"invoice":null,device_type:V(),payment_type:Pe==="INVOICE_COLLECT"?"invoice_pay":"direct_pay",payment_sdk_entry_point:rt(),payment_options:Ae,default_payment_option:null,payment_amount:Number(Ie)||0,is_payment_enabled:Ae.length>0,status:"success",failure_reason:null,error_code:null,error_description:null,failure_stage:null,sdk_version:"2.11.0-beta.8",app_context:Ve(),app_version:"2.11.0-beta.8",mobile_number:qe||null};ai.trackPaymentSDKLaunched(hi)},[Re,Ye,Bt,Ae,fe,We,ze,Ue,Ie,Pe,ot,le,_e,At,ut,Ge]);const tt=async()=>{C(!1),await Lt.navigateHome()},et=V=>{if(!V?.productRules||!Array.isArray(V.productRules))return{tenureMappings:[],repaymentOption:null,disbursementAccount:null};const we=Pe==="INVOICE_COLLECT"?"YES":"NO",Xe=V.productRules.find(rt=>rt.isInvoiceRequired===we&&rt.disbursementAccount==="SUPPLIER")||V.productRules[0];return{tenureMappings:Xe?.tenureMappings||[],repaymentOption:Xe?.repaymentOption||null,disbursementAccount:Xe?.disbursementAccount||null}};return T||gt?t.jsx("div",{style:{fontFamily:"Poppins"},className:"relative w-full h-screen flex items-center justify-center px-4 bg-[#F8FCFF]",children:t.jsxs("div",{className:"w-full max-w-md bg-white border border-red-100 rounded-2xl p-8 text-center shadow-lg",children:[t.jsx("div",{className:"w-16 h-16 mx-auto mb-4 bg-red-50 rounded-full flex items-center justify-center",children:t.jsx("svg",{className:"w-8 h-8 text-red-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})})}),t.jsx("h3",{className:"text-[20px] font-semibold text-gray-800 mb-3",children:"Authentication Failed"}),t.jsx("p",{className:"text-[14px] text-gray-600 mb-4",children:T||gt?.message||"We're unable to authenticate your session at the moment. Please try again later."}),t.jsx("p",{className:"text-[12px] text-gray-500",children:"This window will close automatically in a few seconds..."})]})}):Re?t.jsx(OA,{}):Bt?t.jsxs("div",{style:{fontFamily:"Poppins"},className:"relative w-full h-screen flex items-center justify-center bg-[#F8FCFF]",children:[t.jsx(bo,{open:ce,onClose:()=>{$(),h&&z&&h(z)},paymentData:z,buttonText:Le}),t.jsx(jo,{open:je,onClose:()=>{$(),o&&z&&o(z)},paymentData:z,buttonText:Qe}),t.jsx(Ll,{open:q,onClose:()=>$(),onPaymentCollected:V=>{Z(V)},onPaymentFailed:V=>{X(V)}})]}):t.jsxs("div",{style:{fontFamily:"Poppins"},className:"relative w-full h-screen pt-10 flex flex-col px-4 bg-[#F8FCFF]",children:[t.jsx("div",{className:"w-full h-10 flex items-center space-x-3",children:t.jsx("img",{src:me.backButton,alt:"Back",className:"w-4 h-4 cursor-pointer",onClick:()=>C(!0)})}),t.jsxs("div",{className:"w-full items-center text-center justify-between flex ",children:[t.jsx("h1",{className:"font-medium text-[20px] text-[#222222]",children:"Payment Options"}),t.jsxs("label",{className:"flex items-center text-[14px] cursor-pointer",onClick:()=>P(!0),children:[t.jsx("img",{src:me.QuestionMark,className:"w-4 h-4 mr-1"}),"Get Help"]})]}),t.jsx("div",{className:"flex-1 overflow-y-auto mb-12 mt-2",children:le==="FUNDLY_CUSTOMER_APP"&&!ue?t.jsx("div",{className:"w-full h-full flex items-center justify-center",children:t.jsxs("div",{className:"w-full max-w-md bg-white border border-gray-200 rounded-2xl p-8 text-center shadow-sm",children:[t.jsx("div",{className:"w-16 h-16 mx-auto mb-4 bg-gray-100 rounded-full flex items-center justify-center",children:t.jsx("svg",{className:"w-8 h-8 text-gray-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})})}),t.jsx("h3",{className:"text-[18px] font-semibold text-gray-800 mb-2",children:"Bank Details Not Available"}),t.jsx("p",{className:"text-[14px] text-gray-500",children:"We couldn't find bank details for this distributor. Please contact support for assistance."})]})}):t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"w-full border border-gray-100 bg-white rounded-xl p-4 mt-6 flex flex-col space-y-2",children:[t.jsxs("div",{className:"flex justify-between items-start",children:[t.jsxs("div",{className:"flex flex-col flex-1",children:[t.jsx("h4",{className:"text-[12px] font-normal text-gray-400",children:"Collect For"}),t.jsx("label",{className:"font-semibold text-[16px] text-[#222222]",children:pe})]}),t.jsxs("div",{className:"flex flex-col items-end flex-shrink-0",children:[t.jsx("h4",{className:"text-[12px] font-normal text-gray-400 text-right",children:"Collection Amount"}),t.jsxs("label",{className:"font-semibold text-[16px] text-[#222222]",children:["₹",xt(Ie)]})]})]}),(le==="FUNDLY_CUSTOMER_APP"||le==="FUNDLY_QR_WEB")&&ue&&t.jsxs("div",{className:"w-full mt-2",children:[t.jsxs("label",{className:"cursor-pointer select-none text-[#16558B] font-medium text-[12px]",onClick:()=>F(V=>!V),children:["Bank Details ",a?"▲":"▼"]}),a&&t.jsxs("div",{className:"w-full flex flex-col space-y-3 mt-2",children:[t.jsxs("div",{className:"flex flex-col ",children:[t.jsx("h4",{className:"text-[12px] font-normal text-gray-400",children:"Account Holder Name"}),t.jsx("label",{className:"text-[14px] font-medium text-[#222222]",children:ue.accountName})]}),t.jsxs("div",{className:"flex justify-between",children:[t.jsxs("div",{className:"flex flex-col space-y-1",children:[t.jsx("h4",{className:"text-[12px] font-normal text-gray-400",children:"Account Number"}),t.jsx("label",{className:"text-[14px] font-medium text-[#222222]",children:ue.accountNumber})]}),t.jsxs("div",{className:"flex flex-col space-y-1",children:[t.jsx("h4",{className:"text-[12px] font-normal text-gray-400",children:"IFSC Code"}),t.jsx("label",{className:"text-[14px] font-medium text-[#222222]",children:ue.ifsc})]})]})]})]})]}),Ae.includes(Bi.FUNDLY_PAY)&&(()=>{const V=Number(Ie??0),we=$e??1e3,Ve=Je??null;let Xe=null,rt=!1;V<we?(Xe=`Fundly Pay not available below ₹${we.toLocaleString("en-IN")} payment.`,rt=!0):Ve!==null&&V>Ve?(Xe=`Max Eligible Amount: ₹${xt(Ve)}`,rt=!0):nt&&(Xe=nt,rt=!0);let qt=[],es=0;Fe?.subLimits&&Array.isArray(Fe.subLimits)&&(qt=Fe.subLimits.filter(Pt=>Pt.expired===!1),qt.sort((Pt,di)=>{const js=Pt.maxEligibleAmount||Pt.availableLimit||0;return(di.maxEligibleAmount||di.availableLimit||0)-js}),qt.length>0&&(es=Math.max(...qt.map(Pt=>Pt.maxEligibleAmount||Pt.availableLimit||0))));const hi=qt.length>1,Yt=qt.length===1,Bn=qt.length===0;return t.jsxs("div",{className:"w-full flex flex-col mt-6",children:[t.jsx("h2",{className:"text-[16px] font-semibold",children:"Preferred Payment"}),t.jsxs("div",{className:"w-full flex flex-col mt-2",children:[t.jsxs("div",{className:`w-full border border-gray-100 ${rt?"bg-[#efefef]":"bg-white"} ${Xe||hi&&Ee||Yt?"rounded-t-xl":"rounded-xl"} ${rt?"":"cursor-pointer hover:shadow-2xs"} p-4 flex items-center justify-between`,onClick:()=>{if(!rt)if(hi)De(!Ee);else if(Yt){W(0),_(qt[0].fiCode);const Pt=et(qt[0]);re(Pt.tenureMappings),dt(Pt.repaymentOption),he(Pt.disbursementAccount),J("FUNDLY_PAY")}else J("FUNDLY_PAY")},children:[t.jsxs("div",{className:"flex items-center space-x-2",children:[t.jsx("img",{src:me.logo,className:"w-[32px] h-[32px]"}),t.jsx("label",{className:"text-[14px] font-medium cursor-pointer",children:"Fundly Pay"}),t.jsxs("div",{className:"flex items-center bg-[#34A877] py-1 px-3 rounded-4xl",children:[t.jsx("img",{src:me.primary,className:"w-3 h-3"}),t.jsx("label",{className:"text-[10px] font-medium text-white",children:"1 Click Payment"})]})]}),t.jsxs("div",{className:"flex items-center space-x-2",children:[!rt&&hi&&t.jsx("svg",{className:`w-5 h-5 text-[#16558B] transition-transform duration-200 ${Ee?"rotate-180":""}`,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"3",d:"M19 9l-7 7-7-7"})}),!rt&&!hi&&t.jsx("img",{src:me.cardOpener,className:"w-4 h-4"})]})]}),!rt&&Yt&&t.jsx("div",{className:"w-full bg-[#E6F7EF] flex p-2 text-[#34A877] rounded-b-xl border-x border-b border-gray-100",children:t.jsxs("label",{className:"text-[10px] font-medium",children:["Max Eligible Amount:"," ",t.jsxs("span",{className:"font-bold",children:["₹",xt(qt[0].maxEligibleAmount||qt[0].availableLimit||0)]})]})}),!rt&&hi&&!Ee&&t.jsx("div",{className:"w-[95%] m-auto bg-[#E6F7EF] flex p-2 text-[#34A877] rounded-b-xl border-x border-b border-gray-100",children:t.jsxs("label",{className:"text-[10px] font-medium",children:["Max Eligible Amount:"," ",t.jsxs("span",{className:"font-bold",children:["₹",xt(es)]})]})}),!rt&&hi&&Ee&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"w-full bg-white border-x border-gray-100 rounded-b-xl px-3 pt-3 pb-2 flex flex-col space-y-2.5",children:qt.map((Pt,di)=>{const js=Pt.maxEligibleAmount||Pt.availableLimit||0,pi=js<V;return t.jsx("button",{type:"button",disabled:pi,className:`w-full text-left focus:outline-none transition-all duration-150 ${pi?"cursor-not-allowed opacity-50":Te===di?"bg-[#EBF4FA]":"bg-white hover:border-[#16558B] cursor-pointer"}`,style:{fontFamily:"Poppins",paddingTop:"10px",paddingLeft:"10px",paddingBottom:"10px",paddingRight:"16px",borderRadius:"8px",borderWidth:"0.87px",borderStyle:"solid",borderColor:pi?"#E0E0E0":Te===di?"#C5DBED":"#E8EEF3",height:"35px",display:"flex",alignItems:"center"},onClick:()=>{if(!pi){W(di),_(Pt.fiCode);const Ms=et(Pt);re(Ms.tenureMappings),dt(Ms.repaymentOption),he(Ms.disbursementAccount),De(!1),J("FUNDLY_PAY")}},children:t.jsxs("div",{className:"flex justify-between items-center w-full",style:{lineHeight:"24px"},children:[t.jsx("span",{className:`font-medium ${pi?"text-gray-400":"text-[#16558B]"}`,style:{fontSize:"12px",letterSpacing:"0px",textTransform:"capitalize"},children:Pt.fiCode?.toLowerCase()}),t.jsxs("span",{className:`text-[12px] font-semibold ${pi?"text-gray-400":"text-[#000000]"}`,style:{letterSpacing:"0px",lineHeight:"100%"},children:["₹ ",xt(js)]})]})},di)})}),t.jsx("div",{className:"w-[95%] m-auto bg-[#E6F7EF] flex p-2 text-[#34A877] rounded-b-xl border-x border-b border-gray-100",children:t.jsxs("label",{style:{fontFamily:"Poppins"},children:[t.jsxs("span",{className:"text-[10px] font-medium",children:["Max Eligible Amount:"," "]}),t.jsxs("span",{className:"font-bold text-[10px]",children:["₹",xt(es)]})]})})]}),Xe&&Bn&&t.jsx("div",{className:"w-full bg-red-50 flex p-2 text-red-700 rounded-b-xl border-x border-b border-gray-100",children:t.jsx("label",{className:"text-[11px] ml-2",children:Xe})}),!Xe&&Bn&&Ve!==null&&t.jsx("div",{className:"w-full bg-green-50 flex p-2 text-green-700 rounded-b-xl border-x border-b border-gray-100",children:t.jsxs("label",{className:"text-[11px] ml-2",children:["Max Eligible Amount:"," ",t.jsxs("span",{className:"font-medium",children:["₹",xt(Ve)]})]})})]})]})})(),Ae.includes(Bi.UPI)&&t.jsxs("div",{className:"w-full mt-6 flex flex-col space-y-2",children:[t.jsxs("div",{className:"flex items-center space-x-2",children:[t.jsx("img",{src:me.upi,className:"h-[20px]",alt:"UPI Logo"}),t.jsx("h2",{className:"text-[16px] font-semibold",children:"Pay by UPI"})]}),t.jsxs("div",{className:"w-full border border-gray-100 bg-white hover:shadow-2xs cursor-pointer rounded-xl p-4 flex items-center justify-between",onClick:()=>J("UPI"),children:[t.jsxs("div",{className:"flex items-center space-x-2",children:[t.jsx("img",{src:me.upiIcon,className:"w-[32px] h-[32px]",alt:"UPI"}),t.jsx("label",{className:"text-[14px] font-medium text-[#222222]",children:"UPI"}),t.jsx("div",{className:"flex items-center bg-green-50 rounded-4xl py-1 px-2",children:t.jsx("label",{className:"text-[10px] text-green-700 font-medium",children:"₹ 0 charges"})})]}),t.jsx("img",{src:me.cardOpener,className:"w-4 h-4"})]})]}),Ae.includes(Bi.NETBANKING)&&t.jsxs("div",{className:"w-full mt-6 flex flex-col space-y-2",children:[t.jsx("h2",{className:"text-[16px] font-semibold",children:"Netbanking"}),t.jsxs("div",{className:"w-full border border-gray-100 bg-white hover:shadow-2xs cursor-pointer rounded-xl p-4 flex items-center justify-between",onClick:()=>J("NETBANKING"),children:[t.jsxs("div",{className:"flex items-center space-x-2",children:[t.jsx("img",{src:me.scanqrIcon,className:"w-[32px] h-[32px]"}),t.jsx("label",{className:"text-[14px] font-medium text-[#222222]",children:"Netbanking"})]}),t.jsx("img",{src:me.cardOpener,className:"w-4 h-4"})]})]}),Ae.includes(Bi.DYNAMIC_QR)&&!(le===zs.FUNDLY_CUSTOMER_APP&&Ae.includes(Bi.PAYMENT_LINK))&&t.jsxs("div",{className:"w-full mt-6 flex flex-col space-y-2",children:[t.jsx("h2",{className:"text-[16px] font-semibold",children:"Online Payment Options"}),t.jsxs("div",{className:"w-full border border-gray-100 bg-white hover:shadow-2xs cursor-pointer rounded-xl p-4 flex items-center justify-between",onClick:()=>J("DYNAMIC_QR"),children:[t.jsxs("div",{className:"flex items-center space-x-2",children:[t.jsx("img",{src:me.generateqrIcon,className:"w-[32px] h-[32px]"}),t.jsx("label",{className:"text-[14px] font-medium",children:"Generate QR"}),t.jsx("div",{className:"flex items-center bg-green-50 rounded-4xl py-1 px-2",children:t.jsx("label",{className:"text-[10px] text-green-700 font-medium",children:"₹ 0 charges"})})]}),t.jsx("img",{src:me.cardOpener,className:"w-4 h-4"})]}),Ae.includes(Bi.PAYMENT_LINK)&&le===zs.FUNDLY_COLLECT_APP&&t.jsxs("div",{className:"w-full border border-gray-100 bg-white hover:shadow-2xs cursor-pointer rounded-xl p-4 mt-2 flex items-center justify-between",onClick:()=>J("PAYMENT_LINK"),children:[t.jsxs("div",{className:"flex items-center space-x-2",children:[t.jsx("img",{src:me.paymentlinkIcon,className:"w-[32px] h-[32px]"}),t.jsx("label",{className:"text-[14px] font-medium",children:"Payment Link"}),t.jsx("div",{className:"flex items-center bg-green-50 rounded-4xl py-1 px-2",children:t.jsx("label",{className:"text-[10px] text-green-700 font-medium",children:"₹ 0 charges"})})]}),t.jsx("img",{src:me.cardOpener,className:"w-4 h-4"})]})]}),(Ae.includes(Bi.CASH)||Ae.includes(Bi.CHEQUE))&&t.jsxs("div",{className:"w-full mt-6 flex flex-col space-y-2",children:[t.jsx("h2",{className:"text-[16px] font-semibold",children:"More Payment Options"}),Ae.includes(Bi.CASH)&&t.jsxs("div",{className:"w-full border border-gray-100 bg-white hover:shadow-2xs cursor-pointer rounded-xl p-4 flex items-center justify-between",onClick:()=>J("CASH"),children:[t.jsxs("div",{className:"flex items-center space-x-2",children:[t.jsx("img",{src:me.cashIcon,className:"w-[32px] h-[32px]"}),t.jsx("label",{className:"text-[14px] font-medium text-[#222222]",children:"Cash"})]}),t.jsx("img",{src:me.cardOpener,className:"w-4 h-4"})]}),Ae.includes(Bi.CHEQUE)&&t.jsxs("div",{className:"w-full bg-white border border-gray-100 hover:shadow-2xs cursor-pointer rounded-xl p-4 mt-2 flex items-center justify-between",onClick:()=>J("CHEQUE"),children:[t.jsxs("div",{className:"flex items-center space-x-2",children:[t.jsx("img",{src:me.chequeIcon,className:"w-[32px] h-[32px]"}),t.jsx("label",{className:"text-[14px] font-medium text-[#222222]",children:"Cheque"})]}),t.jsx("img",{src:me.cardOpener,className:"w-4 h-4"})]})]})]})}),t.jsx(jA,{open:Ce,onClose:async()=>{$(),await Lt.navigateHome()},onPaymentCollected:V=>{Z(V)}}),t.jsx(Ll,{open:q,onClose:async()=>{$(),await Lt.navigateHome()},onPaymentCollected:V=>{Z(V)},onPaymentFailed:V=>{X(V)}}),t.jsx(BA,{open:ie,onClose:async()=>{$(),await Lt.navigateHome()},onPaymentCollected:V=>{Z(V)},onPaymentFailed:V=>{X(V)}}),t.jsx(ql,{open:xe,metadata:mt,onClose:async()=>{$(),await Lt.navigateHome()},onPaymentCollected:V=>{Z(V)}}),t.jsx(Vl,{open:Se,metadata:mt,onClose:async()=>{$(),await Lt.navigateHome()},onPaymentCollected:V=>{Z(V)}}),t.jsx(DA,{open:H,onClose:()=>{$()},onPaymentCollected:V=>{Z(V)},selectedLenderIdx:Te,selectedLenderFiCode:ye,selectedLenderTenureMappings:de,selectedLenderRepaymentOption:Be,selectedLenderDisbursementAccount:ge}),t.jsx(SA,{open:ve,onClose:async()=>{$(),await Lt.navigateHome()},onPaymentCollected:()=>{Z()}}),t.jsx(LA,{open:oe,onClose:async()=>{$(),await Lt.navigateHome()},onPaymentCollected:V=>{Z(V)},onPaymentFailed:V=>{X(V)}}),t.jsx(bo,{open:ce,onClose:()=>$(),paymentData:z,buttonText:Le}),t.jsx(jo,{open:je,onClose:()=>$(),paymentData:z,buttonText:Qe}),t.jsx(TA,{open:f,onClose:()=>C(!1),onConfirm:tt}),t.jsx(PA,{open:k,onClose:()=>P(!1)})]})},Kl=D.createContext(void 0);function Zl({children:h,initialValues:o}){Or(o?.environment??"production");const[f,C]=D.useState(o?.partnerCredentials||null),[a,F]=D.useState(o?.businessId||null),[k,P]=D.useState(o?.businessName||null),[T,Q]=D.useState(null),[z,J]=D.useState([]),[$,Z]=D.useState([]),[X,H]=D.useState([]),[q,oe]=D.useState(0),[Ce,ve]=D.useState("FULL"),[ie,xe]=D.useState(null),[Se,ce]=D.useState(o?.onPaymentComplete?()=>o.onPaymentComplete:void 0),[je,Ee]=D.useState(o?.onNavigateHome?()=>o.onNavigateHome:void 0),[De,Te]=D.useState(o?.sessionId||null),[W,ye]=D.useState(o?.erpId||null);D.useEffect(()=>{const de=Fr(),re=Pr();de&&ai.configure({enabled:!0,clevertap:{accountId:de,region:re}})},[]);const _={partnerCredentials:f,setPartnerCredentials:C,businessId:a,setBusinessId:F,businessName:k,setBusinessName:P,selectedLender:T,setSelectedLender:Q,lenderList:z,setLenderList:J,selectedLoans:$,setSelectedLoans:Z,loanList:X,setLoanList:H,totalAmount:q,setTotalAmount:oe,repaymentType:Ce,setRepaymentType:ve,redirectionUrl:ie,setRedirectionUrl:xe,onPaymentComplete:Se,setOnPaymentComplete:ce,onNavigateHome:je,setOnNavigateHome:Ee,sessionId:De,setSessionId:Te,erpId:W,setErpId:ye};return t.jsx(Kl.Provider,{value:_,children:h})}function Ln(){const h=D.useContext(Kl);if(!h)throw new Error("useRepaymentContext must be used within a RepaymentProvider");return h}const Nn={availableLimit:6e4,totalLimit:98e3,outstandingBalance:38e3},JA=({onSelectLender:h,onNavigateBack:o})=>{const{businessId:f,setLenderList:C}=Ln(),[a,F]=D.useState([]),[k,P]=D.useState(!0),[T,Q]=D.useState(null);D.useEffect(()=>{f&&z()},[f]);const z=async()=>{if(!f){Q("Business ID is required"),P(!1);return}try{P(!0),Q(null);const Z=await CA(f);F(Z),C(Z)}catch(Z){console.error("Error loading lenders:",Z);const X=Z?.response?.data?.errorMessage||Z?.response?.data?.message||Z?.message||"Failed to load lenders. Please try again.";Q(X)}finally{P(!1)}},J=Z=>new Date(Z).toLocaleDateString("en-IN",{day:"numeric",month:"short",year:"numeric"}),$=Nn.availableLimit/Nn.totalLimit*100;return k?t.jsx("div",{className:"flex items-center justify-center min-h-screen bg-gray-50",children:t.jsxs("div",{className:"text-center",children:[t.jsx("div",{className:"animate-spin rounded-full h-12 w-12 border-b-2 border-blue-600 mx-auto"}),t.jsx("p",{className:"mt-4 text-gray-600",children:"Loading lenders..."})]})}):T?t.jsxs("div",{className:"min-h-screen bg-gray-50",children:[t.jsx("div",{className:"bg-white border-b border-gray-200 sticky top-0 z-10",children:t.jsxs("div",{className:"flex items-center px-4 py-4",children:[t.jsx("button",{onClick:o,className:"mr-4 p-2 hover:bg-gray-100 rounded-full transition-colors",children:t.jsx("img",{src:me.backButton,alt:"Back",className:"w-6 h-6"})}),t.jsx("h1",{className:"text-xl font-semibold text-gray-900",children:"Fundly Pay"})]})}),t.jsx("div",{className:"flex items-center justify-center min-h-[calc(100vh-80px)] px-4",children:t.jsxs("div",{className:"text-center max-w-md",children:[t.jsx("div",{className:"w-20 h-20 mx-auto mb-4 bg-red-100 rounded-full flex items-center justify-center",children:t.jsx("svg",{className:"w-10 h-10 text-red-600",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})})}),t.jsx("h2",{className:"text-xl font-semibold text-gray-900 mb-2",children:"Error Loading Lenders"}),t.jsx("p",{className:"text-gray-600 mb-6",children:T}),t.jsx("button",{onClick:z,className:"bg-blue-600 hover:bg-blue-700 text-white font-semibold py-3 px-6 rounded-xl transition-colors",children:"Try Again"})]})})]}):t.jsxs("div",{className:"min-h-screen bg-gray-50 pb-24",children:[t.jsx("div",{className:"bg-white border-b border-gray-200 sticky top-0 z-10",children:t.jsxs("div",{className:"flex items-center px-4 py-4",children:[t.jsx("button",{onClick:o,className:"mr-4 p-2 hover:bg-gray-100 rounded-full transition-colors",children:t.jsx("img",{src:me.backButton,alt:"Back",className:"w-6 h-6"})}),t.jsx("h1",{className:"text-xl font-semibold text-gray-900",children:"Fundly Pay"})]})}),t.jsxs("div",{className:"px-4 py-6 space-y-4",children:[t.jsxs("div",{className:"bg-gradient-to-br from-blue-50 to-blue-100 rounded-2xl p-6 shadow-sm relative overflow-visible",children:[t.jsxs("div",{className:"relative z-10 pr-24",children:[t.jsx("p",{className:"text-sm text-gray-700 mb-2",children:"Your Available Limit"}),t.jsxs("div",{className:"flex items-baseline space-x-2 mb-4",children:[t.jsx("span",{className:"text-3xl font-bold text-blue-900",children:xt(Nn.availableLimit)}),t.jsxs("span",{className:"text-lg text-gray-600",children:["/ ",xt(Nn.totalLimit)]})]}),t.jsx("div",{className:"w-full bg-gray-300 rounded-full h-2 mb-4",children:t.jsx("div",{className:"bg-blue-600 h-2 rounded-full transition-all duration-500",style:{width:`${$}%`}})}),t.jsxs("div",{children:[t.jsx("p",{className:"text-sm text-gray-700 mb-1",children:"Outstanding Balance"}),t.jsx("p",{className:"text-2xl font-bold text-red-600",children:xt(Nn.outstandingBalance)})]})]}),t.jsx("div",{className:"absolute right-3 bottom-3 border-2 border-dashed border-blue-400 rounded-lg p-1.5 bg-white/70 shadow-sm",children:t.jsx("img",{src:me.billy13,alt:"Credit",className:"w-20 h-20 object-contain"})})]}),t.jsx("div",{className:"space-y-3",children:a.map(Z=>t.jsx("button",{onClick:()=>h(Z),className:"w-full bg-white rounded-xl p-5 shadow-sm hover:shadow-md transition-all active:scale-98 border border-gray-100",children:t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsxs("div",{className:"flex-1 text-left",children:[t.jsx("h3",{className:"text-lg font-semibold text-gray-900 mb-1",children:Z.lenderName}),t.jsxs("p",{className:"text-sm text-gray-500",children:["Upcoming Due: ",J(Z.nextDueDate)]})]}),t.jsxs("div",{className:"flex-shrink-0 ml-4 text-right",children:[t.jsx("p",{className:"text-xl font-bold text-gray-900",children:xt(Z.outstandingAmount)}),t.jsxs("p",{className:"text-xs text-gray-500 mt-1",children:[Z.loanCount," ",Z.loanCount===1?"loan":"loans"]})]})]})},Z.lenderId))}),a.length===0&&!k&&t.jsxs("div",{className:"text-center py-12",children:[t.jsx("div",{className:"text-gray-400 mb-4",children:t.jsx("svg",{className:"w-20 h-20 mx-auto",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})})}),t.jsx("p",{className:"text-gray-600 font-medium",children:"No loans found"}),t.jsx("p",{className:"text-sm text-gray-500 mt-2",children:"You don't have any active loans at the moment"})]})]}),t.jsx("div",{className:"fixed bottom-8 left-0 right-0 flex justify-end px-4 pointer-events-none",children:t.jsxs("button",{onClick:()=>{console.log("Navigate to transaction history")},className:"bg-blue-600 hover:bg-blue-700 text-white font-semibold py-3.5 px-8 rounded-full transition-colors shadow-lg hover:shadow-xl active:scale-95 flex items-center gap-3 pointer-events-auto",children:[t.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})}),"Transaction"]})})]})},HA=({onNavigateBack:h,onSelectLoans:o,onViewLoanDetails:f})=>{const{businessId:C,selectedLender:a,setLoanList:F}=Ln(),[k,P]=D.useState([]),[T,Q]=D.useState(new Set),[z,J]=D.useState(!0),[$,Z]=D.useState(null),[X,H]=D.useState("");D.useEffect(()=>{C&&a&&q()},[C,a]);const q=async()=>{if(!C||!a){Z("Business ID and lender are required"),J(!1);return}try{J(!0),Z(null);const ie=await yA(C,a.lenderId);P(ie),F(ie)}catch(ie){console.error("Error loading loans:",ie);const xe=ie?.response?.data?.errorMessage||ie?.response?.data?.message||ie?.message||"Failed to load loans. Please try again.";Z(xe)}finally{J(!1)}},oe=ie=>new Date(ie).toLocaleDateString("en-IN",{day:"numeric",month:"short",year:"numeric"}),Ce=ie=>{const xe=new Set(T);xe.has(ie)?xe.delete(ie):xe.add(ie),Q(xe);const Se=k.filter(ce=>xe.has(ce.loanId)).reduce((ce,je)=>ce+je.outstandingAmount,0);H(Se.toFixed(2))},ve=()=>{const ie=k.filter(xe=>T.has(xe.loanId));o(ie)};return z?t.jsx("div",{className:"flex items-center justify-center min-h-screen bg-gray-50",children:t.jsxs("div",{className:"text-center",children:[t.jsx("div",{className:"animate-spin rounded-full h-12 w-12 border-b-2 border-blue-600 mx-auto"}),t.jsx("p",{className:"mt-4 text-gray-600",children:"Loading loans..."})]})}):$?t.jsxs("div",{className:"min-h-screen bg-gray-50",children:[t.jsx("div",{className:"bg-white border-b border-gray-200 sticky top-0 z-10",children:t.jsxs("div",{className:"flex items-center px-4 py-4",children:[t.jsx("button",{onClick:h,className:"mr-4 p-2 hover:bg-gray-100 rounded-full transition-colors",children:t.jsx("img",{src:me.backButton,alt:"Back",className:"w-6 h-6"})}),t.jsx("h1",{className:"text-xl font-semibold text-gray-900",children:a?.lenderName||"Loans"})]})}),t.jsx("div",{className:"flex items-center justify-center min-h-[calc(100vh-80px)] px-4",children:t.jsxs("div",{className:"text-center max-w-md",children:[t.jsx("div",{className:"w-20 h-20 mx-auto mb-4 bg-red-100 rounded-full flex items-center justify-center",children:t.jsx("svg",{className:"w-10 h-10 text-red-600",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})})}),t.jsx("h2",{className:"text-xl font-semibold text-gray-900 mb-2",children:"Error Loading Loans"}),t.jsx("p",{className:"text-gray-600 mb-6",children:$}),t.jsx("button",{onClick:q,className:"bg-blue-600 hover:bg-blue-700 text-white font-semibold py-3 px-6 rounded-xl transition-colors",children:"Try Again"})]})})]}):t.jsxs("div",{className:"min-h-screen bg-gray-50 pb-24",children:[t.jsx("div",{className:"bg-white border-b border-gray-200 sticky top-0 z-10",children:t.jsxs("div",{className:"flex items-center px-4 py-4",children:[t.jsx("button",{onClick:h,className:"mr-4 p-2 hover:bg-gray-100 rounded-full transition-colors",children:t.jsx("img",{src:me.backButton,alt:"Back",className:"w-6 h-6"})}),t.jsx("h1",{className:"text-xl font-semibold text-gray-900",children:a?.lenderName||"Loans"})]})}),t.jsxs("div",{className:"px-4 py-6 space-y-3",children:[k.map(ie=>{const xe=T.has(ie.loanId);return t.jsx("div",{className:`bg-white rounded-xl shadow-sm border transition-all ${xe?"border-blue-500 ring-2 ring-blue-100":"border-gray-100 hover:border-gray-300"}`,children:t.jsx("div",{className:"p-5",children:t.jsxs("div",{className:"flex items-start",children:[t.jsx("button",{onClick:()=>Ce(ie.loanId),className:"flex-shrink-0 mr-4 mt-1",children:t.jsx("div",{className:`w-6 h-6 rounded border-2 flex items-center justify-center transition-colors ${xe?"bg-blue-600 border-blue-600":"border-gray-300 bg-white"}`,children:xe&&t.jsx("svg",{className:"w-4 h-4 text-white",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:3,d:"M5 13l4 4L19 7"})})})}),t.jsx("div",{className:"flex-1",children:t.jsxs("button",{onClick:()=>f(ie),className:"w-full text-left",children:[t.jsx("h3",{className:"text-lg font-semibold text-blue-600 underline mb-1",children:ie.loanNumber}),t.jsxs("p",{className:"text-sm text-gray-500",children:["Due: ",oe(ie.dueDate)]})]})}),t.jsx("div",{className:"flex-shrink-0 ml-4 text-right",children:t.jsx("p",{className:"text-xl font-bold text-gray-900",children:xt(ie.outstandingAmount)})})]})})},ie.loanId)}),k.length===0&&!z&&t.jsxs("div",{className:"text-center py-12",children:[t.jsx("div",{className:"text-gray-400 mb-4",children:t.jsx("svg",{className:"w-20 h-20 mx-auto",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})})}),t.jsx("p",{className:"text-gray-600 font-medium",children:"No loans found"}),t.jsx("p",{className:"text-sm text-gray-500 mt-2",children:"This lender doesn't have any active loans"})]})]}),T.size>0&&t.jsx("div",{className:"fixed bottom-0 left-0 right-0 bg-white border-t border-gray-200 p-4 shadow-lg",children:t.jsx("div",{className:"max-w-md mx-auto",children:t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsxs("div",{className:"flex-1",children:[t.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Custom Amount"}),t.jsxs("div",{className:"relative",children:[t.jsx("span",{className:"absolute left-4 top-1/2 -translate-y-1/2 text-gray-500 text-lg",children:"₹"}),t.jsx("input",{type:"text",inputMode:"decimal",value:X,onChange:ie=>{const xe=ie.target.value.replace(/[^0-9.]/g,"");H(xe)},className:"w-full pl-8 pr-4 py-4 text-lg font-semibold border-2 border-gray-300 rounded-xl focus:outline-none focus:border-blue-500 transition-colors",placeholder:"0.00"})]})]}),t.jsx("div",{className:"flex-shrink-0 pt-7",children:t.jsx("button",{onClick:ve,disabled:!X||parseFloat(X)<=0,className:"bg-blue-600 hover:bg-blue-700 disabled:bg-gray-300 disabled:cursor-not-allowed text-white font-semibold py-4 px-8 rounded-xl transition-colors shadow-md active:scale-98 whitespace-nowrap",children:"Pay now"})})]})})})]})},WA=({loan:h,onNavigateBack:o})=>{const{businessId:f}=Ln(),[C,a]=D.useState(!1),[F,k]=D.useState([]),[P,T]=D.useState(null);D.useEffect(()=>{(async()=>{if(h.loanType==="BULLET"&&f)try{const J=await vA(h.loanId,f);k(J)}catch(J){console.error("Error loading partial payments:",J),k([])}})()},[h.loanId,h.loanType,f]),D.useEffect(()=>{(async()=>{try{const J=await bA(h.loanId);T(J)}catch(J){console.error("Error loading payment details:",J),T(null)}})()},[h.loanId]);const Q=z=>new Date(z).toLocaleDateString("en-IN",{day:"numeric",month:"short",year:"numeric"});return t.jsxs("div",{className:"min-h-screen bg-gray-50",children:[t.jsx("div",{className:"bg-white border-b border-gray-200 sticky top-0 z-10",children:t.jsxs("div",{className:"flex items-center justify-between px-4 py-4",children:[t.jsxs("div",{className:"flex items-center flex-1",children:[t.jsx("button",{onClick:o,className:"mr-4 p-2 hover:bg-gray-100 rounded-full transition-colors",children:t.jsx("img",{src:me.backButton,alt:"Back",className:"w-6 h-6"})}),t.jsx("h1",{className:"text-xl font-semibold text-gray-900",children:h.loanNumber})]}),t.jsxs("button",{className:"flex items-center space-x-2 px-4 py-2 text-blue-600 hover:bg-blue-50 rounded-lg transition-colors",children:[t.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8.228 9c.549-1.165 2.03-2 3.772-2 2.21 0 4 1.343 4 3 0 1.4-1.278 2.575-3.006 2.907-.542.104-.994.54-.994 1.093m0 3h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),t.jsx("span",{className:"text-sm font-medium",children:"Get Help"})]})]})}),t.jsxs("div",{className:"px-4 py-6 space-y-6",children:[t.jsxs("div",{className:"bg-white rounded-2xl p-6 shadow-sm border border-gray-100",children:[t.jsxs("div",{className:"flex items-center space-x-3 mb-6",children:[t.jsx("div",{className:"w-12 h-12 bg-blue-100 rounded-full flex items-center justify-center",children:t.jsx("svg",{className:"w-6 h-6 text-blue-600",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8c-1.657 0-3 .895-3 2s1.343 2 3 2 3 .895 3 2-1.343 2-3 2m0-8c1.11 0 2.08.402 2.599 1M12 8V7m0 1v8m0 0v1m0-1c-1.11 0-2.08-.402-2.599-1M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})})}),t.jsx("h2",{className:"text-lg font-semibold text-gray-900",children:"Loan Details"})]}),t.jsxs("div",{className:"grid grid-cols-2 gap-4 mb-6",children:[t.jsxs("div",{children:[t.jsx("p",{className:"text-sm text-gray-600 mb-1",children:"Disbursed"}),t.jsx("p",{className:"text-xl font-bold text-gray-900",children:xt(h.disbursedAmount)})]}),t.jsxs("div",{children:[t.jsx("p",{className:"text-sm text-gray-600 mb-1",children:"Current O/S"}),t.jsx("p",{className:"text-xl font-bold text-blue-600",children:xt(h.outstandingAmount)})]})]}),t.jsxs("div",{className:"grid grid-cols-3 gap-4 mb-6",children:[t.jsxs("div",{children:[t.jsx("p",{className:"text-sm text-gray-600 mb-1",children:"Principal"}),t.jsx("p",{className:"text-lg font-semibold text-gray-900",children:xt(h.principalOutstanding)})]}),t.jsxs("div",{children:[t.jsx("p",{className:"text-sm text-gray-600 mb-1",children:"Interest"}),t.jsx("p",{className:"text-lg font-semibold text-gray-900",children:xt(h.interestOutstanding)})]}),t.jsxs("div",{children:[t.jsx("p",{className:"text-sm text-gray-600 mb-1",children:"Charges"}),t.jsx("p",{className:"text-lg font-semibold text-gray-900",children:xt(h.chargesOutstanding)})]})]}),t.jsxs("div",{className:"border-t border-gray-200 pt-4",children:[t.jsxs("div",{className:"grid grid-cols-2 gap-4 mb-4",children:[t.jsxs("div",{children:[t.jsx("p",{className:"text-sm text-gray-600 mb-1",children:"Tenure"}),t.jsxs("p",{className:"text-base font-semibold text-gray-900",children:[h.tenure," ",h.tenureUnit==="DAYS"?"Days":"Months"]})]}),t.jsxs("div",{children:[t.jsx("p",{className:"text-sm text-gray-600 mb-1",children:"Due on"}),t.jsx("p",{className:"text-base font-semibold text-gray-900",children:Q(h.dueDate)})]})]}),t.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[t.jsxs("div",{children:[t.jsx("p",{className:"text-sm text-gray-600 mb-1",children:"Lender"}),t.jsx("p",{className:"text-base font-semibold text-gray-900",children:h.lenderName})]}),t.jsxs("div",{children:[t.jsx("p",{className:"text-sm text-gray-600 mb-1",children:"UTR No"}),t.jsx("p",{className:"text-base font-semibold text-gray-900",children:h.utrNumber})]})]})]})]}),P&&t.jsxs("div",{className:"bg-white rounded-2xl p-6 shadow-sm border border-gray-100",children:[t.jsx("h2",{className:"text-lg font-semibold text-gray-900 mb-4",children:"Supplier Details"}),t.jsxs("div",{className:"space-y-4",children:[t.jsxs("div",{className:"flex justify-between items-center",children:[t.jsx("p",{className:"text-sm text-gray-600",children:"Supplier Name"}),t.jsx("p",{className:"text-base font-semibold text-gray-900",children:P.supplierName})]}),t.jsxs("div",{className:"flex justify-between items-center",children:[t.jsx("p",{className:"text-sm text-gray-600",children:"Supplier ID"}),t.jsx("p",{className:"text-base font-semibold text-gray-900",children:P.supplierId})]})]})]}),P&&P.invoices.length>0&&t.jsxs("div",{className:"bg-white rounded-2xl p-6 shadow-sm border border-gray-100",children:[t.jsx("h2",{className:"text-lg font-semibold text-gray-900 mb-4",children:"Invoice Details"}),t.jsx("div",{className:"overflow-x-auto",children:t.jsxs("table",{className:"w-full",children:[t.jsx("thead",{children:t.jsxs("tr",{className:"bg-gray-100 text-left",children:[t.jsx("th",{className:"px-4 py-3 text-sm font-semibold text-gray-700 rounded-tl-lg",children:"Invoice No."}),t.jsx("th",{className:"px-4 py-3 text-sm font-semibold text-gray-700 text-right",children:"OS Amt"}),t.jsx("th",{className:"px-4 py-3 text-sm font-semibold text-gray-700 text-right rounded-tr-lg",children:"Paid Amt"})]})}),t.jsx("tbody",{className:"divide-y divide-gray-200",children:P.invoices.map((z,J)=>t.jsxs("tr",{children:[t.jsx("td",{className:"px-4 py-3 text-sm text-gray-900",children:z.invoiceNo}),t.jsx("td",{className:"px-4 py-3 text-sm text-gray-900 text-right",children:xt(z.osAmount)}),t.jsx("td",{className:"px-4 py-3 text-sm text-gray-900 text-right",children:xt(z.paidAmount)})]},J))})]})})]}),t.jsxs("div",{className:"bg-white rounded-2xl shadow-sm border border-gray-100 overflow-hidden",children:[t.jsxs("button",{onClick:()=>a(!C),className:"w-full p-6 flex items-center justify-between hover:bg-gray-50 transition-colors",children:[t.jsxs("div",{className:"flex items-center space-x-3",children:[t.jsx("div",{className:"w-12 h-12 bg-blue-100 rounded-full flex items-center justify-center",children:t.jsx("svg",{className:"w-6 h-6 text-blue-600",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"})})}),t.jsx("h2",{className:"text-lg font-semibold text-gray-900",children:"Partial Payment History"})]}),t.jsx("svg",{className:`w-6 h-6 text-gray-400 transition-transform ${C?"rotate-180":""}`,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),C&&t.jsxs("div",{className:"px-6 pb-6 space-y-4",children:[F.map((z,J)=>t.jsxs("div",{className:"bg-gray-50 rounded-lg p-4",children:[t.jsxs("div",{className:"flex justify-between items-start mb-3",children:[t.jsxs("div",{children:[t.jsx("p",{className:"text-sm text-gray-600",children:"Payment Date"}),t.jsx("p",{className:"text-base font-semibold text-gray-900",children:Q(z.paymentDate)})]}),t.jsxs("div",{className:"text-right",children:[t.jsx("p",{className:"text-sm text-gray-600",children:"Amount"}),t.jsx("p",{className:"text-lg font-bold text-blue-600",children:xt(z.amount)})]})]}),t.jsxs("div",{className:"grid grid-cols-3 gap-4 text-sm",children:[t.jsxs("div",{children:[t.jsx("p",{className:"text-gray-600",children:"Principal"}),t.jsx("p",{className:"font-semibold text-gray-900",children:xt(z.principalPaid)})]}),t.jsxs("div",{children:[t.jsx("p",{className:"text-gray-600",children:"Interest"}),t.jsx("p",{className:"font-semibold text-gray-900",children:xt(z.interestPaid)})]}),t.jsxs("div",{children:[t.jsx("p",{className:"text-gray-600",children:"Charges"}),t.jsx("p",{className:"font-semibold text-gray-900",children:xt(z.chargesPaid)})]})]}),t.jsx("div",{className:"mt-2 pt-2 border-t border-gray-200",children:t.jsxs("p",{className:"text-xs text-gray-500",children:["TXN ID: ",z.transactionId]})})]},J)),F.length===0&&t.jsx("p",{className:"text-center text-gray-500 py-4",children:"No partial payments made yet"})]})]})]})]})},XA=({selectedLoans:h,onNavigateBack:o,onPaymentComplete:f})=>{const{selectedLender:C,businessId:a}=Ln(),{paymentData:F,openPaymentDrawer:k,closeDrawer:P,handlePaymentSuccess:T,showCashDrawer:Q,showChequeDrawer:z,showSuccessDrawer:J,showFailureDrawer:$}=Gl(),Z=D.useMemo(()=>h.reduce((oe,Ce)=>oe+Ce.outstandingAmount,0),[h]),X=D.useMemo(()=>({type:"repayment",businessId:a||"",lenderId:C?.lenderId||"",lenderName:C?.lenderName||"",loanIds:h.map(oe=>oe.loanId),amount:Z,repaymentType:"FULL"}),[a,C,h,Z]),H=()=>{P(),f&&F?.transactionId&&f(F.transactionId)},q=[{id:"CASH",name:"Cash",icon:me.cashIcon,available:!0},{id:"CHEQUE",name:"Cheque",icon:me.chequeIcon,available:!0},{id:"UPI",name:"UPI",icon:me.upiIcon,available:!1},{id:"NETBANKING",name:"Netbanking",icon:me.Gateway,available:!1}];return t.jsxs("div",{className:"min-h-screen bg-gray-50",children:[t.jsx("div",{className:"bg-white border-b border-gray-200 sticky top-0 z-10",children:t.jsxs("div",{className:"flex items-center px-4 py-4",children:[t.jsx("button",{onClick:o,className:"mr-4 p-2 hover:bg-gray-100 rounded-full transition-colors",children:t.jsx("img",{src:me.backButton,alt:"Back",className:"w-6 h-6"})}),t.jsx("h1",{className:"text-xl font-semibold text-gray-900",children:"Repayment"})]})}),t.jsxs("div",{className:"px-4 py-6 space-y-6",children:[t.jsxs("div",{className:"bg-gradient-to-br from-blue-50 to-blue-100 rounded-2xl p-6 shadow-sm",children:[t.jsxs("div",{className:"mb-4",children:[t.jsx("p",{className:"text-sm text-gray-700 mb-1",children:"Lender"}),t.jsx("p",{className:"text-xl font-bold text-gray-900",children:C?.lenderName})]}),t.jsxs("div",{className:"bg-white/60 backdrop-blur rounded-xl p-4 mb-4",children:[t.jsx("p",{className:"text-sm text-gray-700 mb-1",children:"Selected Loans"}),t.jsxs("p",{className:"text-lg font-semibold text-gray-900",children:[h.length," ",h.length===1?"loan":"loans"]}),t.jsx("div",{className:"mt-2 space-y-1 max-h-32 overflow-y-auto",children:h.map(oe=>t.jsxs("p",{className:"text-xs text-gray-600",children:[oe.loanNumber," - ",xt(oe.outstandingAmount)]},oe.loanId))})]}),t.jsxs("div",{className:"bg-white rounded-xl p-4",children:[t.jsx("p",{className:"text-sm text-gray-700 mb-2",children:"Total Amount to Pay"}),t.jsx("p",{className:"text-3xl font-bold text-blue-600",children:xt(Z)})]})]}),t.jsxs("div",{children:[t.jsx("h2",{className:"text-lg font-semibold text-gray-900 mb-4",children:"Select Payment Method"}),t.jsx("div",{className:"grid grid-cols-2 gap-3",children:q.map(oe=>t.jsxs("button",{onClick:()=>oe.available&&k(oe.id),disabled:!oe.available,className:`bg-white rounded-xl p-5 shadow-sm transition-all border border-gray-100 flex flex-col items-center ${oe.available?"hover:shadow-md active:scale-95":"opacity-50 cursor-not-allowed"}`,children:[t.jsx("div",{className:"w-12 h-12 mb-3",children:t.jsx("img",{src:oe.icon,alt:oe.name,className:"w-full h-full object-contain"})}),t.jsx("p",{className:"text-sm font-semibold text-gray-900",children:oe.name}),!oe.available&&t.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"Coming soon"})]},oe.id))})]})]}),t.jsx(ql,{open:Q,metadata:X,onClose:P,onPaymentCollected:T}),t.jsx(Vl,{open:z,metadata:X,onClose:P,onPaymentCollected:T}),t.jsx(bo,{open:J,onClose:H,paymentData:F,buttonText:"Done"}),t.jsx(jo,{open:$,onClose:P,paymentData:F,buttonText:"Try Again"})]})},qA=({onNavigateHome:h,onPaymentComplete:o})=>{const{setSelectedLender:f,setSelectedLoans:C}=Ln(),[a,F]=D.useState("lenderList"),[k,P]=D.useState([]),[T,Q]=D.useState(null),z=oe=>{f(oe),F("loanList")},J=()=>{F("lenderList"),f(null)},$=oe=>{P(oe),C(oe),F("payment")},Z=oe=>{console.log("Payment completed:",oe),o&&o(oe),F("lenderList"),f(null),P([])},X=()=>{F("loanList")},H=oe=>{Q(oe),F("loanDetails")},q=()=>{F("loanList"),Q(null)};switch(a){case"lenderList":return t.jsx(JA,{onSelectLender:z,onNavigateBack:h});case"loanList":return t.jsx(HA,{onNavigateBack:J,onSelectLoans:$,onViewLoanDetails:H});case"loanDetails":return T?t.jsx(WA,{loan:T,onNavigateBack:q}):(F("loanList"),null);case"payment":return t.jsx(XA,{selectedLoans:k,onNavigateBack:X,onPaymentComplete:Z});default:return null}},_l=D.createContext(void 0);function $l({children:h,initialValues:o}){Or(o?.environment??"production");const[f,C]=D.useState(o?.partnerCredentials||null),[a,F]=D.useState(o?.businessId||null),[k,P]=D.useState(o?.businessName||null),[T,Q]=D.useState([]),[z,J]=D.useState(null),[$,Z]=D.useState(o?.filters||null),[X,H]=D.useState(o?.defaultTab||"all"),[q,oe]=D.useState(1),[Ce,ve]=D.useState(!0),[ie,xe]=D.useState(!1),[Se,ce]=D.useState(o?.onNavigateHome?()=>o.onNavigateHome:void 0),[je,Ee]=D.useState(o?.sessionId||null),[De,Te]=D.useState(o?.erpId||null);D.useEffect(()=>{const ye=Fr(),_=Pr();ye&&ai.configure({enabled:!0,clevertap:{accountId:ye,region:_}})},[]);const W={partnerCredentials:f,setPartnerCredentials:C,businessId:a,setBusinessId:F,businessName:k,setBusinessName:P,transactions:T,setTransactions:Q,selectedTransaction:z,setSelectedTransaction:J,filter:$,setFilter:Z,activeTab:X,setActiveTab:H,currentPage:q,setCurrentPage:oe,hasMore:Ce,setHasMore:ve,isLoading:ie,setIsLoading:xe,onNavigateHome:Se,setOnNavigateHome:ce,sessionId:je,setSessionId:Ee,erpId:De,setErpId:Te};return t.jsx(_l.Provider,{value:W,children:h})}function YA(){const h=D.useContext(_l);if(!h)throw new Error("useTransactionContext must be used within a TransactionProvider");return h}const VA=({onNavigateBack:h,onViewTransaction:o})=>{const{businessId:f}=YA(),[C,a]=D.useState([]),[F,k]=D.useState(!0),[P,T]=D.useState(null),[Q,z]=D.useState("all"),[J,$]=D.useState(""),[Z,X]=D.useState("all"),[H,q]=D.useState(1),[oe,Ce]=D.useState(!1),[ve,ie]=D.useState(0);D.useEffect(()=>{f&&xe()},[f,Q,Z,H]);const xe=async()=>{if(!f){T("Business ID is required"),k(!1);return}try{k(!0),T(null);const ye=await IA({businessId:f,filter:{type:Q,status:Z,searchQuery:J||void 0},page:H,limit:20});a(ye.transactions),ie(ye.totalCount),Ce(ye.hasMore)}catch(W){console.error("Error loading transactions:",W);const ye=W?.response?.data?.errorMessage||W?.response?.data?.message||W?.message||"Failed to load transactions. Please try again.";T(ye)}finally{k(!1)}},Se=()=>{q(1),xe()},ce=W=>{z(W),q(1)},je=W=>{X(W),q(1)},Ee=W=>new Date(W).toLocaleDateString("en-IN",{day:"numeric",month:"short",year:"numeric",hour:"2-digit",minute:"2-digit"}),De=W=>{switch(W.toUpperCase()){case"SUCCESS":return"bg-green-100 text-green-700";case"PENDING":return"bg-yellow-100 text-yellow-700";case"FAILED":return"bg-red-100 text-red-700";default:return"bg-gray-100 text-gray-700"}},Te=W=>{switch(W){case"LOAN_REPAYMENT":return"Loan Repayment";case"SUPPLIER_PAYMENT":return"Supplier Payment";default:return W}};return F&&H===1?t.jsx("div",{className:"flex items-center justify-center min-h-screen bg-gray-50",children:t.jsxs("div",{className:"text-center",children:[t.jsx("div",{className:"animate-spin rounded-full h-12 w-12 border-b-2 border-blue-600 mx-auto"}),t.jsx("p",{className:"mt-4 text-gray-600",children:"Loading transactions..."})]})}):P?t.jsxs("div",{className:"min-h-screen bg-gray-50",children:[t.jsx("div",{className:"bg-white border-b border-gray-200 sticky top-0 z-10",children:t.jsxs("div",{className:"flex items-center px-4 py-4",children:[t.jsx("button",{onClick:h,className:"mr-4 p-2 hover:bg-gray-100 rounded-full transition-colors",children:t.jsx("img",{src:me.backButton,alt:"Back",className:"w-6 h-6"})}),t.jsx("h1",{className:"text-xl font-semibold text-gray-900",children:"Transaction History"})]})}),t.jsx("div",{className:"flex items-center justify-center min-h-[calc(100vh-80px)] px-4",children:t.jsxs("div",{className:"text-center max-w-md",children:[t.jsx("div",{className:"w-20 h-20 mx-auto mb-4 bg-red-100 rounded-full flex items-center justify-center",children:t.jsx("svg",{className:"w-10 h-10 text-red-600",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})})}),t.jsx("h2",{className:"text-xl font-semibold text-gray-900 mb-2",children:"Error Loading Transactions"}),t.jsx("p",{className:"text-gray-600 mb-6",children:P}),t.jsx("button",{onClick:xe,className:"bg-blue-600 hover:bg-blue-700 text-white font-semibold py-3 px-6 rounded-xl transition-colors",children:"Try Again"})]})})]}):t.jsxs("div",{className:"min-h-screen bg-gray-50 pb-24",children:[t.jsxs("div",{className:"bg-white border-b border-gray-200 sticky top-0 z-20",children:[t.jsxs("div",{className:"flex items-center px-4 py-4",children:[t.jsx("button",{onClick:h,className:"mr-4 p-2 hover:bg-gray-100 rounded-full transition-colors",children:t.jsx("img",{src:me.backButton,alt:"Back",className:"w-6 h-6"})}),t.jsx("h1",{className:"text-xl font-semibold text-gray-900",children:"Transaction History"})]}),t.jsxs("div",{className:"flex border-t border-gray-200",children:[t.jsx("button",{onClick:()=>ce("all"),className:`flex-1 py-3 text-sm font-medium transition-colors ${Q==="all"?"text-blue-600 border-b-2 border-blue-600":"text-gray-600 hover:text-gray-900"}`,children:"All"}),t.jsx("button",{onClick:()=>ce("fundly"),className:`flex-1 py-3 text-sm font-medium transition-colors ${Q==="fundly"?"text-blue-600 border-b-2 border-blue-600":"text-gray-600 hover:text-gray-900"}`,children:"Fundly"}),t.jsx("button",{onClick:()=>ce("distributor"),className:`flex-1 py-3 text-sm font-medium transition-colors ${Q==="distributor"?"text-blue-600 border-b-2 border-blue-600":"text-gray-600 hover:text-gray-900"}`,children:"Distributor"})]})]}),t.jsxs("div",{className:"bg-white border-b border-gray-200 p-4 space-y-3",children:[t.jsxs("div",{className:"flex space-x-2",children:[t.jsxs("div",{className:"flex-1 relative",children:[t.jsx("input",{type:"text",placeholder:"Search by transaction ID, lender, supplier...",value:J,onChange:W=>$(W.target.value),onKeyPress:W=>W.key==="Enter"&&Se(),className:"w-full pl-10 pr-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500"}),t.jsx("svg",{className:"absolute left-3 top-2.5 w-5 h-5 text-gray-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})})]}),t.jsx("button",{onClick:Se,className:"px-6 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors",children:"Search"})]}),t.jsx("div",{className:"flex space-x-2 overflow-x-auto pb-2",children:["all","success","pending","failed"].map(W=>t.jsx("button",{onClick:()=>je(W),className:`px-4 py-2 rounded-full text-sm font-medium whitespace-nowrap transition-colors ${Z===W?"bg-blue-600 text-white":"bg-gray-100 text-gray-700 hover:bg-gray-200"}`,children:W.charAt(0).toUpperCase()+W.slice(1)},W))})]}),t.jsx("div",{className:"px-4 py-6 space-y-3",children:C.length===0&&!F?t.jsxs("div",{className:"text-center py-12",children:[t.jsx("div",{className:"text-gray-400 mb-4",children:t.jsx("svg",{className:"w-20 h-20 mx-auto",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})})}),t.jsx("p",{className:"text-gray-600 font-medium",children:"No transactions found"}),t.jsx("p",{className:"text-sm text-gray-500 mt-2",children:J?"Try adjusting your search or filters":"Your transaction history will appear here"})]}):t.jsxs(t.Fragment,{children:[C.map(W=>t.jsxs("button",{onClick:()=>o(W),className:"w-full bg-white rounded-xl p-4 shadow-sm hover:shadow-md transition-all border border-gray-100 text-left",children:[t.jsxs("div",{className:"flex items-start justify-between mb-2",children:[t.jsxs("div",{className:"flex-1",children:[t.jsx("h3",{className:"text-base font-semibold text-gray-900 mb-1",children:W.lenderName||W.supplierName||"N/A"}),t.jsx("p",{className:"text-xs text-gray-500",children:Ee(W.date)})]}),t.jsxs("div",{className:"text-right",children:[t.jsx("p",{className:"text-lg font-bold text-gray-900",children:xt(W.amount)}),t.jsx("span",{className:`inline-block px-2 py-1 rounded-full text-xs font-medium mt-1 ${De(W.status)}`,children:W.status})]})]}),t.jsxs("div",{className:"flex items-center justify-between text-sm",children:[t.jsx("span",{className:"text-gray-600",children:Te(W.transactionType)}),t.jsx("span",{className:"text-gray-600",children:W.paymentMode})]}),t.jsxs("div",{className:"mt-2 text-xs text-gray-500",children:["TXN ID: ",W.transactionId]})]},W.transactionId)),oe&&t.jsx("div",{className:"flex justify-center pt-4",children:t.jsx("button",{onClick:()=>q(H+1),disabled:F,className:"px-6 py-3 bg-blue-600 text-white rounded-xl hover:bg-blue-700 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:F?"Loading...":"Load More"})}),t.jsxs("div",{className:"text-center text-sm text-gray-500 pt-4",children:["Showing ",C.length," of ",ve," transactions"]})]})})]})},GA=({transaction:h,onNavigateBack:o})=>{const[f,C]=D.useState(!1),a=T=>new Date(T).toLocaleDateString("en-IN",{day:"numeric",month:"short",year:"numeric",hour:"2-digit",minute:"2-digit"}),F=T=>{switch(T.toUpperCase()){case"SUCCESS":return"bg-green-100 text-green-700";case"PENDING":return"bg-yellow-100 text-yellow-700";case"FAILED":return"bg-red-100 text-red-700";default:return"bg-gray-100 text-gray-700"}},k=h.transactionType==="LOAN_REPAYMENT",P=h.transactionType==="SUPPLIER_PAYMENT";return t.jsxs("div",{className:"min-h-screen bg-gray-50",children:[t.jsx("div",{className:"bg-white border-b border-gray-200 sticky top-0 z-10",children:t.jsxs("div",{className:"flex items-center px-4 py-4",children:[t.jsx("button",{onClick:o,className:"mr-4 p-2 hover:bg-gray-100 rounded-full transition-colors",children:t.jsx("img",{src:me.backButton,alt:"Back",className:"w-6 h-6"})}),t.jsx("h1",{className:"text-xl font-semibold text-gray-900",children:"Transaction Details"})]})}),t.jsxs("div",{className:"px-4 py-6 space-y-4",children:[t.jsxs("div",{className:`rounded-2xl p-6 shadow-sm ${h.status==="SUCCESS"?"bg-gradient-to-br from-green-50 to-green-100":h.status==="PENDING"?"bg-gradient-to-br from-yellow-50 to-yellow-100":"bg-gradient-to-br from-red-50 to-red-100"}`,children:[t.jsx("div",{className:"flex items-center justify-center mb-4",children:t.jsx("div",{className:`w-16 h-16 rounded-full flex items-center justify-center ${h.status==="SUCCESS"?"bg-green-200":h.status==="PENDING"?"bg-yellow-200":"bg-red-200"}`,children:t.jsx("svg",{className:`w-8 h-8 ${h.status==="SUCCESS"?"text-green-600":h.status==="PENDING"?"text-yellow-600":"text-red-600"}`,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:h.status==="SUCCESS"?t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"}):h.status==="PENDING"?t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"}):t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})}),t.jsxs("div",{className:"text-center",children:[t.jsx("p",{className:"text-4xl font-bold text-gray-900 mb-2",children:xt(h.amount)}),t.jsx("span",{className:`inline-block px-4 py-2 rounded-full text-sm font-semibold ${F(h.status)}`,children:h.status})]})]}),t.jsxs("div",{className:"bg-white rounded-2xl p-6 shadow-sm border border-gray-100",children:[t.jsx("h2",{className:"text-lg font-semibold text-gray-900 mb-4",children:"Transaction Information"}),t.jsxs("div",{className:"space-y-3",children:[t.jsxs("div",{className:"flex justify-between items-center pb-3 border-b border-gray-100",children:[t.jsx("span",{className:"text-sm text-gray-600",children:"Transaction ID"}),t.jsx("span",{className:"text-sm font-semibold text-gray-900",children:h.transactionId})]}),t.jsxs("div",{className:"flex justify-between items-center pb-3 border-b border-gray-100",children:[t.jsx("span",{className:"text-sm text-gray-600",children:"Date & Time"}),t.jsx("span",{className:"text-sm font-semibold text-gray-900",children:a(h.date)})]}),t.jsxs("div",{className:"flex justify-between items-center pb-3 border-b border-gray-100",children:[t.jsx("span",{className:"text-sm text-gray-600",children:"Payment Mode"}),t.jsx("span",{className:"text-sm font-semibold text-gray-900",children:h.paymentMode})]}),h.paymentChannel&&t.jsxs("div",{className:"flex justify-between items-center pb-3 border-b border-gray-100",children:[t.jsx("span",{className:"text-sm text-gray-600",children:"Payment Channel"}),t.jsx("span",{className:"text-sm font-semibold text-gray-900",children:h.paymentChannel})]})]})]}),k&&t.jsxs("div",{className:"bg-white rounded-2xl p-6 shadow-sm border border-gray-100",children:[t.jsx("h2",{className:"text-lg font-semibold text-gray-900 mb-4",children:"Loan Repayment Details"}),t.jsxs("div",{className:"space-y-3",children:[t.jsxs("div",{className:"flex justify-between items-center pb-3 border-b border-gray-100",children:[t.jsx("span",{className:"text-sm text-gray-600",children:"Lender Name"}),t.jsx("span",{className:"text-sm font-semibold text-gray-900",children:h.lenderName})]}),t.jsxs("div",{className:"pb-3 border-b border-gray-100",children:[t.jsx("span",{className:"text-sm text-gray-600 block mb-2",children:"Loan IDs"}),t.jsx("div",{className:"space-y-1",children:h.loanIds?.map(T=>t.jsx("div",{className:"text-sm font-semibold text-gray-900 bg-gray-50 rounded px-3 py-2",children:T},T))})]})]})]}),P&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"bg-white rounded-2xl p-6 shadow-sm border border-gray-100",children:[t.jsx("h2",{className:"text-lg font-semibold text-gray-900 mb-4",children:"Supplier Details"}),t.jsx("div",{className:"space-y-3",children:t.jsxs("div",{className:"flex justify-between items-center pb-3 border-b border-gray-100",children:[t.jsx("span",{className:"text-sm text-gray-600",children:"Supplier Name"}),t.jsx("span",{className:"text-sm font-semibold text-gray-900",children:h.supplierName})]})})]}),h.invoiceDetails&&t.jsxs("div",{className:"bg-white rounded-2xl shadow-sm border border-gray-100 overflow-hidden",children:[t.jsxs("button",{onClick:()=>C(!f),className:"w-full p-6 flex items-center justify-between hover:bg-gray-50 transition-colors",children:[t.jsxs("div",{className:"flex items-center space-x-3",children:[t.jsx("div",{className:"w-12 h-12 bg-blue-100 rounded-full flex items-center justify-center",children:t.jsx("svg",{className:"w-6 h-6 text-blue-600",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})})}),t.jsx("h2",{className:"text-lg font-semibold text-gray-900",children:"Invoice Details"})]}),t.jsx("svg",{className:`w-6 h-6 text-gray-400 transition-transform ${f?"rotate-180":""}`,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),f&&t.jsx("div",{className:"px-6 pb-6",children:t.jsx("div",{className:"overflow-x-auto",children:t.jsxs("table",{className:"w-full",children:[t.jsx("thead",{children:t.jsxs("tr",{className:"bg-gray-100 text-left",children:[t.jsx("th",{className:"px-4 py-3 text-sm font-semibold text-gray-700 rounded-tl-lg",children:"Invoice No."}),t.jsx("th",{className:"px-4 py-3 text-sm font-semibold text-gray-700 text-right",children:"Paid Amount"}),t.jsx("th",{className:"px-4 py-3 text-sm font-semibold text-gray-700 text-right rounded-tr-lg",children:"Status"})]})}),t.jsx("tbody",{className:"divide-y divide-gray-200",children:h.invoiceDetails.map((T,Q)=>t.jsxs("tr",{children:[t.jsx("td",{className:"px-4 py-3 text-sm text-gray-900",children:T.invoiceNumber}),t.jsx("td",{className:"px-4 py-3 text-sm text-gray-900 text-right",children:xt(T.paidAmount)}),t.jsx("td",{className:"px-4 py-3 text-sm text-right",children:t.jsx("span",{className:`inline-block px-2 py-1 rounded-full text-xs font-medium ${T.status==="FULLY_PAID"?"bg-green-100 text-green-700":"bg-yellow-100 text-yellow-700"}`,children:T.status||"PAID"})})]},Q))})]})})})]})]}),t.jsx("div",{className:"pt-4",children:t.jsxs("button",{className:"w-full flex items-center justify-center space-x-2 px-4 py-3 text-blue-600 hover:bg-blue-50 rounded-xl transition-colors border border-blue-200",children:[t.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8.228 9c.549-1.165 2.03-2 3.772-2 2.21 0 4 1.343 4 3 0 1.4-1.278 2.575-3.006 2.907-.542.104-.994.54-.994 1.093m0 3h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),t.jsx("span",{className:"text-sm font-medium",children:"Need Help with this Transaction?"})]})})]})]})},KA=({onNavigateHome:h})=>{const[o,f]=D.useState("list"),[C,a]=D.useState(null),F=P=>{a(P),f("details")},k=()=>{f("list"),a(null)};switch(o){case"list":return t.jsx(VA,{onNavigateBack:h,onViewTransaction:F});case"details":return C?t.jsx(GA,{transaction:C,onNavigateBack:k}):(f("list"),null);default:return null}};function e0({config:h,onPaymentCollected:o,onPaymentFailed:f}){return t.jsx("div",{className:"fundly-sdk-root",children:t.jsx(Hl,{initialValues:h,children:t.jsx(UA,{onPaymentCollected:o,onPaymentFailed:f})})})}const ZA=e0;function _A({config:h,onPaymentComplete:o,onNavigateHome:f}){const C=()=>{f?f():console.warn("RepaymentFlow: onNavigateHome callback not provided")};return t.jsx("div",{className:"fundly-sdk-root",children:t.jsx(Zl,{initialValues:{...h,onPaymentComplete:o,onNavigateHome:C},children:t.jsx(qA,{onNavigateHome:C,onPaymentComplete:o})})})}function $A({config:h,onNavigateHome:o}){const f=()=>{o?o():console.warn("TransactionHistory: onNavigateHome callback not provided")};return t.jsx("div",{className:"fundly-sdk-root",children:t.jsx($l,{initialValues:{...h,onNavigateHome:f},children:t.jsx(KA,{onNavigateHome:f})})})}exports.CleverTapProvider=Fl;exports.CollectionFlow=ZA;exports.PaymentOptionPage=e0;exports.PaymentProvider=Hl;exports.RepaymentFlow=_A;exports.RepaymentProvider=Zl;exports.TransactionHistory=$A;exports.TransactionProvider=$l;exports.analyticsService=ai;exports.getAccessToken=it;exports.sdkConfig=Lt;exports.setAccessToken=Do;
|
package/dist/index.mjs
CHANGED
|
@@ -18645,20 +18645,20 @@ const ih = ({
|
|
|
18645
18645
|
}
|
|
18646
18646
|
};
|
|
18647
18647
|
function sh({ config: m, onPaymentCollected: o, onPaymentFailed: g }) {
|
|
18648
|
-
return /* @__PURE__ */ r(Wu, { initialValues: m, children: /* @__PURE__ */ r(
|
|
18648
|
+
return /* @__PURE__ */ r("div", { className: "fundly-sdk-root", children: /* @__PURE__ */ r(Wu, { initialValues: m, children: /* @__PURE__ */ r(
|
|
18649
18649
|
YA,
|
|
18650
18650
|
{
|
|
18651
18651
|
onPaymentCollected: o,
|
|
18652
18652
|
onPaymentFailed: g
|
|
18653
18653
|
}
|
|
18654
|
-
) });
|
|
18654
|
+
) }) });
|
|
18655
18655
|
}
|
|
18656
18656
|
const dh = sh;
|
|
18657
18657
|
function uh({ config: m, onPaymentComplete: o, onNavigateHome: g }) {
|
|
18658
18658
|
const y = () => {
|
|
18659
18659
|
g ? g() : console.warn("RepaymentFlow: onNavigateHome callback not provided");
|
|
18660
18660
|
};
|
|
18661
|
-
return /* @__PURE__ */ r(
|
|
18661
|
+
return /* @__PURE__ */ r("div", { className: "fundly-sdk-root", children: /* @__PURE__ */ r(
|
|
18662
18662
|
VA,
|
|
18663
18663
|
{
|
|
18664
18664
|
initialValues: {
|
|
@@ -18674,13 +18674,13 @@ function uh({ config: m, onPaymentComplete: o, onNavigateHome: g }) {
|
|
|
18674
18674
|
}
|
|
18675
18675
|
)
|
|
18676
18676
|
}
|
|
18677
|
-
);
|
|
18677
|
+
) });
|
|
18678
18678
|
}
|
|
18679
18679
|
function Ah({ config: m, onNavigateHome: o }) {
|
|
18680
18680
|
const g = () => {
|
|
18681
18681
|
o ? o() : console.warn("TransactionHistory: onNavigateHome callback not provided");
|
|
18682
18682
|
};
|
|
18683
|
-
return /* @__PURE__ */ r(
|
|
18683
|
+
return /* @__PURE__ */ r("div", { className: "fundly-sdk-root", children: /* @__PURE__ */ r(
|
|
18684
18684
|
eh,
|
|
18685
18685
|
{
|
|
18686
18686
|
initialValues: {
|
|
@@ -18689,7 +18689,7 @@ function Ah({ config: m, onNavigateHome: o }) {
|
|
|
18689
18689
|
},
|
|
18690
18690
|
children: /* @__PURE__ */ r(rh, { onNavigateHome: g })
|
|
18691
18691
|
}
|
|
18692
|
-
);
|
|
18692
|
+
) });
|
|
18693
18693
|
}
|
|
18694
18694
|
export {
|
|
18695
18695
|
Ju as CleverTapProvider,
|