@fundly.ai/payment-sdk 1.5.0-beta.0 → 1.5.0-beta.1

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 CHANGED
@@ -595,51 +595,38 @@ The SDK automatically tracks payment events using CleverTap analytics. **No manu
595
595
 
596
596
  When the SDK mounts, it automatically initializes analytics with the appropriate environment settings based on the `environment` parameter in your `PaymentConfig`.
597
597
 
598
- ### Tracked Events
598
+ ### Tracked Events (v2)
599
599
 
600
- The SDK automatically tracks these payment lifecycle events:
600
+ The SDK tracks exactly two events in the payment lifecycle:
601
601
 
602
- 1. **Payment_Initiated** - When any payment is started
603
- 2. **Payment_Link_Generated** - When a payment link is created
604
- 3. **Payment_QR_Generated** - When a dynamic QR code is created
605
- 4. **Payment_Success** - When payment is successfully completed
606
- 5. **Payment_Failed** - When payment fails
602
+ #### 1. `Payment_SDK_Launched`
603
+ Fires when the payment options screen fully loads.
607
604
 
608
- Each event includes:
609
- - Payment mode (CASH, CHEQUE, STATIC_QR, DYNAMIC_QR, PAYMENT_LINK)
610
- - Amount and invoice count
611
- - Salesman information (if provided)
612
- - Transaction ID and timestamp
613
- - Additional mode-specific data
605
+ Key fields included:
606
+ - `invoice_count`, `payment_amount`, `payment_type`, `partial_payment`
607
+ - `supplier_id`, `supplier_name`, `user_type`, `user_uuid`
608
+ - `session_id`, `platform`, `sdk_version`, `sdk_entry_point`
609
+ - `is_payment_enabled`, `status`
610
+ - All 9 `payment_option_*` availability booleans
611
+ - `scan_channel`, `scan_origin`, `salesman_name`
612
+ - Carry-forward fields from upstream: `view_id`, `scan_id`, `bill_id`, `bill_type`, `bill_status`, `bill_total_amount`, `outstanding_amount`, `notification_id`, `notification_channel` (null for non-QR/non-notification flows)
614
613
 
615
- ### Custom Analytics Provider (Optional)
614
+ #### 2. `Payment_Initiated`
615
+ Fires when the user selects a payment method and proceeds.
616
616
 
617
- If you want to use a different analytics provider or disable CleverTap:
617
+ Key fields included:
618
+ - `fundly_transaction_id`, `invoice_count`, `partial_payment`
619
+ - `payment_amount`, `payment_type`, `payment_method`, `payment_mode`
620
+ - `payment_channel`, `payment_gateway`, `otp_required`, `retry_count`
621
+ - `supplier_id`, `supplier_name`, `user_type`, `user_uuid`
622
+ - `session_id`, `platform`, `mobile_changed`
623
+ - FUNDLY_PAY loan fields where applicable
618
624
 
619
- ```typescript
620
- import { analyticsService, IAnalyticsProvider } from '@fundly.ai/payment-sdk';
621
-
622
- // Disable analytics
623
- analyticsService.configure({
624
- enabled: false
625
- });
625
+ > **Note:** `Payment_Transaction` is **not** fired by the SDK. It is owned by the backend.
626
626
 
627
- // Or use your custom provider
628
- class MyAnalyticsProvider implements IAnalyticsProvider {
629
- trackPaymentInitiated(data) { /* your implementation */ }
630
- trackPaymentLinkGenerated(data) { /* your implementation */ }
631
- trackPaymentQRGenerated(data) { /* your implementation */ }
632
- trackPaymentSuccess(data) { /* your implementation */ }
633
- trackPaymentFailed(data) { /* your implementation */ }
634
- }
635
-
636
- analyticsService.configure({
637
- enabled: true,
638
- provider: new MyAnalyticsProvider()
639
- });
640
- ```
627
+ ### Analytics Failures
641
628
 
642
- **Note:** Custom configuration should be done before rendering the `PaymentOptionPage` component.
629
+ All analytics calls are wrapped in try/catch. A tracking failure will never block or interrupt the payment flow.
643
630
 
644
631
  ---
645
632
 
@@ -605,7 +605,7 @@ Thank you for your payment!`;await At.shareByteImage(ee,H,`Transaction_${oe}`)}c
605
605
  #date-picker-input::-webkit-inner-spin-button {
606
606
  display: none;
607
607
  }
608
- `})]})},s0=({open:A,onClose:l,onPaymentCollected:m,metadata:C})=>{const{payableValue:o,typeOfApp:F,salesmanPhoneNumber:P}=Zt(),{analyticsPayloadFields:O}=un(),Y=()=>{l(),G(null),V(null),Ae(""),X(""),ce(""),be([]),Ie(!1),K(!1),ge(!1),J(!1),le("Submit"),q(!1)},[U,G]=I.useState(null),[T,V]=I.useState(null),Z=I.useRef(null),[ee,Ae]=I.useState(""),[oe,K]=I.useState(!1),[xe,ge]=I.useState(!1),[H,J]=I.useState(!1),[ne,le]=I.useState("Submit"),[we,se]=I.useState(!1),[Q,X]=I.useState(""),[W,ce]=I.useState(""),[Oe,be]=I.useState([]),[Ze,Ie]=I.useState(!1),[Me,ae]=I.useState(!1),Ce=I.useRef(null),Be=I.useRef(null),Ee=I.useCallback(async je=>{Be.current&&clearTimeout(Be.current),Be.current=setTimeout(async()=>{ae(!0);try{const Ve=await $l(je),he=Array.isArray(Ve)?Ve:Ve?.data??[];be(he),Ie(he.length>0)}catch{be([])}finally{ae(!1)}},je.trim()?300:0)},[]);I.useEffect(()=>{const je=Ve=>{Ce.current&&!Ce.current.contains(Ve.target)&&Ie(!1)};return document.addEventListener("mousedown",je),()=>document.removeEventListener("mousedown",je)},[]);async function De(je,Ve){try{return(await pt.post(Wi(),{byteString:je,fileName:Ve,type:"CHEQUE"},{headers:{"Content-Type":"application/json",Authorization:`Bearer ${Je()||""}`}})).data}catch(he){throw he}}const Se=je=>new Promise((Ve,he)=>{const Ye=new FileReader;Ye.onload=()=>{const et=Ye.result,lt=et.split(",")[1]||et;Ve(lt)},Ye.onerror=et=>he(et),Ye.readAsDataURL(je)}),Ne=async()=>{if(!navigator.onLine){J(!0),le("Submit Again");return}J(!1),le("Submit"),se(!0);try{let je;if(T){const lt=await Se(T),St=await De(lt,T.name);je=St?.data?.documentId||St?.documentId||St?.id||void 0}const Ve=U?U.toISOString():new Date().toISOString(),he=ai.buildPayload(C,"CHEQUE",Number(o)||0,{chequeNumber:ee,chequeDate:Ve,bankName:Q.trim()||void 0,documentId:je||void 0,salesmanName:ve.trim()||void 0,salesmanPhoneNumber:P||void 0,...O});ai.validatePayload(he);const Ye=await xn(he),et=Ye.data||Ye;et&&!et.chequeNumber&&(et.chequeNumber=ee),m&&m(et)}catch(je){const Ve=je?.response?.data?.errorMessage||je?.response?.data?.errorDesc||je?.response?.data?.message||je?.message||"Cheque payment failed. Please try again.";ht(Ve)}finally{se(!1)}},[Ue,q]=I.useState(!1),[ve,Pe]=I.useState(""),[Ge,ht]=I.useState(""),[ot,Mt]=I.useState(null);return I.useEffect(()=>{A||(G(null),V(null),Ae(""),X(""),ce(""),be([]),Ie(!1),K(!1),ge(!1),J(!1),le("Submit"),q(!1),Pe(""),ht(""),se(!1))},[A]),I.useEffect(()=>{if(T){const je=URL.createObjectURL(T);return Mt(je),()=>{URL.revokeObjectURL(je)}}else Mt(null)},[T]),e.jsxs(e.Fragment,{children:[e.jsxs(ds,{open:A,onClose:Y,children:[e.jsxs("div",{style:{fontFamily:"Poppins"},className:"fp:w-full fp:px-4 fp:pt-6 fp:mb-12 ",children:[e.jsxs("div",{className:"fp:w-full fp:flex fp:items-center fp:justify-between",children:[e.jsxs("h1",{className:"fp:font-normal fp:items-center fp:text-[#222222]",children:["Payable Amount :"," ",e.jsxs("label",{className:"fp:font-semibold",children:["₹",o]})]}),e.jsx("img",{src:me.closingCross,className:"fp:w-4 fp:h-4 fp:cursor-pointer",onClick:()=>K(!0)})]}),Ge&&e.jsxs("div",{className:"fp:w-full fp:bg-red-50 fp:border fp:border-red-200 fp:rounded-xl fp:p-3 fp:flex fp:items-start fp:space-x-2 fp:mt-4",children:[e.jsx("svg",{className:"fp:w-5 fp:h-5 fp:text-red-500 fp:flex-shrink-0 fp:mt-0.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),e.jsxs("div",{className:"fp:flex-1",children:[e.jsx("p",{className:"fp:text-[14px] fp:text-red-700 fp:font-medium",children:"Payment Failed"}),e.jsx("p",{className:"fp:text-[12px] fp:text-red-600 fp:mt-1",children:Ge})]}),e.jsx("button",{onClick:()=>ht(""),className:"fp:text-red-400 fp:hover:text-red-600",children:e.jsx("svg",{className:"fp:w-4 fp:h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M6 18L18 6M6 6l12 12"})})})]}),e.jsx("input",{ref:Z,type:"file",accept:"image/*,application/pdf",hidden:!0,onChange:je=>{const Ve=je.target.files?.[0];if(Ve){if(Ve.size>10485760){ht(`File size exceeds 10MB limit. Please select a smaller file. (Current: ${(Ve.size/1024/1024).toFixed(2)}MB)`);return}V(Ve),ht("")}je.target.value=""}}),e.jsxs("div",{className:"fp:w-full fp:flex fp:flex-col fp:mt-8 fp:space-y-4",children:[e.jsx("div",{children:e.jsx(Hi,{value:U,onChange:je=>G(je),label:"Cheque Date",fullWidth:!0})}),F==="FUNDLY_CUSTOMER_APP"&&e.jsxs("div",{children:[e.jsx("label",{htmlFor:"salesman-name",style:{display:"block",marginBottom:"8px",fontSize:"14px",fontWeight:500,color:"#BBBBBB",fontFamily:"Poppins"},children:"Salesman Name (Optional)"}),e.jsx("input",{id:"salesman-name",type:"text",value:ve,onChange:je=>Pe(je.target.value),style:{width:"100%",height:"48px",padding:"12px 16px",fontSize:"16px",fontFamily:"Poppins",border:"1px solid #ccc",borderRadius:"8px",outline:"none"},onFocus:je=>je.currentTarget.style.borderColor="#16558B",onBlur:je=>je.currentTarget.style.borderColor="#ccc"})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"cheque-number",style:{display:"block",marginBottom:"8px",fontSize:"14px",fontWeight:500,color:"#222222",fontFamily:"Poppins"},children:"Cheque Number"}),e.jsx("input",{id:"cheque-number",type:"text",value:ee,onChange:je=>{const Ve=je.target.value.replace(/\D/g,"").slice(0,50);Ae(Ve)},inputMode:"numeric",pattern:"[0-9]*",maxLength:50,style:{width:"100%",height:"48px",padding:"12px 16px",fontSize:"16px",fontFamily:"Poppins",border:"1px solid #ccc",borderRadius:"8px",outline:"none"},onFocus:je=>je.currentTarget.style.borderColor="#16558B",onBlur:je=>je.currentTarget.style.borderColor="#ccc"}),e.jsx("span",{className:"fp:w-full fp:flex fp:justify-end fp:text-[10px] fp:text-gray-400 fp:mt-1",children:"* Max 50 Char Allowed"})]}),e.jsxs("div",{ref:Ce,style:{position:"relative"},children:[e.jsx("label",{htmlFor:"bank-name",style:{display:"block",marginBottom:"8px",fontSize:"14px",fontWeight:500,color:"#222222",fontFamily:"Poppins"},children:"Bank Name"}),e.jsxs("div",{style:{position:"relative"},children:[e.jsx("input",{id:"bank-name",type:"text",value:Q||W,onChange:je=>{const Ve=je.target.value;X(""),ce(Ve),Ee(Ve)},onFocus:()=>{Q?(ce(Q),X(""),Ee(Q)):Oe.length>0?Ie(!0):Ee("")},placeholder:"Search bank name...",style:{width:"100%",height:"48px",padding:"12px 36px 12px 16px",fontSize:"16px",fontFamily:"Poppins",border:"1px solid #ccc",borderRadius:"8px",outline:"none"},onFocusCapture:je=>je.currentTarget.style.borderColor="#16558B",onBlurCapture:je=>je.currentTarget.style.borderColor="#ccc",autoComplete:"off"}),e.jsx("div",{style:{position:"absolute",right:"12px",top:"50%",transform:"translateY(-50%)",display:"flex",alignItems:"center"},children:Me?e.jsxs("svg",{className:"fp:animate-spin",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10",stroke:"#ccc",strokeWidth:"3"}),e.jsx("path",{d:"M12 2a10 10 0 019.8 8",stroke:"#16558B",strokeWidth:"3",strokeLinecap:"round"})]}):Q?e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"#999",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{cursor:"pointer"},onClick:je=>{je.stopPropagation(),X(""),ce(""),be([]),Ie(!1)},children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]}):e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"#999",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("polyline",{points:"6 9 12 15 18 9"})})})]}),Ze&&Oe.length>0&&e.jsx("div",{style:{position:"absolute",top:"100%",left:0,right:0,backgroundColor:"#fff",border:"1px solid #E0E0E0",borderRadius:"8px",maxHeight:"200px",overflowY:"auto",zIndex:100,boxShadow:"0 4px 12px rgba(0,0,0,0.1)",marginTop:"4px"},children:Oe.map((je,Ve)=>{const he=typeof je=="string"?je:je?.bankName||je?.name||String(je);return e.jsx("div",{onClick:()=>{X(he),ce(""),Ie(!1)},style:{padding:"10px 16px",fontSize:"14px",fontFamily:"Poppins",cursor:"pointer",borderBottom:Ve<Oe.length-1?"1px solid #F0F0F0":"none"},onMouseEnter:Ye=>Ye.currentTarget.style.backgroundColor="#F5F9FD",onMouseLeave:Ye=>Ye.currentTarget.style.backgroundColor="#fff",children:he},Ve)})})]}),!T&&e.jsxs("div",{className:"fp:w-full fp:flex fp:items-center fp:justify-between fp:border-1 fp:border-dashed fp:border-[#cccccc] fp:rounded-lg fp:py-3 fp:px-8 fp:cursor-pointer fp:mt-2",onClick:()=>Z.current?.click(),children:[e.jsxs("div",{className:"fp:flex fp:flex-col fp:items-center",children:[e.jsx("span",{className:"fp:text-[#aaa]",children:"Upload Cheque Image"}),e.jsx("span",{className:"fp:text-[12px] fp:text-[#aaa]",children:"(JPG, JPEG, PNG, PDF - Max 10MB)"})]}),e.jsx("img",{src:me.uploadIcon,className:"fp:w-5 fp:h-5",alt:"Upload"})]}),T&&e.jsxs("div",{className:"fp:w-full fp:flex fp:flex-col fp:p-3 fp:space-y-1 fp:border-2 fp:border-gray-200 fp:rounded-lg",children:[e.jsx("label",{className:"fp:text-[12px] fp:text-[#16558B]",children:"Payment Proof"}),e.jsxs("div",{className:"fp:w-full fp:flex fp:items-center fp:justify-between fp:gap-2",children:[e.jsx("label",{className:"fp:text-[14px] fp:font-medium fp:truncate fp:flex-1 fp:min-w-0",children:T.name}),e.jsxs("div",{className:"fp:flex fp:items-center fp:space-x-4 fp:flex-shrink-0",children:[e.jsx("img",{src:me.trash,className:"fp:w-4 fp:h-4 fp:cursor-pointer",onClick:()=>q(!0)}),e.jsx("img",{src:me.eye,className:"fp:w-4 fp:h-4 fp:cursor-pointer",onClick:()=>ge(!0)})]})]})]}),H&&e.jsx("span",{className:"fp:text-red-500 fp:text-[12px] fp:mt-1",children:"We couldn't process your payment due to a network error. Please retry."}),e.jsx("button",{className:`fp:w-full fp:h-12 fp:mt-4 fp:rounded-lg fp:text-[16px] fp:flex fp:items-center fp:justify-center fp:bg-[#16558B] fp:text-white ${!U||!ee.trim()||!Q.trim()||we?"fp:opacity-50 fp:cursor-not-allowed":"fp:cursor-pointer"}`,onClick:Ne,disabled:!ee.trim()||!Q.trim()||!U||we,children:we?e.jsxs("div",{className:"fp:flex fp:items-center fp:space-x-2",children:[e.jsxs("svg",{className:"fp:animate-spin fp:h-5 fp:w-5 fp:text-white",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"fp:opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"fp:opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8v4a4 4 0 00-4 4H4z"})]}),e.jsx("span",{children:"Processing..."})]}):ne})]})]}),e.jsxs(ls,{open:oe,onClose:()=>K(!1),children:[e.jsx(cs,{children:e.jsxs("div",{className:"fp:w-full fp:flex fp:flex-col fp:justify-center fp:items-center",children:[e.jsx("img",{src:me.Gateway,className:"fp:w-15 fp:h-15"}),e.jsx("span",{style:{fontFamily:"Poppins"},className:"fp:text-[16px] fp:mt-3 fp:text-wrap fp:font-semibold fp:text-center fp:text-[#222222]",children:"Payment has not been completed. Do you still want to close?"})]})}),e.jsx(Ls,{children:e.jsxs("div",{className:"fp:w-full fp:flex fp:justify-between fp:px-3 fp:mb-3 fp:gap-3",children:[e.jsx("button",{style:{fontFamily:"Poppins"},className:"fp:flex-1 fp:h-[48px] fp:text-[18px] fp:border-2 fp:border-gray-300 fp:text-gray-400 fp:rounded-xl",onClick:()=>{K(!1),l()},children:"Exit"}),e.jsx("button",{style:{fontFamily:"Poppins"},className:"fp:flex-1 fp:h-[48px] fp:text-[18px] fp:bg-[#16558B] fp:text-white fp:rounded-xl",onClick:()=>K(!1),children:"Continue"})]})})]}),e.jsxs(ls,{open:Ue,onClose:()=>q(!1),children:[e.jsx(cs,{children:e.jsxs("div",{className:"fp:w-full fp:flex fp:flex-col fp:justify-center fp:items-center fp:space-y-1",children:[e.jsx("img",{src:me.chequeDeleted,className:"fp:w-14 fp:h-14"}),e.jsx("span",{style:{fontFamily:"Poppins"},className:"fp:text-[14px] fp:text-center fp:font-semibold",children:"Are you sure?"}),e.jsx("span",{style:{fontFamily:"Poppins"},className:"fp:text-[12px] fp:text-gray-500 fp:text-center",children:"This cheque image will be deleted."})]})}),e.jsx(Ls,{children:e.jsxs("div",{className:"fp:w-full fp:flex fp:justify-between fp:px-3 fp:mb-3 fp:gap-3",children:[e.jsx("button",{style:{fontFamily:"Poppins"},className:"fp:flex-1 fp:h-[44px] fp:text-[16px] fp:border fp:border-gray-300 fp:text-gray-500 fp:rounded-xl",onClick:()=>{V(null),q(!1)},children:"Yes, Delete"}),e.jsx("button",{style:{fontFamily:"Poppins"},className:"fp:flex-1 fp:h-[44px] fp:text-[16px] fp:bg-[#16558B] fp:text-white fp:rounded-xl",onClick:()=>q(!1),children:"No"})]})})]})]}),e.jsxs(ls,{open:xe,onClose:()=>ge(!1),children:[e.jsx(pn,{sx:{padding:"8px 12px"},children:e.jsx("div",{className:"fp:w-full fp:flex fp:justify-end",children:e.jsx("div",{className:"fp:w-8 fp:h-8 fp:flex fp:items-center fp:justify-center fp:bg-gray-100 fp:hover:bg-gray-200 fp:rounded-full fp:cursor-pointer fp:shadow-md",onClick:()=>ge(!1),children:e.jsx("img",{src:me.closingCross,className:"fp:w-4 fp:h-4",alt:"Close"})})})}),e.jsx(cs,{children:ot&&T&&e.jsx(e.Fragment,{children:T.type.includes("pdf")?e.jsx("iframe",{src:ot,className:"fp:w-full fp:h-[500px] fp:rounded-lg"}):e.jsx("img",{src:ot,alt:"Preview",className:"fp:w-full fp:rounded-lg"})})})]})]})};function $e(A){return Number(A??0).toLocaleString("en-IN",{minimumFractionDigits:2,maximumFractionDigits:2})}const Zf=({open:A,onClose:l,onPaymentCollected:m,selectedLenderIdx:C=-1,selectedLenderFiCode:o=null,selectedLenderTenureMappings:F=[],selectedLenderRepaymentOption:P=null,selectedLenderDisbursementAccount:O=null})=>{const{tenureMappings:Y,payableValue:U,paymentType:G,paymentInvoice:T,invoices:V,chemistId:Z,leadId:ee,fiCode:Ae,typeOfApp:oe,payerMobileNumber:K,distributorIdnum:xe,distributorName:ge,drawdownRepaymentOption:H,creditLimitData:J,payerUuid:ne,salesmanId:le,sessionId:we}=Zt(),{analyticsPayloadFields:se}=un(),Q=oe==="FUNDLY_COLLECT_APP"||oe==="FUNDLY_QR_COLLECT_APP"||oe==="FUNDLY_QR_WEB",X=()=>{const fe=Ht.getCarryForwardContext();return{purpose:"fundly_pay_consent",mobile:K||null,session_id:fe.session_id||we||"",platform:fe.payment_mode?"collect":oe==="FUNDLY_MART"?"fundlymart":"collect",device_type:Hr(),os:Yr(),app_version:null,user_type:le&&le>0?"salesman":"guest",user_uuid:ne||null,scan_id:fe.scan_id??null,view_id:fe.view_id??null,notification_id:null,notification_channel:null}},W=F.length>0?F:Y,[ce,Oe]=I.useState(-1),[be,Ze]=I.useState(C);I.useEffect(()=>{C!==-1&&Ze(C)},[C]);const[Ie,Me]=I.useState(!1),ae=()=>{l()},Ce=o||Ae,Be=Ce==="TRILLIONLOAN",Ee=new Date;Ee.setDate(Ee.getDate()+1);const[De,Se]=I.useState(Be?new Date:Ee),[Ne,Ue]=I.useState(["","","","","",""]),q=I.useRef([]),[ve,Pe]=I.useState(0),[Ge,ht]=I.useState("idle"),[ot,Mt]=I.useState(!1),[je,Ve]=I.useState(!1),[he,Ye]=I.useState(""),[et,lt]=I.useState(""),[St,ps]=I.useState(oe==="FUNDLY_COLLECT_APP"||oe==="FUNDLY_QR_COLLECT_APP"||oe==="FUNDLY_QR_WEB"?"Collect":"Pay Now"),[zt,Cs]=I.useState(!1),[Rt,Hs]=I.useState(null),[Wt,ns]=I.useState(null),[Ds,is]=I.useState(!1),[ys,Ws]=I.useState(null),[vs,Ns]=I.useState([]),[Ss,bs]=I.useState(!1),fs=I.useMemo(()=>I.lazy(()=>Promise.all([Promise.resolve().then(()=>require("./index-Kayg4b3E.cjs")).then(fe=>fe.index),Promise.resolve().then(()=>require("./index-BhGsHHd0.cjs")).then(fe=>fe.index)]).then(([{Worker:fe,Viewer:Le},{defaultLayoutPlugin:ye}])=>({default:({fileUrl:He})=>{const Re=/Android|iPhone|iPad|iPod/i.test(navigator.userAgent),tt=()=>{let st;if(He.startsWith("data:application/pdf;base64,")){const ft=He.replace("data:application/pdf;base64,",""),dt=Uint8Array.from(atob(ft),Gt=>Gt.charCodeAt(0)),Vt=new Blob([dt],{type:"application/pdf"});st=URL.createObjectURL(Vt)}else st=He;if(Re){const ft=document.createElement("a");ft.href=st,ft.download="KFS_Document.pdf",document.body.appendChild(ft),ft.click(),document.body.removeChild(ft),setTimeout(()=>{st.startsWith("blob:")&&URL.revokeObjectURL(st)},1e3)}else{const ft=document.createElement("iframe");ft.style.display="none",ft.src=st,document.body.appendChild(ft),ft.onload=()=>{ft.contentWindow?.focus(),ft.contentWindow?.print(),setTimeout(()=>{document.body.removeChild(ft),st.startsWith("blob:")&&URL.revokeObjectURL(st)},1e3)}}},rs=ye({sidebarTabs:()=>[],renderToolbar:st=>e.jsx(st,{children:ft=>{const{CurrentPageInput:dt,NumberOfPages:Vt,Zoom:Gt,ZoomIn:os,ZoomOut:An}=ft;return e.jsxs("div",{style:{display:"flex",alignItems:"center",width:"100%",padding:"0 8px",gap:"4px"},children:[e.jsx(An,{}),e.jsx(Gt,{}),e.jsx(os,{}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",marginLeft:"8px"},children:[e.jsx(dt,{}),e.jsx("span",{style:{fontSize:"13px",color:"#555"},children:"/"}),e.jsx(Vt,{})]}),e.jsx("button",{onClick:tt,style:{marginLeft:"auto",background:"none",border:"none",cursor:"pointer",padding:"4px",display:"flex",alignItems:"center"},title:"Print",children:e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"#16558B",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("polyline",{points:"6 9 6 2 18 2 18 9"}),e.jsx("path",{d:"M6 18H4a2 2 0 0 1-2-2v-5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2"}),e.jsx("rect",{x:"6",y:"14",width:"12",height:"8"})]})})]})}})});return e.jsx(fe,{workerUrl:"https://unpkg.com/pdfjs-dist@3.11.174/build/pdf.worker.min.js",children:e.jsx(Le,{fileUrl:He,plugins:[rs]})})}}))),[]),Qt=I.useCallback(fe=>{const Le=fe.getFullYear(),ye=String(fe.getMonth()+1).padStart(2,"0"),He=String(fe.getDate()).padStart(2,"0");return`${Le}-${ye}-${He}`},[]),qt=I.useCallback(async()=>{if(Ce!=="TRILLIONLOAN"){Cs(!1);return}Cs(!0);try{const fe=Je(),Le=o||Ae||"",ye=P||H||"BULLET",He=new URLSearchParams({loanAmount:String(U),businessId:Z||"",openedOnDate:Qt(De||Ee),productType:"INSTACASH",tenureMagnitude:String(W[ce]?.tenureValue||""),tenureUnit:String(W[ce]?.tenureUnit||""),fiCode:Le,repaymentOption:ye,supplierId:xe||""});G==="INVOICE_COLLECT"&&T?.length>0&&He.append("invoiceNumber",T.map(rs=>rs.invoiceId).join(","));const Re=`${Wn()}/kfs/report?${He.toString()}`,tt=await pt.get(Re,{headers:{accept:"application/json",Authorization:`Bearer ${fe}`}});Hs(tt.data),ns(tt.data?.documentId??null),is(!1)}catch(fe){console.error("[Fundly Pay] Error fetching KFS:",fe),Hs(null),ns(null),is(!1)}finally{Cs(!1)}},[o,Ae,P,H,U,Z,De,ce,W,xe,G,T,Qt]),Vs=I.useCallback(async()=>{if(Ce==="TRILLIONLOAN")try{const fe=Je(),Le=new URLSearchParams({businessId:Z||"",intents:"DRAWDOWN_KFS_SIGN",fiCode:Ce||""}),ye=`${Wn()}/consent?${Le.toString()}`,Re=(await pt.get(ye,{headers:{accept:"*/*","Content-Type":"application/json",Authorization:`Bearer ${fe}`}})).data;if(Ns(Array.isArray(Re)?Re:[]),Re?.[0]?.consentMessage){let tt=Re[0].consentMessage;tt=tt.replace("{{lenderName}}",Ce||""),tt=tt.replace("Drawdown Request Letter",'<span class="kfs-link" style="color:#16558B;text-decoration:underline;cursor:pointer">Drawdown Request Letter</span>'),tt=tt.replace("Sanction Letter",'<span class="kfs-link" style="color:#16558B;text-decoration:underline;cursor:pointer">Sanction Letter</span>'),tt=tt.replace("Key Fact Statement",'<span class="kfs-link" style="color:#16558B;text-decoration:underline;cursor:pointer">Key Fact Statement</span>'),Ws(tt)}}catch(fe){console.error("[Fundly Pay] Error fetching consent:",fe),Ws(null)}},[Z]),In=I.useCallback(async()=>{try{const fe=Je(),Le=`${Wn()}/consent`;await pt.post(Le,{businessId:Z||"",intent:"DRAWDOWN_KFS_SIGN",consents:vs.map(ye=>({consentId:ye.consentId,accepted:!0}))},{headers:{Accept:"application/json","Content-Type":"application/json",Authorization:`Bearer ${fe}`}})}catch(fe){console.error("[Fundly Pay] Error submitting consent:",fe)}},[Z,vs]),us=I.useCallback(()=>{Rt&&bs(!0)},[Rt]),Bs=I.useMemo(()=>Rt?Rt.kfsDocumentBytes?`data:application/pdf;base64,${Rt.kfsDocumentBytes}`:Rt.kfsDocumentUrl||Rt.documentUrl||null:null,[Rt]),Xt=I.useRef(null);I.useEffect(()=>{const fe=Xt.current;if(!fe)return;const Le=ye=>{ye.target.classList.contains("kfs-link")&&us()};return fe.addEventListener("click",Le),()=>fe.removeEventListener("click",Le)},[us,ys]);const ks=async(fe=!1)=>{lt("");try{K&&ge&&await bf(K,ge),Q&&Ht.trackOtpInitiated({...X(),is_resend:fe})}catch(Le){console.error("Error sending OTP:",Le);const ye=Le,He=ye?.response?.data?.errorMessage||ye?.response?.data?.message||ye?.message||"Failed to send OTP. Please try again.";lt(He),ht("resend"),Pe(0)}},Xs=async()=>{if(!navigator.onLine){Ve(!0),ps("Submit Again");return}if(Q){const Re=Ne.every(tt=>tt!=="");if(Ge==="idle"||!Re)return}if(Ve(!1),ot)return;if(Mt(!0),!De){console.error("[Fundly Pay] Payment date is required"),Mt(!1);return}const fe=De.toISOString(),Le=fe.split("T")[0],ye=o||Ae,He={paymentMode:"FUNDLY_PAY",paymentDate:fe,paymentType:G,distributorCode:xe,...Wt&&{documentId:Wt},invoiceCount:T?.length||V?.length||0,otpRequired:Q,...se,loanDueDate:Te?.maturityDate??null,loanCreditedAmount:Te?.creditedAmount??null,loanTenure:Te?.tenure??null,loanDrawdownRequestDTO:{businessId:Z||ee,fiCode:ye,requestedAmount:U,scheduledDate:Le,tenure:W[ce]?.tenureValue||"",tenureUnit:W[ce]?.tenureUnit?.replace(/s$/i,"")||"",invoiceIds:oe==="FUNDLY_MART"||oe==="FUNDLY_TRADE"?[]:G==="INVOICE_COLLECT"?T?.map(Re=>Re.invoiceId)??[]:V??[],sourceSystem:oe,paymentType:G}};Z&&Z.trim()!==""?He.chemistBusinessId=Z:ee&&ee.trim()!==""&&(He.leadId=ee),G==="INVOICE_COLLECT"?He.paymentInvoice=T:G==="DIRECT_COLLECT"&&(He.invoiceIds=V,He.paidAmount=U),Q&&(He.loanDrawdownRequestDTO.mobileNumber=K,He.loanDrawdownRequestDTO.loanInitiateOtp=Ne.join("")),K&&(He.payerMobileNumber=K),Ce==="TRILLIONLOAN"&&In();try{const Re=await xn(He),tt=Re?.data||Re;tt&&!tt.scheduleDate&&(tt.scheduleDate=Le),tt&&Te?.lastRepaymentDate&&(tt.dueDate=Te.lastRepaymentDate),m&&m(tt)}catch(Re){const tt=Re?.response?.data?.errorMessage||Re?.response?.data?.errorDesc||Re?.response?.data?.message||Re?.message||"Payment failed. Please try again.";Q&&Ht.trackOtpVerified({...X(),status:"failed",failure_reason:tt,error_code:Re?.response?.data?.errorCode||null}),Ye(tt)}finally{Mt(!1)}},gt=(fe,Le)=>{if(!/^[0-9]?$/.test(fe))return;const ye=[...Ne];ye[Le]=fe,Ue(ye),fe&&Le<5&&q.current[Le+1]?.focus()},js=(fe,Le)=>{fe.key==="Backspace"&&!Ne[Le]&&Le>0&&q.current[Le-1]?.focus()},Cn=()=>{ht("countdown"),Pe(30),ks(Ge==="resend")};I.useEffect(()=>{if(Ge==="countdown"&&ve>0){const fe=setInterval(()=>{Pe(Le=>Le-1)},1e3);return()=>clearInterval(fe)}else Ge==="countdown"&&ve===0&&(ht("resend"),ks(!0))},[ve,Ge]);const ct=I.useMemo(()=>{if(Be&&zt)return!0;const fe=ce!==-1,Le=De!==null,ye=be!==-1||!J?.subLimits,He=Be?Ds:!0;if(Q){const Re=Ne.every(tt=>tt!=="");return!(fe&&Re&&Le&&ye&&He)}return!(fe&&Le&&ye&&He)},[ce,be,Ne,oe,De,J,Ds,zt]),[Te,bt]=I.useState(null),[Es,yn]=I.useState(!1),ze=async()=>{if(ce===-1)return;const fe=W[ce],Le=o||Ae||"",ye=P||H||"BULLET",He=O||"SUPPLIER";yn(!0);try{const Re=await Ff({loanAmount:Number(U),businessId:Z||"",openedOnDate:Qt(De||Ee),productType:"INSTACASH",tenureMagnitude:fe.tenureValue,tenureUnit:fe.tenureUnit,fiCode:Le,repaymentOption:ye,disbursementAccount:He});bt(Re)}catch(Re){console.error("Error fetching EMI:",Re),bt(null)}finally{yn(!1)}};return I.useEffect(()=>{let fe;return A&&ce!==-1&&be!==-1&&(fe=window.setTimeout(()=>{ze()},1e3)),()=>{clearTimeout(fe)}},[ce,be,De]),I.useEffect(()=>{if(A){if(Oe(0),Be)Se(new Date),is(!1);else{const fe=new Date;fe.setDate(fe.getDate()+1),Se(fe)}Vs()}},[A,Vs]),I.useEffect(()=>{if(!A||Ce!=="TRILLIONLOAN")return;const fe=window.setTimeout(()=>{qt()},400);return()=>clearTimeout(fe)},[ce,De,qt]),I.useEffect(()=>{const fe=()=>{A&&ce!==-1&&(ze(),qt())};return window.addEventListener("online",fe),()=>{window.removeEventListener("online",fe)}},[A,ce,qt]),e.jsxs(ds,{open:A,onClose:ae,children:[e.jsxs("div",{style:{fontFamily:"Poppins"},className:"fp:w-full fp:px-4 fp:pt-6 fp:mb-12 ",children:[e.jsx("div",{className:"fp:w-full fp:flex fp:items-center fp:justify-end",children:e.jsx("img",{src:me.closingCross,className:"fp:w-4 fp:h-4 fp:cursor-pointer",onClick:()=>Me(!0)})}),he&&e.jsxs("div",{className:"fp:w-full fp:bg-red-50 fp:border fp:border-red-200 fp:rounded-xl fp:p-3 fp:flex fp:items-start fp:space-x-2 fp:mt-4",children:[e.jsx("svg",{className:"fp:w-5 fp:h-5 fp:text-red-500 fp:flex-shrink-0 fp:mt-0.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),e.jsxs("div",{className:"fp:flex-1",children:[e.jsx("p",{className:"fp:text-[14px] fp:text-red-700 fp:font-medium",children:"Payment Failed"}),e.jsx("p",{className:"fp:text-[12px] fp:text-red-600 fp:mt-1",children:he})]}),e.jsx("button",{onClick:()=>Ye(""),className:"fp:text-red-400 fp:hover:text-red-600",children:e.jsx("svg",{className:"fp:w-4 fp:h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M6 18L18 6M6 6l12 12"})})})]}),e.jsxs("div",{className:"fp:w-full fp:flex fp:flex-col fp:mt-4 fp:space-y-4",children:[e.jsx("div",{children:e.jsx(Hi,{value:De,onChange:fe=>Se(fe),minDate:Be?void 0:Ee,label:"Select Payment Date",fullWidth:!0,disabled:Be})}),e.jsxs("div",{className:"fp:w-full fp:flex fp:flex-col fp:space-y-2 ",children:[e.jsx("span",{className:"fp:text-[15px] fp:font-medium fp:text-[#222222]",children:"Tenure"}),e.jsx("div",{className:"fp:w-full fp:flex fp:space-x-4 ",children:W&&W.length>0?W.map((fe,Le)=>e.jsxs("button",{type:"button",className:`fp:py-1 fp:px-6 fp:border-[] fp:rounded-2xl fp:text-[14px] fp:font-medium fp:focus:outline-none fp:transition-colors fp:duration-150 ${ce===Le?"fp:border-[#16558B] fp:bg-[#E6F0FA] fp:text-[#16558B]":"fp:border-[#D0D0D0] fp:text-gray-700 fp:bg-white"}`,onClick:()=>{Oe(Le)},children:[fe.tenureValue," ",fe.tenureUnit]},Le)):e.jsx("span",{className:"fp:py-1 fp:px-6 fp:border-2 fp:rounded-2xl fp:text-[14px] fp:border-[#D0D0D0] fp:text-gray-700 fp:font-medium",children:"No tenure available"})})]}),!Be&&e.jsxs("span",{className:"fp:text-[12px] fp:font-medium fp:text-green-600 fp:text-wrap",children:["₹",$e(U)," will be processed via Fundly Credit — a loan will be set up in retailer's account."]}),e.jsxs("div",{className:"fp:text-[12px] fp:w-full fp:border fp:p-4 fp:space-y-3 fp:rounded-2xl fp:flex fp:flex-col fp:border-[#E8EEF3] ",children:[e.jsxs("div",{className:"fp:flex fp:justify-between",children:[e.jsx("label",{className:"fp:text-gray-700",children:"Due date"}),e.jsx("label",{className:"fp:font-medium",children:Te?.lastRepaymentDate?oi(Te.lastRepaymentDate):"—"})]}),e.jsxs("div",{className:"fp:flex fp:justify-between",children:[e.jsx("label",{className:"fp:text-gray-700",children:"ROI (Annualised)"}),e.jsx("label",{className:"fp:font-medium",children:Te?.normalInterestRate!=null?`${Te.normalInterestRate}%`:"—"})]}),e.jsxs("div",{className:"fp:flex fp:justify-between",children:[e.jsx("label",{className:"fp:text-gray-700",children:"Interest/₹ 10,000/day"}),e.jsx("label",{className:"fp:font-medium",children:Te?.interestPerDay!=null?`₹${Te.interestPerDay}`:"—"})]}),e.jsxs("div",{className:"fp:flex fp:justify-between",children:[e.jsx("label",{className:"fp:text-gray-700",children:"Penal Charges"}),e.jsx("label",{className:"fp:font-medium",children:Te?.penalInterestRate!=null?`${Te.penalInterestRate}% p.a`:"—"})]}),e.jsxs("div",{className:"fp:flex fp:justify-between",children:[e.jsx("label",{className:"fp:text-gray-700",children:"Processing Fee"}),e.jsx("label",{className:"fp:font-medium",children:Te?.processingFeeExclGst!=null?`₹${Number(Te.processingFeeExclGst).toLocaleString("en-IN")}`:"—"})]}),e.jsxs("div",{className:"fp:flex fp:justify-between",children:[e.jsx("label",{className:"fp:text-gray-700",children:"APR"}),e.jsx("label",{className:"fp:font-medium",children:Te?.apr!=null?`${Te.apr}%`:"—"})]}),e.jsxs("div",{className:"fp:flex fp:justify-between",children:[e.jsx("label",{className:"fp:text-gray-700",children:"Net Disbursed Amount"}),e.jsx("label",{className:"fp:font-medium",children:Te?.creditedAmount!=null?`₹${Number(Te.creditedAmount).toLocaleString("en-IN")}`:"—"})]})]}),Q&&e.jsxs("div",{className:"fp:w-full fp:flex fp:flex-col fp:space-y-4 fp:border-2 fp:border-[#E8EEF3] fp:mt-2 fp:rounded-2xl fp:p-3",children:[e.jsx("label",{className:"fp:font-medium fp:text-[15px]",children:"Retailer Verification"}),e.jsxs("div",{className:"fp:w-full fp:flex fp:space-x-2 fp:justify-between",children:[e.jsx("div",{className:"fp:flex fp:border-2 fp:rounded-lg fp:px-1 fp:space-x-2 ",children:Ne.map((fe,Le)=>e.jsx("input",{type:"text",value:fe,maxLength:1,placeholder:"●",ref:ye=>{q.current[Le]=ye},onChange:ye=>gt(ye.target.value,Le),onKeyDown:ye=>js(ye,Le),className:"fp:w-7 fp:h-8 fp:text-center fp:text-[16px] fp:outline-none"},Le))}),e.jsxs("button",{onClick:Cn,disabled:Ge==="countdown",className:`fp:text-white fp:text-[12px] fp:px-7 fp:rounded-lg ${Ge==="resend"?"fp:bg-gray-500":"fp:bg-[#16558B]"}`,children:[Ge==="idle"&&"Get OTP",Ge==="countdown"&&`${ve}s`,Ge==="resend"&&"Resend"]})]}),et?e.jsxs("div",{className:"fp:w-full fp:bg-red-50 fp:border fp:border-red-200 fp:rounded-lg fp:p-2 fp:flex fp:items-start fp:space-x-2",children:[e.jsx("svg",{className:"fp:w-4 fp:h-4 fp:text-red-500 fp:flex-shrink-0 fp:mt-0.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),e.jsx("p",{className:"fp:text-[11px] fp:text-red-700",children:et})]}):e.jsxs("label",{className:"fp:text-[13px] fp:flex fp:text-center fp:items-center fp:text-[#16558B]",children:[e.jsx("img",{src:me.info,className:"fp:w-4 fp:h-4 fp:mr-1"}),Ge==="idle"?"OTP will be sent to the retailer for consent.":"An OTP has been sent to the retailer for consent."]})]}),ys&&e.jsx("div",{ref:Xt,className:"fp:text-[12px] fp:text-gray-600 fp:leading-relaxed fp:select-none",dangerouslySetInnerHTML:{__html:ys}}),Be&&e.jsxs("label",{className:"fp:flex fp:items-start fp:space-x-2 fp:cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:Ds,onChange:fe=>{const Le=fe.target.checked;is(Le),Le&&us()},className:"fp:mt-0.5 fp:w-4 fp:h-4 fp:flex-shrink-0 fp:accent-[#16558B]"}),e.jsxs("span",{className:"fp:text-[12px] fp:text-gray-700",children:["I agree to the loan terms and accept the"," ",e.jsx("span",{className:"fp:text-[#16558B] fp:underline fp:cursor-pointer",onClick:fe=>{fe.preventDefault(),us()},children:"Key Fact Statement (KFS)"})]})]}),je&&e.jsx("span",{className:"fp:text-red-500 fp:text-[12px] fp:mt-1",children:"We couldn't process your payment due to a network error. Please retry."}),e.jsx("button",{className:`fp:w-full fp:h-12 fp:mt-4 fp:rounded-lg fp:text-[16px] fp:flex fp:items-center fp:justify-center
608
+ `})]})},s0=({open:A,onClose:l,onPaymentCollected:m,metadata:C})=>{const{payableValue:o,typeOfApp:F,salesmanPhoneNumber:P}=Zt(),{analyticsPayloadFields:O}=un(),Y=()=>{l(),G(null),V(null),Ae(""),X(""),ce(""),be([]),Ie(!1),K(!1),ge(!1),J(!1),le("Submit"),q(!1)},[U,G]=I.useState(null),[T,V]=I.useState(null),Z=I.useRef(null),[ee,Ae]=I.useState(""),[oe,K]=I.useState(!1),[xe,ge]=I.useState(!1),[H,J]=I.useState(!1),[ne,le]=I.useState("Submit"),[we,se]=I.useState(!1),[Q,X]=I.useState(""),[W,ce]=I.useState(""),[Oe,be]=I.useState([]),[Ze,Ie]=I.useState(!1),[Me,ae]=I.useState(!1),Ce=I.useRef(null),Be=I.useRef(null),Ee=I.useCallback(async je=>{Be.current&&clearTimeout(Be.current),Be.current=setTimeout(async()=>{ae(!0);try{const Ve=await $l(je),he=Array.isArray(Ve)?Ve:Ve?.data??[];be(he),Ie(he.length>0)}catch{be([])}finally{ae(!1)}},je.trim()?300:0)},[]);I.useEffect(()=>{const je=Ve=>{Ce.current&&!Ce.current.contains(Ve.target)&&Ie(!1)};return document.addEventListener("mousedown",je),()=>document.removeEventListener("mousedown",je)},[]);async function De(je,Ve){try{return(await pt.post(Wi(),{byteString:je,fileName:Ve,type:"CHEQUE"},{headers:{"Content-Type":"application/json",Authorization:`Bearer ${Je()||""}`}})).data}catch(he){throw he}}const Se=je=>new Promise((Ve,he)=>{const Ye=new FileReader;Ye.onload=()=>{const et=Ye.result,lt=et.split(",")[1]||et;Ve(lt)},Ye.onerror=et=>he(et),Ye.readAsDataURL(je)}),Ne=async()=>{if(!navigator.onLine){J(!0),le("Submit Again");return}J(!1),le("Submit"),se(!0);try{let je;if(T){const lt=await Se(T),St=await De(lt,T.name);je=St?.data?.documentId||St?.documentId||St?.id||void 0}const Ve=U?U.toISOString():new Date().toISOString(),he=ai.buildPayload(C,"CHEQUE",Number(o)||0,{chequeNumber:ee,chequeDate:Ve,bankName:Q.trim()||void 0,documentId:je||void 0,salesmanName:ve.trim()||void 0,salesmanPhoneNumber:P||void 0,...O});ai.validatePayload(he);const Ye=await xn(he),et=Ye.data||Ye;et&&!et.chequeNumber&&(et.chequeNumber=ee),m&&m(et)}catch(je){const Ve=je?.response?.data?.errorMessage||je?.response?.data?.errorDesc||je?.response?.data?.message||je?.message||"Cheque payment failed. Please try again.";ht(Ve)}finally{se(!1)}},[Ue,q]=I.useState(!1),[ve,Pe]=I.useState(""),[Ge,ht]=I.useState(""),[ot,Mt]=I.useState(null);return I.useEffect(()=>{A||(G(null),V(null),Ae(""),X(""),ce(""),be([]),Ie(!1),K(!1),ge(!1),J(!1),le("Submit"),q(!1),Pe(""),ht(""),se(!1))},[A]),I.useEffect(()=>{if(T){const je=URL.createObjectURL(T);return Mt(je),()=>{URL.revokeObjectURL(je)}}else Mt(null)},[T]),e.jsxs(e.Fragment,{children:[e.jsxs(ds,{open:A,onClose:Y,children:[e.jsxs("div",{style:{fontFamily:"Poppins"},className:"fp:w-full fp:px-4 fp:pt-6 fp:mb-12 ",children:[e.jsxs("div",{className:"fp:w-full fp:flex fp:items-center fp:justify-between",children:[e.jsxs("h1",{className:"fp:font-normal fp:items-center fp:text-[#222222]",children:["Payable Amount :"," ",e.jsxs("label",{className:"fp:font-semibold",children:["₹",o]})]}),e.jsx("img",{src:me.closingCross,className:"fp:w-4 fp:h-4 fp:cursor-pointer",onClick:()=>K(!0)})]}),Ge&&e.jsxs("div",{className:"fp:w-full fp:bg-red-50 fp:border fp:border-red-200 fp:rounded-xl fp:p-3 fp:flex fp:items-start fp:space-x-2 fp:mt-4",children:[e.jsx("svg",{className:"fp:w-5 fp:h-5 fp:text-red-500 fp:flex-shrink-0 fp:mt-0.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),e.jsxs("div",{className:"fp:flex-1",children:[e.jsx("p",{className:"fp:text-[14px] fp:text-red-700 fp:font-medium",children:"Payment Failed"}),e.jsx("p",{className:"fp:text-[12px] fp:text-red-600 fp:mt-1",children:Ge})]}),e.jsx("button",{onClick:()=>ht(""),className:"fp:text-red-400 fp:hover:text-red-600",children:e.jsx("svg",{className:"fp:w-4 fp:h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M6 18L18 6M6 6l12 12"})})})]}),e.jsx("input",{ref:Z,type:"file",accept:"image/*,application/pdf",hidden:!0,onChange:je=>{const Ve=je.target.files?.[0];if(Ve){if(Ve.size>10485760){ht(`File size exceeds 10MB limit. Please select a smaller file. (Current: ${(Ve.size/1024/1024).toFixed(2)}MB)`);return}V(Ve),ht("")}je.target.value=""}}),e.jsxs("div",{className:"fp:w-full fp:flex fp:flex-col fp:mt-8 fp:space-y-4",children:[e.jsx("div",{children:e.jsx(Hi,{value:U,onChange:je=>G(je),label:"Cheque Date",fullWidth:!0})}),F==="FUNDLY_CUSTOMER_APP"&&e.jsxs("div",{children:[e.jsx("label",{htmlFor:"salesman-name",style:{display:"block",marginBottom:"8px",fontSize:"14px",fontWeight:500,color:"#BBBBBB",fontFamily:"Poppins"},children:"Salesman Name (Optional)"}),e.jsx("input",{id:"salesman-name",type:"text",value:ve,onChange:je=>Pe(je.target.value),style:{width:"100%",height:"48px",padding:"12px 16px",fontSize:"16px",fontFamily:"Poppins",border:"1px solid #ccc",borderRadius:"8px",outline:"none"},onFocus:je=>je.currentTarget.style.borderColor="#16558B",onBlur:je=>je.currentTarget.style.borderColor="#ccc"})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"cheque-number",style:{display:"block",marginBottom:"8px",fontSize:"14px",fontWeight:500,color:"#222222",fontFamily:"Poppins"},children:"Cheque Number"}),e.jsx("input",{id:"cheque-number",type:"text",value:ee,onChange:je=>{const Ve=je.target.value.replace(/\D/g,"").slice(0,50);Ae(Ve)},inputMode:"numeric",pattern:"[0-9]*",maxLength:50,style:{width:"100%",height:"48px",padding:"12px 16px",fontSize:"16px",fontFamily:"Poppins",border:"1px solid #ccc",borderRadius:"8px",outline:"none"},onFocus:je=>je.currentTarget.style.borderColor="#16558B",onBlur:je=>je.currentTarget.style.borderColor="#ccc"}),e.jsx("span",{className:"fp:w-full fp:flex fp:justify-end fp:text-[10px] fp:text-gray-400 fp:mt-1",children:"* Max 50 Char Allowed"})]}),e.jsxs("div",{ref:Ce,style:{position:"relative"},children:[e.jsx("label",{htmlFor:"bank-name",style:{display:"block",marginBottom:"8px",fontSize:"14px",fontWeight:500,color:"#222222",fontFamily:"Poppins"},children:"Bank Name"}),e.jsxs("div",{style:{position:"relative"},children:[e.jsx("input",{id:"bank-name",type:"text",value:Q||W,onChange:je=>{const Ve=je.target.value;X(""),ce(Ve),Ee(Ve)},onFocus:()=>{Q?(ce(Q),X(""),Ee(Q)):Oe.length>0?Ie(!0):Ee("")},placeholder:"Search bank name...",style:{width:"100%",height:"48px",padding:"12px 36px 12px 16px",fontSize:"16px",fontFamily:"Poppins",border:"1px solid #ccc",borderRadius:"8px",outline:"none"},onFocusCapture:je=>je.currentTarget.style.borderColor="#16558B",onBlurCapture:je=>je.currentTarget.style.borderColor="#ccc",autoComplete:"off"}),e.jsx("div",{style:{position:"absolute",right:"12px",top:"50%",transform:"translateY(-50%)",display:"flex",alignItems:"center"},children:Me?e.jsxs("svg",{className:"fp:animate-spin",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10",stroke:"#ccc",strokeWidth:"3"}),e.jsx("path",{d:"M12 2a10 10 0 019.8 8",stroke:"#16558B",strokeWidth:"3",strokeLinecap:"round"})]}):Q?e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"#999",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{cursor:"pointer"},onClick:je=>{je.stopPropagation(),X(""),ce(""),be([]),Ie(!1)},children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]}):e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"#999",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("polyline",{points:"6 9 12 15 18 9"})})})]}),Ze&&Oe.length>0&&e.jsx("div",{style:{position:"absolute",top:"100%",left:0,right:0,backgroundColor:"#fff",border:"1px solid #E0E0E0",borderRadius:"8px",maxHeight:"200px",overflowY:"auto",zIndex:100,boxShadow:"0 4px 12px rgba(0,0,0,0.1)",marginTop:"4px"},children:Oe.map((je,Ve)=>{const he=typeof je=="string"?je:je?.bankName||je?.name||String(je);return e.jsx("div",{onClick:()=>{X(he),ce(""),Ie(!1)},style:{padding:"10px 16px",fontSize:"14px",fontFamily:"Poppins",cursor:"pointer",borderBottom:Ve<Oe.length-1?"1px solid #F0F0F0":"none"},onMouseEnter:Ye=>Ye.currentTarget.style.backgroundColor="#F5F9FD",onMouseLeave:Ye=>Ye.currentTarget.style.backgroundColor="#fff",children:he},Ve)})})]}),!T&&e.jsxs("div",{className:"fp:w-full fp:flex fp:items-center fp:justify-between fp:border-1 fp:border-dashed fp:border-[#cccccc] fp:rounded-lg fp:py-3 fp:px-8 fp:cursor-pointer fp:mt-2",onClick:()=>Z.current?.click(),children:[e.jsxs("div",{className:"fp:flex fp:flex-col fp:items-center",children:[e.jsx("span",{className:"fp:text-[#aaa]",children:"Upload Cheque Image"}),e.jsx("span",{className:"fp:text-[12px] fp:text-[#aaa]",children:"(JPG, JPEG, PNG, PDF - Max 10MB)"})]}),e.jsx("img",{src:me.uploadIcon,className:"fp:w-5 fp:h-5",alt:"Upload"})]}),T&&e.jsxs("div",{className:"fp:w-full fp:flex fp:flex-col fp:p-3 fp:space-y-1 fp:border-2 fp:border-gray-200 fp:rounded-lg",children:[e.jsx("label",{className:"fp:text-[12px] fp:text-[#16558B]",children:"Payment Proof"}),e.jsxs("div",{className:"fp:w-full fp:flex fp:items-center fp:justify-between fp:gap-2",children:[e.jsx("label",{className:"fp:text-[14px] fp:font-medium fp:truncate fp:flex-1 fp:min-w-0",children:T.name}),e.jsxs("div",{className:"fp:flex fp:items-center fp:space-x-4 fp:flex-shrink-0",children:[e.jsx("img",{src:me.trash,className:"fp:w-4 fp:h-4 fp:cursor-pointer",onClick:()=>q(!0)}),e.jsx("img",{src:me.eye,className:"fp:w-4 fp:h-4 fp:cursor-pointer",onClick:()=>ge(!0)})]})]})]}),H&&e.jsx("span",{className:"fp:text-red-500 fp:text-[12px] fp:mt-1",children:"We couldn't process your payment due to a network error. Please retry."}),e.jsx("button",{className:`fp:w-full fp:h-12 fp:mt-4 fp:rounded-lg fp:text-[16px] fp:flex fp:items-center fp:justify-center fp:bg-[#16558B] fp:text-white ${!U||!ee.trim()||!Q.trim()||we?"fp:opacity-50 fp:cursor-not-allowed":"fp:cursor-pointer"}`,onClick:Ne,disabled:!ee.trim()||!Q.trim()||!U||we,children:we?e.jsxs("div",{className:"fp:flex fp:items-center fp:space-x-2",children:[e.jsxs("svg",{className:"fp:animate-spin fp:h-5 fp:w-5 fp:text-white",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"fp:opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"fp:opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8v4a4 4 0 00-4 4H4z"})]}),e.jsx("span",{children:"Processing..."})]}):ne})]})]}),e.jsxs(ls,{open:oe,onClose:()=>K(!1),children:[e.jsx(cs,{children:e.jsxs("div",{className:"fp:w-full fp:flex fp:flex-col fp:justify-center fp:items-center",children:[e.jsx("img",{src:me.Gateway,className:"fp:w-15 fp:h-15"}),e.jsx("span",{style:{fontFamily:"Poppins"},className:"fp:text-[16px] fp:mt-3 fp:text-wrap fp:font-semibold fp:text-center fp:text-[#222222]",children:"Payment has not been completed. Do you still want to close?"})]})}),e.jsx(Ls,{children:e.jsxs("div",{className:"fp:w-full fp:flex fp:justify-between fp:px-3 fp:mb-3 fp:gap-3",children:[e.jsx("button",{style:{fontFamily:"Poppins"},className:"fp:flex-1 fp:h-[48px] fp:text-[18px] fp:border-2 fp:border-gray-300 fp:text-gray-400 fp:rounded-xl",onClick:()=>{K(!1),l()},children:"Exit"}),e.jsx("button",{style:{fontFamily:"Poppins"},className:"fp:flex-1 fp:h-[48px] fp:text-[18px] fp:bg-[#16558B] fp:text-white fp:rounded-xl",onClick:()=>K(!1),children:"Continue"})]})})]}),e.jsxs(ls,{open:Ue,onClose:()=>q(!1),children:[e.jsx(cs,{children:e.jsxs("div",{className:"fp:w-full fp:flex fp:flex-col fp:justify-center fp:items-center fp:space-y-1",children:[e.jsx("img",{src:me.chequeDeleted,className:"fp:w-14 fp:h-14"}),e.jsx("span",{style:{fontFamily:"Poppins"},className:"fp:text-[14px] fp:text-center fp:font-semibold",children:"Are you sure?"}),e.jsx("span",{style:{fontFamily:"Poppins"},className:"fp:text-[12px] fp:text-gray-500 fp:text-center",children:"This cheque image will be deleted."})]})}),e.jsx(Ls,{children:e.jsxs("div",{className:"fp:w-full fp:flex fp:justify-between fp:px-3 fp:mb-3 fp:gap-3",children:[e.jsx("button",{style:{fontFamily:"Poppins"},className:"fp:flex-1 fp:h-[44px] fp:text-[16px] fp:border fp:border-gray-300 fp:text-gray-500 fp:rounded-xl",onClick:()=>{V(null),q(!1)},children:"Yes, Delete"}),e.jsx("button",{style:{fontFamily:"Poppins"},className:"fp:flex-1 fp:h-[44px] fp:text-[16px] fp:bg-[#16558B] fp:text-white fp:rounded-xl",onClick:()=>q(!1),children:"No"})]})})]})]}),e.jsxs(ls,{open:xe,onClose:()=>ge(!1),children:[e.jsx(pn,{sx:{padding:"8px 12px"},children:e.jsx("div",{className:"fp:w-full fp:flex fp:justify-end",children:e.jsx("div",{className:"fp:w-8 fp:h-8 fp:flex fp:items-center fp:justify-center fp:bg-gray-100 fp:hover:bg-gray-200 fp:rounded-full fp:cursor-pointer fp:shadow-md",onClick:()=>ge(!1),children:e.jsx("img",{src:me.closingCross,className:"fp:w-4 fp:h-4",alt:"Close"})})})}),e.jsx(cs,{children:ot&&T&&e.jsx(e.Fragment,{children:T.type.includes("pdf")?e.jsx("iframe",{src:ot,className:"fp:w-full fp:h-[500px] fp:rounded-lg"}):e.jsx("img",{src:ot,alt:"Preview",className:"fp:w-full fp:rounded-lg"})})})]})]})};function $e(A){return Number(A??0).toLocaleString("en-IN",{minimumFractionDigits:2,maximumFractionDigits:2})}const Zf=({open:A,onClose:l,onPaymentCollected:m,selectedLenderIdx:C=-1,selectedLenderFiCode:o=null,selectedLenderTenureMappings:F=[],selectedLenderRepaymentOption:P=null,selectedLenderDisbursementAccount:O=null})=>{const{tenureMappings:Y,payableValue:U,paymentType:G,paymentInvoice:T,invoices:V,chemistId:Z,leadId:ee,fiCode:Ae,typeOfApp:oe,payerMobileNumber:K,distributorIdnum:xe,distributorName:ge,drawdownRepaymentOption:H,creditLimitData:J,payerUuid:ne,salesmanId:le,sessionId:we}=Zt(),{analyticsPayloadFields:se}=un(),Q=oe==="FUNDLY_COLLECT_APP"||oe==="FUNDLY_QR_COLLECT_APP"||oe==="FUNDLY_QR_WEB",X=()=>{const fe=Ht.getCarryForwardContext();return{purpose:"fundly_pay_consent",mobile:K||null,session_id:fe.session_id||we||"",platform:fe.payment_mode?"collect":oe==="FUNDLY_MART"?"fundlymart":"collect",device_type:Hr(),os:Yr(),app_version:null,user_type:le&&le>0?"salesman":"guest",user_uuid:ne||null,scan_id:fe.scan_id??null,view_id:fe.view_id??null,notification_id:null,notification_channel:null}},W=F.length>0?F:Y,[ce,Oe]=I.useState(-1),[be,Ze]=I.useState(C);I.useEffect(()=>{C!==-1&&Ze(C)},[C]);const[Ie,Me]=I.useState(!1),ae=()=>{l()},Ce=o||Ae,Be=Ce==="TRILLIONLOAN",Ee=new Date;Ee.setDate(Ee.getDate()+1);const[De,Se]=I.useState(Be?new Date:Ee),[Ne,Ue]=I.useState(["","","","","",""]),q=I.useRef([]),[ve,Pe]=I.useState(0),[Ge,ht]=I.useState("idle"),[ot,Mt]=I.useState(!1),[je,Ve]=I.useState(!1),[he,Ye]=I.useState(""),[et,lt]=I.useState(""),[St,ps]=I.useState(oe==="FUNDLY_COLLECT_APP"||oe==="FUNDLY_QR_COLLECT_APP"||oe==="FUNDLY_QR_WEB"?"Collect":"Pay Now"),[zt,Cs]=I.useState(!1),[Rt,Hs]=I.useState(null),[Wt,ns]=I.useState(null),[Ds,is]=I.useState(!1),[ys,Ws]=I.useState(null),[vs,Ns]=I.useState([]),[Ss,bs]=I.useState(!1),fs=I.useMemo(()=>I.lazy(()=>Promise.all([Promise.resolve().then(()=>require("./index-dakp3H4r.cjs")).then(fe=>fe.index),Promise.resolve().then(()=>require("./index-DcMNzMFf.cjs")).then(fe=>fe.index)]).then(([{Worker:fe,Viewer:Le},{defaultLayoutPlugin:ye}])=>({default:({fileUrl:He})=>{const Re=/Android|iPhone|iPad|iPod/i.test(navigator.userAgent),tt=()=>{let st;if(He.startsWith("data:application/pdf;base64,")){const ft=He.replace("data:application/pdf;base64,",""),dt=Uint8Array.from(atob(ft),Gt=>Gt.charCodeAt(0)),Vt=new Blob([dt],{type:"application/pdf"});st=URL.createObjectURL(Vt)}else st=He;if(Re){const ft=document.createElement("a");ft.href=st,ft.download="KFS_Document.pdf",document.body.appendChild(ft),ft.click(),document.body.removeChild(ft),setTimeout(()=>{st.startsWith("blob:")&&URL.revokeObjectURL(st)},1e3)}else{const ft=document.createElement("iframe");ft.style.display="none",ft.src=st,document.body.appendChild(ft),ft.onload=()=>{ft.contentWindow?.focus(),ft.contentWindow?.print(),setTimeout(()=>{document.body.removeChild(ft),st.startsWith("blob:")&&URL.revokeObjectURL(st)},1e3)}}},rs=ye({sidebarTabs:()=>[],renderToolbar:st=>e.jsx(st,{children:ft=>{const{CurrentPageInput:dt,NumberOfPages:Vt,Zoom:Gt,ZoomIn:os,ZoomOut:An}=ft;return e.jsxs("div",{style:{display:"flex",alignItems:"center",width:"100%",padding:"0 8px",gap:"4px"},children:[e.jsx(An,{}),e.jsx(Gt,{}),e.jsx(os,{}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",marginLeft:"8px"},children:[e.jsx(dt,{}),e.jsx("span",{style:{fontSize:"13px",color:"#555"},children:"/"}),e.jsx(Vt,{})]}),e.jsx("button",{onClick:tt,style:{marginLeft:"auto",background:"none",border:"none",cursor:"pointer",padding:"4px",display:"flex",alignItems:"center"},title:"Print",children:e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"#16558B",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("polyline",{points:"6 9 6 2 18 2 18 9"}),e.jsx("path",{d:"M6 18H4a2 2 0 0 1-2-2v-5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2"}),e.jsx("rect",{x:"6",y:"14",width:"12",height:"8"})]})})]})}})});return e.jsx(fe,{workerUrl:"https://unpkg.com/pdfjs-dist@3.11.174/build/pdf.worker.min.js",children:e.jsx(Le,{fileUrl:He,plugins:[rs]})})}}))),[]),Qt=I.useCallback(fe=>{const Le=fe.getFullYear(),ye=String(fe.getMonth()+1).padStart(2,"0"),He=String(fe.getDate()).padStart(2,"0");return`${Le}-${ye}-${He}`},[]),qt=I.useCallback(async()=>{if(Ce!=="TRILLIONLOAN"){Cs(!1);return}Cs(!0);try{const fe=Je(),Le=o||Ae||"",ye=P||H||"BULLET",He=new URLSearchParams({loanAmount:String(U),businessId:Z||"",openedOnDate:Qt(De||Ee),productType:"INSTACASH",tenureMagnitude:String(W[ce]?.tenureValue||""),tenureUnit:String(W[ce]?.tenureUnit||""),fiCode:Le,repaymentOption:ye,supplierId:xe||""});G==="INVOICE_COLLECT"&&T?.length>0&&He.append("invoiceNumber",T.map(rs=>rs.invoiceId).join(","));const Re=`${Wn()}/kfs/report?${He.toString()}`,tt=await pt.get(Re,{headers:{accept:"application/json",Authorization:`Bearer ${fe}`}});Hs(tt.data),ns(tt.data?.documentId??null),is(!1)}catch(fe){console.error("[Fundly Pay] Error fetching KFS:",fe),Hs(null),ns(null),is(!1)}finally{Cs(!1)}},[o,Ae,P,H,U,Z,De,ce,W,xe,G,T,Qt]),Vs=I.useCallback(async()=>{if(Ce==="TRILLIONLOAN")try{const fe=Je(),Le=new URLSearchParams({businessId:Z||"",intents:"DRAWDOWN_KFS_SIGN",fiCode:Ce||""}),ye=`${Wn()}/consent?${Le.toString()}`,Re=(await pt.get(ye,{headers:{accept:"*/*","Content-Type":"application/json",Authorization:`Bearer ${fe}`}})).data;if(Ns(Array.isArray(Re)?Re:[]),Re?.[0]?.consentMessage){let tt=Re[0].consentMessage;tt=tt.replace("{{lenderName}}",Ce||""),tt=tt.replace("Drawdown Request Letter",'<span class="kfs-link" style="color:#16558B;text-decoration:underline;cursor:pointer">Drawdown Request Letter</span>'),tt=tt.replace("Sanction Letter",'<span class="kfs-link" style="color:#16558B;text-decoration:underline;cursor:pointer">Sanction Letter</span>'),tt=tt.replace("Key Fact Statement",'<span class="kfs-link" style="color:#16558B;text-decoration:underline;cursor:pointer">Key Fact Statement</span>'),Ws(tt)}}catch(fe){console.error("[Fundly Pay] Error fetching consent:",fe),Ws(null)}},[Z]),In=I.useCallback(async()=>{try{const fe=Je(),Le=`${Wn()}/consent`;await pt.post(Le,{businessId:Z||"",intent:"DRAWDOWN_KFS_SIGN",consents:vs.map(ye=>({consentId:ye.consentId,accepted:!0}))},{headers:{Accept:"application/json","Content-Type":"application/json",Authorization:`Bearer ${fe}`}})}catch(fe){console.error("[Fundly Pay] Error submitting consent:",fe)}},[Z,vs]),us=I.useCallback(()=>{Rt&&bs(!0)},[Rt]),Bs=I.useMemo(()=>Rt?Rt.kfsDocumentBytes?`data:application/pdf;base64,${Rt.kfsDocumentBytes}`:Rt.kfsDocumentUrl||Rt.documentUrl||null:null,[Rt]),Xt=I.useRef(null);I.useEffect(()=>{const fe=Xt.current;if(!fe)return;const Le=ye=>{ye.target.classList.contains("kfs-link")&&us()};return fe.addEventListener("click",Le),()=>fe.removeEventListener("click",Le)},[us,ys]);const ks=async(fe=!1)=>{lt("");try{K&&ge&&await bf(K,ge),Q&&Ht.trackOtpInitiated({...X(),is_resend:fe})}catch(Le){console.error("Error sending OTP:",Le);const ye=Le,He=ye?.response?.data?.errorMessage||ye?.response?.data?.message||ye?.message||"Failed to send OTP. Please try again.";lt(He),ht("resend"),Pe(0)}},Xs=async()=>{if(!navigator.onLine){Ve(!0),ps("Submit Again");return}if(Q){const Re=Ne.every(tt=>tt!=="");if(Ge==="idle"||!Re)return}if(Ve(!1),ot)return;if(Mt(!0),!De){console.error("[Fundly Pay] Payment date is required"),Mt(!1);return}const fe=De.toISOString(),Le=fe.split("T")[0],ye=o||Ae,He={paymentMode:"FUNDLY_PAY",paymentDate:fe,paymentType:G,distributorCode:xe,...Wt&&{documentId:Wt},invoiceCount:T?.length||V?.length||0,otpRequired:Q,...se,loanDueDate:Te?.maturityDate??null,loanCreditedAmount:Te?.creditedAmount??null,loanTenure:Te?.tenure??null,loanDrawdownRequestDTO:{businessId:Z||ee,fiCode:ye,requestedAmount:U,scheduledDate:Le,tenure:W[ce]?.tenureValue||"",tenureUnit:W[ce]?.tenureUnit?.replace(/s$/i,"")||"",invoiceIds:oe==="FUNDLY_MART"||oe==="FUNDLY_TRADE"?[]:G==="INVOICE_COLLECT"?T?.map(Re=>Re.invoiceId)??[]:V??[],sourceSystem:oe,paymentType:G}};Z&&Z.trim()!==""?He.chemistBusinessId=Z:ee&&ee.trim()!==""&&(He.leadId=ee),G==="INVOICE_COLLECT"?He.paymentInvoice=T:G==="DIRECT_COLLECT"&&(He.invoiceIds=V,He.paidAmount=U),Q&&(He.loanDrawdownRequestDTO.mobileNumber=K,He.loanDrawdownRequestDTO.loanInitiateOtp=Ne.join("")),K&&(He.payerMobileNumber=K),Ce==="TRILLIONLOAN"&&In();try{const Re=await xn(He),tt=Re?.data||Re;tt&&!tt.scheduleDate&&(tt.scheduleDate=Le),tt&&Te?.lastRepaymentDate&&(tt.dueDate=Te.lastRepaymentDate),m&&m(tt)}catch(Re){const tt=Re?.response?.data?.errorMessage||Re?.response?.data?.errorDesc||Re?.response?.data?.message||Re?.message||"Payment failed. Please try again.";Q&&Ht.trackOtpVerified({...X(),status:"failed",failure_reason:tt,error_code:Re?.response?.data?.errorCode||null}),Ye(tt)}finally{Mt(!1)}},gt=(fe,Le)=>{if(!/^[0-9]?$/.test(fe))return;const ye=[...Ne];ye[Le]=fe,Ue(ye),fe&&Le<5&&q.current[Le+1]?.focus()},js=(fe,Le)=>{fe.key==="Backspace"&&!Ne[Le]&&Le>0&&q.current[Le-1]?.focus()},Cn=()=>{ht("countdown"),Pe(30),ks(Ge==="resend")};I.useEffect(()=>{if(Ge==="countdown"&&ve>0){const fe=setInterval(()=>{Pe(Le=>Le-1)},1e3);return()=>clearInterval(fe)}else Ge==="countdown"&&ve===0&&(ht("resend"),ks(!0))},[ve,Ge]);const ct=I.useMemo(()=>{if(Be&&zt)return!0;const fe=ce!==-1,Le=De!==null,ye=be!==-1||!J?.subLimits,He=Be?Ds:!0;if(Q){const Re=Ne.every(tt=>tt!=="");return!(fe&&Re&&Le&&ye&&He)}return!(fe&&Le&&ye&&He)},[ce,be,Ne,oe,De,J,Ds,zt]),[Te,bt]=I.useState(null),[Es,yn]=I.useState(!1),ze=async()=>{if(ce===-1)return;const fe=W[ce],Le=o||Ae||"",ye=P||H||"BULLET",He=O||"SUPPLIER";yn(!0);try{const Re=await Ff({loanAmount:Number(U),businessId:Z||"",openedOnDate:Qt(De||Ee),productType:"INSTACASH",tenureMagnitude:fe.tenureValue,tenureUnit:fe.tenureUnit,fiCode:Le,repaymentOption:ye,disbursementAccount:He});bt(Re)}catch(Re){console.error("Error fetching EMI:",Re),bt(null)}finally{yn(!1)}};return I.useEffect(()=>{let fe;return A&&ce!==-1&&be!==-1&&(fe=window.setTimeout(()=>{ze()},1e3)),()=>{clearTimeout(fe)}},[ce,be,De]),I.useEffect(()=>{if(A){if(Oe(0),Be)Se(new Date),is(!1);else{const fe=new Date;fe.setDate(fe.getDate()+1),Se(fe)}Vs()}},[A,Vs]),I.useEffect(()=>{if(!A||Ce!=="TRILLIONLOAN")return;const fe=window.setTimeout(()=>{qt()},400);return()=>clearTimeout(fe)},[ce,De,qt]),I.useEffect(()=>{const fe=()=>{A&&ce!==-1&&(ze(),qt())};return window.addEventListener("online",fe),()=>{window.removeEventListener("online",fe)}},[A,ce,qt]),e.jsxs(ds,{open:A,onClose:ae,children:[e.jsxs("div",{style:{fontFamily:"Poppins"},className:"fp:w-full fp:px-4 fp:pt-6 fp:mb-12 ",children:[e.jsx("div",{className:"fp:w-full fp:flex fp:items-center fp:justify-end",children:e.jsx("img",{src:me.closingCross,className:"fp:w-4 fp:h-4 fp:cursor-pointer",onClick:()=>Me(!0)})}),he&&e.jsxs("div",{className:"fp:w-full fp:bg-red-50 fp:border fp:border-red-200 fp:rounded-xl fp:p-3 fp:flex fp:items-start fp:space-x-2 fp:mt-4",children:[e.jsx("svg",{className:"fp:w-5 fp:h-5 fp:text-red-500 fp:flex-shrink-0 fp:mt-0.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),e.jsxs("div",{className:"fp:flex-1",children:[e.jsx("p",{className:"fp:text-[14px] fp:text-red-700 fp:font-medium",children:"Payment Failed"}),e.jsx("p",{className:"fp:text-[12px] fp:text-red-600 fp:mt-1",children:he})]}),e.jsx("button",{onClick:()=>Ye(""),className:"fp:text-red-400 fp:hover:text-red-600",children:e.jsx("svg",{className:"fp:w-4 fp:h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M6 18L18 6M6 6l12 12"})})})]}),e.jsxs("div",{className:"fp:w-full fp:flex fp:flex-col fp:mt-4 fp:space-y-4",children:[e.jsx("div",{children:e.jsx(Hi,{value:De,onChange:fe=>Se(fe),minDate:Be?void 0:Ee,label:"Select Payment Date",fullWidth:!0,disabled:Be})}),e.jsxs("div",{className:"fp:w-full fp:flex fp:flex-col fp:space-y-2 ",children:[e.jsx("span",{className:"fp:text-[15px] fp:font-medium fp:text-[#222222]",children:"Tenure"}),e.jsx("div",{className:"fp:w-full fp:flex fp:space-x-4 ",children:W&&W.length>0?W.map((fe,Le)=>e.jsxs("button",{type:"button",className:`fp:py-1 fp:px-6 fp:border-[] fp:rounded-2xl fp:text-[14px] fp:font-medium fp:focus:outline-none fp:transition-colors fp:duration-150 ${ce===Le?"fp:border-[#16558B] fp:bg-[#E6F0FA] fp:text-[#16558B]":"fp:border-[#D0D0D0] fp:text-gray-700 fp:bg-white"}`,onClick:()=>{Oe(Le)},children:[fe.tenureValue," ",fe.tenureUnit]},Le)):e.jsx("span",{className:"fp:py-1 fp:px-6 fp:border-2 fp:rounded-2xl fp:text-[14px] fp:border-[#D0D0D0] fp:text-gray-700 fp:font-medium",children:"No tenure available"})})]}),!Be&&e.jsxs("span",{className:"fp:text-[12px] fp:font-medium fp:text-green-600 fp:text-wrap",children:["₹",$e(U)," will be processed via Fundly Credit — a loan will be set up in retailer's account."]}),e.jsxs("div",{className:"fp:text-[12px] fp:w-full fp:border fp:p-4 fp:space-y-3 fp:rounded-2xl fp:flex fp:flex-col fp:border-[#E8EEF3] ",children:[e.jsxs("div",{className:"fp:flex fp:justify-between",children:[e.jsx("label",{className:"fp:text-gray-700",children:"Due date"}),e.jsx("label",{className:"fp:font-medium",children:Te?.lastRepaymentDate?oi(Te.lastRepaymentDate):"—"})]}),e.jsxs("div",{className:"fp:flex fp:justify-between",children:[e.jsx("label",{className:"fp:text-gray-700",children:"ROI (Annualised)"}),e.jsx("label",{className:"fp:font-medium",children:Te?.normalInterestRate!=null?`${Te.normalInterestRate}%`:"—"})]}),e.jsxs("div",{className:"fp:flex fp:justify-between",children:[e.jsx("label",{className:"fp:text-gray-700",children:"Interest/₹ 10,000/day"}),e.jsx("label",{className:"fp:font-medium",children:Te?.interestPerDay!=null?`₹${Te.interestPerDay}`:"—"})]}),e.jsxs("div",{className:"fp:flex fp:justify-between",children:[e.jsx("label",{className:"fp:text-gray-700",children:"Penal Charges"}),e.jsx("label",{className:"fp:font-medium",children:Te?.penalInterestRate!=null?`${Te.penalInterestRate}% p.a`:"—"})]}),e.jsxs("div",{className:"fp:flex fp:justify-between",children:[e.jsx("label",{className:"fp:text-gray-700",children:"Processing Fee"}),e.jsx("label",{className:"fp:font-medium",children:Te?.processingFeeExclGst!=null?`₹${Number(Te.processingFeeExclGst).toLocaleString("en-IN")}`:"—"})]}),e.jsxs("div",{className:"fp:flex fp:justify-between",children:[e.jsx("label",{className:"fp:text-gray-700",children:"APR"}),e.jsx("label",{className:"fp:font-medium",children:Te?.apr!=null?`${Te.apr}%`:"—"})]}),e.jsxs("div",{className:"fp:flex fp:justify-between",children:[e.jsx("label",{className:"fp:text-gray-700",children:"Net Disbursed Amount"}),e.jsx("label",{className:"fp:font-medium",children:Te?.creditedAmount!=null?`₹${Number(Te.creditedAmount).toLocaleString("en-IN")}`:"—"})]})]}),Q&&e.jsxs("div",{className:"fp:w-full fp:flex fp:flex-col fp:space-y-4 fp:border-2 fp:border-[#E8EEF3] fp:mt-2 fp:rounded-2xl fp:p-3",children:[e.jsx("label",{className:"fp:font-medium fp:text-[15px]",children:"Retailer Verification"}),e.jsxs("div",{className:"fp:w-full fp:flex fp:space-x-2 fp:justify-between",children:[e.jsx("div",{className:"fp:flex fp:border-2 fp:rounded-lg fp:px-1 fp:space-x-2 ",children:Ne.map((fe,Le)=>e.jsx("input",{type:"text",value:fe,maxLength:1,placeholder:"●",ref:ye=>{q.current[Le]=ye},onChange:ye=>gt(ye.target.value,Le),onKeyDown:ye=>js(ye,Le),className:"fp:w-7 fp:h-8 fp:text-center fp:text-[16px] fp:outline-none"},Le))}),e.jsxs("button",{onClick:Cn,disabled:Ge==="countdown",className:`fp:text-white fp:text-[12px] fp:px-7 fp:rounded-lg ${Ge==="resend"?"fp:bg-gray-500":"fp:bg-[#16558B]"}`,children:[Ge==="idle"&&"Get OTP",Ge==="countdown"&&`${ve}s`,Ge==="resend"&&"Resend"]})]}),et?e.jsxs("div",{className:"fp:w-full fp:bg-red-50 fp:border fp:border-red-200 fp:rounded-lg fp:p-2 fp:flex fp:items-start fp:space-x-2",children:[e.jsx("svg",{className:"fp:w-4 fp:h-4 fp:text-red-500 fp:flex-shrink-0 fp:mt-0.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),e.jsx("p",{className:"fp:text-[11px] fp:text-red-700",children:et})]}):e.jsxs("label",{className:"fp:text-[13px] fp:flex fp:text-center fp:items-center fp:text-[#16558B]",children:[e.jsx("img",{src:me.info,className:"fp:w-4 fp:h-4 fp:mr-1"}),Ge==="idle"?"OTP will be sent to the retailer for consent.":"An OTP has been sent to the retailer for consent."]})]}),ys&&e.jsx("div",{ref:Xt,className:"fp:text-[12px] fp:text-gray-600 fp:leading-relaxed fp:select-none",dangerouslySetInnerHTML:{__html:ys}}),Be&&e.jsxs("label",{className:"fp:flex fp:items-start fp:space-x-2 fp:cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:Ds,onChange:fe=>{const Le=fe.target.checked;is(Le),Le&&us()},className:"fp:mt-0.5 fp:w-4 fp:h-4 fp:flex-shrink-0 fp:accent-[#16558B]"}),e.jsxs("span",{className:"fp:text-[12px] fp:text-gray-700",children:["I agree to the loan terms and accept the"," ",e.jsx("span",{className:"fp:text-[#16558B] fp:underline fp:cursor-pointer",onClick:fe=>{fe.preventDefault(),us()},children:"Key Fact Statement (KFS)"})]})]}),je&&e.jsx("span",{className:"fp:text-red-500 fp:text-[12px] fp:mt-1",children:"We couldn't process your payment due to a network error. Please retry."}),e.jsx("button",{className:`fp:w-full fp:h-12 fp:mt-4 fp:rounded-lg fp:text-[16px] fp:flex fp:items-center fp:justify-center
609
609
  ${ct||ot?"fp:bg-gray-400 fp:text-white fp:cursor-not-allowed":"fp:bg-[#16558B] fp:text-white"}`,onClick:()=>{!ct&&!ot&&Xs()},disabled:ct||ot,children:ot?"Processing...":St})]})]}),Ss&&Bs&&Pp.createPortal(e.jsx("div",{style:{position:"fixed",top:0,left:0,right:0,bottom:0,zIndex:99999,display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"rgba(0,0,0,0.6)"},onClick:()=>bs(!1),children:e.jsxs("div",{style:{backgroundColor:"#fff",borderRadius:"16px",display:"flex",flexDirection:"column",width:"calc(100% - 40px)",height:"calc(100% - 80px)",maxWidth:"700px",overflow:"hidden",boxShadow:"0 8px 32px rgba(0,0,0,0.2)"},onClick:fe=>fe.stopPropagation(),children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 16px",borderBottom:"1px solid #E8EEF3",fontFamily:"Poppins",flexShrink:0},children:[e.jsx("span",{style:{fontSize:"16px",fontWeight:600,color:"#222",fontFamily:"Poppins"},children:"Key Fact Statement"}),e.jsx("button",{onClick:()=>bs(!1),style:{padding:"4px",background:"none",border:"none",cursor:"pointer"},children:e.jsx("img",{src:me.closingCross,style:{width:"20px",height:"20px"}})})]}),e.jsx("div",{style:{flex:1,overflow:"hidden"},children:e.jsx(I.Suspense,{fallback:e.jsx("div",{style:{padding:"20px",color:"#666",fontFamily:"Poppins"},children:"Loading..."}),children:e.jsx(fs,{fileUrl:Bs})})})]})}),document.body),e.jsxs(ls,{open:Ie,onClose:()=>Me(!1),children:[e.jsx(cs,{children:e.jsxs("div",{className:"fp:w-full fp:flex fp:flex-col fp:justify-center fp:items-center",children:[e.jsx("img",{src:me.Gateway,className:"fp:w-15 fp:h-15"}),e.jsx("span",{style:{fontFamily:"Poppins"},className:"fp:text-[16px] fp:mt-3 fp:text-wrap fp:font-semibold fp:text-center fp:text-[#222222]",children:"Payment has not been completed. Do you still want to close?"})]})}),e.jsx(Ls,{children:e.jsxs("div",{className:"fp:w-full fp:flex fp:justify-between fp:px-3 fp:mb-3 fp:gap-3",children:[e.jsx("button",{style:{fontFamily:"Poppins"},className:"fp:flex-1 fp:h-[48px] fp:text-[18px] fp:border-2 fp:border-gray-300 fp:text-gray-400 fp:rounded-xl",onClick:()=>{Me(!1),ae()},children:"Exit"}),e.jsx("button",{style:{fontFamily:"Poppins"},className:"fp:flex-1 fp:h-[48px] fp:text-[18px] fp:bg-[#16558B] fp:text-white fp:rounded-xl",onClick:()=>Me(!1),children:"Continue"})]})})]})]})},qf=({open:A,onClose:l})=>{const{paymentType:m,paymentInvoice:C,invoices:o,payableValue:F,salesmanPhoneNumber:P,distributorIdnum:O,distributorName:Y,payerMobileNumber:U,chemistId:G,leadId:T}=Zt(),{analyticsPayloadFields:V}=un(),Z=()=>{l()},[ee,Ae]=I.useState(""),[oe,K]=I.useState(!1),[xe,ge]=I.useState(""),[H,J]=I.useState(!1),[ne,le]=I.useState(5),[we,se]=I.useState(""),Q=I.useRef(null),X=I.useRef(null);I.useEffect(()=>{A||(Ae(""),ge(""),J(!1),le(5),Q.current&&clearTimeout(Q.current),X.current&&clearInterval(X.current))},[A]);const W=()=>{le(5),Q.current&&clearTimeout(Q.current),X.current&&clearInterval(X.current);let Me=5;X.current=setInterval(()=>{Me--,le(Me),Me<=0&&X.current&&clearInterval(X.current)},1e3),Q.current=setTimeout(async()=>{await At.navigateHome()},5e3)},ce=async()=>{J(!0),ge("");const Me={paymentMode:"PAYMENT_LINK",paymentDate:new Date().toISOString(),paymentType:m,paidAmount:F,distributorCode:O,salesmanPhoneNumber:P?.trim()||void 0,invoiceCount:C?.length||o?.length||0,...V};G&&G.trim()!==""?Me.chemistBusinessId=G:T&&T.trim()!==""&&(Me.leadId=T),m==="INVOICE_COLLECT"?Me.paymentInvoice=C:m==="DIRECT_COLLECT"&&(Me.invoiceIds=o),U&&(Me.payerMobileNumber=U);try{const ae=await xn(Me),Ce=ae.data||ae;se(Ce.chemistCode||""),Ce?.link?(Ae(Ce.link),ge("")):(Ae(""),ge("Failed to generate payment link. Please try again."),W())}catch(ae){Ae("");const Ce=ae?.response?.data?.errorResponse?.errorMessage||ae?.response?.data?.errorMessage||ae?.response?.data?.errorResponse?.errorDesc||ae?.response?.data?.errorDesc||ae?.response?.data?.message||ae?.message||"Failed to generate payment link. Please try again.";ge(Ce),W()}finally{J(!1)}},[Oe,be]=I.useState(!1),Ze=async()=>{if(ee)try{await navigator.clipboard.writeText(ee),be(!0),setTimeout(()=>be(!1),1500)}catch{}},Ie=async()=>{if(ee){const Me=`Complete your payment:
610
610
 
611
611
  Amount: ₹${Number(F).toLocaleString("en-IN")}
@@ -662,7 +662,7 @@ Fundly Team`;await At.shareString(Me)}};return e.jsxs(ds,{open:A,onClose:Z,child
662
662
  .animate-spin-slow {
663
663
  animation: spin-slow 2s linear infinite;
664
664
  }
665
- `})]}),eu=({size:A=24,color:l="currentColor",className:m,style:C})=>e.jsx("svg",{width:A,height:A,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:m,style:C,"aria-hidden":"true",children:e.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:l,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}),tu=({size:A=24,color:l="currentColor",className:m,style:C})=>e.jsxs("svg",{width:A,height:A,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:m,style:C,"aria-hidden":"true",children:[e.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:l,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),e.jsx("path",{d:"M22 6L12 13L2 6",stroke:l,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]}),Ur={PHONE:"+91-9892422528",EMAIL:"connect@fundly.ai"},Et={FUNDLY_PAY:"FUNDLY_PAY",DYNAMIC_QR:"DYNAMIC_QR",STATIC_QR:"STATIC_QR",PAYMENT_LINK:"PAYMENT_LINK",CASH:"CASH",CHEQUE:"CHEQUE",UPI:"UPI",NETBANKING:"NETBANKING",BANK_TRANSFER:"BANK_TRANSFER"},ti={FUNDLY_CUSTOMER_APP:"FUNDLY_CUSTOMER_APP",FUNDLY_COLLECT_APP:"FUNDLY_COLLECT_APP",FUNDLY_TRADE:"FUNDLY_TRADE"},su=({open:A,onClose:l})=>{const m=C=>{navigator.clipboard.writeText(C)};return e.jsx(ds,{open:A,onClose:l,children:e.jsxs("div",{className:"fp:w-full fp:flex fp:flex-col fp:px-8 fp:py-4 fp:space-y-4 fp:mt-2 fp:mb-12",children:[e.jsx("div",{className:"fp:w-full fp:flex fp:items-center fp:justify-end",children:e.jsx("img",{src:me.closingCross,className:"fp:w-4 fp:h-4 fp:cursor-pointer",onClick:l,alt:"Close"})}),e.jsx("img",{src:me.customerSup,className:"fp:w-14 fp:h-14",alt:"Support"}),e.jsxs("div",{className:"fp:flex fp:space-x-6 fp:items-center",children:[e.jsx(eu,{size:24,color:"#16558B"}),e.jsx("span",{className:"fp:font-semibold",children:Ur.PHONE}),e.jsx("img",{src:me.copy,className:"fp:w-5 fp:h-5 fp:cursor-pointer",onClick:()=>m(Ur.PHONE),alt:"Copy"})]}),e.jsxs("div",{className:"fp:flex fp:space-x-6 fp:items-center",children:[e.jsx(tu,{size:24,color:"#16558B"}),e.jsx("span",{className:"fp:font-semibold",children:Ur.EMAIL}),e.jsx("img",{src:me.copy,className:"fp:w-5 fp:h-5 fp:cursor-pointer",onClick:()=>m(Ur.EMAIL),alt:"Copy"})]})]})})},nu=({open:A,onClose:l,onConfirm:m})=>e.jsxs(ls,{open:A,onClose:l,children:[e.jsx(pn,{children:e.jsx("div",{className:"fp:w-full fp:flex fp:justify-end",children:e.jsx("img",{src:me.closingCross,className:"fp:w-4 fp:h-4 fp:cursor-pointer",onClick:l,alt:"Close"})})}),e.jsx(cs,{children:e.jsxs("div",{style:{fontFamily:"Poppins"},className:"fp:w-full fp:flex fp:flex-col fp:justify-center fp:items-center",children:[e.jsx("img",{src:me.paymentLeave,className:"fp:w-18 fp:h-18",alt:"Leave"}),e.jsx("span",{className:"fp:text-[18px] fp:text-wrap fp:font-bold fp:text-center",children:"Leave this page?"}),e.jsx("span",{className:"fp:text-[14px] fp:text-wrap fp:font-semibold fp:text-center fp:text-[#6D6D6D]",children:"Any unsaved payment details will be lost."})]})}),e.jsx(Ls,{children:e.jsxs("div",{style:{fontFamily:"Poppins"},className:"fp:w-full fp:flex fp:justify-between fp:px-3 fp:mb-3 fp:gap-3",children:[e.jsx("button",{className:"fp:flex-1 fp:w-[96px] fp:h-[48px] fp:border-2 fp:border-gray-400 fp:text-gray-400 fp:rounded-xl",onClick:m,children:"Yes, Leave"}),e.jsx("button",{className:"fp:flex-1 fp:w-[96px] fp:h-[48px] fp:bg-[#16558B] fp:text-white fp:rounded-xl",onClick:l,children:"No"})]})})]}),iu=()=>{const{partnerCredentials:A}=Zt(),[l,m]=I.useState(null),[C,o]=I.useState(!1),[F,P]=I.useState(null);return{login:I.useCallback(async()=>{o(!0),P(null);try{if(!A)throw new Error("Partner credentials not provided");const Y={loginType:"PARTNER",username:A.username,password:A.password},U=await vf(Y);if(U?.accessToken){const G=U.accessToken;return _l(G),m(G),G}throw new Error("No access token received")}catch(Y){const U=Y instanceof Error?Y:new Error("Login failed");throw P(U),U}finally{o(!1)}},[A]),token:l,isLoading:C,error:F}},ru=A=>{const{setChemistId:l,setLeadId:m,setDistributorIdnum:C,setTypeOfApp:o,setAnalyticsContext:F,setPaymentInvoice:P,setPayableValue:O,setInvoices:Y,setPaymentType:U,setSalesmanId:G,setSalesmanName:T,setScanChannel:V,setScanOrigin:Z,setSdkEntryPoint:ee,distributorIdnum:Ae,chemistId:oe,leadId:K}=Zt(),xe=I.useRef(!1);I.useEffect(()=>{const ge=ne=>{if(typeof ne.data!="object"||ne.data===null||ne.source!==window||ne.data?.source==="react-devtools-content-script"||ne.source!==window||ne.data?.source?.includes("react-devtools")||ne.origin!==window.origin)return;const{source:le,analyticsContext:we,distributorId:se,chemistId:Q,paymentType:X,payableAmount:W,invoices:ce,paymentInvoice:Oe,salesmanId:be,salesmanName:Ze,scanChannel:Ie,scanOrigin:Me,sdkEntryPoint:ae}=ne.data;se&&C(se),Q&&l(Q),le&&o(le),we&&F(we),Array.isArray(Oe)&&P(Oe),W&&O(W),Array.isArray(ce)&&Y(ce),X&&U(X),be&&G(be),Ze&&T(Ze),V(Ie??null),Z(Me??null),ae&&ee(ae),xe.current||(A(),xe.current=!0)},H=oe&&oe.trim()!=="",J=K&&K.trim()!=="";return Ae&&(H||J)&&!xe.current&&(A(),xe.current=!0),window.addEventListener("message",ge),()=>window.removeEventListener("message",ge)},[A,l,m,C,o,F,P,O,Y,U,G,T,V,Z,ee,Ae,oe,K])},ou=A=>{const{distributorIdnum:l,typeOfApp:m,chemistId:C,leadId:o,payableValue:F,salesmanId:P,paymentType:O,setDistributorName:Y,setChemistName:U,setPayerMobileNumber:G,setSalesmanPhoneNumber:T,setTenureMappings:V,setFiCode:Z,setDrawdownRepaymentOption:ee,setCreditLimitData:Ae,setPayerUuid:oe}=Zt(),[K,xe]=I.useState([]),[ge,H]=I.useState(null),[J,ne]=I.useState(null),[le,we]=I.useState(null),[se,Q]=I.useState(null),[X,W]=I.useState(!0);return I.useEffect(()=>{A&&(async()=>{const Oe={distributorBusinessId:l,source:m,...C&&C.trim()!==""&&{chemistBusinessId:C},...o&&o.trim()!==""&&{leadId:o},payableAmount:F,...P&&{salesmanId:P},...O&&{collectType:O}};try{const be=await jf(Oe);H(be.bankDetails),be.bankDetails&&(Y(be.bankDetails.distributorName||""),U(be.bankDetails.chemistName||""),G(be.bankDetails.mobileNumber||""),T(be.bankDetails.salesmanPhoneNumber||""),be.bankDetails.mobileNumber&&Yf(be.bankDetails.mobileNumber).then(Me=>{Me&&oe(Me)}));const Ze=be.paymentOption.find(Me=>Me.name==="FUNDLY_PAY");Ze?.details?.tenureMappings&&V(Ze.details.tenureMappings),ne(Ze?.details?.maxEligibleLimit??null),we(Ze?.details?.minEligibleLimit??null),Q(Ze?.reason??null),Ze?.details?.fiCode&&Z(Ze.details.fiCode),Ze?.details?.drawdownRepaymentOption&&ee(Ze.details.drawdownRepaymentOption);const Ie=be.paymentOption.filter(Me=>Me.isActive).map(Me=>Me.name);if(xe(Ie),Ze?.isActive&&be.bankDetails?.chemistBusinessId)try{const Me=await Mf(be.bankDetails.chemistBusinessId);Ae(Me)}catch(Me){console.warn("Credit limit filter API failed:",Me),Ae(null)}W(!1)}catch{W(!1)}})()},[A]),{paymentOptions:K,bankDetails:ge,maxEligibleLimit:J,minEligibleLimit:le,fundlyPayReason:se,loading:X}};function i0(){const[A,l]=I.useState({activeDrawer:null,paymentData:null}),m=I.useCallback(O=>{l({activeDrawer:O,paymentData:null})},[]),C=I.useCallback(()=>{l({activeDrawer:null,paymentData:null})},[]),o=I.useCallback(O=>{l({activeDrawer:"SUCCESS",paymentData:O||null})},[]),F=I.useCallback(O=>{l({activeDrawer:"FAILURE",paymentData:O||null})},[]),P=I.useCallback(O=>A.activeDrawer===O,[A.activeDrawer]);return{activeDrawer:A.activeDrawer,paymentData:A.paymentData,openPaymentDrawer:m,closeDrawer:C,isDrawerOpen:P,handlePaymentSuccess:o,handlePaymentFailure:F,showFundlyPayDrawer:P("FUNDLY_PAY"),showUpiDrawer:P("UPI"),showDynamicQrDrawer:P("DYNAMIC_QR"),showStaticQrDrawer:P("STATIC_QR"),showPaymentLinkDrawer:P("PAYMENT_LINK"),showNetbankingDrawer:P("NETBANKING"),showCashDrawer:P("CASH"),showChequeDrawer:P("CHEQUE"),showBankTransferDrawer:P("BANK_TRANSFER"),showSuccessDrawer:P("SUCCESS"),showFailureDrawer:P("FAILURE")}}const au=({onPaymentCollected:A,onPaymentFailed:l})=>{const[m,C]=I.useState(!1),[o,F]=I.useState(!1),[P,O]=I.useState(!1),[Y,U]=I.useState(null),{paymentData:G,openPaymentDrawer:T,closeDrawer:V,handlePaymentSuccess:Z,handlePaymentFailure:ee,showFundlyPayDrawer:Ae,showUpiDrawer:oe,showDynamicQrDrawer:K,showStaticQrDrawer:xe,showPaymentLinkDrawer:ge,showNetbankingDrawer:H,showCashDrawer:J,showChequeDrawer:ne,showBankTransferDrawer:le,showSuccessDrawer:we,showFailureDrawer:se}=i0(),[Q,X]=I.useState(!1),[W,ce]=I.useState(-1),[Oe,be]=I.useState(null),[Ze,Ie]=I.useState([]),[Me,ae]=I.useState(null),[Ce,Be]=I.useState(null),Ee=I.useRef(!1),{distributorName:De,distributorIdnum:Se,payableValue:Ne,typeOfApp:Ue,analyticsContext:q,transactionId:ve,showResultOnly:Pe,successButtonText:Ge,failureButtonText:ht,creditLimitData:ot,paymentType:Mt,paymentInvoice:je,invoices:Ve,chemistId:he,chemistName:Ye,leadId:et,salesmanId:lt,salesmanName:St,payerMobileNumber:ps,payerUuid:zt,scanId:Cs,viewId:Rt,sessionId:Hs,erpId:Wt,outstandingAmount:ns,billId:Ds,billType:is,billStatus:ys,billTotalAmount:Ws,dueDate:vs,fromDate:Ns,toDate:Ss,notificationId:bs,notificationChannel:fs,mobileChanged:Qt,scanOrigin:qt,scanChannel:Vs,sdkEntryPoint:In}=Zt(),us=I.useMemo(()=>({type:"collection",distributorId:Se||"",chemistId:he||void 0,leadId:et||void 0,invoices:je||[],paymentType:Mt||"INVOICE_COLLECT",salesmanId:lt||void 0,payerMobileNumber:ps||void 0}),[Se,he,et,je,Mt,lt,ps]),{login:Bs,token:Xt,error:ks}=iu(),Xs=I.useCallback(async()=>{try{await Bs(),U(null)}catch(ze){const fe=ze instanceof Error?ze.message:"Authentication failed. Please try again later.";U(fe)}},[Bs]);ru(Xs);const{paymentOptions:gt,bankDetails:js,maxEligibleLimit:Cn,minEligibleLimit:ct,fundlyPayReason:Te,loading:bt}=ou(Xt);I.useEffect(()=>{if(!Pe&&!ve){const ze=new URLSearchParams(window.location.search);if((ze.has("orderId")||ze.has("transactionId"))&&!Xt){const Le=new URL(window.location.href);Le.searchParams.delete("orderId"),Le.searchParams.delete("transactionId"),window.history.replaceState({},"",Le.toString())}}},[Pe,Xt,ve]),I.useEffect(()=>{if(Y||ks){const ze=setTimeout(async()=>{await At.navigateHome()},1e4);return()=>clearTimeout(ze)}},[Y,ks]),I.useEffect(()=>{const ze=new URLSearchParams(window.location.search);(ze.get("orderId")||ze.get("transactionId"))&&Xt&&!Pe&&T("UPI")},[Xt,Pe,T]),I.useEffect(()=>{!Pe||!ve||!Xt||!we&&!se&&!oe&&T("UPI")},[Pe,ve,Xt,we,se,oe,T]),I.useEffect(()=>{if(Pe||bt||!Xt||Ee.current||gt.length===0)return;const ze=q?.userType?String(q.userType).trim().toLowerCase():null;if(!zt)return;Ee.current=!0,zt&&Ht.setUserIdentity(zt);const fe=q?.platform?String(q.platform).trim().toLowerCase():null,Le=()=>In||"",ye=ft=>gt.includes(ft),He=Number(Ne)||0,Re=Hs||`sdk_session_${Date.now()}_${Math.random().toString(36).substring(2,11)}`,tt=ns!=null?He<ns:null,st=(ft=>{if(!ft)return null;const dt=ft.toUpperCase();return["PARTIAL_PAID","PENDING","OUTSTANDING","UNPAID"].includes(dt)?"outstanding":["PAID","COMPLETED","CLEARED"].includes(dt)?"paid":["PROCESSING","IN_PROCESS","IN_PROGRESS"].includes(dt)?"in_process":["OUTDATED","OVERDUE","EXPIRED"].includes(dt)?"outdated":ft})(ys);Ht.saveCarryForwardContext({scan_id:Cs||null,view_id:Rt||null,bill_id:Ds,bill_type:is,bill_status:st,bill_total_amount:Ws,outstanding_amount:ns,due_date:vs,from_date:Ns,to_date:Ss,notification_id:bs,notification_channel:fs,scan_channel:Vs||null,scan_origin:qt||null,partial_payment:tt,sdk_version:"1.5.0-beta.0",app_version:q?.appVersion?String(q.appVersion):null,session_id:Re}),Ht.trackPaymentSDKLaunched({scan_id:Cs||null,view_id:Rt||null,bill_id:Ds,bill_type:is,bill_status:st,bill_total_amount:Ws,outstanding_amount:ns,due_date:vs,from_date:Ns,to_date:Ss,notification_id:bs,notification_channel:fs,scan_channel:Vs||null,scan_origin:qt||null,mobile_changed:Qt,invoice_count:Mt==="DIRECT_COLLECT"?Ve?.length||0:je?.length||0,partial_payment:tt,supplier_id:Se?.toString()||"",supplier_name:De||"",business_id:he||null,business_name:Ye||null,erp_id:Wt||null,erp_name:null,salesman_id:lt?.toString()||null,salesman_name:St||null,party_code:null,user_type:ze,user_uuid:zt||"",payment_amount:He,payment_type:Mt==="INVOICE_COLLECT"?"invoice_pay":"direct_pay",session_id:Re,platform:fe,device_type:Hr(),os:Yr(),app_version:q?.appVersion?String(q.appVersion):null,sdk_version:"1.5.0-beta.0",sdk_entry_point:Le(),is_payment_enabled:gt.length>0,payment_option_upi:ye(Et.UPI)||ye("UPI"),payment_option_net_banking:ye("NETBANKING")||ye("NET_BANKING"),payment_option_fundly_pay:ye(Et.FUNDLY_PAY)||ye("FUNDLY_PAY"),payment_option_cash:ye(Et.CASH)||ye("CASH"),payment_option_cheque:ye(Et.CHEQUE)||ye("CHEQUE"),payment_option_distributor_qr:ye(Et.STATIC_QR)||ye("STATIC_QR"),payment_option_payment_qr:ye(Et.DYNAMIC_QR)||ye("DYNAMIC_QR"),payment_option_payment_link:ye(Et.PAYMENT_LINK)||ye("PAYMENT_LINK"),payment_option_bank_transfer:ye("BANK_TRANSFER"),status:"success",failure_reason:null,failure_stage:null,error_code:null,error_description:null,mobile_number:ps||null,uuid:zt||null})},[bt,Xt,Pe,gt,zt,Se,De,he,Ye,et,lt,Ne,Mt,je,Ue,Cs,Rt,Hs,Wt,ns,Ds,is,ys,Ws,vs,Ns,Ss,bs,fs,Qt,q,qt]);const Es=async()=>{C(!1),await At.navigateHome()},yn=ze=>{if(!ze?.productRules||!Array.isArray(ze.productRules))return{tenureMappings:[],repaymentOption:null,disbursementAccount:null};const fe=Mt==="INVOICE_COLLECT"?"YES":"NO",ye=ze.productRules.find(He=>He.isInvoiceRequired===fe&&He.disbursementAccount==="SUPPLIER")||ze.productRules[0];return{tenureMappings:ye?.tenureMappings||[],repaymentOption:ye?.repaymentOption||null,disbursementAccount:ye?.disbursementAccount||null}};return Y||ks?e.jsx("div",{style:{fontFamily:"Poppins"},className:"fp:relative fp:w-full fp:h-screen fp:flex fp:items-center fp:justify-center fp:px-4 fp:bg-[#F8FCFF]",children:e.jsxs("div",{className:"fp:w-full fp:max-w-md fp:bg-white fp:border fp:border-red-100 fp:rounded-2xl fp:p-8 fp:text-center fp:shadow-lg",children:[e.jsx("div",{className:"fp:w-16 fp:h-16 fp:mx-auto fp:mb-4 fp:bg-red-50 fp:rounded-full fp:flex fp:items-center fp:justify-center",children:e.jsx("svg",{className:"fp:w-8 fp:h-8 fp:text-red-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.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"})})}),e.jsx("h3",{className:"fp:text-[20px] fp:font-semibold fp:text-gray-800 fp:mb-3",children:"Authentication Failed"}),e.jsx("p",{className:"fp:text-[14px] fp:text-gray-600 fp:mb-4",children:Y||ks?.message||"We're unable to authenticate your session at the moment. Please try again later."}),e.jsx("p",{className:"fp:text-[12px] fp:text-gray-500",children:"This window will close automatically in a few seconds..."})]})}):bt?e.jsx($f,{}):Pe?e.jsxs("div",{style:{fontFamily:"Poppins"},className:"fp:relative fp:w-full fp:h-screen fp:flex fp:items-center fp:justify-center fp:bg-[#F8FCFF]",children:[e.jsx(To,{open:we,onClose:()=>{V(),A&&G&&A(G)},paymentData:G,buttonText:Ge}),e.jsx(zo,{open:se,onClose:()=>{V(),l&&G&&l(G)},paymentData:G,buttonText:ht}),e.jsx(Fl,{open:oe,onClose:()=>V(),onPaymentCollected:ze=>{Z(ze)},onPaymentFailed:ze=>{ee(ze)}})]}):e.jsxs("div",{style:{fontFamily:"Poppins"},className:"fp:relative fp:w-full fp:h-screen fp:pt-10 fp:flex fp:flex-col fp:px-4 fp:bg-[#F8FCFF] fp:overflow-x-hidden",children:[e.jsx("div",{className:"fp:w-full fp:h-10 fp:flex fp:items-center fp:space-x-3",children:e.jsx("img",{src:me.backButton,alt:"Back",className:"fp:w-4 fp:h-4 fp:cursor-pointer",onClick:()=>C(!0)})}),e.jsxs("div",{className:"fp:w-full fp:items-center fp:text-center fp:justify-between fp:flex ",children:[e.jsx("h1",{className:"fp:font-medium fp:text-[20px] fp:text-[#222222]",children:"Payment Options"}),e.jsxs("label",{className:"fp:flex fp:items-center fp:text-[14px] fp:cursor-pointer",onClick:()=>O(!0),children:[e.jsx("img",{src:me.QuestionMark,className:"fp:w-4 fp:h-4 fp:mr-1"}),"Get Help"]})]}),e.jsx("div",{className:"fp:flex-1 fp:overflow-y-auto fp:mb-12 fp:mt-2",children:Ue==="FUNDLY_CUSTOMER_APP"&&!js?e.jsx("div",{className:"fp:w-full fp:h-full fp:flex fp:items-center fp:justify-center",children:e.jsxs("div",{className:"fp:w-full fp:max-w-md fp:bg-white fp:border fp:border-gray-200 fp:rounded-2xl fp:p-8 fp:text-center fp:shadow-sm",children:[e.jsx("div",{className:"fp:w-16 fp:h-16 fp:mx-auto fp:mb-4 fp:bg-gray-100 fp:rounded-full fp:flex fp:items-center fp:justify-center",children:e.jsx("svg",{className:"fp:w-8 fp:h-8 fp:text-gray-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.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"})})}),e.jsx("h3",{className:"fp:text-[18px] fp:font-semibold fp:text-gray-800 fp:mb-2",children:"Bank Details Not Available"}),e.jsx("p",{className:"fp:text-[14px] fp:text-gray-500",children:"We couldn't find bank details for this distributor. Please contact support for assistance."})]})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"fp:w-full fp:border fp:border-gray-100 fp:bg-white fp:rounded-xl fp:p-4 fp:mt-6 fp:flex fp:flex-col fp:space-y-2",children:[e.jsxs("div",{className:"fp:flex fp:justify-between fp:items-start",children:[e.jsxs("div",{className:"fp:flex fp:flex-col fp:flex-1",children:[e.jsx("h4",{className:"fp:text-[12px] fp:font-normal fp:text-gray-400",children:"Collect For"}),e.jsx("label",{className:"fp:font-semibold fp:text-[16px] fp:text-[#222222]",children:De})]}),e.jsxs("div",{className:"fp:flex fp:flex-col fp:items-end fp:flex-shrink-0",children:[e.jsx("h4",{className:"fp:text-[12px] fp:font-normal fp:text-gray-400 fp:text-right",children:"Collection Amount"}),e.jsxs("label",{className:"fp:font-semibold fp:text-[16px] fp:text-[#222222]",children:["₹",$e(Ne)]})]})]}),(Ue==="FUNDLY_CUSTOMER_APP"||Ue==="FUNDLY_QR_WEB")&&js&&e.jsxs("div",{className:"fp:w-full fp:mt-2",children:[e.jsxs("label",{className:"fp:cursor-pointer fp:select-none fp:text-[#16558B] fp:font-medium fp:text-[12px]",onClick:()=>F(ze=>!ze),children:["Bank Details ",o?"▲":"▼"]}),o&&e.jsxs("div",{className:"fp:w-full fp:flex fp:flex-col fp:space-y-3 fp:mt-2",children:[e.jsxs("div",{className:"fp:flex fp:flex-col ",children:[e.jsx("h4",{className:"fp:text-[12px] fp:font-normal fp:text-gray-400",children:"Account Holder Name"}),e.jsx("label",{className:"fp:text-[14px] fp:font-medium fp:text-[#222222]",children:js.accountName})]}),e.jsxs("div",{className:"fp:flex fp:justify-between",children:[e.jsxs("div",{className:"fp:flex fp:flex-col fp:space-y-1",children:[e.jsx("h4",{className:"fp:text-[12px] fp:font-normal fp:text-gray-400",children:"Account Number"}),e.jsx("label",{className:"fp:text-[14px] fp:font-medium fp:text-[#222222]",children:js.accountNumber})]}),e.jsxs("div",{className:"fp:flex fp:flex-col fp:space-y-1",children:[e.jsx("h4",{className:"fp:text-[12px] fp:font-normal fp:text-gray-400",children:"IFSC Code"}),e.jsx("label",{className:"fp:text-[14px] fp:font-medium fp:text-[#222222]",children:js.ifsc})]})]})]})]})]}),gt.includes(Et.FUNDLY_PAY)&&(()=>{const ze=Number(Ne??0),fe=ct??1e3,Le=Cn??null;let ye=null,He=!1;ze<fe?(ye=`Fundly Pay not available below ₹${fe.toLocaleString("en-IN")} payment.`,He=!0):Le!==null&&ze>Le?(ye=`Max Eligible Amount: ₹${$e(Le)}`,He=!0):Te&&(ye=Te);let Re=[],tt=0;ot?.subLimits&&Array.isArray(ot.subLimits)&&(Re=ot.subLimits.filter(dt=>dt.expired===!1),Re.sort((dt,Vt)=>{const Gt=dt.maxEligibleAmount||dt.availableLimit||0;return(Vt.maxEligibleAmount||Vt.availableLimit||0)-Gt}),Re.length>0&&(tt=Math.max(...Re.map(dt=>dt.maxEligibleAmount||dt.availableLimit||0))));const rs=Re.length>1,st=Re.length===1,ft=Re.length===0;return e.jsxs("div",{className:"fp:w-full fp:flex fp:flex-col fp:mt-6",children:[e.jsx("h2",{className:"fp:text-[16px] fp:font-semibold",children:"Preferred Payment"}),e.jsxs("div",{className:"fp:w-full fp:flex fp:flex-col fp:mt-2",children:[e.jsxs("div",{className:`fp:w-full fp:border fp:border-gray-100 ${He?"fp:bg-[#efefef]":"fp:bg-white"} ${ye||rs&&Q||st?"fp:rounded-t-xl":"fp:rounded-xl"} ${He?"":"fp:cursor-pointer fp:hover:shadow-2xs"} fp:p-4 fp:flex fp:items-center fp:justify-between`,onClick:()=>{if(!He)if(rs)X(!Q);else if(st){ce(0),be(Re[0].fiCode);const dt=yn(Re[0]);Ie(dt.tenureMappings),ae(dt.repaymentOption),Be(dt.disbursementAccount),T("FUNDLY_PAY")}else T("FUNDLY_PAY")},children:[e.jsxs("div",{className:"fp:flex fp:items-center fp:space-x-2",children:[e.jsx("img",{src:me.logo,className:"fp:w-[32px] fp:h-[32px]"}),e.jsx("label",{className:"fp:text-[14px] fp:font-medium fp:cursor-pointer",children:"Fundly Pay"}),e.jsxs("div",{className:"fp:flex fp:items-center fp:bg-[#34A877] fp:py-1 fp:px-3 fp:rounded-4xl",children:[e.jsx("img",{src:me.primary,className:"fp:w-3 fp:h-3"}),e.jsx("label",{className:"fp:text-[10px] fp:font-medium fp:text-white",children:"1 Click Payment"})]})]}),e.jsxs("div",{className:"fp:flex fp:items-center fp:space-x-2",children:[!He&&rs&&e.jsx("svg",{className:`fp:w-5 fp:h-5 fp:text-[#16558B] fp:transition-transform fp:duration-200 ${Q?"fp:rotate-180":""}`,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"3",d:"M19 9l-7 7-7-7"})}),!He&&!rs&&e.jsx("img",{src:me.cardOpener,className:"fp:w-4 fp:h-4"})]})]}),!He&&st&&e.jsx("div",{className:"fp:w-full fp:bg-[#E6F7EF] fp:flex fp:p-2 fp:text-[#34A877] fp:rounded-b-xl fp:border-x fp:border-b fp:border-gray-100",children:e.jsxs("label",{className:"fp:text-[10px] fp:font-medium",children:["Max Eligible Amount:"," ",e.jsxs("span",{className:"fp:font-bold",children:["₹",$e(Re[0].maxEligibleAmount||Re[0].availableLimit||0)]})]})}),!He&&rs&&!Q&&e.jsx("div",{className:"fp:w-[95%] fp:m-auto fp:bg-[#E6F7EF] fp:flex fp:p-2 fp:text-[#34A877] fp:rounded-b-xl fp:border-x fp:border-b fp:border-gray-100",children:e.jsxs("label",{className:"fp:text-[10px] fp:font-medium",children:["Max Eligible Amount:"," ",e.jsxs("span",{className:"fp:font-bold",children:["₹",$e(tt)]})]})}),!He&&rs&&Q&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fp:w-full fp:bg-white fp:border-x fp:border-gray-100 fp:rounded-b-xl fp:px-3 fp:pt-3 fp:pb-2 fp:flex fp:flex-col fp:space-y-2.5",children:Re.map((dt,Vt)=>{const Gt=dt.maxEligibleAmount||dt.availableLimit||0,os=Gt<ze;return e.jsx("button",{type:"button",disabled:os,className:`fp:w-full fp:text-left fp:focus:outline-none fp:transition-all fp:duration-150 ${os?"fp:cursor-not-allowed fp:opacity-50":W===Vt?"fp:bg-[#EBF4FA]":"fp:bg-white fp:hover:border-[#16558B] fp:cursor-pointer"}`,style:{fontFamily:"Poppins",paddingTop:"10px",paddingLeft:"10px",paddingBottom:"10px",paddingRight:"16px",borderRadius:"8px",borderWidth:"0.87px",borderStyle:"solid",borderColor:os?"#E0E0E0":W===Vt?"#C5DBED":"#E8EEF3",height:"35px",display:"flex",alignItems:"center"},onClick:()=>{if(!os){ce(Vt),be(dt.fiCode);const An=yn(dt);Ie(An.tenureMappings),ae(An.repaymentOption),Be(An.disbursementAccount),X(!1),T("FUNDLY_PAY")}},children:e.jsxs("div",{className:"fp:flex fp:justify-between fp:items-center fp:w-full",style:{lineHeight:"24px"},children:[e.jsx("span",{className:`fp:font-medium ${os?"fp:text-gray-400":"fp:text-[#16558B]"}`,style:{fontSize:"12px",letterSpacing:"0px",textTransform:"capitalize"},children:dt.fiCode?.toLowerCase()}),e.jsxs("span",{className:`fp:text-[12px] fp:font-semibold ${os?"fp:text-gray-400":"fp:text-[#000000]"}`,style:{letterSpacing:"0px",lineHeight:"100%"},children:["₹ ",$e(Gt)]})]})},Vt)})}),e.jsx("div",{className:"fp:w-[95%] fp:m-auto fp:bg-[#E6F7EF] fp:flex fp:p-2 fp:text-[#34A877] fp:rounded-b-xl fp:border-x fp:border-b fp:border-gray-100",children:e.jsxs("label",{style:{fontFamily:"Poppins"},children:[e.jsxs("span",{className:"fp:text-[10px] fp:font-medium",children:["Max Eligible Amount:"," "]}),e.jsxs("span",{className:"fp:font-bold fp:text-[10px]",children:["₹",$e(tt)]})]})})]}),ye&&ft&&e.jsx("div",{className:"fp:w-full fp:bg-red-50 fp:flex fp:p-2 fp:text-red-700 fp:rounded-b-xl fp:border-x fp:border-b fp:border-gray-100",children:e.jsx("label",{className:"fp:text-[11px] fp:ml-2",children:ye})}),!ye&&ft&&Le!==null&&e.jsx("div",{className:"fp:w-full fp:bg-green-50 fp:flex fp:p-2 fp:text-green-700 fp:rounded-b-xl fp:border-x fp:border-b fp:border-gray-100",children:e.jsxs("label",{className:"fp:text-[11px] fp:ml-2",children:["Max Eligible Amount:"," ",e.jsxs("span",{className:"fp:font-medium",children:["₹",$e(Le)]})]})})]})]})})(),gt.includes(Et.UPI)&&e.jsxs("div",{className:"fp:w-full fp:mt-6 fp:flex fp:flex-col fp:space-y-2",children:[e.jsxs("div",{className:"fp:flex fp:items-center fp:space-x-2",children:[e.jsx("img",{src:me.upi,className:"fp:h-[20px]",alt:"UPI Logo"}),e.jsx("h2",{className:"fp:text-[16px] fp:font-semibold",children:"Pay by UPI"})]}),e.jsxs("div",{className:"fp:w-full fp:border fp:border-gray-100 fp:bg-white fp:hover:shadow-2xs fp:cursor-pointer fp:rounded-xl fp:p-4 fp:flex fp:items-center fp:justify-between",onClick:()=>T("UPI"),children:[e.jsxs("div",{className:"fp:flex fp:items-center fp:space-x-2",children:[e.jsx("img",{src:me.upiIcon,className:"fp:w-[32px] fp:h-[32px]",alt:"UPI"}),e.jsx("label",{className:"fp:text-[14px] fp:font-medium fp:text-[#222222]",children:"UPI"}),e.jsx("div",{className:"fp:flex fp:items-center fp:bg-green-50 fp:rounded-4xl fp:py-1 fp:px-2",children:e.jsx("label",{className:"fp:text-[10px] fp:text-green-700 fp:font-medium",children:"₹ 0 charges"})})]}),e.jsx("img",{src:me.cardOpener,className:"fp:w-4 fp:h-4"})]})]}),gt.includes(Et.NETBANKING)&&e.jsxs("div",{className:"fp:w-full fp:mt-6 fp:flex fp:flex-col fp:space-y-2",children:[e.jsx("h2",{className:"fp:text-[16px] fp:font-semibold",children:"Netbanking"}),e.jsxs("div",{className:"fp:w-full fp:border fp:border-gray-100 fp:bg-white fp:hover:shadow-2xs fp:cursor-pointer fp:rounded-xl fp:p-4 fp:flex fp:items-center fp:justify-between",onClick:()=>T("NETBANKING"),children:[e.jsxs("div",{className:"fp:flex fp:items-center fp:space-x-2",children:[e.jsx("img",{src:me.scanqrIcon,className:"fp:w-[32px] fp:h-[32px]"}),e.jsx("label",{className:"fp:text-[14px] fp:font-medium fp:text-[#222222]",children:"Netbanking"})]}),e.jsx("img",{src:me.cardOpener,className:"fp:w-4 fp:h-4"})]})]}),(gt.includes(Et.BANK_TRANSFER)||gt.includes(Et.DYNAMIC_QR)&&!(Ue===ti.FUNDLY_CUSTOMER_APP&&gt.includes(Et.PAYMENT_LINK))||gt.includes(Et.PAYMENT_LINK)&&(Ue===ti.FUNDLY_COLLECT_APP||Ue===ti.FUNDLY_TRADE))&&e.jsxs("div",{className:"fp:w-full fp:mt-6 fp:flex fp:flex-col fp:space-y-2",children:[e.jsx("h2",{className:"fp:text-[16px] fp:font-semibold",children:"Online Payment Options"}),gt.includes(Et.DYNAMIC_QR)&&!(Ue===ti.FUNDLY_CUSTOMER_APP&&gt.includes(Et.PAYMENT_LINK))&&e.jsxs("div",{className:"fp:w-full fp:border fp:border-gray-100 fp:bg-white fp:hover:shadow-2xs fp:cursor-pointer fp:rounded-xl fp:p-4 fp:flex fp:items-center fp:justify-between",onClick:()=>T("DYNAMIC_QR"),children:[e.jsxs("div",{className:"fp:flex fp:items-center fp:space-x-2",children:[e.jsx("img",{src:me.generateqrIcon,className:"fp:w-[32px] fp:h-[32px]"}),e.jsx("label",{className:"fp:text-[14px] fp:font-medium",children:"Generate QR"}),e.jsx("div",{className:"fp:flex fp:items-center fp:bg-green-50 fp:rounded-4xl fp:py-1 fp:px-2",children:e.jsx("label",{className:"fp:text-[10px] fp:text-green-700 fp:font-medium",children:"₹ 0 charges"})})]}),e.jsx("img",{src:me.cardOpener,className:"fp:w-4 fp:h-4"})]}),gt.includes(Et.PAYMENT_LINK)&&(Ue===ti.FUNDLY_COLLECT_APP||Ue===ti.FUNDLY_TRADE)&&e.jsxs("div",{className:"fp:w-full fp:border fp:border-gray-100 fp:bg-white fp:hover:shadow-2xs fp:cursor-pointer fp:rounded-xl fp:p-4 fp:mt-2 fp:flex fp:items-center fp:justify-between",onClick:()=>T("PAYMENT_LINK"),children:[e.jsxs("div",{className:"fp:flex fp:items-center fp:space-x-2",children:[e.jsx("img",{src:me.paymentlinkIcon,className:"fp:w-[32px] fp:h-[32px]"}),e.jsx("label",{className:"fp:text-[14px] fp:font-medium",children:"Payment Link"}),e.jsx("div",{className:"fp:flex fp:items-center fp:bg-green-50 fp:rounded-4xl fp:py-1 fp:px-2",children:e.jsx("label",{className:"fp:text-[10px] fp:text-green-700 fp:font-medium",children:"₹ 0 charges"})})]}),e.jsx("img",{src:me.cardOpener,className:"fp:w-4 fp:h-4"})]}),gt.includes(Et.BANK_TRANSFER)&&e.jsxs("div",{className:"fp:w-full fp:border fp:border-gray-100 fp:bg-white fp:hover:shadow-2xs fp:cursor-pointer fp:rounded-xl fp:p-4 fp:mt-2 fp:flex fp:items-center fp:justify-between",onClick:()=>T("BANK_TRANSFER"),children:[e.jsxs("div",{className:"fp:flex fp:items-center fp:space-x-2",children:[e.jsx("img",{src:me.bankTransferIcon,className:"fp:w-[32px] fp:h-[32px]"}),e.jsx("label",{className:"fp:text-[14px] fp:font-medium fp:text-[#222222]",children:"Bank Transfer"})]}),e.jsx("img",{src:me.cardOpener,className:"fp:w-4 fp:h-4"})]})]}),(gt.includes(Et.CASH)||gt.includes(Et.CHEQUE)||gt.includes(Et.STATIC_QR))&&e.jsxs("div",{className:"fp:w-full fp:mt-6 fp:flex fp:flex-col fp:space-y-2",children:[e.jsx("h2",{className:"fp:text-[16px] fp:font-semibold",children:"More Payment Options"}),gt.includes(Et.STATIC_QR)&&e.jsxs("div",{className:"fp:w-full fp:border fp:border-gray-100 fp:bg-white fp:hover:shadow-2xs fp:cursor-pointer fp:rounded-xl fp:p-4 fp:flex fp:items-center fp:justify-between",onClick:()=>T("STATIC_QR"),children:[e.jsxs("div",{className:"fp:flex fp:items-center fp:space-x-2",children:[e.jsx("img",{src:me.scanqrIcon,className:"fp:w-[32px] fp:h-[32px]"}),e.jsx("label",{className:"fp:text-[14px] fp:font-medium fp:text-[#222222]",children:"Scan QR"})]}),e.jsx("img",{src:me.cardOpener,className:"fp:w-4 fp:h-4"})]}),gt.includes(Et.CASH)&&e.jsxs("div",{className:"fp:w-full fp:border fp:border-gray-100 fp:bg-white fp:hover:shadow-2xs fp:cursor-pointer fp:rounded-xl fp:p-4 fp:flex fp:items-center fp:justify-between",onClick:()=>T("CASH"),children:[e.jsxs("div",{className:"fp:flex fp:items-center fp:space-x-2",children:[e.jsx("img",{src:me.cashIcon,className:"fp:w-[32px] fp:h-[32px]"}),e.jsx("label",{className:"fp:text-[14px] fp:font-medium fp:text-[#222222]",children:"Cash"})]}),e.jsx("img",{src:me.cardOpener,className:"fp:w-4 fp:h-4"})]}),gt.includes(Et.CHEQUE)&&e.jsxs("div",{className:"fp:w-full fp:bg-white fp:border fp:border-gray-100 fp:hover:shadow-2xs fp:cursor-pointer fp:rounded-xl fp:p-4 fp:mt-2 fp:flex fp:items-center fp:justify-between",onClick:()=>T("CHEQUE"),children:[e.jsxs("div",{className:"fp:flex fp:items-center fp:space-x-2",children:[e.jsx("img",{src:me.chequeIcon,className:"fp:w-[32px] fp:h-[32px]"}),e.jsx("label",{className:"fp:text-[14px] fp:font-medium fp:text-[#222222]",children:"Cheque"})]}),e.jsx("img",{src:me.cardOpener,className:"fp:w-4 fp:h-4"})]})]})]})}),e.jsx(Hf,{open:xe,onClose:async()=>{V(),await At.navigateHome()},onPaymentCollected:ze=>{Z(ze)}}),e.jsx(Fl,{open:oe,onClose:async()=>{V(),await At.navigateHome()},onPaymentCollected:ze=>{Z(ze)},onPaymentFailed:ze=>{ee(ze)}}),e.jsx(Kf,{open:H,onClose:async()=>{V(),await At.navigateHome()},onPaymentCollected:ze=>{Z(ze)},onPaymentFailed:ze=>{ee(ze)}}),e.jsx(t0,{open:J,metadata:us,onClose:async()=>{V(),await At.navigateHome()},onPaymentCollected:ze=>{Z(ze)}}),e.jsx(s0,{open:ne,metadata:us,onClose:async()=>{V(),await At.navigateHome()},onPaymentCollected:ze=>{Z(ze)}}),e.jsx(n0,{open:le,metadata:us,onClose:async()=>{V(),await At.navigateHome()},onPaymentCollected:ze=>{Z(ze)}}),e.jsx(Zf,{open:Ae,onClose:()=>{V()},onPaymentCollected:ze=>{Z(ze)},selectedLenderIdx:W,selectedLenderFiCode:Oe,selectedLenderTenureMappings:Ze,selectedLenderRepaymentOption:Me,selectedLenderDisbursementAccount:Ce}),e.jsx(qf,{open:ge,onClose:async()=>{V(),await At.navigateHome()},onPaymentCollected:()=>{Z()}}),e.jsx(Vf,{open:K,onClose:async()=>{V(),await At.navigateHome()},onPaymentCollected:ze=>{Z(ze)},onPaymentFailed:ze=>{ee(ze)}}),e.jsx(To,{open:we,onClose:()=>V(),paymentData:G,buttonText:Ge}),e.jsx(zo,{open:se,onClose:()=>V(),paymentData:G,buttonText:ht}),e.jsx(nu,{open:m,onClose:()=>C(!1),onConfirm:Es}),e.jsx(su,{open:P,onClose:()=>O(!1)}),e.jsxs("div",{className:"fp:absolute fp:bottom-0 fp:left-0 fp:w-full fp:flex fp:flex-col fp:items-center fp:justify-center fp:py-2 fp:bg-[#F8FCFF]",children:[e.jsx("span",{className:"fp:text-[10px] fp:text-[#9CA3AF] fp:font-medium",children:"Powered by"}),e.jsx("a",{href:"https://fundly.ai",target:"_blank",rel:"noopener noreferrer",className:"fp:text-[12px] fp:text-[#16558B] fp:font-bold fp:no-underline",children:"Fundly.ai"})]})]})},r0=I.createContext(void 0);function o0({children:A,initialValues:l}){Gr(l?.environment??"production");const[m,C]=I.useState(l?.partnerCredentials||null),[o,F]=I.useState(l?.businessId||null),[P,O]=I.useState(l?.businessName||null),[Y,U]=I.useState(null),[G,T]=I.useState([]),[V,Z]=I.useState([]),[ee,Ae]=I.useState([]),[oe,K]=I.useState(0),[xe,ge]=I.useState("FULL"),[H,J]=I.useState(null),[ne,le]=I.useState(l?.onPaymentComplete?()=>l.onPaymentComplete:void 0),[we,se]=I.useState(l?.onNavigateHome?()=>l.onNavigateHome:void 0),[Q,X]=I.useState(l?.sessionId||null),[W,ce]=I.useState(l?.erpId||null);I.useEffect(()=>{const be=qr(),Ze=Vr();be&&Ht.configure({enabled:!0,clevertap:{accountId:be,region:Ze}})},[]);const Oe={partnerCredentials:m,setPartnerCredentials:C,businessId:o,setBusinessId:F,businessName:P,setBusinessName:O,selectedLender:Y,setSelectedLender:U,lenderList:G,setLenderList:T,selectedLoans:V,setSelectedLoans:Z,loanList:ee,setLoanList:Ae,totalAmount:oe,setTotalAmount:K,repaymentType:xe,setRepaymentType:ge,redirectionUrl:H,setRedirectionUrl:J,onPaymentComplete:ne,setOnPaymentComplete:le,onNavigateHome:we,setOnNavigateHome:se,sessionId:Q,setSessionId:X,erpId:W,setErpId:ce};return e.jsx(r0.Provider,{value:Oe,children:A})}function Xi(){const A=I.useContext(r0);if(!A)throw new Error("useRepaymentContext must be used within a RepaymentProvider");return A}const a0=I.createContext(void 0);function Qo({children:A,initialValues:l}){Gr(l?.environment??"production");const[m,C]=I.useState(l?.partnerCredentials||null),[o,F]=I.useState(l?.businessId||null),[P,O]=I.useState(l?.businessName||null),[Y,U]=I.useState([]),[G,T]=I.useState(null),[V,Z]=I.useState(l?.filters||null),[ee,Ae]=I.useState(l?.defaultTab||"all"),[oe,K]=I.useState(1),[xe,ge]=I.useState(!0),[H,J]=I.useState(!1),[ne,le]=I.useState(l?.onNavigateHome?()=>l.onNavigateHome:void 0),[we,se]=I.useState(l?.sessionId||null),[Q,X]=I.useState(l?.erpId||null);I.useEffect(()=>{const ce=qr(),Oe=Vr();ce&&Ht.configure({enabled:!0,clevertap:{accountId:ce,region:Oe}})},[]);const W={partnerCredentials:m,setPartnerCredentials:C,businessId:o,setBusinessId:F,businessName:P,setBusinessName:O,transactions:Y,setTransactions:U,selectedTransaction:G,setSelectedTransaction:T,filter:V,setFilter:Z,activeTab:ee,setActiveTab:Ae,currentPage:oe,setCurrentPage:K,hasMore:xe,setHasMore:ge,isLoading:H,setIsLoading:J,onNavigateHome:ne,setOnNavigateHome:le,sessionId:we,setSessionId:se,erpId:Q,setErpId:X};return e.jsx(a0.Provider,{value:W,children:A})}function lu(){const A=I.useContext(a0);if(!A)throw new Error("useTransactionContext must be used within a TransactionProvider");return A}const Qe=({className:A=""})=>e.jsx("div",{className:`fp:animate-pulse fp:bg-gray-200 fp:rounded ${A}`}),cu=[{label:"All",value:"all"},{label:"Success",value:"success"},{label:"Failure",value:"failed"},{label:"Pending",value:"pending"}],du=[{label:"Last 30 days",value:"30"},{label:"Last 60 days",value:"60"},{label:"Last 90 days",value:"90"},{label:"Custom date range",value:"custom"}],pu=[{label:"All",value:"all"},{label:"UPI",value:"UPI"},{label:"NEFT",value:"NEFT"},{label:"RTGS",value:"RTGS"},{label:"IMPS",value:"IMPS"}],fu=A=>{if(!A)return null;const l=new Date,m=new Date(l.getFullYear(),l.getMonth(),l.getDate()),C=Math.round((m.getTime()-A.from.getTime())/(1e3*60*60*24));return C>=29&&C<=31?"30":C>=59&&C<=61?"60":C>=89&&C<=91?"90":"custom"},uu=A=>{if(A==="custom")return;const l=Number(A),m=new Date,C=new Date;return C.setDate(C.getDate()-l),{from:C,to:m}},xu=({open:A,onClose:l,currentFilter:m,onApply:C})=>{const[o,F]=I.useState(["all"]),[P,O]=I.useState(null),[Y,U]=I.useState(null),[G,T]=I.useState(null),[V,Z]=I.useState(["all"]);I.useEffect(()=>{if(A){const H=m.statuses;F(H&&H.length>0?H:["all"]);const J=m.paymentMethods;Z(J&&J.length>0?J:["all"]);const ne=fu(m.dateRange);O(ne),ne==="custom"&&m.dateRange?(U(m.dateRange.from),T(m.dateRange.to)):(U(null),T(null))}},[A]);const ee=H=>{if(H==="all"){F(["all"]);return}F(J=>{const ne=J.filter(le=>le!=="all");if(ne.includes(H)){const le=ne.filter(we=>we!==H);return le.length===0?["all"]:le}return[...ne,H]})},Ae=H=>{if(H==="all"){Z(["all"]);return}Z(J=>{const ne=J.filter(le=>le!=="all");if(ne.includes(H)){const le=ne.filter(we=>we!==H);return le.length===0?["all"]:le}return[...ne,H]})},oe=()=>{F(["all"]),O(null),U(null),T(null),Z(["all"])},K=()=>{const H={...m,statuses:o,paymentMethods:V};P&&P!=="custom"?H.dateRange=uu(P):P==="custom"&&Y&&G?H.dateRange={from:Y,to:G}:H.dateRange=void 0,C(H),l()},xe=H=>{P===H?(O(null),U(null),T(null)):(O(H),H!=="custom"&&(U(null),T(null)))},ge=H=>`fp:px-4 fp:py-2 fp:rounded-full fp:text-[13px] fp:font-medium fp:transition-colors ${H?"fp:bg-[#16558B] fp:text-white":"fp:border fp:border-[#D0D0D0] fp:text-[#222222] fp:bg-white"}`;return e.jsx(ds,{open:A,onClose:l,children:e.jsxs("div",{className:"fp:px-5 fp:pt-5 fp:pb-6",children:[e.jsx("div",{className:"fp:flex fp:justify-center fp:mb-4",children:e.jsx("div",{className:"fp:w-10 fp:h-1 fp:rounded-full fp:bg-[#D0D0D0]"})}),e.jsxs("div",{className:"fp:flex fp:items-center fp:gap-2.5 fp:mb-6",children:[e.jsx("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none",stroke:"#16558B",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M22 12h-4l-3 9L9 3l-3 9H2"})}),e.jsx("h2",{className:"fp:text-[18px] fp:font-semibold fp:text-[#222222]",children:"Apply filters"})]}),e.jsxs("div",{className:"fp:mb-5",children:[e.jsx("p",{className:"fp:text-[14px] fp:font-medium fp:text-[#222222] fp:mb-3",children:"Status"}),e.jsx("div",{className:"fp:flex fp:flex-wrap fp:gap-2",children:cu.map(H=>e.jsx("button",{className:ge(o.includes(H.value)),onClick:()=>ee(H.value),children:H.label},H.value))})]}),e.jsxs("div",{className:"fp:mb-5",children:[e.jsx("p",{className:"fp:text-[14px] fp:font-medium fp:text-[#222222] fp:mb-3",children:"Date Range"}),e.jsx("div",{className:"fp:flex fp:flex-wrap fp:gap-2",children:du.map(H=>e.jsx("button",{className:ge(P===H.value),onClick:()=>xe(H.value),children:H.label},H.value))}),P==="custom"&&e.jsxs("div",{className:"fp:flex fp:gap-3 fp:mt-3",children:[e.jsx("div",{className:"fp:flex-1",children:e.jsx(Hi,{value:Y,onChange:U,label:"From",placeholder:"Start date",fullWidth:!0})}),e.jsx("div",{className:"fp:flex-1",children:e.jsx(Hi,{value:G,onChange:T,minDate:Y||void 0,label:"To",placeholder:"End date",fullWidth:!0})})]})]}),e.jsxs("div",{className:"fp:mb-6",children:[e.jsx("p",{className:"fp:text-[14px] fp:font-medium fp:text-[#222222] fp:mb-3",children:"Payment Mode"}),e.jsx("div",{className:"fp:flex fp:flex-wrap fp:gap-2",children:pu.map(H=>e.jsx("button",{className:ge(V.includes(H.value)),onClick:()=>Ae(H.value),children:H.label},H.value))})]}),e.jsxs("div",{className:"fp:flex fp:gap-3",children:[e.jsx("button",{onClick:oe,className:"fp:flex-1 fp:py-3 fp:rounded-xl fp:border fp:border-[#16558B] fp:text-[#16558B] fp:font-semibold fp:text-[14px] fp:active:scale-[0.97] fp:transition-transform",children:"Clear All"}),e.jsx("button",{onClick:K,className:"fp:flex-1 fp:py-3 fp:rounded-xl fp:bg-[#16558B] fp:text-white fp:font-semibold fp:text-[14px] fp:active:scale-[0.97] fp:transition-transform",children:"Apply"})]})]})})},Au=({status:A})=>{switch(A.toUpperCase()){case"SUCCESS":return e.jsx("div",{className:"fp:w-8 fp:h-8 fp:flex fp:items-center fp:justify-center fp:flex-shrink-0",children:e.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 16 16",fill:"none",children:[e.jsx("path",{d:"M8 0.0996094C10.0945 0.101867 12.1029 0.934966 13.584 2.41602C15.065 3.89706 15.8981 5.90548 15.9004 8L15.8945 8.29297C15.8404 9.75276 15.382 11.1709 14.5684 12.3887C13.7003 13.6878 12.4669 14.7009 11.0234 15.2988C9.57995 15.8967 7.99139 16.0528 6.45898 15.748C4.92653 15.4432 3.5189 14.6908 2.41406 13.5859C1.30923 12.4811 0.556776 11.0735 0.251953 9.54102C-0.0528274 8.00861 0.10326 6.42005 0.701172 4.97656C1.29911 3.53309 2.31222 2.29968 3.61133 1.43164C4.82912 0.617965 6.24724 0.159629 7.70703 0.105469L8 0.0996094ZM10.334 2.36426C9.21945 1.90269 7.99273 1.78223 6.80957 2.01758C5.62646 2.253 4.53952 2.83353 3.68652 3.68652C2.83353 4.53952 2.253 5.62645 2.01758 6.80957C1.78223 7.99273 1.90269 9.21945 2.36426 10.334C2.82595 11.4486 3.60819 12.402 4.61133 13.0723C5.61439 13.7424 6.79368 14.0996 8 14.0996C9.61725 14.0978 11.168 13.4551 12.3115 12.3115C13.4551 11.168 14.0978 9.61725 14.0996 8L14.0957 7.77441C14.054 6.64712 13.7006 5.55177 13.0723 4.61133C12.402 3.60819 11.4486 2.82595 10.334 2.36426Z",fill:"#2FB551",stroke:"white",strokeWidth:"0.2"}),e.jsx("g",{transform:"translate(4.5, 5)",children:e.jsx("path",{d:"M5.91895 0.103516C6.03691 0.0926467 6.15642 0.105413 6.26953 0.140625C6.3824 0.175812 6.48733 0.232873 6.57812 0.308594C6.66904 0.384472 6.74396 0.478068 6.79883 0.583008C6.8537 0.687993 6.88803 0.802895 6.89844 0.920898C6.90882 1.03885 6.89501 1.1576 6.85938 1.27051C6.82373 1.38344 6.76666 1.48847 6.69043 1.5791H6.68945L3.35547 5.5791C3.27113 5.68031 3.16618 5.76248 3.04688 5.81836C2.92748 5.87424 2.79687 5.90243 2.66504 5.90234C2.5332 5.90226 2.40254 5.87342 2.2832 5.81738C2.16405 5.76135 2.05877 5.67939 1.97461 5.57812L0.308594 3.57812C0.233081 3.48748 0.175742 3.38313 0.140625 3.27051C0.105548 3.15793 0.0929033 3.03931 0.103516 2.92188C0.114206 2.80428 0.148246 2.68951 0.203125 2.58496C0.257993 2.48043 0.333141 2.38808 0.423828 2.3125C0.514465 2.23697 0.618817 2.17966 0.731445 2.14453C0.84418 2.10941 0.963459 2.09673 1.08105 2.10742C1.19848 2.11816 1.31258 2.15223 1.41699 2.20703C1.52132 2.26181 1.61396 2.33629 1.68945 2.42676H1.69043L2.58887 3.50391L2.66504 3.59668L2.74219 3.50391L5.30859 0.425781C5.38413 0.334582 5.4773 0.259367 5.58203 0.204102C5.6867 0.148897 5.80111 0.114394 5.91895 0.103516Z",fill:"#2FB551",stroke:"white",strokeWidth:"0.2"})})]})});case"FAILED":return e.jsx("div",{className:"fp:w-8 fp:h-8 fp:flex fp:items-center fp:justify-center fp:flex-shrink-0",children:e.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 16 16",fill:"none",children:[e.jsx("path",{d:"M8 0.75C12.0041 0.75 15.25 3.99594 15.25 8C15.25 12.0041 12.0041 15.25 8 15.25C3.99594 15.25 0.75 12.0041 0.75 8C0.75 3.99594 3.99594 0.75 8 0.75Z",stroke:"#E80000",strokeWidth:"1.5",strokeLinecap:"round"}),e.jsx("path",{d:"M9.88595 6.11719L6.11475 9.88842",stroke:"#E80000",strokeWidth:"1.5",strokeLinecap:"round"}),e.jsx("path",{d:"M6.11475 6.11719L9.88598 9.88842",stroke:"#E80000",strokeWidth:"1.5",strokeLinecap:"round"})]})});case"INITIATED":return e.jsx("div",{className:"fp:w-8 fp:h-8 fp:flex fp:items-center fp:justify-center fp:flex-shrink-0",children:e.jsx("svg",{width:"24",height:"24",viewBox:"-2 -1 16 17",fill:"none",children:e.jsx("path",{d:"M0.75 1.00098C0.750262 0.801579 0.97265 0.682461 1.13867 0.792969L10.3359 6.9248C10.4843 7.02376 10.4843 7.24186 10.3359 7.34082L1.13867 13.4727C0.972648 13.5832 0.750262 13.464 0.75 13.2646V1.00098Z",stroke:"#1E88E5",strokeWidth:"1.5"})})});case"PENDING":default:return e.jsx("div",{className:"fp:w-8 fp:h-8 fp:flex fp:items-center fp:justify-center fp:flex-shrink-0",children:e.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 16 16",fill:"none",children:[e.jsx("path",{d:"M8 0.0996094C10.0945 0.101867 12.1029 0.934966 13.584 2.41602C15.065 3.89706 15.8981 5.90548 15.9004 8L15.8945 8.29297C15.8404 9.75276 15.382 11.1709 14.5684 12.3887C13.7003 13.6878 12.4669 14.7009 11.0234 15.2988C9.57995 15.8967 7.99139 16.0528 6.45898 15.748C4.92653 15.4432 3.5189 14.6908 2.41406 13.5859C1.30923 12.4811 0.556776 11.0735 0.251953 9.54102C-0.0528275 8.00862 0.10326 6.42005 0.701172 4.97656C1.29911 3.53309 2.31222 2.29968 3.61133 1.43164C4.82912 0.617965 6.24724 0.159629 7.70703 0.105469L8 0.0996094ZM10.334 2.36426C9.21945 1.90269 7.99273 1.78223 6.80957 2.01758C5.62646 2.253 4.53952 2.83353 3.68652 3.68652C2.83353 4.53952 2.253 5.62646 2.01758 6.80957C1.78223 7.99273 1.90268 9.21945 2.36426 10.334C2.82595 11.4486 3.60819 12.402 4.61133 13.0723C5.61439 13.7424 6.79368 14.0996 8 14.0996C9.61725 14.0978 11.168 13.4551 12.3115 12.3115C13.4551 11.168 14.0978 9.61725 14.0996 8L14.0957 7.77441C14.054 6.64712 13.7006 5.55177 13.0723 4.61133C12.402 3.60819 11.4486 2.82595 10.334 2.36426Z",fill:"#FFA500",stroke:"white",strokeWidth:"0.2"}),e.jsx("path",{d:"M9.58325 10.4995L7.5404 8.9791C7.24263 8.80264 7 8.37804 7 8.03064V5",stroke:"#FFA500",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]})})}},hu=({onNavigateBack:A,onViewTransaction:l})=>{const{businessId:m}=lu(),[C,o]=I.useState([]),[F,P]=I.useState(!0),[O,Y]=I.useState(null),[U,G]=I.useState(0),[T,V]=I.useState(!1),[Z,ee]=I.useState(0),[Ae,oe]=I.useState({}),[K,xe]=I.useState(!1);I.useEffect(()=>{m&&ge()},[m,U,Ae]);const ge=async()=>{if(!m){Y("Business ID is required"),P(!1);return}try{P(!0),Y(null);const J=await Bf({businessId:m,filter:Ae,page:U,size:10});o(U===0?J.transactions:ne=>[...ne,...J.transactions]),ee(J.totalCount),V(J.hasMore)}catch(J){console.error("Error loading transactions:",J);const ne=J?.response?.data?.errorMessage||J?.response?.data?.message||J?.message||"Failed to load transactions. Please try again.";Y(ne)}finally{P(!1)}},H=J=>new Date(J).toLocaleDateString("en-IN",{day:"numeric",month:"short",year:"numeric"});return F&&U===0?e.jsxs("div",{className:"fp:min-h-screen fp:bg-[#F8FCFF]",children:[e.jsxs("div",{className:"fp:bg-[#F8FCFF] fp:px-4 fp:pt-4 fp:pb-3",children:[e.jsxs("div",{className:"fp:flex fp:items-center fp:justify-between fp:mb-3",children:[e.jsx(Qe,{className:"fp:w-6 fp:h-6 fp:rounded-full"}),e.jsx(Qe,{className:"fp:w-9 fp:h-9 fp:rounded-[10px]"})]}),e.jsx(Qe,{className:"fp:w-40 fp:h-7 fp:rounded-lg"})]}),e.jsx("div",{className:"fp:px-4 fp:py-4 fp:space-y-3",children:[1,2,3,4,5].map(J=>e.jsxs("div",{className:"fp:bg-white fp:rounded-[12px] fp:border fp:border-[#E8EEF8] fp:px-4 fp:py-3.5 fp:flex fp:items-center fp:gap-3",children:[e.jsx(Qe,{className:"fp:w-8 fp:h-8 fp:rounded-full fp:flex-shrink-0"}),e.jsxs("div",{className:"fp:flex-1",children:[e.jsx(Qe,{className:"fp:w-36 fp:h-3.5 fp:rounded fp:mb-2"}),e.jsx(Qe,{className:"fp:w-28 fp:h-3 fp:rounded"})]}),e.jsx(Qe,{className:"fp:w-16 fp:h-3.5 fp:rounded fp:flex-shrink-0"})]},J))})]}):O?e.jsxs("div",{className:"fp:min-h-screen fp:bg-[#F8FCFF]",children:[e.jsxs("div",{className:"fp:bg-[#F8FCFF] fp:px-4 fp:pt-4 fp:pb-3",children:[e.jsx("button",{onClick:A,className:"fp:mb-3 fp:p-1 fp:-ml-1",children:e.jsx("img",{src:me.backButton,alt:"Back",className:"fp:w-6 fp:h-6"})}),e.jsx("h1",{className:"fp:text-2xl fp:font-bold fp:text-[#222222]",children:"Transactions"})]}),e.jsx("div",{className:"fp:flex fp:items-center fp:justify-center fp:min-h-[calc(100vh-80px)] fp:px-4",children:e.jsxs("div",{className:"fp:text-center fp:max-w-md",children:[e.jsx("div",{className:"fp:w-20 fp:h-20 fp:mx-auto fp:mb-4 fp:bg-red-100 fp:rounded-full fp:flex fp:items-center fp:justify-center",children:e.jsx("svg",{className:"fp:w-10 fp:h-10 fp:text-red-600",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})})}),e.jsx("h2",{className:"fp:text-lg fp:font-semibold fp:text-gray-900 fp:mb-2",children:"Failed to Load"}),e.jsx("p",{className:"fp:text-gray-600 fp:mb-6 fp:text-sm",children:O}),e.jsx("button",{onClick:()=>{G(0),ge()},className:"fp:bg-[#16558B] fp:text-white fp:font-semibold fp:py-3 fp:px-6 fp:rounded-xl fp:transition-colors",children:"Try Again"})]})})]}):e.jsxs("div",{className:"fp:min-h-screen fp:bg-[#F8FCFF] fp:pb-10",children:[e.jsxs("div",{className:"fp:bg-[#F8FCFF] fp:px-4 fp:pt-4 fp:pb-3",children:[e.jsxs("div",{className:"fp:flex fp:items-center fp:justify-between fp:mb-2",children:[e.jsx("button",{onClick:A,className:"fp:p-1 fp:-ml-1",children:e.jsx("img",{src:me.backButton,alt:"Back",className:"fp:w-6 fp:h-6"})}),e.jsx("button",{onClick:()=>xe(!0),className:"fp:w-9 fp:h-9 fp:rounded-[10px] fp:bg-[#EAF2FF] fp:flex fp:items-center fp:justify-center",children:e.jsxs("svg",{className:"fp:w-5 fp:h-5 fp:text-[#16558B]",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",strokeWidth:1.8,children:[e.jsx("line",{x1:"4",y1:"6",x2:"20",y2:"6",strokeLinecap:"round"}),e.jsx("line",{x1:"4",y1:"12",x2:"20",y2:"12",strokeLinecap:"round"}),e.jsx("line",{x1:"4",y1:"18",x2:"20",y2:"18",strokeLinecap:"round"}),e.jsx("circle",{cx:"8",cy:"6",r:"2",fill:"#16558B",stroke:"#16558B"}),e.jsx("circle",{cx:"16",cy:"12",r:"2",fill:"#16558B",stroke:"#16558B"}),e.jsx("circle",{cx:"10",cy:"18",r:"2",fill:"#16558B",stroke:"#16558B"})]})})]}),e.jsx("h1",{className:"fp:text-2xl fp:font-bold fp:text-[#222222]",children:"Transactions"})]}),e.jsx(xu,{open:K,onClose:()=>xe(!1),currentFilter:Ae,onApply:J=>{oe(J),G(0),o([])}}),e.jsx("div",{className:"fp:px-4 fp:space-y-3",children:C.length===0&&!F?e.jsxs("div",{className:"fp:flex fp:flex-col fp:items-center fp:justify-center fp:py-20 fp:px-6",children:[e.jsx("div",{className:"fp:w-20 fp:h-20 fp:rounded-full fp:bg-[#D6E8FF] fp:flex fp:items-center fp:justify-center fp:mb-5",children:e.jsx("svg",{className:"fp:w-9 fp:h-9 fp:text-[#16558B]",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,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"})})}),e.jsx("p",{className:"fp:text-[16px] fp:font-medium fp:text-[#222222] fp:mb-2",children:"No Transactions"}),e.jsx("p",{className:"fp:text-[13px] fp:font-normal fp:text-[#6D6D6D] fp:text-center fp:leading-5",children:"Your payment history will appear here once you make a transaction."})]}):e.jsxs(e.Fragment,{children:[C.map(J=>e.jsxs("button",{onClick:()=>l(J),className:"fp:w-full fp:bg-white fp:rounded-[12px] fp:border fp:border-[#E8EEF8] fp:px-4 fp:py-3.5 fp:flex fp:items-center fp:gap-3 fp:text-left fp:active:scale-[0.98] fp:transition-all",children:[e.jsx(Au,{status:J.status}),e.jsxs("div",{className:"fp:flex-1 fp:min-w-0",children:[e.jsx("p",{className:"fp:text-[14px] fp:font-medium fp:text-[#16558B] fp:leading-[14px] fp:truncate",children:J.name||J.supplierName||J.lenderName||"N/A"}),e.jsxs("p",{className:"fp:text-[12px] fp:font-normal fp:text-[#6D6D6D] fp:leading-[14px] fp:mt-1.5",children:[H(J.date),"  •  ",J.paymentMode]})]}),e.jsxs("p",{className:"fp:text-[14px] fp:font-medium fp:text-[#222222] fp:leading-[14px] fp:flex-shrink-0",children:["₹",$e(J.amount)]})]},J.transactionId)),T&&e.jsx("div",{className:"fp:flex fp:justify-center fp:pt-2 fp:pb-4",children:e.jsx("button",{onClick:()=>G(U+1),disabled:F,className:"fp:text-sm fp:font-medium fp:text-[#16558B] fp:py-2 fp:px-6 fp:rounded-full fp:border fp:border-[#16558B] fp:disabled:opacity-50 fp:disabled:cursor-not-allowed fp:active:scale-95 fp:transition-transform",children:F?"Loading...":"Load More"})}),!T&&Z>0&&e.jsxs("p",{className:"fp:text-center fp:text-xs fp:text-[#6D6D6D] fp:py-4",children:[Z," transaction",Z!==1?"s":""," total"]})]})})]})},mu=({open:A,onClose:l,transaction:m})=>{const C=I.useRef(null),[o,F]=I.useState(null),[P,O]=I.useState(!1),[Y,U]=I.useState(null),[G,T]=I.useState([]),[V,Z]=I.useState(!1),[ee,Ae]=I.useState(!1),[oe,K]=I.useState(""),xe=async q=>{const ve=q.documentIds.flat().map(Pe=>Pe.documentId);if(ve.length!==0){Ae(!0),K(q.invoiceNumber),Z(!0);try{const Pe=await Pf(ve);T(Array.isArray(Pe)?Pe:[])}catch(Pe){console.error("Error fetching documents:",Pe),T([])}finally{Ae(!1)}}},ge=()=>{Z(!1),T([]),K("")};I.useEffect(()=>{A&&m&&H(),A||(F(null),U(null))},[A,m?.transactionId]);const H=async()=>{if(m){O(!0),U(null);try{const q=m.source==="LOS"?"LMS":m.source,ve=await kf(m.transactionId,q);F(ve)}catch(q){console.error("Error fetching transaction details:",q);const ve=q?.response?.data?.errorMessage||q?.response?.data?.message||q?.message||"Failed to load details";U(ve)}finally{O(!1)}}};if(!m)return null;const J=q=>{const ve=new Date(q),Pe=ve.getDate(),Ge=ve.toLocaleDateString("en-IN",{month:"short"}),ht=ve.getFullYear(),ot=ve.getHours(),Mt=ve.getMinutes().toString().padStart(2,"0"),je=ot>=12?"PM":"AM",Ve=ot%12||12;return`${Pe} ${Ge} ${ht}, ${Ve}:${Mt} ${je}`},ne=q=>{switch(q.toUpperCase()){case"SUCCESS":return"fp:text-[#2FB551]";case"FAILED":case"FAILURE":return"fp:text-[#E80000]";case"INITIATED":return"fp:text-[#1E88E5]";case"PENDING":return"fp:text-[#FFA500]";default:return"fp:text-[#6D6D6D]"}},le=q=>{switch(q.toUpperCase()){case"SUCCESS":return"Success";case"FAILED":case"FAILURE":return"Failed";case"INITIATED":return"Initiated";case"PENDING":return"Pending";default:return q}},we=o?.id??m.transactionId,se=o?.amount??m.amount,Q=o?.status??m.status,X=o?.date??m.date,W=o?.paymentMode??m.paymentMode,ce=o?.supplierName&&o.supplierName.trim()||m.supplierName||m.name||"",Oe=o?.lender||m.lenderName||"",be=o?.type==="LENDING"||m.transactionType==="LOAN_REPAYMENT",Ie=o?.loan?.loans||[],Me=o?.invoice||[],ae=m.invoiceNumbers||[],Ce=Me.length>0||ae.length>0,Be=Me.length>0?Me.map(q=>q.invoiceNumber).join(", "):ae.join(", "),Ee=Me.find(q=>q.remark&&q.remark.trim())?.remark||o?.settlement?.find(q=>q.description&&q.description.trim())?.description||"",De=Me.filter(q=>q.documentIds&&q.documentIds.length>0),Se=async()=>{let q=`Transaction Details
665
+ `})]}),eu=({size:A=24,color:l="currentColor",className:m,style:C})=>e.jsx("svg",{width:A,height:A,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:m,style:C,"aria-hidden":"true",children:e.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:l,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}),tu=({size:A=24,color:l="currentColor",className:m,style:C})=>e.jsxs("svg",{width:A,height:A,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:m,style:C,"aria-hidden":"true",children:[e.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:l,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),e.jsx("path",{d:"M22 6L12 13L2 6",stroke:l,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]}),Ur={PHONE:"+91-9892422528",EMAIL:"connect@fundly.ai"},Et={FUNDLY_PAY:"FUNDLY_PAY",DYNAMIC_QR:"DYNAMIC_QR",STATIC_QR:"STATIC_QR",PAYMENT_LINK:"PAYMENT_LINK",CASH:"CASH",CHEQUE:"CHEQUE",UPI:"UPI",NETBANKING:"NETBANKING",BANK_TRANSFER:"BANK_TRANSFER"},ti={FUNDLY_CUSTOMER_APP:"FUNDLY_CUSTOMER_APP",FUNDLY_COLLECT_APP:"FUNDLY_COLLECT_APP",FUNDLY_TRADE:"FUNDLY_TRADE"},su=({open:A,onClose:l})=>{const m=C=>{navigator.clipboard.writeText(C)};return e.jsx(ds,{open:A,onClose:l,children:e.jsxs("div",{className:"fp:w-full fp:flex fp:flex-col fp:px-8 fp:py-4 fp:space-y-4 fp:mt-2 fp:mb-12",children:[e.jsx("div",{className:"fp:w-full fp:flex fp:items-center fp:justify-end",children:e.jsx("img",{src:me.closingCross,className:"fp:w-4 fp:h-4 fp:cursor-pointer",onClick:l,alt:"Close"})}),e.jsx("img",{src:me.customerSup,className:"fp:w-14 fp:h-14",alt:"Support"}),e.jsxs("div",{className:"fp:flex fp:space-x-6 fp:items-center",children:[e.jsx(eu,{size:24,color:"#16558B"}),e.jsx("span",{className:"fp:font-semibold",children:Ur.PHONE}),e.jsx("img",{src:me.copy,className:"fp:w-5 fp:h-5 fp:cursor-pointer",onClick:()=>m(Ur.PHONE),alt:"Copy"})]}),e.jsxs("div",{className:"fp:flex fp:space-x-6 fp:items-center",children:[e.jsx(tu,{size:24,color:"#16558B"}),e.jsx("span",{className:"fp:font-semibold",children:Ur.EMAIL}),e.jsx("img",{src:me.copy,className:"fp:w-5 fp:h-5 fp:cursor-pointer",onClick:()=>m(Ur.EMAIL),alt:"Copy"})]})]})})},nu=({open:A,onClose:l,onConfirm:m})=>e.jsxs(ls,{open:A,onClose:l,children:[e.jsx(pn,{children:e.jsx("div",{className:"fp:w-full fp:flex fp:justify-end",children:e.jsx("img",{src:me.closingCross,className:"fp:w-4 fp:h-4 fp:cursor-pointer",onClick:l,alt:"Close"})})}),e.jsx(cs,{children:e.jsxs("div",{style:{fontFamily:"Poppins"},className:"fp:w-full fp:flex fp:flex-col fp:justify-center fp:items-center",children:[e.jsx("img",{src:me.paymentLeave,className:"fp:w-18 fp:h-18",alt:"Leave"}),e.jsx("span",{className:"fp:text-[18px] fp:text-wrap fp:font-bold fp:text-center",children:"Leave this page?"}),e.jsx("span",{className:"fp:text-[14px] fp:text-wrap fp:font-semibold fp:text-center fp:text-[#6D6D6D]",children:"Any unsaved payment details will be lost."})]})}),e.jsx(Ls,{children:e.jsxs("div",{style:{fontFamily:"Poppins"},className:"fp:w-full fp:flex fp:justify-between fp:px-3 fp:mb-3 fp:gap-3",children:[e.jsx("button",{className:"fp:flex-1 fp:w-[96px] fp:h-[48px] fp:border-2 fp:border-gray-400 fp:text-gray-400 fp:rounded-xl",onClick:m,children:"Yes, Leave"}),e.jsx("button",{className:"fp:flex-1 fp:w-[96px] fp:h-[48px] fp:bg-[#16558B] fp:text-white fp:rounded-xl",onClick:l,children:"No"})]})})]}),iu=()=>{const{partnerCredentials:A}=Zt(),[l,m]=I.useState(null),[C,o]=I.useState(!1),[F,P]=I.useState(null);return{login:I.useCallback(async()=>{o(!0),P(null);try{if(!A)throw new Error("Partner credentials not provided");const Y={loginType:"PARTNER",username:A.username,password:A.password},U=await vf(Y);if(U?.accessToken){const G=U.accessToken;return _l(G),m(G),G}throw new Error("No access token received")}catch(Y){const U=Y instanceof Error?Y:new Error("Login failed");throw P(U),U}finally{o(!1)}},[A]),token:l,isLoading:C,error:F}},ru=A=>{const{setChemistId:l,setLeadId:m,setDistributorIdnum:C,setTypeOfApp:o,setAnalyticsContext:F,setPaymentInvoice:P,setPayableValue:O,setInvoices:Y,setPaymentType:U,setSalesmanId:G,setSalesmanName:T,setScanChannel:V,setScanOrigin:Z,setSdkEntryPoint:ee,distributorIdnum:Ae,chemistId:oe,leadId:K}=Zt(),xe=I.useRef(!1);I.useEffect(()=>{const ge=ne=>{if(typeof ne.data!="object"||ne.data===null||ne.source!==window||ne.data?.source==="react-devtools-content-script"||ne.source!==window||ne.data?.source?.includes("react-devtools")||ne.origin!==window.origin)return;const{source:le,analyticsContext:we,distributorId:se,chemistId:Q,paymentType:X,payableAmount:W,invoices:ce,paymentInvoice:Oe,salesmanId:be,salesmanName:Ze,scanChannel:Ie,scanOrigin:Me,sdkEntryPoint:ae}=ne.data;se&&C(se),Q&&l(Q),le&&o(le),we&&F(we),Array.isArray(Oe)&&P(Oe),W&&O(W),Array.isArray(ce)&&Y(ce),X&&U(X),be&&G(be),Ze&&T(Ze),V(Ie??null),Z(Me??null),ae&&ee(ae),xe.current||(A(),xe.current=!0)},H=oe&&oe.trim()!=="",J=K&&K.trim()!=="";return Ae&&(H||J)&&!xe.current&&(A(),xe.current=!0),window.addEventListener("message",ge),()=>window.removeEventListener("message",ge)},[A,l,m,C,o,F,P,O,Y,U,G,T,V,Z,ee,Ae,oe,K])},ou=A=>{const{distributorIdnum:l,typeOfApp:m,chemistId:C,leadId:o,payableValue:F,salesmanId:P,paymentType:O,setDistributorName:Y,setChemistName:U,setPayerMobileNumber:G,setSalesmanPhoneNumber:T,setTenureMappings:V,setFiCode:Z,setDrawdownRepaymentOption:ee,setCreditLimitData:Ae,setPayerUuid:oe}=Zt(),[K,xe]=I.useState([]),[ge,H]=I.useState(null),[J,ne]=I.useState(null),[le,we]=I.useState(null),[se,Q]=I.useState(null),[X,W]=I.useState(!0);return I.useEffect(()=>{A&&(async()=>{const Oe={distributorBusinessId:l,source:m,...C&&C.trim()!==""&&{chemistBusinessId:C},...o&&o.trim()!==""&&{leadId:o},payableAmount:F,...P&&{salesmanId:P},...O&&{collectType:O}};try{const be=await jf(Oe);H(be.bankDetails),be.bankDetails&&(Y(be.bankDetails.distributorName||""),U(be.bankDetails.chemistName||""),G(be.bankDetails.mobileNumber||""),T(be.bankDetails.salesmanPhoneNumber||""),be.bankDetails.mobileNumber&&Yf(be.bankDetails.mobileNumber).then(Me=>{Me&&oe(Me)}));const Ze=be.paymentOption.find(Me=>Me.name==="FUNDLY_PAY");Ze?.details?.tenureMappings&&V(Ze.details.tenureMappings),ne(Ze?.details?.maxEligibleLimit??null),we(Ze?.details?.minEligibleLimit??null),Q(Ze?.reason??null),Ze?.details?.fiCode&&Z(Ze.details.fiCode),Ze?.details?.drawdownRepaymentOption&&ee(Ze.details.drawdownRepaymentOption);const Ie=be.paymentOption.filter(Me=>Me.isActive).map(Me=>Me.name);if(xe(Ie),Ze?.isActive&&be.bankDetails?.chemistBusinessId)try{const Me=await Mf(be.bankDetails.chemistBusinessId);Ae(Me)}catch(Me){console.warn("Credit limit filter API failed:",Me),Ae(null)}W(!1)}catch{W(!1)}})()},[A]),{paymentOptions:K,bankDetails:ge,maxEligibleLimit:J,minEligibleLimit:le,fundlyPayReason:se,loading:X}};function i0(){const[A,l]=I.useState({activeDrawer:null,paymentData:null}),m=I.useCallback(O=>{l({activeDrawer:O,paymentData:null})},[]),C=I.useCallback(()=>{l({activeDrawer:null,paymentData:null})},[]),o=I.useCallback(O=>{l({activeDrawer:"SUCCESS",paymentData:O||null})},[]),F=I.useCallback(O=>{l({activeDrawer:"FAILURE",paymentData:O||null})},[]),P=I.useCallback(O=>A.activeDrawer===O,[A.activeDrawer]);return{activeDrawer:A.activeDrawer,paymentData:A.paymentData,openPaymentDrawer:m,closeDrawer:C,isDrawerOpen:P,handlePaymentSuccess:o,handlePaymentFailure:F,showFundlyPayDrawer:P("FUNDLY_PAY"),showUpiDrawer:P("UPI"),showDynamicQrDrawer:P("DYNAMIC_QR"),showStaticQrDrawer:P("STATIC_QR"),showPaymentLinkDrawer:P("PAYMENT_LINK"),showNetbankingDrawer:P("NETBANKING"),showCashDrawer:P("CASH"),showChequeDrawer:P("CHEQUE"),showBankTransferDrawer:P("BANK_TRANSFER"),showSuccessDrawer:P("SUCCESS"),showFailureDrawer:P("FAILURE")}}const au=({onPaymentCollected:A,onPaymentFailed:l})=>{const[m,C]=I.useState(!1),[o,F]=I.useState(!1),[P,O]=I.useState(!1),[Y,U]=I.useState(null),{paymentData:G,openPaymentDrawer:T,closeDrawer:V,handlePaymentSuccess:Z,handlePaymentFailure:ee,showFundlyPayDrawer:Ae,showUpiDrawer:oe,showDynamicQrDrawer:K,showStaticQrDrawer:xe,showPaymentLinkDrawer:ge,showNetbankingDrawer:H,showCashDrawer:J,showChequeDrawer:ne,showBankTransferDrawer:le,showSuccessDrawer:we,showFailureDrawer:se}=i0(),[Q,X]=I.useState(!1),[W,ce]=I.useState(-1),[Oe,be]=I.useState(null),[Ze,Ie]=I.useState([]),[Me,ae]=I.useState(null),[Ce,Be]=I.useState(null),Ee=I.useRef(!1),{distributorName:De,distributorIdnum:Se,payableValue:Ne,typeOfApp:Ue,analyticsContext:q,transactionId:ve,showResultOnly:Pe,successButtonText:Ge,failureButtonText:ht,creditLimitData:ot,paymentType:Mt,paymentInvoice:je,invoices:Ve,chemistId:he,chemistName:Ye,leadId:et,salesmanId:lt,salesmanName:St,payerMobileNumber:ps,payerUuid:zt,scanId:Cs,viewId:Rt,sessionId:Hs,erpId:Wt,outstandingAmount:ns,billId:Ds,billType:is,billStatus:ys,billTotalAmount:Ws,dueDate:vs,fromDate:Ns,toDate:Ss,notificationId:bs,notificationChannel:fs,mobileChanged:Qt,scanOrigin:qt,scanChannel:Vs,sdkEntryPoint:In}=Zt(),us=I.useMemo(()=>({type:"collection",distributorId:Se||"",chemistId:he||void 0,leadId:et||void 0,invoices:je||[],paymentType:Mt||"INVOICE_COLLECT",salesmanId:lt||void 0,payerMobileNumber:ps||void 0}),[Se,he,et,je,Mt,lt,ps]),{login:Bs,token:Xt,error:ks}=iu(),Xs=I.useCallback(async()=>{try{await Bs(),U(null)}catch(ze){const fe=ze instanceof Error?ze.message:"Authentication failed. Please try again later.";U(fe)}},[Bs]);ru(Xs);const{paymentOptions:gt,bankDetails:js,maxEligibleLimit:Cn,minEligibleLimit:ct,fundlyPayReason:Te,loading:bt}=ou(Xt);I.useEffect(()=>{if(!Pe&&!ve){const ze=new URLSearchParams(window.location.search);if((ze.has("orderId")||ze.has("transactionId"))&&!Xt){const Le=new URL(window.location.href);Le.searchParams.delete("orderId"),Le.searchParams.delete("transactionId"),window.history.replaceState({},"",Le.toString())}}},[Pe,Xt,ve]),I.useEffect(()=>{if(Y||ks){const ze=setTimeout(async()=>{await At.navigateHome()},1e4);return()=>clearTimeout(ze)}},[Y,ks]),I.useEffect(()=>{const ze=new URLSearchParams(window.location.search);(ze.get("orderId")||ze.get("transactionId"))&&Xt&&!Pe&&T("UPI")},[Xt,Pe,T]),I.useEffect(()=>{!Pe||!ve||!Xt||!we&&!se&&!oe&&T("UPI")},[Pe,ve,Xt,we,se,oe,T]),I.useEffect(()=>{if(Pe||bt||!Xt||Ee.current||gt.length===0)return;const ze=q?.userType?String(q.userType).trim().toLowerCase():null;if(!zt)return;Ee.current=!0,zt&&Ht.setUserIdentity(zt);const fe=q?.platform?String(q.platform).trim().toLowerCase():null,Le=()=>In||"",ye=ft=>gt.includes(ft),He=Number(Ne)||0,Re=Hs||`sdk_session_${Date.now()}_${Math.random().toString(36).substring(2,11)}`,tt=ns!=null?He<ns:null,st=(ft=>{if(!ft)return null;const dt=ft.toUpperCase();return["PARTIAL_PAID","PENDING","OUTSTANDING","UNPAID"].includes(dt)?"outstanding":["PAID","COMPLETED","CLEARED"].includes(dt)?"paid":["PROCESSING","IN_PROCESS","IN_PROGRESS"].includes(dt)?"in_process":["OUTDATED","OVERDUE","EXPIRED"].includes(dt)?"outdated":ft})(ys);Ht.saveCarryForwardContext({scan_id:Cs||null,view_id:Rt||null,bill_id:Ds,bill_type:is,bill_status:st,bill_total_amount:Ws,outstanding_amount:ns,due_date:vs,from_date:Ns,to_date:Ss,notification_id:bs,notification_channel:fs,scan_channel:Vs||null,scan_origin:qt||null,partial_payment:tt,sdk_version:"1.5.0-beta.1",app_version:q?.appVersion?String(q.appVersion):null,session_id:Re}),Ht.trackPaymentSDKLaunched({scan_id:Cs||null,view_id:Rt||null,bill_id:Ds,bill_type:is,bill_status:st,bill_total_amount:Ws,outstanding_amount:ns,due_date:vs,from_date:Ns,to_date:Ss,notification_id:bs,notification_channel:fs,scan_channel:Vs||null,scan_origin:qt||null,mobile_changed:Qt,invoice_count:Mt==="DIRECT_COLLECT"?Ve?.length||0:je?.length||0,partial_payment:tt,supplier_id:Se?.toString()||"",supplier_name:De||"",business_id:he||null,business_name:Ye||null,erp_id:Wt||null,erp_name:null,salesman_id:lt?.toString()||null,salesman_name:St||null,party_code:null,user_type:ze,user_uuid:zt||"",payment_amount:He,payment_type:Mt==="INVOICE_COLLECT"?"invoice_pay":"direct_pay",session_id:Re,platform:fe,device_type:Hr(),os:Yr(),app_version:q?.appVersion?String(q.appVersion):null,sdk_version:"1.5.0-beta.1",sdk_entry_point:Le(),is_payment_enabled:gt.length>0,payment_option_upi:ye(Et.UPI)||ye("UPI"),payment_option_net_banking:ye("NETBANKING")||ye("NET_BANKING"),payment_option_fundly_pay:ye(Et.FUNDLY_PAY)||ye("FUNDLY_PAY"),payment_option_cash:ye(Et.CASH)||ye("CASH"),payment_option_cheque:ye(Et.CHEQUE)||ye("CHEQUE"),payment_option_distributor_qr:ye(Et.STATIC_QR)||ye("STATIC_QR"),payment_option_payment_qr:ye(Et.DYNAMIC_QR)||ye("DYNAMIC_QR"),payment_option_payment_link:ye(Et.PAYMENT_LINK)||ye("PAYMENT_LINK"),payment_option_bank_transfer:ye("BANK_TRANSFER"),status:"success",failure_reason:null,failure_stage:null,error_code:null,error_description:null,mobile_number:ps||null,uuid:zt||null})},[bt,Xt,Pe,gt,zt,Se,De,he,Ye,et,lt,Ne,Mt,je,Ue,Cs,Rt,Hs,Wt,ns,Ds,is,ys,Ws,vs,Ns,Ss,bs,fs,Qt,q,qt]);const Es=async()=>{C(!1),await At.navigateHome()},yn=ze=>{if(!ze?.productRules||!Array.isArray(ze.productRules))return{tenureMappings:[],repaymentOption:null,disbursementAccount:null};const fe=Mt==="INVOICE_COLLECT"?"YES":"NO",ye=ze.productRules.find(He=>He.isInvoiceRequired===fe&&He.disbursementAccount==="SUPPLIER")||ze.productRules[0];return{tenureMappings:ye?.tenureMappings||[],repaymentOption:ye?.repaymentOption||null,disbursementAccount:ye?.disbursementAccount||null}};return Y||ks?e.jsx("div",{style:{fontFamily:"Poppins"},className:"fp:relative fp:w-full fp:h-screen fp:flex fp:items-center fp:justify-center fp:px-4 fp:bg-[#F8FCFF]",children:e.jsxs("div",{className:"fp:w-full fp:max-w-md fp:bg-white fp:border fp:border-red-100 fp:rounded-2xl fp:p-8 fp:text-center fp:shadow-lg",children:[e.jsx("div",{className:"fp:w-16 fp:h-16 fp:mx-auto fp:mb-4 fp:bg-red-50 fp:rounded-full fp:flex fp:items-center fp:justify-center",children:e.jsx("svg",{className:"fp:w-8 fp:h-8 fp:text-red-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.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"})})}),e.jsx("h3",{className:"fp:text-[20px] fp:font-semibold fp:text-gray-800 fp:mb-3",children:"Authentication Failed"}),e.jsx("p",{className:"fp:text-[14px] fp:text-gray-600 fp:mb-4",children:Y||ks?.message||"We're unable to authenticate your session at the moment. Please try again later."}),e.jsx("p",{className:"fp:text-[12px] fp:text-gray-500",children:"This window will close automatically in a few seconds..."})]})}):bt?e.jsx($f,{}):Pe?e.jsxs("div",{style:{fontFamily:"Poppins"},className:"fp:relative fp:w-full fp:h-screen fp:flex fp:items-center fp:justify-center fp:bg-[#F8FCFF]",children:[e.jsx(To,{open:we,onClose:()=>{V(),A&&G&&A(G)},paymentData:G,buttonText:Ge}),e.jsx(zo,{open:se,onClose:()=>{V(),l&&G&&l(G)},paymentData:G,buttonText:ht}),e.jsx(Fl,{open:oe,onClose:()=>V(),onPaymentCollected:ze=>{Z(ze)},onPaymentFailed:ze=>{ee(ze)}})]}):e.jsxs("div",{style:{fontFamily:"Poppins"},className:"fp:relative fp:w-full fp:h-screen fp:pt-10 fp:flex fp:flex-col fp:px-4 fp:bg-[#F8FCFF] fp:overflow-x-hidden",children:[e.jsx("div",{className:"fp:w-full fp:h-10 fp:flex fp:items-center fp:space-x-3",children:e.jsx("img",{src:me.backButton,alt:"Back",className:"fp:w-4 fp:h-4 fp:cursor-pointer",onClick:()=>C(!0)})}),e.jsxs("div",{className:"fp:w-full fp:items-center fp:text-center fp:justify-between fp:flex ",children:[e.jsx("h1",{className:"fp:font-medium fp:text-[20px] fp:text-[#222222]",children:"Payment Options"}),e.jsxs("label",{className:"fp:flex fp:items-center fp:text-[14px] fp:cursor-pointer",onClick:()=>O(!0),children:[e.jsx("img",{src:me.QuestionMark,className:"fp:w-4 fp:h-4 fp:mr-1"}),"Get Help"]})]}),e.jsx("div",{className:"fp:flex-1 fp:overflow-y-auto fp:mb-12 fp:mt-2",children:Ue==="FUNDLY_CUSTOMER_APP"&&!js?e.jsx("div",{className:"fp:w-full fp:h-full fp:flex fp:items-center fp:justify-center",children:e.jsxs("div",{className:"fp:w-full fp:max-w-md fp:bg-white fp:border fp:border-gray-200 fp:rounded-2xl fp:p-8 fp:text-center fp:shadow-sm",children:[e.jsx("div",{className:"fp:w-16 fp:h-16 fp:mx-auto fp:mb-4 fp:bg-gray-100 fp:rounded-full fp:flex fp:items-center fp:justify-center",children:e.jsx("svg",{className:"fp:w-8 fp:h-8 fp:text-gray-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.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"})})}),e.jsx("h3",{className:"fp:text-[18px] fp:font-semibold fp:text-gray-800 fp:mb-2",children:"Bank Details Not Available"}),e.jsx("p",{className:"fp:text-[14px] fp:text-gray-500",children:"We couldn't find bank details for this distributor. Please contact support for assistance."})]})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"fp:w-full fp:border fp:border-gray-100 fp:bg-white fp:rounded-xl fp:p-4 fp:mt-6 fp:flex fp:flex-col fp:space-y-2",children:[e.jsxs("div",{className:"fp:flex fp:justify-between fp:items-start",children:[e.jsxs("div",{className:"fp:flex fp:flex-col fp:flex-1",children:[e.jsx("h4",{className:"fp:text-[12px] fp:font-normal fp:text-gray-400",children:"Collect For"}),e.jsx("label",{className:"fp:font-semibold fp:text-[16px] fp:text-[#222222]",children:De})]}),e.jsxs("div",{className:"fp:flex fp:flex-col fp:items-end fp:flex-shrink-0",children:[e.jsx("h4",{className:"fp:text-[12px] fp:font-normal fp:text-gray-400 fp:text-right",children:"Collection Amount"}),e.jsxs("label",{className:"fp:font-semibold fp:text-[16px] fp:text-[#222222]",children:["₹",$e(Ne)]})]})]}),(Ue==="FUNDLY_CUSTOMER_APP"||Ue==="FUNDLY_QR_WEB")&&js&&e.jsxs("div",{className:"fp:w-full fp:mt-2",children:[e.jsxs("label",{className:"fp:cursor-pointer fp:select-none fp:text-[#16558B] fp:font-medium fp:text-[12px]",onClick:()=>F(ze=>!ze),children:["Bank Details ",o?"▲":"▼"]}),o&&e.jsxs("div",{className:"fp:w-full fp:flex fp:flex-col fp:space-y-3 fp:mt-2",children:[e.jsxs("div",{className:"fp:flex fp:flex-col ",children:[e.jsx("h4",{className:"fp:text-[12px] fp:font-normal fp:text-gray-400",children:"Account Holder Name"}),e.jsx("label",{className:"fp:text-[14px] fp:font-medium fp:text-[#222222]",children:js.accountName})]}),e.jsxs("div",{className:"fp:flex fp:justify-between",children:[e.jsxs("div",{className:"fp:flex fp:flex-col fp:space-y-1",children:[e.jsx("h4",{className:"fp:text-[12px] fp:font-normal fp:text-gray-400",children:"Account Number"}),e.jsx("label",{className:"fp:text-[14px] fp:font-medium fp:text-[#222222]",children:js.accountNumber})]}),e.jsxs("div",{className:"fp:flex fp:flex-col fp:space-y-1",children:[e.jsx("h4",{className:"fp:text-[12px] fp:font-normal fp:text-gray-400",children:"IFSC Code"}),e.jsx("label",{className:"fp:text-[14px] fp:font-medium fp:text-[#222222]",children:js.ifsc})]})]})]})]})]}),gt.includes(Et.FUNDLY_PAY)&&(()=>{const ze=Number(Ne??0),fe=ct??1e3,Le=Cn??null;let ye=null,He=!1;ze<fe?(ye=`Fundly Pay not available below ₹${fe.toLocaleString("en-IN")} payment.`,He=!0):Le!==null&&ze>Le?(ye=`Max Eligible Amount: ₹${$e(Le)}`,He=!0):Te&&(ye=Te);let Re=[],tt=0;ot?.subLimits&&Array.isArray(ot.subLimits)&&(Re=ot.subLimits.filter(dt=>dt.expired===!1),Re.sort((dt,Vt)=>{const Gt=dt.maxEligibleAmount||dt.availableLimit||0;return(Vt.maxEligibleAmount||Vt.availableLimit||0)-Gt}),Re.length>0&&(tt=Math.max(...Re.map(dt=>dt.maxEligibleAmount||dt.availableLimit||0))));const rs=Re.length>1,st=Re.length===1,ft=Re.length===0;return e.jsxs("div",{className:"fp:w-full fp:flex fp:flex-col fp:mt-6",children:[e.jsx("h2",{className:"fp:text-[16px] fp:font-semibold",children:"Preferred Payment"}),e.jsxs("div",{className:"fp:w-full fp:flex fp:flex-col fp:mt-2",children:[e.jsxs("div",{className:`fp:w-full fp:border fp:border-gray-100 ${He?"fp:bg-[#efefef]":"fp:bg-white"} ${ye||rs&&Q||st?"fp:rounded-t-xl":"fp:rounded-xl"} ${He?"":"fp:cursor-pointer fp:hover:shadow-2xs"} fp:p-4 fp:flex fp:items-center fp:justify-between`,onClick:()=>{if(!He)if(rs)X(!Q);else if(st){ce(0),be(Re[0].fiCode);const dt=yn(Re[0]);Ie(dt.tenureMappings),ae(dt.repaymentOption),Be(dt.disbursementAccount),T("FUNDLY_PAY")}else T("FUNDLY_PAY")},children:[e.jsxs("div",{className:"fp:flex fp:items-center fp:space-x-2",children:[e.jsx("img",{src:me.logo,className:"fp:w-[32px] fp:h-[32px]"}),e.jsx("label",{className:"fp:text-[14px] fp:font-medium fp:cursor-pointer",children:"Fundly Pay"}),e.jsxs("div",{className:"fp:flex fp:items-center fp:bg-[#34A877] fp:py-1 fp:px-3 fp:rounded-4xl",children:[e.jsx("img",{src:me.primary,className:"fp:w-3 fp:h-3"}),e.jsx("label",{className:"fp:text-[10px] fp:font-medium fp:text-white",children:"1 Click Payment"})]})]}),e.jsxs("div",{className:"fp:flex fp:items-center fp:space-x-2",children:[!He&&rs&&e.jsx("svg",{className:`fp:w-5 fp:h-5 fp:text-[#16558B] fp:transition-transform fp:duration-200 ${Q?"fp:rotate-180":""}`,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"3",d:"M19 9l-7 7-7-7"})}),!He&&!rs&&e.jsx("img",{src:me.cardOpener,className:"fp:w-4 fp:h-4"})]})]}),!He&&st&&e.jsx("div",{className:"fp:w-full fp:bg-[#E6F7EF] fp:flex fp:p-2 fp:text-[#34A877] fp:rounded-b-xl fp:border-x fp:border-b fp:border-gray-100",children:e.jsxs("label",{className:"fp:text-[10px] fp:font-medium",children:["Max Eligible Amount:"," ",e.jsxs("span",{className:"fp:font-bold",children:["₹",$e(Re[0].maxEligibleAmount||Re[0].availableLimit||0)]})]})}),!He&&rs&&!Q&&e.jsx("div",{className:"fp:w-[95%] fp:m-auto fp:bg-[#E6F7EF] fp:flex fp:p-2 fp:text-[#34A877] fp:rounded-b-xl fp:border-x fp:border-b fp:border-gray-100",children:e.jsxs("label",{className:"fp:text-[10px] fp:font-medium",children:["Max Eligible Amount:"," ",e.jsxs("span",{className:"fp:font-bold",children:["₹",$e(tt)]})]})}),!He&&rs&&Q&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fp:w-full fp:bg-white fp:border-x fp:border-gray-100 fp:rounded-b-xl fp:px-3 fp:pt-3 fp:pb-2 fp:flex fp:flex-col fp:space-y-2.5",children:Re.map((dt,Vt)=>{const Gt=dt.maxEligibleAmount||dt.availableLimit||0,os=Gt<ze;return e.jsx("button",{type:"button",disabled:os,className:`fp:w-full fp:text-left fp:focus:outline-none fp:transition-all fp:duration-150 ${os?"fp:cursor-not-allowed fp:opacity-50":W===Vt?"fp:bg-[#EBF4FA]":"fp:bg-white fp:hover:border-[#16558B] fp:cursor-pointer"}`,style:{fontFamily:"Poppins",paddingTop:"10px",paddingLeft:"10px",paddingBottom:"10px",paddingRight:"16px",borderRadius:"8px",borderWidth:"0.87px",borderStyle:"solid",borderColor:os?"#E0E0E0":W===Vt?"#C5DBED":"#E8EEF3",height:"35px",display:"flex",alignItems:"center"},onClick:()=>{if(!os){ce(Vt),be(dt.fiCode);const An=yn(dt);Ie(An.tenureMappings),ae(An.repaymentOption),Be(An.disbursementAccount),X(!1),T("FUNDLY_PAY")}},children:e.jsxs("div",{className:"fp:flex fp:justify-between fp:items-center fp:w-full",style:{lineHeight:"24px"},children:[e.jsx("span",{className:`fp:font-medium ${os?"fp:text-gray-400":"fp:text-[#16558B]"}`,style:{fontSize:"12px",letterSpacing:"0px",textTransform:"capitalize"},children:dt.fiCode?.toLowerCase()}),e.jsxs("span",{className:`fp:text-[12px] fp:font-semibold ${os?"fp:text-gray-400":"fp:text-[#000000]"}`,style:{letterSpacing:"0px",lineHeight:"100%"},children:["₹ ",$e(Gt)]})]})},Vt)})}),e.jsx("div",{className:"fp:w-[95%] fp:m-auto fp:bg-[#E6F7EF] fp:flex fp:p-2 fp:text-[#34A877] fp:rounded-b-xl fp:border-x fp:border-b fp:border-gray-100",children:e.jsxs("label",{style:{fontFamily:"Poppins"},children:[e.jsxs("span",{className:"fp:text-[10px] fp:font-medium",children:["Max Eligible Amount:"," "]}),e.jsxs("span",{className:"fp:font-bold fp:text-[10px]",children:["₹",$e(tt)]})]})})]}),ye&&ft&&e.jsx("div",{className:"fp:w-full fp:bg-red-50 fp:flex fp:p-2 fp:text-red-700 fp:rounded-b-xl fp:border-x fp:border-b fp:border-gray-100",children:e.jsx("label",{className:"fp:text-[11px] fp:ml-2",children:ye})}),!ye&&ft&&Le!==null&&e.jsx("div",{className:"fp:w-full fp:bg-green-50 fp:flex fp:p-2 fp:text-green-700 fp:rounded-b-xl fp:border-x fp:border-b fp:border-gray-100",children:e.jsxs("label",{className:"fp:text-[11px] fp:ml-2",children:["Max Eligible Amount:"," ",e.jsxs("span",{className:"fp:font-medium",children:["₹",$e(Le)]})]})})]})]})})(),gt.includes(Et.UPI)&&e.jsxs("div",{className:"fp:w-full fp:mt-6 fp:flex fp:flex-col fp:space-y-2",children:[e.jsxs("div",{className:"fp:flex fp:items-center fp:space-x-2",children:[e.jsx("img",{src:me.upi,className:"fp:h-[20px]",alt:"UPI Logo"}),e.jsx("h2",{className:"fp:text-[16px] fp:font-semibold",children:"Pay by UPI"})]}),e.jsxs("div",{className:"fp:w-full fp:border fp:border-gray-100 fp:bg-white fp:hover:shadow-2xs fp:cursor-pointer fp:rounded-xl fp:p-4 fp:flex fp:items-center fp:justify-between",onClick:()=>T("UPI"),children:[e.jsxs("div",{className:"fp:flex fp:items-center fp:space-x-2",children:[e.jsx("img",{src:me.upiIcon,className:"fp:w-[32px] fp:h-[32px]",alt:"UPI"}),e.jsx("label",{className:"fp:text-[14px] fp:font-medium fp:text-[#222222]",children:"UPI"}),e.jsx("div",{className:"fp:flex fp:items-center fp:bg-green-50 fp:rounded-4xl fp:py-1 fp:px-2",children:e.jsx("label",{className:"fp:text-[10px] fp:text-green-700 fp:font-medium",children:"₹ 0 charges"})})]}),e.jsx("img",{src:me.cardOpener,className:"fp:w-4 fp:h-4"})]})]}),gt.includes(Et.NETBANKING)&&e.jsxs("div",{className:"fp:w-full fp:mt-6 fp:flex fp:flex-col fp:space-y-2",children:[e.jsx("h2",{className:"fp:text-[16px] fp:font-semibold",children:"Netbanking"}),e.jsxs("div",{className:"fp:w-full fp:border fp:border-gray-100 fp:bg-white fp:hover:shadow-2xs fp:cursor-pointer fp:rounded-xl fp:p-4 fp:flex fp:items-center fp:justify-between",onClick:()=>T("NETBANKING"),children:[e.jsxs("div",{className:"fp:flex fp:items-center fp:space-x-2",children:[e.jsx("img",{src:me.scanqrIcon,className:"fp:w-[32px] fp:h-[32px]"}),e.jsx("label",{className:"fp:text-[14px] fp:font-medium fp:text-[#222222]",children:"Netbanking"})]}),e.jsx("img",{src:me.cardOpener,className:"fp:w-4 fp:h-4"})]})]}),(gt.includes(Et.BANK_TRANSFER)||gt.includes(Et.DYNAMIC_QR)&&!(Ue===ti.FUNDLY_CUSTOMER_APP&&gt.includes(Et.PAYMENT_LINK))||gt.includes(Et.PAYMENT_LINK)&&(Ue===ti.FUNDLY_COLLECT_APP||Ue===ti.FUNDLY_TRADE))&&e.jsxs("div",{className:"fp:w-full fp:mt-6 fp:flex fp:flex-col fp:space-y-2",children:[e.jsx("h2",{className:"fp:text-[16px] fp:font-semibold",children:"Online Payment Options"}),gt.includes(Et.DYNAMIC_QR)&&!(Ue===ti.FUNDLY_CUSTOMER_APP&&gt.includes(Et.PAYMENT_LINK))&&e.jsxs("div",{className:"fp:w-full fp:border fp:border-gray-100 fp:bg-white fp:hover:shadow-2xs fp:cursor-pointer fp:rounded-xl fp:p-4 fp:flex fp:items-center fp:justify-between",onClick:()=>T("DYNAMIC_QR"),children:[e.jsxs("div",{className:"fp:flex fp:items-center fp:space-x-2",children:[e.jsx("img",{src:me.generateqrIcon,className:"fp:w-[32px] fp:h-[32px]"}),e.jsx("label",{className:"fp:text-[14px] fp:font-medium",children:"Generate QR"}),e.jsx("div",{className:"fp:flex fp:items-center fp:bg-green-50 fp:rounded-4xl fp:py-1 fp:px-2",children:e.jsx("label",{className:"fp:text-[10px] fp:text-green-700 fp:font-medium",children:"₹ 0 charges"})})]}),e.jsx("img",{src:me.cardOpener,className:"fp:w-4 fp:h-4"})]}),gt.includes(Et.PAYMENT_LINK)&&(Ue===ti.FUNDLY_COLLECT_APP||Ue===ti.FUNDLY_TRADE)&&e.jsxs("div",{className:"fp:w-full fp:border fp:border-gray-100 fp:bg-white fp:hover:shadow-2xs fp:cursor-pointer fp:rounded-xl fp:p-4 fp:mt-2 fp:flex fp:items-center fp:justify-between",onClick:()=>T("PAYMENT_LINK"),children:[e.jsxs("div",{className:"fp:flex fp:items-center fp:space-x-2",children:[e.jsx("img",{src:me.paymentlinkIcon,className:"fp:w-[32px] fp:h-[32px]"}),e.jsx("label",{className:"fp:text-[14px] fp:font-medium",children:"Payment Link"}),e.jsx("div",{className:"fp:flex fp:items-center fp:bg-green-50 fp:rounded-4xl fp:py-1 fp:px-2",children:e.jsx("label",{className:"fp:text-[10px] fp:text-green-700 fp:font-medium",children:"₹ 0 charges"})})]}),e.jsx("img",{src:me.cardOpener,className:"fp:w-4 fp:h-4"})]}),gt.includes(Et.BANK_TRANSFER)&&e.jsxs("div",{className:"fp:w-full fp:border fp:border-gray-100 fp:bg-white fp:hover:shadow-2xs fp:cursor-pointer fp:rounded-xl fp:p-4 fp:mt-2 fp:flex fp:items-center fp:justify-between",onClick:()=>T("BANK_TRANSFER"),children:[e.jsxs("div",{className:"fp:flex fp:items-center fp:space-x-2",children:[e.jsx("img",{src:me.bankTransferIcon,className:"fp:w-[32px] fp:h-[32px]"}),e.jsx("label",{className:"fp:text-[14px] fp:font-medium fp:text-[#222222]",children:"Bank Transfer"})]}),e.jsx("img",{src:me.cardOpener,className:"fp:w-4 fp:h-4"})]})]}),(gt.includes(Et.CASH)||gt.includes(Et.CHEQUE)||gt.includes(Et.STATIC_QR))&&e.jsxs("div",{className:"fp:w-full fp:mt-6 fp:flex fp:flex-col fp:space-y-2",children:[e.jsx("h2",{className:"fp:text-[16px] fp:font-semibold",children:"More Payment Options"}),gt.includes(Et.STATIC_QR)&&e.jsxs("div",{className:"fp:w-full fp:border fp:border-gray-100 fp:bg-white fp:hover:shadow-2xs fp:cursor-pointer fp:rounded-xl fp:p-4 fp:flex fp:items-center fp:justify-between",onClick:()=>T("STATIC_QR"),children:[e.jsxs("div",{className:"fp:flex fp:items-center fp:space-x-2",children:[e.jsx("img",{src:me.scanqrIcon,className:"fp:w-[32px] fp:h-[32px]"}),e.jsx("label",{className:"fp:text-[14px] fp:font-medium fp:text-[#222222]",children:"Scan QR"})]}),e.jsx("img",{src:me.cardOpener,className:"fp:w-4 fp:h-4"})]}),gt.includes(Et.CASH)&&e.jsxs("div",{className:"fp:w-full fp:border fp:border-gray-100 fp:bg-white fp:hover:shadow-2xs fp:cursor-pointer fp:rounded-xl fp:p-4 fp:flex fp:items-center fp:justify-between",onClick:()=>T("CASH"),children:[e.jsxs("div",{className:"fp:flex fp:items-center fp:space-x-2",children:[e.jsx("img",{src:me.cashIcon,className:"fp:w-[32px] fp:h-[32px]"}),e.jsx("label",{className:"fp:text-[14px] fp:font-medium fp:text-[#222222]",children:"Cash"})]}),e.jsx("img",{src:me.cardOpener,className:"fp:w-4 fp:h-4"})]}),gt.includes(Et.CHEQUE)&&e.jsxs("div",{className:"fp:w-full fp:bg-white fp:border fp:border-gray-100 fp:hover:shadow-2xs fp:cursor-pointer fp:rounded-xl fp:p-4 fp:mt-2 fp:flex fp:items-center fp:justify-between",onClick:()=>T("CHEQUE"),children:[e.jsxs("div",{className:"fp:flex fp:items-center fp:space-x-2",children:[e.jsx("img",{src:me.chequeIcon,className:"fp:w-[32px] fp:h-[32px]"}),e.jsx("label",{className:"fp:text-[14px] fp:font-medium fp:text-[#222222]",children:"Cheque"})]}),e.jsx("img",{src:me.cardOpener,className:"fp:w-4 fp:h-4"})]})]})]})}),e.jsx(Hf,{open:xe,onClose:async()=>{V(),await At.navigateHome()},onPaymentCollected:ze=>{Z(ze)}}),e.jsx(Fl,{open:oe,onClose:async()=>{V(),await At.navigateHome()},onPaymentCollected:ze=>{Z(ze)},onPaymentFailed:ze=>{ee(ze)}}),e.jsx(Kf,{open:H,onClose:async()=>{V(),await At.navigateHome()},onPaymentCollected:ze=>{Z(ze)},onPaymentFailed:ze=>{ee(ze)}}),e.jsx(t0,{open:J,metadata:us,onClose:async()=>{V(),await At.navigateHome()},onPaymentCollected:ze=>{Z(ze)}}),e.jsx(s0,{open:ne,metadata:us,onClose:async()=>{V(),await At.navigateHome()},onPaymentCollected:ze=>{Z(ze)}}),e.jsx(n0,{open:le,metadata:us,onClose:async()=>{V(),await At.navigateHome()},onPaymentCollected:ze=>{Z(ze)}}),e.jsx(Zf,{open:Ae,onClose:()=>{V()},onPaymentCollected:ze=>{Z(ze)},selectedLenderIdx:W,selectedLenderFiCode:Oe,selectedLenderTenureMappings:Ze,selectedLenderRepaymentOption:Me,selectedLenderDisbursementAccount:Ce}),e.jsx(qf,{open:ge,onClose:async()=>{V(),await At.navigateHome()},onPaymentCollected:()=>{Z()}}),e.jsx(Vf,{open:K,onClose:async()=>{V(),await At.navigateHome()},onPaymentCollected:ze=>{Z(ze)},onPaymentFailed:ze=>{ee(ze)}}),e.jsx(To,{open:we,onClose:()=>V(),paymentData:G,buttonText:Ge}),e.jsx(zo,{open:se,onClose:()=>V(),paymentData:G,buttonText:ht}),e.jsx(nu,{open:m,onClose:()=>C(!1),onConfirm:Es}),e.jsx(su,{open:P,onClose:()=>O(!1)}),e.jsxs("div",{className:"fp:absolute fp:bottom-0 fp:left-0 fp:w-full fp:flex fp:flex-col fp:items-center fp:justify-center fp:py-2 fp:bg-[#F8FCFF]",children:[e.jsx("span",{className:"fp:text-[10px] fp:text-[#9CA3AF] fp:font-medium",children:"Powered by"}),e.jsx("a",{href:"https://fundly.ai",target:"_blank",rel:"noopener noreferrer",className:"fp:text-[12px] fp:text-[#16558B] fp:font-bold fp:no-underline",children:"Fundly.ai"})]})]})},r0=I.createContext(void 0);function o0({children:A,initialValues:l}){Gr(l?.environment??"production");const[m,C]=I.useState(l?.partnerCredentials||null),[o,F]=I.useState(l?.businessId||null),[P,O]=I.useState(l?.businessName||null),[Y,U]=I.useState(null),[G,T]=I.useState([]),[V,Z]=I.useState([]),[ee,Ae]=I.useState([]),[oe,K]=I.useState(0),[xe,ge]=I.useState("FULL"),[H,J]=I.useState(null),[ne,le]=I.useState(l?.onPaymentComplete?()=>l.onPaymentComplete:void 0),[we,se]=I.useState(l?.onNavigateHome?()=>l.onNavigateHome:void 0),[Q,X]=I.useState(l?.sessionId||null),[W,ce]=I.useState(l?.erpId||null);I.useEffect(()=>{const be=qr(),Ze=Vr();be&&Ht.configure({enabled:!0,clevertap:{accountId:be,region:Ze}})},[]);const Oe={partnerCredentials:m,setPartnerCredentials:C,businessId:o,setBusinessId:F,businessName:P,setBusinessName:O,selectedLender:Y,setSelectedLender:U,lenderList:G,setLenderList:T,selectedLoans:V,setSelectedLoans:Z,loanList:ee,setLoanList:Ae,totalAmount:oe,setTotalAmount:K,repaymentType:xe,setRepaymentType:ge,redirectionUrl:H,setRedirectionUrl:J,onPaymentComplete:ne,setOnPaymentComplete:le,onNavigateHome:we,setOnNavigateHome:se,sessionId:Q,setSessionId:X,erpId:W,setErpId:ce};return e.jsx(r0.Provider,{value:Oe,children:A})}function Xi(){const A=I.useContext(r0);if(!A)throw new Error("useRepaymentContext must be used within a RepaymentProvider");return A}const a0=I.createContext(void 0);function Qo({children:A,initialValues:l}){Gr(l?.environment??"production");const[m,C]=I.useState(l?.partnerCredentials||null),[o,F]=I.useState(l?.businessId||null),[P,O]=I.useState(l?.businessName||null),[Y,U]=I.useState([]),[G,T]=I.useState(null),[V,Z]=I.useState(l?.filters||null),[ee,Ae]=I.useState(l?.defaultTab||"all"),[oe,K]=I.useState(1),[xe,ge]=I.useState(!0),[H,J]=I.useState(!1),[ne,le]=I.useState(l?.onNavigateHome?()=>l.onNavigateHome:void 0),[we,se]=I.useState(l?.sessionId||null),[Q,X]=I.useState(l?.erpId||null);I.useEffect(()=>{const ce=qr(),Oe=Vr();ce&&Ht.configure({enabled:!0,clevertap:{accountId:ce,region:Oe}})},[]);const W={partnerCredentials:m,setPartnerCredentials:C,businessId:o,setBusinessId:F,businessName:P,setBusinessName:O,transactions:Y,setTransactions:U,selectedTransaction:G,setSelectedTransaction:T,filter:V,setFilter:Z,activeTab:ee,setActiveTab:Ae,currentPage:oe,setCurrentPage:K,hasMore:xe,setHasMore:ge,isLoading:H,setIsLoading:J,onNavigateHome:ne,setOnNavigateHome:le,sessionId:we,setSessionId:se,erpId:Q,setErpId:X};return e.jsx(a0.Provider,{value:W,children:A})}function lu(){const A=I.useContext(a0);if(!A)throw new Error("useTransactionContext must be used within a TransactionProvider");return A}const Qe=({className:A=""})=>e.jsx("div",{className:`fp:animate-pulse fp:bg-gray-200 fp:rounded ${A}`}),cu=[{label:"All",value:"all"},{label:"Success",value:"success"},{label:"Failure",value:"failed"},{label:"Pending",value:"pending"}],du=[{label:"Last 30 days",value:"30"},{label:"Last 60 days",value:"60"},{label:"Last 90 days",value:"90"},{label:"Custom date range",value:"custom"}],pu=[{label:"All",value:"all"},{label:"UPI",value:"UPI"},{label:"NEFT",value:"NEFT"},{label:"RTGS",value:"RTGS"},{label:"IMPS",value:"IMPS"}],fu=A=>{if(!A)return null;const l=new Date,m=new Date(l.getFullYear(),l.getMonth(),l.getDate()),C=Math.round((m.getTime()-A.from.getTime())/(1e3*60*60*24));return C>=29&&C<=31?"30":C>=59&&C<=61?"60":C>=89&&C<=91?"90":"custom"},uu=A=>{if(A==="custom")return;const l=Number(A),m=new Date,C=new Date;return C.setDate(C.getDate()-l),{from:C,to:m}},xu=({open:A,onClose:l,currentFilter:m,onApply:C})=>{const[o,F]=I.useState(["all"]),[P,O]=I.useState(null),[Y,U]=I.useState(null),[G,T]=I.useState(null),[V,Z]=I.useState(["all"]);I.useEffect(()=>{if(A){const H=m.statuses;F(H&&H.length>0?H:["all"]);const J=m.paymentMethods;Z(J&&J.length>0?J:["all"]);const ne=fu(m.dateRange);O(ne),ne==="custom"&&m.dateRange?(U(m.dateRange.from),T(m.dateRange.to)):(U(null),T(null))}},[A]);const ee=H=>{if(H==="all"){F(["all"]);return}F(J=>{const ne=J.filter(le=>le!=="all");if(ne.includes(H)){const le=ne.filter(we=>we!==H);return le.length===0?["all"]:le}return[...ne,H]})},Ae=H=>{if(H==="all"){Z(["all"]);return}Z(J=>{const ne=J.filter(le=>le!=="all");if(ne.includes(H)){const le=ne.filter(we=>we!==H);return le.length===0?["all"]:le}return[...ne,H]})},oe=()=>{F(["all"]),O(null),U(null),T(null),Z(["all"])},K=()=>{const H={...m,statuses:o,paymentMethods:V};P&&P!=="custom"?H.dateRange=uu(P):P==="custom"&&Y&&G?H.dateRange={from:Y,to:G}:H.dateRange=void 0,C(H),l()},xe=H=>{P===H?(O(null),U(null),T(null)):(O(H),H!=="custom"&&(U(null),T(null)))},ge=H=>`fp:px-4 fp:py-2 fp:rounded-full fp:text-[13px] fp:font-medium fp:transition-colors ${H?"fp:bg-[#16558B] fp:text-white":"fp:border fp:border-[#D0D0D0] fp:text-[#222222] fp:bg-white"}`;return e.jsx(ds,{open:A,onClose:l,children:e.jsxs("div",{className:"fp:px-5 fp:pt-5 fp:pb-6",children:[e.jsx("div",{className:"fp:flex fp:justify-center fp:mb-4",children:e.jsx("div",{className:"fp:w-10 fp:h-1 fp:rounded-full fp:bg-[#D0D0D0]"})}),e.jsxs("div",{className:"fp:flex fp:items-center fp:gap-2.5 fp:mb-6",children:[e.jsx("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none",stroke:"#16558B",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M22 12h-4l-3 9L9 3l-3 9H2"})}),e.jsx("h2",{className:"fp:text-[18px] fp:font-semibold fp:text-[#222222]",children:"Apply filters"})]}),e.jsxs("div",{className:"fp:mb-5",children:[e.jsx("p",{className:"fp:text-[14px] fp:font-medium fp:text-[#222222] fp:mb-3",children:"Status"}),e.jsx("div",{className:"fp:flex fp:flex-wrap fp:gap-2",children:cu.map(H=>e.jsx("button",{className:ge(o.includes(H.value)),onClick:()=>ee(H.value),children:H.label},H.value))})]}),e.jsxs("div",{className:"fp:mb-5",children:[e.jsx("p",{className:"fp:text-[14px] fp:font-medium fp:text-[#222222] fp:mb-3",children:"Date Range"}),e.jsx("div",{className:"fp:flex fp:flex-wrap fp:gap-2",children:du.map(H=>e.jsx("button",{className:ge(P===H.value),onClick:()=>xe(H.value),children:H.label},H.value))}),P==="custom"&&e.jsxs("div",{className:"fp:flex fp:gap-3 fp:mt-3",children:[e.jsx("div",{className:"fp:flex-1",children:e.jsx(Hi,{value:Y,onChange:U,label:"From",placeholder:"Start date",fullWidth:!0})}),e.jsx("div",{className:"fp:flex-1",children:e.jsx(Hi,{value:G,onChange:T,minDate:Y||void 0,label:"To",placeholder:"End date",fullWidth:!0})})]})]}),e.jsxs("div",{className:"fp:mb-6",children:[e.jsx("p",{className:"fp:text-[14px] fp:font-medium fp:text-[#222222] fp:mb-3",children:"Payment Mode"}),e.jsx("div",{className:"fp:flex fp:flex-wrap fp:gap-2",children:pu.map(H=>e.jsx("button",{className:ge(V.includes(H.value)),onClick:()=>Ae(H.value),children:H.label},H.value))})]}),e.jsxs("div",{className:"fp:flex fp:gap-3",children:[e.jsx("button",{onClick:oe,className:"fp:flex-1 fp:py-3 fp:rounded-xl fp:border fp:border-[#16558B] fp:text-[#16558B] fp:font-semibold fp:text-[14px] fp:active:scale-[0.97] fp:transition-transform",children:"Clear All"}),e.jsx("button",{onClick:K,className:"fp:flex-1 fp:py-3 fp:rounded-xl fp:bg-[#16558B] fp:text-white fp:font-semibold fp:text-[14px] fp:active:scale-[0.97] fp:transition-transform",children:"Apply"})]})]})})},Au=({status:A})=>{switch(A.toUpperCase()){case"SUCCESS":return e.jsx("div",{className:"fp:w-8 fp:h-8 fp:flex fp:items-center fp:justify-center fp:flex-shrink-0",children:e.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 16 16",fill:"none",children:[e.jsx("path",{d:"M8 0.0996094C10.0945 0.101867 12.1029 0.934966 13.584 2.41602C15.065 3.89706 15.8981 5.90548 15.9004 8L15.8945 8.29297C15.8404 9.75276 15.382 11.1709 14.5684 12.3887C13.7003 13.6878 12.4669 14.7009 11.0234 15.2988C9.57995 15.8967 7.99139 16.0528 6.45898 15.748C4.92653 15.4432 3.5189 14.6908 2.41406 13.5859C1.30923 12.4811 0.556776 11.0735 0.251953 9.54102C-0.0528274 8.00861 0.10326 6.42005 0.701172 4.97656C1.29911 3.53309 2.31222 2.29968 3.61133 1.43164C4.82912 0.617965 6.24724 0.159629 7.70703 0.105469L8 0.0996094ZM10.334 2.36426C9.21945 1.90269 7.99273 1.78223 6.80957 2.01758C5.62646 2.253 4.53952 2.83353 3.68652 3.68652C2.83353 4.53952 2.253 5.62645 2.01758 6.80957C1.78223 7.99273 1.90269 9.21945 2.36426 10.334C2.82595 11.4486 3.60819 12.402 4.61133 13.0723C5.61439 13.7424 6.79368 14.0996 8 14.0996C9.61725 14.0978 11.168 13.4551 12.3115 12.3115C13.4551 11.168 14.0978 9.61725 14.0996 8L14.0957 7.77441C14.054 6.64712 13.7006 5.55177 13.0723 4.61133C12.402 3.60819 11.4486 2.82595 10.334 2.36426Z",fill:"#2FB551",stroke:"white",strokeWidth:"0.2"}),e.jsx("g",{transform:"translate(4.5, 5)",children:e.jsx("path",{d:"M5.91895 0.103516C6.03691 0.0926467 6.15642 0.105413 6.26953 0.140625C6.3824 0.175812 6.48733 0.232873 6.57812 0.308594C6.66904 0.384472 6.74396 0.478068 6.79883 0.583008C6.8537 0.687993 6.88803 0.802895 6.89844 0.920898C6.90882 1.03885 6.89501 1.1576 6.85938 1.27051C6.82373 1.38344 6.76666 1.48847 6.69043 1.5791H6.68945L3.35547 5.5791C3.27113 5.68031 3.16618 5.76248 3.04688 5.81836C2.92748 5.87424 2.79687 5.90243 2.66504 5.90234C2.5332 5.90226 2.40254 5.87342 2.2832 5.81738C2.16405 5.76135 2.05877 5.67939 1.97461 5.57812L0.308594 3.57812C0.233081 3.48748 0.175742 3.38313 0.140625 3.27051C0.105548 3.15793 0.0929033 3.03931 0.103516 2.92188C0.114206 2.80428 0.148246 2.68951 0.203125 2.58496C0.257993 2.48043 0.333141 2.38808 0.423828 2.3125C0.514465 2.23697 0.618817 2.17966 0.731445 2.14453C0.84418 2.10941 0.963459 2.09673 1.08105 2.10742C1.19848 2.11816 1.31258 2.15223 1.41699 2.20703C1.52132 2.26181 1.61396 2.33629 1.68945 2.42676H1.69043L2.58887 3.50391L2.66504 3.59668L2.74219 3.50391L5.30859 0.425781C5.38413 0.334582 5.4773 0.259367 5.58203 0.204102C5.6867 0.148897 5.80111 0.114394 5.91895 0.103516Z",fill:"#2FB551",stroke:"white",strokeWidth:"0.2"})})]})});case"FAILED":return e.jsx("div",{className:"fp:w-8 fp:h-8 fp:flex fp:items-center fp:justify-center fp:flex-shrink-0",children:e.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 16 16",fill:"none",children:[e.jsx("path",{d:"M8 0.75C12.0041 0.75 15.25 3.99594 15.25 8C15.25 12.0041 12.0041 15.25 8 15.25C3.99594 15.25 0.75 12.0041 0.75 8C0.75 3.99594 3.99594 0.75 8 0.75Z",stroke:"#E80000",strokeWidth:"1.5",strokeLinecap:"round"}),e.jsx("path",{d:"M9.88595 6.11719L6.11475 9.88842",stroke:"#E80000",strokeWidth:"1.5",strokeLinecap:"round"}),e.jsx("path",{d:"M6.11475 6.11719L9.88598 9.88842",stroke:"#E80000",strokeWidth:"1.5",strokeLinecap:"round"})]})});case"INITIATED":return e.jsx("div",{className:"fp:w-8 fp:h-8 fp:flex fp:items-center fp:justify-center fp:flex-shrink-0",children:e.jsx("svg",{width:"24",height:"24",viewBox:"-2 -1 16 17",fill:"none",children:e.jsx("path",{d:"M0.75 1.00098C0.750262 0.801579 0.97265 0.682461 1.13867 0.792969L10.3359 6.9248C10.4843 7.02376 10.4843 7.24186 10.3359 7.34082L1.13867 13.4727C0.972648 13.5832 0.750262 13.464 0.75 13.2646V1.00098Z",stroke:"#1E88E5",strokeWidth:"1.5"})})});case"PENDING":default:return e.jsx("div",{className:"fp:w-8 fp:h-8 fp:flex fp:items-center fp:justify-center fp:flex-shrink-0",children:e.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 16 16",fill:"none",children:[e.jsx("path",{d:"M8 0.0996094C10.0945 0.101867 12.1029 0.934966 13.584 2.41602C15.065 3.89706 15.8981 5.90548 15.9004 8L15.8945 8.29297C15.8404 9.75276 15.382 11.1709 14.5684 12.3887C13.7003 13.6878 12.4669 14.7009 11.0234 15.2988C9.57995 15.8967 7.99139 16.0528 6.45898 15.748C4.92653 15.4432 3.5189 14.6908 2.41406 13.5859C1.30923 12.4811 0.556776 11.0735 0.251953 9.54102C-0.0528275 8.00862 0.10326 6.42005 0.701172 4.97656C1.29911 3.53309 2.31222 2.29968 3.61133 1.43164C4.82912 0.617965 6.24724 0.159629 7.70703 0.105469L8 0.0996094ZM10.334 2.36426C9.21945 1.90269 7.99273 1.78223 6.80957 2.01758C5.62646 2.253 4.53952 2.83353 3.68652 3.68652C2.83353 4.53952 2.253 5.62646 2.01758 6.80957C1.78223 7.99273 1.90268 9.21945 2.36426 10.334C2.82595 11.4486 3.60819 12.402 4.61133 13.0723C5.61439 13.7424 6.79368 14.0996 8 14.0996C9.61725 14.0978 11.168 13.4551 12.3115 12.3115C13.4551 11.168 14.0978 9.61725 14.0996 8L14.0957 7.77441C14.054 6.64712 13.7006 5.55177 13.0723 4.61133C12.402 3.60819 11.4486 2.82595 10.334 2.36426Z",fill:"#FFA500",stroke:"white",strokeWidth:"0.2"}),e.jsx("path",{d:"M9.58325 10.4995L7.5404 8.9791C7.24263 8.80264 7 8.37804 7 8.03064V5",stroke:"#FFA500",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]})})}},hu=({onNavigateBack:A,onViewTransaction:l})=>{const{businessId:m}=lu(),[C,o]=I.useState([]),[F,P]=I.useState(!0),[O,Y]=I.useState(null),[U,G]=I.useState(0),[T,V]=I.useState(!1),[Z,ee]=I.useState(0),[Ae,oe]=I.useState({}),[K,xe]=I.useState(!1);I.useEffect(()=>{m&&ge()},[m,U,Ae]);const ge=async()=>{if(!m){Y("Business ID is required"),P(!1);return}try{P(!0),Y(null);const J=await Bf({businessId:m,filter:Ae,page:U,size:10});o(U===0?J.transactions:ne=>[...ne,...J.transactions]),ee(J.totalCount),V(J.hasMore)}catch(J){console.error("Error loading transactions:",J);const ne=J?.response?.data?.errorMessage||J?.response?.data?.message||J?.message||"Failed to load transactions. Please try again.";Y(ne)}finally{P(!1)}},H=J=>new Date(J).toLocaleDateString("en-IN",{day:"numeric",month:"short",year:"numeric"});return F&&U===0?e.jsxs("div",{className:"fp:min-h-screen fp:bg-[#F8FCFF]",children:[e.jsxs("div",{className:"fp:bg-[#F8FCFF] fp:px-4 fp:pt-4 fp:pb-3",children:[e.jsxs("div",{className:"fp:flex fp:items-center fp:justify-between fp:mb-3",children:[e.jsx(Qe,{className:"fp:w-6 fp:h-6 fp:rounded-full"}),e.jsx(Qe,{className:"fp:w-9 fp:h-9 fp:rounded-[10px]"})]}),e.jsx(Qe,{className:"fp:w-40 fp:h-7 fp:rounded-lg"})]}),e.jsx("div",{className:"fp:px-4 fp:py-4 fp:space-y-3",children:[1,2,3,4,5].map(J=>e.jsxs("div",{className:"fp:bg-white fp:rounded-[12px] fp:border fp:border-[#E8EEF8] fp:px-4 fp:py-3.5 fp:flex fp:items-center fp:gap-3",children:[e.jsx(Qe,{className:"fp:w-8 fp:h-8 fp:rounded-full fp:flex-shrink-0"}),e.jsxs("div",{className:"fp:flex-1",children:[e.jsx(Qe,{className:"fp:w-36 fp:h-3.5 fp:rounded fp:mb-2"}),e.jsx(Qe,{className:"fp:w-28 fp:h-3 fp:rounded"})]}),e.jsx(Qe,{className:"fp:w-16 fp:h-3.5 fp:rounded fp:flex-shrink-0"})]},J))})]}):O?e.jsxs("div",{className:"fp:min-h-screen fp:bg-[#F8FCFF]",children:[e.jsxs("div",{className:"fp:bg-[#F8FCFF] fp:px-4 fp:pt-4 fp:pb-3",children:[e.jsx("button",{onClick:A,className:"fp:mb-3 fp:p-1 fp:-ml-1",children:e.jsx("img",{src:me.backButton,alt:"Back",className:"fp:w-6 fp:h-6"})}),e.jsx("h1",{className:"fp:text-2xl fp:font-bold fp:text-[#222222]",children:"Transactions"})]}),e.jsx("div",{className:"fp:flex fp:items-center fp:justify-center fp:min-h-[calc(100vh-80px)] fp:px-4",children:e.jsxs("div",{className:"fp:text-center fp:max-w-md",children:[e.jsx("div",{className:"fp:w-20 fp:h-20 fp:mx-auto fp:mb-4 fp:bg-red-100 fp:rounded-full fp:flex fp:items-center fp:justify-center",children:e.jsx("svg",{className:"fp:w-10 fp:h-10 fp:text-red-600",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})})}),e.jsx("h2",{className:"fp:text-lg fp:font-semibold fp:text-gray-900 fp:mb-2",children:"Failed to Load"}),e.jsx("p",{className:"fp:text-gray-600 fp:mb-6 fp:text-sm",children:O}),e.jsx("button",{onClick:()=>{G(0),ge()},className:"fp:bg-[#16558B] fp:text-white fp:font-semibold fp:py-3 fp:px-6 fp:rounded-xl fp:transition-colors",children:"Try Again"})]})})]}):e.jsxs("div",{className:"fp:min-h-screen fp:bg-[#F8FCFF] fp:pb-10",children:[e.jsxs("div",{className:"fp:bg-[#F8FCFF] fp:px-4 fp:pt-4 fp:pb-3",children:[e.jsxs("div",{className:"fp:flex fp:items-center fp:justify-between fp:mb-2",children:[e.jsx("button",{onClick:A,className:"fp:p-1 fp:-ml-1",children:e.jsx("img",{src:me.backButton,alt:"Back",className:"fp:w-6 fp:h-6"})}),e.jsx("button",{onClick:()=>xe(!0),className:"fp:w-9 fp:h-9 fp:rounded-[10px] fp:bg-[#EAF2FF] fp:flex fp:items-center fp:justify-center",children:e.jsxs("svg",{className:"fp:w-5 fp:h-5 fp:text-[#16558B]",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",strokeWidth:1.8,children:[e.jsx("line",{x1:"4",y1:"6",x2:"20",y2:"6",strokeLinecap:"round"}),e.jsx("line",{x1:"4",y1:"12",x2:"20",y2:"12",strokeLinecap:"round"}),e.jsx("line",{x1:"4",y1:"18",x2:"20",y2:"18",strokeLinecap:"round"}),e.jsx("circle",{cx:"8",cy:"6",r:"2",fill:"#16558B",stroke:"#16558B"}),e.jsx("circle",{cx:"16",cy:"12",r:"2",fill:"#16558B",stroke:"#16558B"}),e.jsx("circle",{cx:"10",cy:"18",r:"2",fill:"#16558B",stroke:"#16558B"})]})})]}),e.jsx("h1",{className:"fp:text-2xl fp:font-bold fp:text-[#222222]",children:"Transactions"})]}),e.jsx(xu,{open:K,onClose:()=>xe(!1),currentFilter:Ae,onApply:J=>{oe(J),G(0),o([])}}),e.jsx("div",{className:"fp:px-4 fp:space-y-3",children:C.length===0&&!F?e.jsxs("div",{className:"fp:flex fp:flex-col fp:items-center fp:justify-center fp:py-20 fp:px-6",children:[e.jsx("div",{className:"fp:w-20 fp:h-20 fp:rounded-full fp:bg-[#D6E8FF] fp:flex fp:items-center fp:justify-center fp:mb-5",children:e.jsx("svg",{className:"fp:w-9 fp:h-9 fp:text-[#16558B]",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,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"})})}),e.jsx("p",{className:"fp:text-[16px] fp:font-medium fp:text-[#222222] fp:mb-2",children:"No Transactions"}),e.jsx("p",{className:"fp:text-[13px] fp:font-normal fp:text-[#6D6D6D] fp:text-center fp:leading-5",children:"Your payment history will appear here once you make a transaction."})]}):e.jsxs(e.Fragment,{children:[C.map(J=>e.jsxs("button",{onClick:()=>l(J),className:"fp:w-full fp:bg-white fp:rounded-[12px] fp:border fp:border-[#E8EEF8] fp:px-4 fp:py-3.5 fp:flex fp:items-center fp:gap-3 fp:text-left fp:active:scale-[0.98] fp:transition-all",children:[e.jsx(Au,{status:J.status}),e.jsxs("div",{className:"fp:flex-1 fp:min-w-0",children:[e.jsx("p",{className:"fp:text-[14px] fp:font-medium fp:text-[#16558B] fp:leading-[14px] fp:truncate",children:J.name||J.supplierName||J.lenderName||"N/A"}),e.jsxs("p",{className:"fp:text-[12px] fp:font-normal fp:text-[#6D6D6D] fp:leading-[14px] fp:mt-1.5",children:[H(J.date),"  •  ",J.paymentMode]})]}),e.jsxs("p",{className:"fp:text-[14px] fp:font-medium fp:text-[#222222] fp:leading-[14px] fp:flex-shrink-0",children:["₹",$e(J.amount)]})]},J.transactionId)),T&&e.jsx("div",{className:"fp:flex fp:justify-center fp:pt-2 fp:pb-4",children:e.jsx("button",{onClick:()=>G(U+1),disabled:F,className:"fp:text-sm fp:font-medium fp:text-[#16558B] fp:py-2 fp:px-6 fp:rounded-full fp:border fp:border-[#16558B] fp:disabled:opacity-50 fp:disabled:cursor-not-allowed fp:active:scale-95 fp:transition-transform",children:F?"Loading...":"Load More"})}),!T&&Z>0&&e.jsxs("p",{className:"fp:text-center fp:text-xs fp:text-[#6D6D6D] fp:py-4",children:[Z," transaction",Z!==1?"s":""," total"]})]})})]})},mu=({open:A,onClose:l,transaction:m})=>{const C=I.useRef(null),[o,F]=I.useState(null),[P,O]=I.useState(!1),[Y,U]=I.useState(null),[G,T]=I.useState([]),[V,Z]=I.useState(!1),[ee,Ae]=I.useState(!1),[oe,K]=I.useState(""),xe=async q=>{const ve=q.documentIds.flat().map(Pe=>Pe.documentId);if(ve.length!==0){Ae(!0),K(q.invoiceNumber),Z(!0);try{const Pe=await Pf(ve);T(Array.isArray(Pe)?Pe:[])}catch(Pe){console.error("Error fetching documents:",Pe),T([])}finally{Ae(!1)}}},ge=()=>{Z(!1),T([]),K("")};I.useEffect(()=>{A&&m&&H(),A||(F(null),U(null))},[A,m?.transactionId]);const H=async()=>{if(m){O(!0),U(null);try{const q=m.source==="LOS"?"LMS":m.source,ve=await kf(m.transactionId,q);F(ve)}catch(q){console.error("Error fetching transaction details:",q);const ve=q?.response?.data?.errorMessage||q?.response?.data?.message||q?.message||"Failed to load details";U(ve)}finally{O(!1)}}};if(!m)return null;const J=q=>{const ve=new Date(q),Pe=ve.getDate(),Ge=ve.toLocaleDateString("en-IN",{month:"short"}),ht=ve.getFullYear(),ot=ve.getHours(),Mt=ve.getMinutes().toString().padStart(2,"0"),je=ot>=12?"PM":"AM",Ve=ot%12||12;return`${Pe} ${Ge} ${ht}, ${Ve}:${Mt} ${je}`},ne=q=>{switch(q.toUpperCase()){case"SUCCESS":return"fp:text-[#2FB551]";case"FAILED":case"FAILURE":return"fp:text-[#E80000]";case"INITIATED":return"fp:text-[#1E88E5]";case"PENDING":return"fp:text-[#FFA500]";default:return"fp:text-[#6D6D6D]"}},le=q=>{switch(q.toUpperCase()){case"SUCCESS":return"Success";case"FAILED":case"FAILURE":return"Failed";case"INITIATED":return"Initiated";case"PENDING":return"Pending";default:return q}},we=o?.id??m.transactionId,se=o?.amount??m.amount,Q=o?.status??m.status,X=o?.date??m.date,W=o?.paymentMode??m.paymentMode,ce=o?.supplierName&&o.supplierName.trim()||m.supplierName||m.name||"",Oe=o?.lender||m.lenderName||"",be=o?.type==="LENDING"||m.transactionType==="LOAN_REPAYMENT",Ie=o?.loan?.loans||[],Me=o?.invoice||[],ae=m.invoiceNumbers||[],Ce=Me.length>0||ae.length>0,Be=Me.length>0?Me.map(q=>q.invoiceNumber).join(", "):ae.join(", "),Ee=Me.find(q=>q.remark&&q.remark.trim())?.remark||o?.settlement?.find(q=>q.description&&q.description.trim())?.description||"",De=Me.filter(q=>q.documentIds&&q.documentIds.length>0),Se=async()=>{let q=`Transaction Details
666
666
 
667
667
  Transaction ID: ${we}
668
668
  Paid Amount: ₹${Number(se).toLocaleString("en-IN")}