PageSourceSearch

https://freightcompare.ai/assets/AddVendor-VlhoZ9yn.js

js freightcompare.ai collected 2026-10-02 01:11:10 UTC 388,051 bytes, 141 lines download raw bytes

1import{c as f0,b8 as vn,b9 as dt,r as x,ao as Ea,j as n,R as un,Q as ea,J as Fa,A as au,F as Nr,B as ct,an as m0,z as ie,I as gi,X as Sr,G as $l,Y as iu,ba as lo,bb as ou,bc as h0,a0 as p0,E as g0,aF as x0,aj as lu,bd as li,aK as ns,x as b0,T as v0,$ as xi,aJ as ci,al as cu,a4 as y0}from"./index-BFYamPZN.js";import{r as Ul,u as Wl}from"./xlsx-Bw6bjxR0.js";import{u as go,a as N0,F as w0,b as C0,p as _l,P as kl,A as S0,Z as j0,V as _0}from"./AddIndividualFtlTransporter-B65seYEe.js";import{g as k0,u as A0}from"./useWizardStorage-BsmR43Bt.js";import{a as Md,b as Od,c as Ld,v as Bl,d as zd,e as Al,f as $d,u as E0}from"./validators-DT4es2Ig.js";import{X as bi}from"./x-circle-jbJE_-5e.js";import{H as P0}from"./hash-CmvCi1bY.js";import{C as wr}from"./check-circle-DPMESBDo.js";import{C as Cr}from"./chevron-right-BQMONOUr.js";import{D as Vl}from"./download--ZTl6XPZ.js";import{F as po}from"./DecimalInput-CPqrmR4-.js";import{T as D0}from"./trash-2-B04TDMPX.js";import{U as ho}from"./upload-CTtH1oD6.js";import{I as du}from"./info-CQ4LeTEy.js";import{A as F0}from"./alert-circle-Cy-MNOhZ.js";import{C as T0}from"./chevron-up-wsqDDVKp.js";import{S as Kl}from"./save-6x4ljonr.js";import{B as El}from"./building-2-U2uqivYG.js";import{P as Pl}from"./pen-line-x9z111H2.js";import{C as Dl}from"./chevron-left-DGmjOTui.js";import{P as R0}from"./package-search-CXcVp5E_.js";import{S as I0,B as M0}from"./scan-search-CBsrEg2x.js";import"./arrow-left-xOH_e3v_.js";import"./leaflet-uR8xTtQN.js";import"./individualFtl-Bt5Pc2Pk.js";import"./upload-cloud-CFZk11NZ.js";/**
2 * @license lucide-react v0.344.0 - ISC
3 *
4 * This source code is licensed under the ISC license.
5 * See the LICENSE file in the root directory of this source tree.
6 */const O0=f0("Table",[["path",{d:"M12 3v18",key:"108xh3"}],["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M3 9h18",key:"1pudct"}],["path",{d:"M3 15h18",key:"5xshup"}]]),Gl=()=>`addVendorV2_draft_${k0()||"guest"}`,uu=()=>{try{const d=localStorage.getItem(Gl());if(!d)return null;const l=JSON.parse(d);return dt("DRAFT_READ",{hasBasics:!!l.basics,hasGeo:!!l.geo,hasVolumetric:!!l.volumetric,hasCharges:!!l.charges,hasZoneRates:!!l.zoneRates,lastSaved:l.lastSaved}),l}catch(d){return vn("DRAFT_READ_ERROR",{error:d instanceof Error?d.message:String(d)}),null}},L0=d=>{try{d.lastSaved=new Date().toISOString(),localStorage.setItem(Gl(),JSON.stringify(d)),dt("DRAFT_WRITE",{hasBasics:!!d.basics,hasGeo:!!d.geo,hasVolumetric:!!d.volumetric,hasCharges:!!d.charges,hasZoneRates:!!d.zoneRates,timestamp:d.lastSaved})}catch(l){vn("DRAFT_WRITE_ERROR",{error:l instanceof Error?l.message:String(l)})}},Pa=d=>{try{const l=uu()||{},s={...l,...d,lastSaved:new Date().toISOString()};d.basics&&(s.basics={...l.basics,...d.basics}),d.geo&&(s.geo={...l.geo,...d.geo}),d.volumetric&&(s.volumetric={...l.volumetric,...d.volumetric}),d.charges&&(s.charges={...l.charges,...d.charges}),d.zoneRates&&(s.zoneRates={...l.zoneRates,...d.zoneRates}),L0(s)}catch(l){vn("DRAFT_PERSIST_ERROR",{error:l instanceof Error?l.message:String(l)})}},Fl=()=>{try{localStorage.removeItem(Gl()),dt("DRAFT_CLEARED")}catch(d){vn("DRAFT_CLEAR_ERROR",{error:d instanceof Error?d.message:String(d)})}},Ud={companyName:"",legalCompanyName:"",contactPersonName:"",vendorPhoneNumber:"",vendorEmailAddress:"",gstin:"",transportMode:null,displayName:"",subVendor:"",vendorCode:"",primaryContactName:"",primaryContactPhone:"",primaryContactEmail:"",address:"",serviceMode:null,companyRating:4},Wd={unit:"cm",volumetricDivisor:2800,cftFactor:null};function z0(d){const{vendorBasics:l,pincodeLookup:s,volumetric:f,charges:m,setWizardData:g,setZpm:A,setIsAutoFilled:O,setAutoFilledFromName:U,setAutoFilledFromId:k,setWizardValidation:z,setWizardStatus:E,validateWizardData:me,getWizardStatus:ve,setServiceabilityData:q}=d,ee=x.useRef(!1);return{applyVendorAutofill:x.useCallback(async(Y,le)=>{if(ee.current){console.warn("[AutoFill] Blocked concurrent execution");return}try{ee.current=!0,console.log("[AutoFill] Starting application for:",Y.companyName);const J={overwriteBasics:!0,overwriteGeo:!0,overwriteVolumetric:!0,overwriteZones:!0,overwriteCharges:!1,overwritePriceMatrix:!1,blankCellValue:"",wizardStep:3,writeLegacyZpm:!0,...le||{}};if(J.overwriteBasics&&l?.setBasics&&l.setBasics({...Ud,legalCompanyName:Y.legalCompanyName||Y.companyName||"",companyName:Y.companyName||Y.legalCompanyName||"",contactPersonName:Y.contactPersonName||"",vendorPhoneNumber:String(Y.vendorPhone??""),vendorEmailAddress:Y.vendorEmail??"",vendorCode:Y.vendorCode??"",gstin:Y.gstNo??"",subVendor:Y.subVendor??"",address:Y.address??"",transportMode:Y.mode||"road",serviceMode:Y.charges?.serviceMode?.toUpperCase()||"PTL",companyRating:Y.rating??Ud.companyRating}),J.overwriteGeo&&s){typeof s.reset=="function"&&s.reset();const G=Y.pincode?String(Y.pincode):"";G&&typeof s.setPincode=="function"&&s.setPincode(G)}if(J.overwriteVolumetric&&f?.setState){const ue=(Y.volumetricUnit||"cm").toLowerCase().startsWith("in")?"in":"cm";f.setState({...Wd,unit:ue,volumetricDivisor:ue==="cm"?Y.charges?.divisor??Wd.volumetricDivisor:null,cftFactor:ue==="in"?Y.cftFactor??6:null})}if(J.overwriteCharges&&m?.loadFromDraft&&Y.charges){const G=Y.charges,ue=V=>{if(!V)return;const he=(V.variable??0)>0;return{mode:he?"VARIABLE":"FIXED",currency:he?"PERCENT":"INR",fixedAmount:V.fixed??0,variable:V.variable??0,unit:V.unit||"per kg"}};m.loadFromDraft({docketCharges:G.docketCharges??0,minWeightKg:G.minWeight??0,minCharges:G.minCharges??0,fuelSurchargePct:G.fuel??0,rovCharges:ue(G.rovCharges),odaCharges:ue(G.odaCharges)})}if(J.overwriteZones){let G=[],ue=[],V=[];const he=L=>L.startsWith("N")?"North":L.startsWith("S")?"South":L.startsWith("E")?"East":L.startsWith("W")?"West":L.startsWith("
6C")?"Central":L.startsWith("NE")?"Northeast":"Other";if(Y.serviceability&&!Array.isArray(Y.serviceability)){console.log("[AutoFill] Expanding v3.0 range-based serviceability");const L=Y.serviceability;let ce=null;try{const fe=await Ea();ce=new Map(fe.map(Ae=>[String(Ae.pincode),Ae]))}catch(fe){console.warn("Pincode enrichment failed",fe)}for(const[fe,Ae]of Object.entries(L)){const re=[],I=[];Ae.servedSingles&&Ae.servedSingles.forEach(we=>re.push(String(we))),Ae.servedRanges&&Ae.servedRanges.forEach(([we,ye])=>{for(let We=we;We<=ye;We++)re.push(String(We))}),Ae.odaSingles&&Ae.odaSingles.forEach(we=>I.push(String(we))),Ae.odaRanges&&Ae.odaRanges.forEach(we=>{let ye,We;Array.isArray(we)?[ye,We]=we:(ye=we.s,We=we.e);for(let Vt=ye;Vt<=We;Vt++)I.push(String(Vt))});const Ne=new Set,ge=new Set;re.forEach(we=>{const ye=ce?.get(we);ye&&(ye.city&&Ne.add(ye.city),ye.state&&ge.add(ye.state)),G.push({pincode:we,zone:fe,city:ye?.city||"",state:ye?.state||"",isODA:!1,active:!0})}),I.forEach(we=>{const ye=ce?.get(we);ye&&(ye.city&&Ne.add(ye.city),ye.state&&ge.add(ye.state)),G.push({pincode:we,zone:fe,city:ye?.city||"",state:ye?.state||"",isODA:!0,active:!0})}),ue.push({zoneCode:fe,region:he(fe),pincodeCount:re.length+I.length,states:Array.from(ge),cities:Array.from(Ne),odaCount:I.length}),V.push(fe)}}else if(Array.isArray(Y.serviceability)){const L=new Map;Y.serviceability.forEach(ce=>{if(!ce.zone)return;L.has(ce.zone)||L.set(ce.zone,{cities:new Set,states:new Set,count:0,oda:0});const fe=L.get(ce.zone);fe.count++,ce.city&&fe.cities.add(ce.city),ce.state&&fe.states.add(ce.state),ce.isODA&&fe.oda++,G.push({...ce,active:!0})}),V=Array.from(L.keys()),ue=Array.from(L.entries()).map(([ce,fe])=>({zoneCode:ce,region:he(ce),pincodeCount:fe.count,states:Array.from(fe.states),cities:Array.from(fe.cities),odaCount:fe.oda}))}if(V.length>0){const L=J.overwritePriceMatrix?Y.priceChart||{}:{},ce={};V.forEach(Ae=>{ce[Ae]={},V.forEach(re=>{const I=L[Ae]?.[re];ce[Ae][re]=I??J.blankCellValue??""})});const fe={selectedZones:V.map(Ae=>({zoneCode:Ae,zoneName:Ae})),zones:ue.map(Ae=>({zoneCode:Ae.zoneCode,zoneName:Ae.zoneCode,region:Ae.region,selectedStates:Ae.states,selectedCities:Ae.cities,isComplete:Ae.cities.length>0})),priceMatrix:ce,step:J.wizardStep,lastUpdated:new Date().toISOString(),serviceability:G,autoFilledFrom:{vendorId:Y.id,vendorName:Y.companyName}};localStorage.setItem("vendorWizard.v1",JSON.stringify(fe)),A&&A({zones:V,priceMatr
6ix:ce}),g&&g(fe),q&&q({serviceability:G,zoneSummary:ue,source:"cloned"})}}O&&O(!0),U&&U(Y.companyName||null)}finally{ee.current=!1}},[l,s,f,m,g,A,O,U,k,z,E,me,ve,q])}}const er=(d,l,s,f,m)=>!d&&m?`${l} is required`:d?s!=null&&d.length<s?`${l} must be at least ${s} character${s!==1?"s":""}`:f!=null&&d.length>f?`${l} must be at most ${f} character${f!==1?"s":""}`:"":"",$0={priceSupport:0,deliveryTime:0,tracking:0,salesSupport:0,damageLoss:0},Bd={companyName:"",contactPersonName:"",vendorPhoneNumber:"",whatsappNumber:"",vendorEmailAddress:"",gstin:"",transportMode:"road",displayName:"",subVendor:"",vendorCode:"",primaryContactName:"",primaryContactPhone:"",primaryContactEmail:"",address:"",serviceMode:"PTL",companyRating:null,vendorRatings:$0},U0=d=>{const[l,s]=x.useState(Bd),[f,m]=x.useState({}),{getField:g,getConstraint:A}=go("add-vendor");x.useEffect(()=>{const q=setTimeout(()=>{Pa({basics:l}),dt("BASICS_DRAFT_SAVED",l)},400);return()=>clearTimeout(q)},[l]),x.useEffect(()=>{},[l,d]);const O=x.useCallback(q=>{s(ee=>{const de=typeof q=="function"?q(ee):q;return dt("BASICS_BULK_SET",de),de}),m({})},[]),U=x.useCallback((q,ee)=>{s(de=>{const Y={...de,[q]:ee};return dt("BASICS_FIELD_CHANGED",{field:q,value:ee}),Y}),m(de=>{const Y={...de};return delete Y[q],Y})},[]),k=x.useCallback(q=>{let ee="";switch(q){case"companyName":ee=er(l.companyName,"Company name",A("companyName","minLength",1),A("companyName","maxLength",60),g("companyName")?.required??!0);break;case"contactPersonName":ee=er(l.contactPersonName,"Contact person name",A("contactPersonName","minLength",1),A("contactPersonName","maxLength",30),g("contactPersonName")?.required??!0),!ee&&l.contactPersonName&&!/^[a-zA-Z\s\-']+$/.test(l.contactPersonName)&&(ee="Contact name can only contain letters, spaces, hyphens, and apostrophes");break;case"vendorPhoneNumber":ee=Al(l.vendorPhoneNumber);break;case"whatsappNumber":l.whatsappNumber&&(ee=Al(l.whatsappNumber));break;case"vendorEmailAddress":l.vendorEmailAddress&&(ee=zd(l.vendorEmailAddress));break;case"gstin":ee=l.gstin?Bl(l.gstin):"GST number is required and must be filled before saving.";break;case"displayName":ee=er(l.displayName,"Display name",A("displayName","minLength",null),A("displayName","maxLength",30),g("displayName")?.required??!1);break;case"subVendor":ee=er(l.subVendor,"Sub transporter",A("subVendor","minLength",null),A("subVendor","maxLength",20),!1);break;case"vendorCode":ee=er(l.vendorCode,"Vendor code",A("vendorCode","minLength",null),A("vendorCode","maxLength",20),!1),!ee&&l.vendorCode&&!/^[A-Z0-9]+$/.test(l.vendorCode.toUpperCase())&&(ee="Vendor code can only contain letters and numbers");break;case"primaryContactName":ee=Ld(l.primaryContactName);break;case"primaryContactPhone":ee=Od(l.primaryContactPhone);break;case"primaryContactEmail":ee=Md(l.primaryContactEmail);break;case"address":ee=er(l.address,"Address",A("address","minLength",1),150,g("address")?.required??!0);break;case"transportMode":l.transportMode||(ee="Transport Mode is required");break;case"serviceMode":{const de=l.serviceMode;(!de||de!=="FTL"&&de!=="PTL")&&(ee="Please select a service mode");break}case"companyRating":{const de=l.companyRating;if(de!=null){const Y=Number(de);(!Number.isFinite(Y)||Y<1||Y>5)&&(ee="Rating must be between 1 and 5")}break}}return ee?(m(de=>({...de,[q]:ee})),dt("BASICS_VALIDATION_ERROR",{field:q,error:ee}),!1):(m(de=>{const Y={...de};return delete Y[q],Y}),!0)},[l,g,A]),z=x.useCallback(()=>{const q=["companyName","contactPersonName","vendorPhoneNumber","vendorEmailAddress","subVendor","vendorCode","address","transportMode","serviceMode"];q.push("gstin"),l.companyRating!==null&&l.companyRating!==void 0&&q.push("companyRating");let ee=!0;const de={};return q.forEach(Y=>{let le="";switch(Y){case"companyName":le=er(l.companyName,"Company name",A("companyName","minLength",1),A("companyName","maxLength",60),g("companyName")?.required??!0);break;case"contactPersonName":le=er(l.contactPersonName,"Contact person name",A("contactPersonName","minLength",1),A("contactPersonName","maxLength",30),g("contactPersonName")?.required??!0),!le&&l.contactPersonName&&!/^[a-zA-Z\s\-']+$/.test(l.contactPersonName)&&(le="Contact name can only contain letters, space
6s, hyphens, and apostrophes");break;case"vendorPhoneNumber":le=Al(l.vendorPhoneNumber);break;case"vendorEmailAddress":l.vendorEmailAddress&&(le=zd(l.vendorEmailAddress));break;case"gstin":le=l.gstin?Bl(l.gstin):"GST number is required and must be filled before saving.";break;case"displayName":le=er(l.displayName,"Display name",A("displayName","minLength",null),A("displayName","maxLength",30),g("displayName")?.required??!1);break;case"subVendor":le=er(l.subVendor,"Sub transporter",A("subVendor","minLength",null),A("subVendor","maxLength",20),!1);break;case"vendorCode":le=er(l.vendorCode,"Vendor code",A("vendorCode","minLength",null),A("vendorCode","maxLength",20),g("vendorCode")?.required??!0),!le&&l.vendorCode&&!/^[A-Z0-9]+$/.test(l.vendorCode.toUpperCase())&&(le="Vendor code can only contain letters and numbers");break;case"primaryContactName":le=Ld(l.primaryContactName);break;case"primaryContactPhone":le=Od(l.primaryContactPhone);break;case"primaryContactEmail":le=Md(l.primaryContactEmail);break;case"address":le=er(l.address,"Address",A("address","minLength",1),150,g("address")?.required??!0);break;case"transportMode":l.transportMode||(le="Please select a transport mode");break;case"serviceMode":{const J=l.serviceMode;(!J||J!=="FTL"&&J!=="PTL")&&(le="Please select a service mode");break}case"companyRating":{const J=l.companyRating;if(J!=null){const G=Number(J);(!Number.isFinite(G)||G<1||G>5)&&(le="Rating must be between 1 and 5")}break}}le&&(de[Y]=le,ee=!1)}),m(de),ee?dt("BASICS_VALIDATION_PASSED"):dt("BASICS_VALIDATION_FAILED",de),{isValid:ee,errors:de}},[l,g,A]),E=x.useCallback(()=>{s(Bd),m({}),dt("BASICS_RESET")},[]),me=x.useCallback(q=>{s(ee=>({...ee,...q})),dt("BASICS_LOADED_FROM_DRAFT",q)},[]),ve=x.useCallback((q,ee)=>{s(de=>{const Y={...de.vendorRatings,[q]:ee},J=Object.values(Y).filter(ue=>ue>0);let G=null;if(J.length===5){const ue=J.reduce((V,he)=>V+he,0);
6G=Math.round(ue/5*10)/10}return dt("VENDOR_RATING_CHANGED",{field:q,value:ee,overallRating:G}),{...de,vendorRatings:Y,companyRating:G}}),m(de=>{const Y={...de};return delete Y.vendorRatings,delete Y.companyRating,Y})},[]);return{basics:l,errors:f,setField:U,validateField:k,validateAll:z,reset:E,loadFromDraft:me,setBasics:O,setVendorRating:ve}},co=4500,Vd=6;function W0(){const[d,l]=x.useState({unit:"cm",volumetricDivisor:co,cftFactor:null}),s=x.useMemo(()=>[2800,3e3,3200,3500,3800,4e3,4200,4500,4720,4750,4800,5e3,5200,5500,5800,6e3,7e3],[]),f=x.useMemo(()=>[4,5,6,7,8,9,10],[]),m=x.useCallback(z=>{l(E=>({...E,unit:z,volumetricDivisor:E.volumetricDivisor??(z==="cm"?co:null),cftFactor:E.cftFactor??(z==="in"?Vd:null)}))},[]),g=x.useCallback(z=>{l(E=>E.unit==="cm"?{...E,volumetricDivisor:z}:{...E,cftFactor:z})},[]),A=x.useCallback(()=>d.unit==="cm"?!!d.volumetricDivisor:!!d.cftFactor,[d.unit,d.volumetricDivisor,d.cftFactor]),O=x.useCallback(()=>{l({unit:"cm",volumetricDivisor:co,cftFactor:null})},[]),U=x.useCallback(z=>{l(E=>({unit:z?.unit??E.unit,volumetricDivisor:z?.volumetricDivisor??E.volumetricDivisor??co,cftFactor:z?.cftFactor??E.cftFactor??Vd}))},[]),k=x.useMemo(()=>({unit:d.unit,volumetricDivisor:d.unit==="cm"?d.volumetricDivisor:null,cftFactor:d.unit==="in"?d.cftFactor:null}),[d]);return{state:d,setState:l,volumetric:k,volumetricDivisorOptions:s,cftFactorOptions:f,setUnit:m,setDynamicVolumetricValue:g,validateVolumetric:A,loadFromDraft:U,reset:O}}const B0=["per kg","per piece","per box","per shipment"],V0=["0%","0.1% - 1%","1.25% - 2.5%","3% - 4%","4% - 5%"],fu=(d,l=!1)=>d==null||isNaN(d)||d===0?"":d<1||d>5e3?"Enter amount between 1-5,000":"",Kd=d=>{if(d===0||d==="0"||d==="0%"||!d&&d!==0)return"";if(typeof d=="number")return d<0||d>100?"Percentage must be between 0-100%":"";if(typeof d=="string"){if(d.endsWith(".")){const s=Number(d.slice(0,-1));if(Number.isFinite(s)&&s>=0&&s<=100)return""}const l=Number(d);return Number.isFinite(l)?l<0||l>100?"Percentage must be between 0-100%":"":V0.includes(d)?"":"Please enter a valid percentage (0-100%)"}return"Invalid value"},mu=d=>d==null||isNaN(d)||d===0?"":d<1||d>2e4?"Enter amount between 1-20,000":"",K0=d=>d?B0.includes(d)?"":"Invalid unit selection":"",G0=(d,l=!1,s=!1)=>{if(!d)return{};const f={},m=K0(d.unit);if(m&&(f.unit=m),d.currency==="INR")if(d.mode==="FIXED"){const g=fu(d.fixedAmount,s);g&&(f.fixedAmount=g)}else{const g=Kd(d.variableRange);g&&(f.variableRange=g)}else{const g=Kd(d.variableRange);g&&(f.variableRange=g)}if(l){const g=mu(d.weightThreshold);g&&(f.weightThreshold=g)}return f},Xe=()=>({unit:"per kg",currency:"INR",mode:"FIXED",fixedAmount:null,variableRange:"0%",weightThreshold:null}),Z0=d=>{const l=Number(d);return Number.isFinite(l)?Math.round(l*100)/100:0},X0=d=>{const l=Number(d);return!Number.isFinite(l)||isNaN(l)?0:Z0(l)},Gd=(d,l=0,s=1/0)=>{const f=Number(d);return!Number.isFinite(f)||isNaN(f)?!1:f>=l&&f<=s},di={docketCharges:{min:0,max:1e4},minWeightKg:{min:0,max:1e4},minCharges:{min:0,max:1e4},fuelSurchargePct:{min:0,max:50},gstPct:{min:0,max:100},invoiceValueSurcharge:{min:0,max:100}},Zd={docketCharges:"Docket Charges",fuelSurchargePct:"Fuel Surcharge",gstPct:"GST %"};function Xd(d){const l=d==null?"":String(d).trim();if(l==="")return"Please choose a valid percentage range";const s=Number(l);if(!Number.isFinite(s)||s<0||s>100)return"Please choose a valid percentage range (0–100)";const f=l.match(/^\d+(?:\.(\d+))?$/);return f&&f[1]&&f[1].length>2?"Maximum 2 decimal places allowed":null}const qd={docketCharges:null,minWeightKg:null,minCharges:null,fuelSurchargePct:null,gstPct:null,invoiceValueSurcharge:null,handlingCharges:Xe(),rovCharges:Xe(),odaCharges:{...Xe(),billingType:"per_kg"},codCharges:Xe(),toPayCharges:Xe(),appointmentCharges:Xe(),greenTax:Xe(),hamaliCharges:Xe(),miscCharges:Xe(),daccCharges:Xe()},q0=d=>{const[l,s]=x.useState(qd),[f,m]=x.useState({}),g=x.useRef(null),[A,O]=x.useState([]),U=x.useCallback(()=>{O(J=>[...J,{id:`sc_${Date.now()}_${Math.random().toString(36).slice(2,7)}`,label:"",formula:"PCT_OF_BASE",value:0,value2:0,order:J.length+1,enabled:!0}])},[]),k=x.useCallback(J=>{O(G=>G.filter(ue=>ue.id!==J))},[]),z=x.useCallback((J,G)=>{O(ue=>ue.map(V=>V.id===J?{...V,...G}:V))},[]),E=x.useCallback(J=>{O(J??[])},[]);x.useEffect(()=>{const J=setTimeout(()=>{Pa({charges:l}),dt("CHARGES_DRAFT_SAVED",l)},400);return()=>clearTimeout(J)},[l]),x.useEffect(()=>{},[l,d]);const me=x.useCallback((J,G)=>{if(J in di){let ue=null;G===null||G===""?ue=null:ue=X0(G),s(V=>{const he={...V,[J]:ue};return dt("CHARGE_FIELD_CHANGED",{field:J,value:ue}),he}),m(V=>{const he={...V};return delete he[J],he})}}
6,[]),ve=x.useCallback((J,G,ue)=>{s(V=>{const he=V[J],L={...V,[J]:{...he,[G]:ue}};return dt("CARD_FIELD_CHANGED",{cardName:J,field:G,value:ue}),L}),m(V=>{const L={...V[J]||{}};return delete L[G],{...V,[J]:Object.keys(L).length>0?L:void 0}})},[]),q=x.useCallback(J=>{if(!(J in di))return!0;const G=l[J],ue=di[J],V=Zd[J];if(G==null||String(G).trim()==="")return V?(m(he=>({...he,[J]:`${V} is required and must be filled before saving.`})),!1):(m(he=>{const L={...he};return delete L[J],L}),!0);if(J==="fuelSurchargePct"){const he=$d(G);if(he)return m(L=>({...L,fuelSurchargePct:he})),!1}if(G!=null&&!Gd(G,ue.min,ue.max)){let he="Enter amount between 1-10,000";return J==="fuelSurchargePct"&&(he=`Must be between ${ue.min} and ${ue.max}`),J==="gstPct"&&(he=`Must be between ${ue.min} and ${ue.max}`),J==="invoiceValueSurcharge"&&(he=`Must be between ${ue.min} and ${ue.max}`),m(L=>({...L,[J]:he})),!1}return m(he=>{const L={...he};return delete L[J],L}),!0},[l]),ee=x.useCallback((J,G)=>{const ue=l[J];let V="";const he=G==="fixedAmount"&&(ue.mode==="FIXED"||ue.currency==="INR")||G==="variableRange"&&!(ue.mode==="FIXED"||ue.currency==="INR");if(J==="handlingCharges"&&he){const L=G==="fixedAmount"?ue.fixedAmount:ue.variableRange;if(L==null||String(L).trim()==="")return m(ce=>({...ce,handlingCharges:{...ce.handlingCharges||{},[G]:"Handling is required and must be filled before saving."}})),!1}if(G==="fixedAmount"&&ue.currency==="INR"&&ue.mode==="FIXED"?V=fu(ue.fixedAmount,J==="handlingCharges"):G==="weightThreshold"&&J==="handlingCharges"&&(V=mu(Number(ue.weightThreshold)||0)),V)return m(L=>({...L,[J]:{...L[J]||{},[G]:V}})),!1;if(G==="variableRange"&&ue.currency==="PERCENT"&&ue.mode==="VARIABLE"){const L=ue.variableRange,ce=Xd(L);return ce?(m(fe=>({...fe,[J]:{...fe[J]||{},[G]:ce}})),!1):(m(fe=>{const Ae={...fe[J]||{}};return delete Ae[G],{...fe,[J]:Object.keys(Ae).length>0?Ae:void 0}}),!0)}return m(L=>{const ce={...L[J]||{}};return delete ce[G],{...L,[J]:Object.keys(ce).length>0?ce:void 0}}),!0},[l]),de=x.useCallback(()=>{let J=!0;const G={};g.current=null,Object.entries(Zd).forEach(([L,ce])=>{const fe=l[L];(fe==null||String(fe).trim()==="")&&(G[L]=`${ce} is required and must be filled before saving.`,J=!1)}),Object.keys(di).forEach(L=>{const ce=l[L],fe=di[L];if(!G[L]){if(L==="fuelSurchargePct"){const Ae=$d(ce||0);if(Ae){G.fuelSurchargePct=Ae,J=!1;return}}ce!=null&&(Gd(ce,fe.min,fe.max)||(G[L]=L==="fuelSurchargePct"||L==="gstPct"||L==="invoiceValueSurcharge"?`Must be between ${fe.min} and ${fe.max}`:"Enter amount between 0-10,000",J=!1))}});const ue=["handlingCharges","rovCharges","odaCharges","codCharges","toPayCharges","appointmentCharges","greenTax","hamaliCharges","miscCharges","daccCharges"],V=new Set(["toPayCharges","codCharges","appointmentCharges","hamaliCharges","miscCharges","daccCharges","rovCharges","odaCharges","insuranceCharges","greenTax"]),he=new Set(["toPayCharges","codCharges","rovCharges","insuranceCharges"]);return ue.forEach(L=>{const ce=l[L];if(!ce)return;if(V.has(L)){const I=ce.fixedAmount,Ne=ce.variableRange;if((I==null||I===0)&&(Ne==null||Ne===0||Ne==="0%"||Ne==="0"||Ne===""))return}const fe=L==="handlingCharges",Ae=L==="handlingCharges";let re=G0(ce,fe,Ae)||{};if(Ae){const I=ce.mode==="FIXED"||ce.currency==="INR"?ce.fixedAmount:ce.variableRange;(I==null||String(I).trim()==="")&&(re={...re,[ce.mode==="FIXED"||ce.currency==="INR"?"fixedAmount":"variableRange"]:"Handling is required and must be filled before saving."})}if(he.has(L)&&re.variableRange?.includes("0-100%")){const{variableRange:I,...Ne}=re;re=Ne}try{if((ce.currency==="PERCENT"||ce.currency==="PERCENT")&&(ce.mode==="VARIABLE"||ce.mode==="VARIABLE")){const Ne=ce.variableRange,ge=Xd(Ne);if(ge)re={...re,variableRange:ge};else if(re.variableRange){const{variableRange:we,...ye}=re;re=ye}}}catch{}Object.keys(re).length>0&&(G[L]=re,J=!1)}),m(G),J?dt("CHARGES_VALIDATION_PASSED"):dt("CHARGES_VALIDATION_FAILED",G),{isValid:J,errors:G}},[l]),Y=x.useCallback(()=>{s(qd),m({}),O([]),g.current=null,dt("CHARGES_RESET")},[]),le=x.useCallback(J=>{s(G=>({...G,...J})),dt("CHARGES_LOADED_FROM_DRAFT",J)},[]);return{charges:l,errors:f,setCharge:me,setCardField:ve,validateField:q,validateCardField:ee,validateAll:de,reset:Y,loadFromDraft:le,firstErrorRef:g,surcharges:A,addSurcharge:U,removeSurcharge:k,updateSurcharge:z,loadSurchargesFromDraft:E}},Zl=({children:d,className:l})=>{const{containerRef:s,handleKeyDown:f}=N0();return n.jsx("div",{ref:s,onKeyDown:f,className:l,children:d})},H0=({conflicts:d,onApply:l,onKeep:s})=>{const[f,m]=x.useState(()=>Object.fromEntries(d.map(O=>[O.key,!0]))),g=O=>m(U=>({...U,[O]:!U[O]})),A=()=>{l(Object.entries(f).filter(([,O])=>O).map(([O])=>O))};return n.jsxs("div",{className:"mt-1.5 rounded-lg border border-amber-200 bg-amber-50 p-2.5 text-xs shadow-sm",children:[n.jsx("p",{className:"font-semibold text-amber-800 mb-2 text-[11px]",children:"GST data found — review conflicts"}),n.jsx("div",{className:"space-y-2",children:d.map(O=>n.jsxs("div",{className:"flex items-start gap-2",children:[n.jsx("input",{type:"checkbox",id:`gst-conflict-${O.key}`,checked:f[O.key]??!0,onChange:()=>g(O.key),className:"mt-0.5 h-3 w-3 rounded border-amber-400 text-amber-600 cursor-pointer shrink-0"}),n.jsxs("label",{htmlFor:`gst-conflict-${O.key}`,className:"cursor-pointer flex-1 min-w-0",children:[n.jsx("span",{className:"font-semibold text-amber-900",children:O.label}),n.jsxs("div",{className:"flex flex-col gap-0.5 mt-0.5 text-[10px] leading-tight",children:[n.jsxs("span",{className:"text-slate-500 truncate",children:["Your entry:"," ",n.jsx("span",{className:"text-slate-700 font-medium",children:O.currentValue})]}),n.jsxs("span",{className:"text-amber-700 truncate",children:["From GST:"," ",n.jsx("span",{className:"font-semibold",children:O.gstValue})]})]})]})]}
6,O.key))}),n.jsxs("div",{className:"flex gap-1.5 mt-2.5",children:[n.jsx("button",{type:"button",onClick:A,className:"flex-1 rounded-md bg-amber-600 px-2 py-1 text-[10px] font-semibold text-white hover:bg-amber-700 transition-colors",children:"Apply selected"}),n.jsx("button",{type:"button",onClick:s,className:"flex-1 rounded-md border border-slate-300 bg-white px-2 py-1 text-[10px] font-semibold text-slate-700 hover:bg-slate-50 transition-colors",children:"Keep my entries"})]})]})},J0=({vendorBasics:d,pincodeLookup:l,attemptedSubmit:s=!1})=>{const{basics:f,errors:m,setField:g,validateField:A}=d,[O,U]=x.useState({contactPersonName:!0,vendorPhoneNumber:!0,vendorEmailAddress:!0}),k=re=>U(I=>I[re]?{...I,[re]:!1}:I),{geo:z,loading:E,error:me,setPincode:ve,setState:q,setCity:ee,isManual:de}=l;x.useEffect(()=>{if(f.vendorCode)return;const re=f.companyName?.trim();if(!re)return;const I=re.toUpperCase().replace(/[^A-Z0-9]/g,"").slice(0,8);I&&g("vendorCode",I)},[f.companyName]);const Y=E0(),[le,J]=x.useState(!1),G=x.useRef(null);x.useEffect(()=>{const re={companyName:f.companyName||"",address:f.address||"",state:z.state||"",city:z.city||"",pincode:z.pincode||""};Y.lookup(f.gstin||"",re)},[f.gstin]),x.useEffect(()=>{const re=Y.gstData;if(!re||Y.status!=="success"&&Y.status!=="partial"||G.current===re.gstin)return;if(G.current=re.gstin,Y.status==="partial"){re.stateName&&q(re.stateName);return}const I=new Set(Y.conflicts.map(Ne=>Ne.key));!I.has("companyName")&&re.legalName&&g("companyName",re.legalName),!I.has("address")&&re.address&&g("address",re.address),!I.has("state")&&!I.has("city")&&!I.has("pincode")&&re.pincode?ve(re.pincode):(!I.has("state")&&re.stateName&&q(re.stateName),!I.has("city")&&re.city&&ee(re.city))},[Y.gstData,Y.status,Y.conflicts]);const ue=x.useCallback(re=>{const I=Y.gstData;I&&(re.forEach(Ne=>{switch(Ne){case"companyName":I.legalName&&g("companyName",I.legalName);break;case"address":I.address&&g("address",I.address);break;case"state":I.stateName&&q(I.stateName);break;case"city":I.city&&ee(I.city);break;case"pincode":I.pincode&&ve(I.pincode);break}}),Y.dismissConflictPanel())},[Y,g,q,ee,ve]),{getField:V,getConstraint:he}=go("add-vendor"),L=(re,I)=>V(re)?.label??I,ce=(re,I)=>V(re)?.placeholder??I,fe=re=>re==="subVendor"?!1:V(re)?.required??!1,Ae=re=>V(re)?.visible??!0;return n.jsxs(Zl,{className:"px-5 pt-2 pb-3",children:[n.jsxs("h2",{className:"text-sm font-bold text-slate-800 mb-3 flex items-center gap-1.5",children:[n.jsx(w0,{className:"w-4 h-4 text-blue-500"}),"Company & Contact Information"]}),n.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-6 gap-3 items-start",children:[n.jsxs("div",{className:"col-span-1",children:[n.jsxs("label",{htmlFor:"gstin",className:"block text-xs font-semibold text-slate-600 uppercase tracking-wider truncate",title:L("gstin","GST Number"),children:[L("gstin","GST Number"),n.jsx("span",{className:"text-red-500",children:" *"})]}),n.jsxs("div",{className:"relative mt-1",children:[n.jsx("input",{type:"text",id:"gstin",name:"gstin",value:f.gstin||"",onChange:re=>{const I=re.target.value.toUpperCase().replace(/[^A-Z0-9]/g,"").slice(0,he("gstin","maxLength",15));g("gstin",I)},onFocus:()=>J(!0),onBlur:()=>{J(!1),A("gstin")},maxLength:20,className:`block w-full border rounded-lg shadow-sm px-2.5 py-1.5 text-xs text-slate-800 placeholder-slate-400
7                         focus:outline-none focus:ring-1 focus:border-blue-500 transition bg-slate-50/70 pr-7
8                         ${m.gstin?"border-red-500 focus:ring-red-500":"border-slate-300 focus:ring-blue-500"}`,placeholder:ce("gstin","GST Number")}),Y.status==="loading"&&n.jsx("div",{className:"absolute right-2 top-1/2 -translate-y-1/2 pointer-events-none",children:n.jsx(un,{className:"w-3.5 h-3.5 text-blue-500 animate-spin"})}),Y.status==="success"&&!Y.showConflictPanel&&n.jsx("div",{className:"absolute right-2 top-1/2 -translate-y-1/2 pointer-events-none",children:n.jsx(ea,{className:"w-3.5 h-3.5 text-green-500"})}),Y.status==="failed"&&n.jsx("div",{className:"absolute right-2 top-1/2 -translate-y-1/2 pointer-events-none",children:n.jsx(Fa,{className:"w-3.5 h-3.5 text-orange-400"})}),Y.status==="invalid"&&n.jsx("div",{className:"absolute right-2 top-1/2 -translate-y-1/2 pointer-events-none",children:n.jsx(bi,{className:"w-3.5 h-3.5 text-red-400"})})]}),m.gstin&&n.jsx("p",{className:"mt-1 text-xs text-red-600 truncate",children:m.gstin}),le&&!f.gstin&&n.jsx("p",{className:"mt-1 text-[10px] text-slate-400",children:"Enter your GSTIN to auto-fill company details"}),Y.status==="invalid"&&n.jsx("p",{className:"mt-1 text-[10px] text-red-500",children:"Invalid GSTIN format"}),Y.status==="loading"&&n.jsx("p",{className:"mt-1 text-[10px] text-blue-500",children:"Looking up…"}),Y.successMessage&&n.jsx("p",{className:"mt-1 text-[10px] text-green-600",children:Y.successMessage}),Y.errorMessage&&n.jsx("p",{className:"mt-1 text-[10px] text-orange-500",children:Y.errorMessage}),Y.showConflictPanel&&Y.conflicts.length>0&&n.jsx(H0,{conflicts:Y.conflicts,onApply:ue,onKeep:Y.dismissConflictPanel})]}),Ae("companyName")&&n.jsxs("div",{className:"col-span-1",children:[n.jsxs("label",{htmlFor:"companyName",className:"block text-xs font-semibold text-slate-600 uppercase tracking-wider truncate",title:L("companyName","Company Name"),children:[L("companyName","Company Name"),fe("companyName")&&n.jsx("span",{className:"text-red-500",children:" *"})]}),n.jsx("input",{type:"text",id:"companyName",name:"companyName",value:f.companyName,onChange:re=>g("companyName",re.target.value.slice(0,he("companyName","maxLength",60))),onBlur:()=>A("companyName"),maxLength:he("companyName","maxLength",60),className:`mt-1 block w-full border rounded-lg shadow-sm px-2.5 py-1.5 text-xs text-slate-800 placeholder-slate-400
9                       focus:outline-none focus:ring-1 focus:border-blue-500 transition bg-slate-50/70
10                       ${m.companyName?"border-red-500 focus:ring-red-500":"border-slate-300 focus:ring-blue-500"}`,placeholder:ce("companyName","Company Name"),required:!0}),m.companyName&&n.jsx("p",{className:"mt-1 text-xs text-red-600 truncate",children:m.companyName})]}),n.jsxs("div",{className:"col-span-1",children:[n.jsxs("label",{htmlFor:"contactPersonName",className:"block text-xs font-semibold text-slate-600 uppercase tracking-wider truncate",title:L("contactPersonName","Contact Person"),children:[L("contactPersonName","Contact Person"),fe("contactPersonName")&&n.jsx("span",{className:"text-red-500",children:" *"})]}),n.jsx("input",{type:"text",id:"contactPersonName",name:"contactPersonName",value:f.contactPersonName,readOnly:O.contactPersonName,onFocus:()=>k("contactPersonName"),onChange:re=>{const I=re.target.value.replace(/[^a-zA-Z\s\-']/g,"").slice(0,he("contactPersonName","maxLength",30));g("contactPersonName",I.toUpperCase())},onBlur:()=>A("contactPersonName"),maxLength:he("contactPersonName","maxLength",30),className:`mt-1 block w-full border rounded-lg shadow-sm px-2.5 py-1.5 text-xs text-slate-800 placeholder-slate-400
11                       focus:outline-none focus:ring-1 focus:border-blue-500 transition bg-slate-50/70
12                       ${m.contactPersonName?"border-red-500 focus:ring-red-500":"border-slate-300 focus:ring-blue-500"}`,placeholder:ce("contactPersonName","Contact Person"),required:!0}),m.contactPersonName&&n.jsx("p",{className:"mt-1 text-xs text-red-600 truncate",children:m.contactPersonName})]}),n.jsxs("div",{className:"col-span-1",children:[n.jsxs("label",{htmlFor:"vendorPhoneNumber",className:"block text-xs font-semibold text-slate-600 uppercase tracking-wider truncate",title:L("vendorPhoneNumber","Phone Number"),children:[L("vendorPhoneNumber","Phone Number"),fe("vendorPhoneNumber")&&n.jsx("span",{className:"text-red-500",children:" *"})]}),n.jsx("input",{type:"text",id:"vendorPhoneNumber",name:"vendorPhoneNumber",value:f.vendorPhoneNumber,readOnly:O.vendorPhoneNumber,onFocus:()=>k("vendorPhoneNumber"),onChange:re=>{const I=re.target.value.replace(/\D/g,"").slice(0,he("vendorPhoneNumber","maxLength",10));g("vendorPhoneNumber",I),g("whatsappNumber",I)},onBlur:()=>A("vendorPhoneNumber"),inputMode:"numeric",maxLength:he("vendorPhoneNumber","maxLength",10),className:`mt-1 block w-full border rounded-lg shadow-sm px-2.5 py-1.5 text-xs text-slate-800 placeholder-slate-400
13                       focus:outline-none focus:ring-1 focus:border-blue-500 transition bg-slate-50/70
14                       ${m.vendorPhoneNumber?"border-red-500 focus:ring-red-500":"border-slate-300 focus:ring-blue-500"}`,placeholder:ce("vendorPhoneNumber","Phone Number"),required:!0}),m.vendorPhoneNumber&&n.jsx("p",{className:"mt-1 text-xs text-red-600 truncate",children:m.vendorPhoneNumber})]}),n.jsxs("div",{className:"col-span-1",children:[n.jsxs("label",{htmlFor:"whatsappNumber",className:"block text-xs font-semibold text-slate-600 uppercase tracking-wider truncate",title:L("whatsappNumber","WhatsApp Number"),children:[L("whatsappNumber","WhatsApp Number"),fe("whatsappNumber")&&n.jsx("span",{className:"text-red-500",children:" *"})]}),n.jsx("input",{type:"text",id:"whatsappNumber",name:"whatsappNumber",value:f.whatsappNumber||"",onChange:re=>{const I=re.target.value.replace(/\D/g,"").slice(0,10);g("whatsappNumber",I)},onBlur:()=>A("whatsappNumber"),inputMode:"numeric",maxLength:10,className:`mt-1 block w-full border rounded-lg shadow-sm px-2.5 py-1.5 text-xs text-slate-800 placeholder-slate-400
15                       focus:outline-none focus:ring-1 focus:border-blue-500 transition bg-slate-50/70
16                       ${m.whatsappNumber?"border-red-500 focus:ring-red-500":"border-slate-300 focus:ring-blue-500"}`,placeholder:ce("whatsappNumber","10-digit number"),required:fe("whatsappNumber")}),m.whatsappNumber&&n.jsx("p",{className:"mt-1 text-xs text-red-600 truncate",children:m.whatsappNumber})]}),n.jsxs("div",{className:"col-span-1",children:[n.jsxs("label",{htmlFor:"vendorEmailAddress",className:"block text-xs font-semibold text-slate-600 uppercase tracking-wider truncate",title:L("vendorEmailAddress","Email Address"),children:[L("vendorEmailAddress","Email Address"),fe("vendorEmailAddress")&&n.jsx("span",{className:"text-red-500",children:" *"})]}),n.jsx("input",{type:"email",id:"vendorEmailAddress",name:"vendorEmailAddress",autoComplete:"off",value:f.vendorEmailAddress,readOnly:O.vendorEmailAddress,onFocus:()=>k("vendorEmailAddress"),onChange:re=>{const I=re.target.value.replace(/\s/g,"").slice(0,30).toLowerCase();g("vendorEmailAddress",I)},onBlur:()=>A("vendorEmailAddress"),maxLength:30,className:`mt-1 block w-full border rounded-lg shadow-sm px-2.5 py-1.5 text-xs text-slate-800 placeholder-slate-400
17                       focus:outline-none focus:ring-1 focus:border-blue-500 transition bg-slate-50/70
18                       ${m.vendorEmailAddress?"border-red-500 focus:ring-red-500":"border-slate-300 focus:ring-blue-500"}`,placeholder:ce("vendorEmailAddress","Email Address"),required:fe("vendorEmailAddress")}),m.vendorEmailAddress&&n.jsx("p",{className:"mt-1 text-xs text-red-600 truncate",children:m.vendorEmailAddress})]}),n.jsxs("div",{className:"col-span-1",children:[n.jsxs("label",{htmlFor:"pincode",className:"block text-xs font-semibold text-slate-600 uppercase tracking-wider truncate",title:L("pincode","Pincode"),children:[L("pincode","Pincode"),fe("pincode")&&n.jsx("span",{className:"text-red-500",children:" *"})]}),n.jsxs("div",{className:"relative",children:[n.jsx("input",{type:"text",id:"pincode",name:"pincode",value:z.pincode||"",onChange:re=>{const I=re.target.value.replace(/\D/g,"").slice(0,he("pincode","maxLength",6));ve(I)},maxLength:he("pincode","maxLength",6),className:`mt-1 block w-full border rounded-lg shadow-sm px-2.5 py-1.5 text-xs text-slate-800 placeholder-slate-400
19                         focus:outline-none focus:ring-1 focus:border-blue-500 transition bg-slate-50/70
20                         ${me||s&&!z.pincode?"border-red-500 focus:ring-red-500":"border-slate-300 focus:ring-blue-500"}`,placeholder:ce("pincode","Pincode"),required:!0}),E&&n.jsx("div",{className:"absolute right-3 top-1/2 -translate-y-1/2",children:n.jsx("div",{className:"animate-spin rounded-full h-4 w-4 border-b-2 border-blue-500"})})]}),me?n.jsx("p",{className:"mt-1 text-xs text-orange-600 truncate",children:me}):s&&!z.pincode?n.jsx("p",{className:"mt-1 text-xs text-red-600 truncate",children:"Pincode is required and must be filled before saving."}):null]}),n.jsxs("div",{className:"col-span-1",children:[n.jsxs("label",{htmlFor:"state",className:"block text-xs font-semibold text-slate-600 uppercase tracking-wider truncate",title:L("state","State"),children:[L("state","State"),fe("state")&&n.jsx("span",{className:"text-red-500",children:" *"}),de&&n.jsx("span",{className:"text-xs text-orange-500 ml-1",children:"(M)"})]}),n.jsx("input",{type:"text",id:"state",name:"state",value:z.state||"",onChange:re=>q(re.target.value),readOnly:!de&&!me,tabIndex:!de&&!me?-1:void 0,className:`mt-1 block w-full border rounded-lg shadow-sm px-2.5 py-1.5 text-xs text-slate-800 placeholder-slate-400
21                       focus:outline-none focus:ring-1 focus:border-blue-500 transition
22                       ${!de&&!me?"bg-slate-100 cursor-not-allowed":"bg-slate-50/70"}
23                       ${s&&!z.state?"border-red-500 focus:ring-red-500":"border-slate-300 focus:ring-blue-500"}`,placeholder:ce("state","State"),required:!0}),s&&!z.state&&n.jsx("p",{className:"mt-1 text-xs text-red-600 truncate",children:"State is required and must be filled before saving."})]}),n.jsxs("div",{className:"col-span-1",children:[n.jsxs("label",{htmlFor:"city",className:"block text-xs font-semibold text-slate-600 uppercase tracking-wider truncate",title:L("city","City"),children:[L("city","City"),fe("city")&&n.jsx("span",{className:"text-red-500",children:" *"}),de&&n.jsx("span",{className:"text-xs text-orange-500 ml-1",children:"(M)"})]}),n.jsx("input",{type:"text",id:"city",name:"city",value:z.city||"",onChange:re=>ee(re.target.value),readOnly:!de&&!me,tabIndex:!de&&!me?-1:void 0,className:`mt-1 block w-full border rounded-lg shadow-sm px-2.5 py-1.5 text-xs text-slate-800 placeholder-slate-400
24                       focus:outline-none focus:ring-1 focus:border-blue-500 transition
25                       ${!de&&!me?"bg-slate-100 cursor-not-allowed":"bg-slate-50/70"}
26                       border-slate-300 focus:ring-blue-500`,placeholder:ce("city","City"),required:!0})]}),n.jsxs("div",{className:"col-span-1",children:[n.jsxs("label",{htmlFor:"subVendor",className:"block text-xs font-semibold text-slate-600 uppercase tracking-wider truncate",title:L("subVendor","Sub Transporter"),children:[L("subVendor","Sub Transporter"),fe("subVendor")&&n.jsx("span",{className:"text-red-500",children:" *"})]}),n.jsx("input",{type:"text",id:"subVendor",name:"subVendor",value:f.subVendor,onChange:re=>{const I=re.target.value.replace(/[^a-zA-Z\s\-']/g,"").slice(0,he("subVendor","maxLength",20));g("subVendor",I.toUpperCase())},onBlur:()=>A("subVendor"),maxLength:he("subVendor","maxLength",20),className:`mt-1 block w-full border rounded-lg shadow-sm px-2.5 py-1.5 text-xs text-slate-800 placeholder-slate-400
27                       focus:outline-none focus:ring-1 focus:border-blue-500 transition bg-slate-50/70
28                       ${m.subVendor?"border-red-500 focus:ring-red-500":"border-slate-300 focus:ring-blue-500"}`,placeholder:ce("subVendor","Sub Transporter")}),m.subVendor&&n.jsx("p",{className:"mt-1 text-xs text-red-600 truncate",children:m.subVendor})]}),n.jsxs("div",{className:"col-span-1",children:[n.jsxs("label",{htmlFor:"vendorCode",className:"block text-xs font-semibold text-slate-600 uppercase tracking-wider truncate",title:L("vendorCode","Transporter Code"),children:[L("vendorCode","Transporter Code"),n.jsx("span",{className:"text-red-500",children:" *"})]}),n.jsx("input",{type:"text",id:"vendorCode",name:"vendorCode",value:f.vendorCode,onChange:re=>{const I=re.target.value.toUpperCase().replace(/[^A-Z0-9]/g,"").slice(0,he("vendorCode","maxLength",20));g("vendorCode",I)},onBlur:()=>A("vendorCode"),maxLength:he("vendorCode","maxLength",20),className:`mt-1 block w-full border rounded-lg shadow-sm px-2.5 py-1.5 text-xs text-slate-800 placeholder-slate-400
29                       focus:outline-none focus:ring-1 focus:border-blue-500 transition 
29bg-slate-50/70
30                       ${m.vendorCode?"border-red-500 focus:ring-red-500":"border-slate-300 focus:ring-blue-500"}`,placeholder:ce("vendorCode","Code")}),m.vendorCode&&n.jsx("p",{className:"mt-1 text-xs text-red-600 truncate",children:m.vendorCode})]}),n.jsxs("div",{className:"col-span-1 md:col-span-3",children:[n.jsxs("label",{htmlFor:"address",className:"block text-xs font-semibold text-slate-600 uppercase tracking-wider truncate",title:L("address","Address"),children:[L("address","Address"),fe("address")&&n.jsx("span",{className:"text-red-500",children:" *"})]}),n.jsx("textarea",{id:"address",name:"address",value:f.address,onChange:re=>g("address",re.target.value.slice(0,150)),onBlur:()=>A("address"),maxLength:150,rows:2,onInput:re=>{const I=re.currentTarget;I.style.height="auto",I.style.height=I.scrollHeight+"px"},className:`mt-1 block w-full border rounded-lg shadow-sm px-2.5 py-1.5 text-xs text-slate-800 placeholder-slate-400
31                       focus:outline-none focus:ring-1 focus:border-blue-500 transition bg-slate-50/70 resize-none overflow-hidden
32                       ${m.address?"border-red-500 focus:ring-red-500":"border-slate-300 focus:ring-blue-500"}`,placeholder:ce("address","Enter complete address"),required:!0}),m.address&&n.jsx("p",{className:"mt-1 text-xs text-red-600 truncate",children:m.address})]}),n.jsxs("div",{className:"col-span-1 md:col-span-2 flex flex-col justify-end",children:[n.jsxs("label",{className:"block text-xs font-semibold text-slate-600 uppercase tracking-wider mb-1 truncate",children:[L("serviceMode","Service Modes"),fe("serviceMode")&&n.jsx("span",{className:"text-red-500",children:" *"})]}),n.jsx("div",{className:"mt-1 rounded-lg border border-slate-200 bg-white p-1 w-full",children:n.jsxs("div",{className:"flex w-full gap-1",children:[n.jsx("button",{type:"button",tabIndex:-1,onClick:()=>{g("serviceMode","FTL"),m.serviceMode&&A("serviceMode")},onDoubleClick:()=>{f.serviceMode==="FTL"&&(g("serviceMode",null),A("serviceMode"))},"aria-pressed":f.serviceMode==="FTL",className:`flex-1 items-center justify-center px-3 py-1.5 text-xs font-semibold rounded-lg transition-all outline-none whitespace-nowrap
33                  focus:ring-2 focus:ring-blue-400 focus:ring-offset-1
34                  ${f.serviceMode==="FTL"?"bg-blue-600 text-white border-blue-700 shadow-md transform scale-[1.02]":"bg-white text-slate-700 border-transparent hover:bg-slate-50 hover:text-blue-600"}`,children:"Full Truck Load"}),n.jsx("button",{type:"button",tabIndex:-1,onClick:()=>{g("serviceMode","PTL"),m.serviceMode&&A("serviceMode")},onDoubleClick:()=>{f.serviceMode==="PTL"&&(g("serviceMode",null),A("serviceMode"))},"aria-pressed":f.serviceMode==="PTL",className:`flex-1 items-center justify-center px-3 py-1.5 text-xs font-semibold rounded-lg transition-all outline-none whitespace-nowrap
35                  focus:ring-2 focus:ring-blue-400 focus:ring-offset-1
36                  ${f.serviceMode==="PTL"?"bg-blue-600 text-white border-blue-700 shadow-md transform scale-[1.02]":"bg-white text-slate-700 border-transparent hover:bg-slate-50 hover:text-blue-600"}`,children:"Part Truck Load"})]})}),m.serviceMode&&n.jsx("p",{className:"mt-2 text-xs text-red-600 truncate",children:m.serviceMode})]})]})]})},Js=4,ui=40,Y0=({transportMode:d,onTransportModeChange:l,volumetric:s,maxShipmentLengthFt:f,onMaxShipmentLengthFtChange:m})=>{const{state:g,volumetricDivisorOptions:A,cftFactorOptions:O,setUnit:U,setDynamicVolumetricValue:k}=s,{getField:z}=go("add-vendor"),E=(ge,we)=>z(ge)?.label??we,me=ge=>z(ge)?.required??!0,q=z("transportMode")?.options||[{value:"road",label:"Road",enabled:!0},{value:"air",label:"Air",enabled:!1},{value:"rail",label:"Rail",enabled:!1},{value:"ship",label:"Ship",enabled:!1}],ee=g.unit==="cm",de=ee?"Volumetric Divisor":"CFT Factor",Y=ee?A:O,le=ee?g.volumetricDivisor:g.cftFactor,J=f!==null,G=f??Js,[ue,V]=x.useState(String(G)),[he,L]=x.useState(!1);x.useEffect(()=>{he||V(String(G))},[G,he]);const ce=()=>{m(J?null:Js)},fe=ge=>{m(Number(ge.target.value))},Ae=ge=>{const we=ge.target.value;if(we!==""&&!/^\d{1,2}$/.test(we))return;V(we);const ye=parseInt(we,10);!isNaN(ye)&&ye>=Js&&ye<=ui&&m(ye)},re=()=>L(!0),I=()=>{L(!1);const ge=parseInt(ue,10);!isNaN(ge)&&ge>=Js&&ge<=ui?V(String(ge)):V(String(G))},Ne=ge=>{ge.preventDefault();const we=ge.deltaY<0?1:-1,ye=Math.max(Js,Math.min(ui,G+we));m(ye)};return n.jsxs(Zl,{className:"px-5 pt-3 pb-3",children:[n.jsx("h2",{className:"text-sm font-bold text-slate-900 mb-2",children:"Transport & Volumetric Configuration"}),n.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-2",children:[n.jsxs("div",{children:[n.jsxs("label",{className:"block text-xs font-medium text-slate-700 mb-1",children:[E("transportMode","Transport Mode"),me("transportMode")&&n.jsx("span",{className:"text-red-500",children:" *"})]}),n.jsx("select",{value:d,onChange:ge=>l(ge.target.value),className:"w-full rounded-md border border-slate-300 focus:ring-blue-500 focus:border-blue-500 text-xs py-1.5 px-2.5 bg-slate-50/70",children:q.map(ge=>n.jsxs("option",{value:ge.value,disabled:ge.enabled===!1,title:ge.enabled===!1?`${ge.label} — Coming soon`:void 0,children:[ge.label,ge.enabled===!1?" — Coming soon":""]},ge.value))})]}),n.jsxs("div",{children:[n.jsxs("label",{className:"block text-xs font-medium text-slate-700 mb-1 flex items-center gap-1",children:[n.jsxs("span",{children:[E("volumetricDivisor",de),me("volumetricDivisor")&&n.jsx("span",{className:"text-red-500",children:" *"})]}),n.jsxs("span",{className:"relative group/note cursor-help",children:[n.jsxs("svg",{className:"w-3.5 h-3.5 text-slate-400 hover:text-blue-500 transition-colors",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:[n.jsx("circle",{cx:"12",cy:"12",r:"10",strokeWidth:"2"}),n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M12 16v-4M12 8h.01"})]}),n.jsx("div",{className:"absolute left-0 top-5 z-50 w-64 bg-slate-800 text-white text-xs rounded-lg px-3 py-2 shadow-xl opacity-0 invisible group-hover/note:opacity-100 group-hover/note:visible transition-all pointer-events-none leading-relaxed",children:"Volumetric weight = (L × W × H) / Divisor. The divisor determines how much space is considered per unit of weight. Changes based on the selected volumetric unit."})]})]}),n.jsxs("select",{value:le??"",onChange:ge=>k(Number(ge.target.value)),className:"w-full rounded-md border border-slate-300 focus:ring-blue-500 focus:border-blue-500 text-xs py-1.5 px-2.5 bg-slate-50/70",children:[n.jsxs("option",{value:"",disabled:!0,children:["Select ",de]}),Y.map(ge=>n.jsx("option",{value:ge,children:ge},ge))]})]}),n.jsxs("div",{children:[n.jsxs("label",{className:"block text-xs font-medium text-slate-700 mb-1",children:[E("volumetricUnit","Volumetric Unit"),me("volumetricUnit")&&n.jsx("span",{className:"text-red-500",children:" *"})]}),n.jsxs("div",{className:"inline-flex rounded-md shadow-sm border border-slate-300 w-full",children:[n.jsx("button",{type:"button",tabIndex:-1,onClick:()=>U("cm"),className:"flex-1 px-3 py-1.5 text-xs font-medium rounded-l-md "+(ee?"bg-blue-600 text-white":"bg-white text-slate-700 hover:bg-slate-50"),children:"Centimeters (cm)"}),n.jsx("button",{type:"button",tabIndex:-1,onClick:()=>U("in"),className:"flex-1 px-3 py-1.5 text-xs font-medium rounded-r-md border-l border-slate-300 "+(ee?"bg-white text-slate-700 hover:bg-slate-50":"bg-blue-600 text-white"),children:"Inches (in)"})]})]})]}),n.jsxs("div",{className:"mt-3 pt-3 border-t border-slate-100",children:[n.jsxs("div",{className:"flex items-center gap-2 mb-0.5",children:[n.jsx("span",{className:"text-xs font-semibold text-slate-700",children:"Maximum Shipment Length"}),n.jsx("button",{type:"button",onClick:ce,className:`relative inline-flex h-5 w-9 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 focus:outline-none ${J?"bg-blue-600":"bg-slate-200"}`,children:n.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white shadow ring-0 transition duration-200 ${J?"translate-x-4":"translate-x-0"}`})})]}),n.jsx("p",{className:"text-[10px] text-slate-400 mb-2",children:"If this vendor cannot accept long shipments, set a limit here."}),J&&n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsxs("span",{className:"text-[10px] text-slate-400 w-6 text-right shrink-0",children:[Js,"ft"]}),n.jsx("input",{type:"range",min:Js,max:ui,step:1,value:G,onChange:fe,className:"flex-1 h-1.5 accent-blue-600 cursor-pointer"}),n.jsxs("span",{className:"text-[10px] text-slate-400 w-7 shrink-0",children:[ui,"ft"]}),n.jsxs("div",{className:"flex items-center gap-1 border border-blue-200 rounded-md px-2 py-1 bg-white shadow-sm",children:[n.jsx("input",{type:"text",inputMode:"numeric",value:ue,onChange:Ae,onFocus:re,onBlur:I,onWheel:Ne,className:"w-8 text-xs font-bold text-blue-700 text-center border-none outline-none bg-transparent"}),n.jsx("span",{className:"text-[10px] text-blue-400 font-medium",children:"ft"})]})]})]})]})},Q0=[{type:"per_kg",label:"Per KG",blurb:"Charged purely by weight — a fixed ₹ rate for every kilogram of the shipment."},{type:"per_shipment",label:"Flat Fee",blurb:"One fixed charge per shipment, no matter how much it weighs."},{type:"per_kg_minimum",label:"Per KG, with a Floor (+Min)",blurb
36:"Charged per kg, but never less than a minimum amount — a safety-net rate."},{type:"per_kg_excess",label:"Base + Extra Beyond Limit (+Extra)",blurb:"A fixed base amount covers weight up to a limit; anything heavier is billed extra per kg."},{type:"matrix",label:"Weight / Distance Slabs (Matrix)",blurb:"Different rates for different weight or distance ranges — for tiered vendor pricing."},{type:"negotiable",label:"Negotiable",blurb:"Rate is decided case-by-case at the time of booking."}],ex="w-full h-9 text-sm bg-white border border-slate-200 rounded-lg px-3 focus:outline-none focus:border-blue-400 focus:ring-1 focus:ring-blue-100 transition-colors [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",Ys=({label:d,hint:l,unit:s,value:f,onChange:m,autoFocus:g})=>n.jsxs("div",{className:"flex-1 min-w-[120px]",children:[n.jsx("label",{className:"block text-[10px] font-semibold uppercase tracking-wide text-slate-500 mb-1",children:d}),n.jsxs("div",{className:"relative",children:[n.jsx("input",{type:"number",autoFocus:g,className:ex+" pr-12",value:f,min:0,placeholder:"0",onChange:A=>m(A.target.value?parseFloat(A.target.value):null)}),n.jsx("span",{className:"absolute right-3 top-1/2 -translate-y-1/2 text-[10px] font-bold text-slate-400 pointer-events-none",children:s})]}),l&&n.jsx("p",{className:"text-[10px] text-slate-400 mt-1 leading-snug",children:l})]}),tx=({open:d,onClose:l,billingType:s,odaCard:f,onSelectType:m,onFieldChange:g,onOpenMatrix:A})=>typeof document>"u"?null:au.createPortal(n.jsx(Nr,{children:d&&n.jsx(ct.div,{initial:{opacity:0}
36,animate:{opacity:1},exit:{opacity:0},onClick:l,className:"fixed inset-0 z-[200] flex items-center justify-center bg-slate-900/60 backdrop-blur-sm p-4",children:n.jsxs(ct.div,{initial:{opacity:0,scale:.95,y:8},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:8},onClick:O=>O.stopPropagation(),role:"radiogroup","aria-label":"ODA charge type",onKeyDown:O=>{O.key==="Escape"&&l()},className:"bg-white rounded-2xl shadow-2xl w-full max-w-[440px] max-h-[85vh] flex flex-col overflow-hidden",children:[n.jsxs("div",{className:"flex items-center justify-between px-5 py-3.5 bg-slate-50 border-b border-slate-200",children:[n.jsxs("div",{children:[n.jsx("h3",{className:"text-sm font-bold text-slate-800",children:"How is ODA charged?"}),n.jsx("p",{className:"text-[11px] text-slate-500 mt-0.5",children:"Pick the billing logic this vendor uses for out-of-delivery-area shipments."})]}),n.jsx("button",{onClick:l,className:"p-1.5 text-slate-400 hover:text-slate-600 hover:bg-slate-200/50 rounded-full transition-colors shrink-0","aria-label":"Close",children:n.jsx("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})})]}),n.jsx("div",{className:"overflow-y-auto flex-1 p-3 space-y-1.5",children:Q0.map(O=>{const U=s===O.type;return n.jsxs("div",{className:`rounded-xl border transition-colors ${U?"border-blue-400 bg-blue-50/60":"border-slate-200 hover:border-slate-300 hover:bg-slate-50"}`,children:[n.jsxs("button",{type:"button",role:"radio","aria-checked":U,onClick:()=>m(O.type),className:"w-full flex items-start gap-2.5 text-left px-3 py-2.5",children:[n.jsx("span",{className:`mt-0.5 w-4 h-4 rounded-full border-2 flex items-center justify-center shrink-0 transition-colors ${U?"border-blue-500":"border-slate-300"}`,children:U&&n.jsx("span",{className:"w-2 h-2 rounded-full bg-blue-500"})}),n.jsxs("span",{className:"min-w-0",children:[n.jsx("span",{className:`block text-[13px] font-semibold ${U?"text-blue-800":"text-slate-700"}`,children:O.label}),n.jsx("span",{className:"block text-[11px] text-slate-500 leading-snug mt-0.5",children:O.blurb})]})]}),U&&n.jsxs("div",{className:"px-3 pb-3 pt-0.5",children:[O.type==="per_kg"&&n.jsx("div",{className:"flex gap-2 pl-6",children:n.jsx(Ys,{label:"Rate",unit:"₹/KG",value:f?.fixedAmount??"",onChange:k=>g("fixedAmount",k),autoFocus:!0})}),O.type==="per_shipment"&&n.jsx("div",{className:"flex gap-2 pl-6",children:n.jsx(Ys,{label:"Flat Amount",unit:"₹",value:f?.fixedAmount??"",onChange:k=>g("fixedAmount",k),autoFocus:!0})}),O.type==="per_kg_minimum"&&n.jsxs("div",{className:"flex gap-2 pl-6",children:[n.jsx(Ys,{label:"Rate",unit:"₹/KG",value:f?.perKg??"",onChange:k=>g("perKg",k),autoFocus:!0}),n.jsx(Ys,{label:"Minimum Floor",hint:"Charge never drops below this",unit:"₹",value:f?.minimum??"",onChange:k=>g("minimum",k)})]}),O.type==="per_kg_excess"&&n.jsxs("div",{className:"flex flex-wrap gap-2 pl-6",children:[n.jsx(Ys,{label:"Base Amount",hint:"Covers weight up to the limit",unit:"₹",value:f?.fixedAmount??"",onChange:k=>g("fixedAmount",k),autoFocus:!0}),n.jsx(Ys,{label:"Weight Limit",hint:"Base amount applies up to here",unit:"KG",value:f?.thresholdWeight??"",onChange:k=>g("thresholdWeight",k)}),n.jsx(Ys,{label:"Extra Rate",hint:"Only on weight above the limit",unit:"₹/KG",value:f?.variableRange??"",onChange:k=>g("variableRange",k)})]}),O.type==="matrix"&&n.jsxs("div",{className:"pl-6",children:[n.jsx("button",{type:"button",onClick:A,className:"text-[11px] font-bold text-blue-700 bg-blue-50 border border-blue-200 hover:bg-blue-100 px-3 py-1.5 rounded-lg transition-colors",children:Array.isArray(f?.matrix)&&f.matrix.length>0?"Edit Slab Table →":"Configure Slab Table →"}),Array.isArray(f?.matrix)&&f.matrix.length>0&&n.jsxs("p",{className:"text-[10px] text-slate-400 mt-1.5",children:[f.matrix.length," row(s) configured."]})]}),O.type==="negotiable"&&n.jsx("p",{className:"text-[11px] text-slate-400 pl-6",children:'No amount needed — this will show as "Negotiable" to your team until confirmed at booking.'})]})]},O.type)})}),n.jsx("div",{className:"flex items-center justify-end px-4 py-3 border-t border-slate-200 bg-slate-50",children:n.jsx("button",{type:"button",onClick:l,className:"text-xs font-bold text-white bg-blue-600 hover:bg-blue-700 px-4 py-2 rounded-lg transition-colors",children:"Done"})})]})})}),document.body),Hd=({isFixed:d,onChange:l,disabled:s})=>n.jsxs("span",{className:"inline-flex items-center bg-slate-100 rounded-full p-0.5 border border-slate-200 gap-0.5",children:[n.jsx("button",{type:"button",disabled:s,onClick:()=>l(!0),className:`text-[10px] font-semibold px-2 py-0.5 rounded-full transition-all
37        ${d?"bg-white text-indigo-700 shadow-sm border border-indigo-100":"text-slate-400 hover:text-slate-600"}`,children:"Fixed"}),n.jsx("button",{type:"button",disabled:s,onClick:()=>l(!1),className:`text-[10px] font-semibold px-2 py-0.5 rounded-full transition-all
38        ${d?"text-slate-400 hover:text-slate-600":"bg-white text-indigo-700 shadow-sm border border-indigo-100"}`,children:"Variable"})]}),nx=({value:d,onChange:l,min:s=0,max:f=1e3,decimals:m=2,disabled:g,placeholder:A="",error:O,onFieldBlur:U})=>{const k=z=>{const E=Math.min(Math.max(z,s??0),f??1e3),me=Math.pow(10,m??2);return String(Math.round(E*me)/me)};return n.jsx("input",{type:"number",inputMode:"decimal",min:s,max:f,step:m!=null&&m>0?Math.pow(10,-m):1,disabled:g,value:d??"",placeholder:A,title:O,onChange:z=>
38{if(z.target.value===""){l("");return}const E=parseFloat(z.target.value);isNaN(E)||l(k(E))},onBlur:z=>{const E=parseFloat(z.target.value);isNaN(E)||l(k(E)),U?.()},className:`w-16 text-xs text-right border rounded px-1.5 py-0.5 transition
39        focus:outline-none focus:ring-1
40        shadow-sm bg-white text-slate-700
41        disabled:bg-slate-50 disabled:text-slate-400 disabled:cursor-not-allowed
42        [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none
43        [&::-webkit-inner-spin-button]:appearance-none
44        ${O?"border-red-400 ring-1 ring-red-100 focus:ring-red-300 focus:border-red-400":"border-slate-200 focus:ring-indigo-400 focus:border-indigo-400"}`})},Tl=({icon:d,title:l,open:s,onToggle:f,count:m,countLabel:g="rows",first:A})=>n.jsxs("button",{type:"button",onClick:f,className:`flex items-center gap-2 w-full ${A?"pt-0":"pt-4"} pb-1.5 px-2 group cursor-pointer focus:outline-none rounded-lg hover:bg-slate-50 transition-colors`,children:[n.jsx("span",{className:"text-base",children:d}),n.jsx("span",{className:"text-xs font-extrabold text-slate-700 uppercase tracking-widest group-hover:text-blue-600 transition-colors",children:l}),!s&&m!==void 0&&n.jsxs("span",{className:"text-[9px] font-bold text-indigo-600 bg-indigo-50 border border-indigo-200 rounded-full px-2 py-0.5 ml-1",children:[m," ",g]}),n.jsx("div",{className:"flex-1 h-px bg-slate-200 ml-1 group-hover:bg-blue-100 transition-colors"}),n.jsx("svg",{className:`w-4 h-4 text-slate-400 group-hover:text-blue-500 transition-all duration-200 shrink-0 ${s?"rotate-0":"-rotate-90"}`,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:n.jsx("path",{d:"M6 9l6 6 6-6"})})]}),Rl=({children:d,open:l})=>n.jsx("div",{className:`overflow-hidden transition-all duration-200 ease-in-out ${l?"max-h-[1000px] opacity-100":"max-h-0 opacity-0"}`,children:n.jsxs("table",{className:"w-full text-xs border-collapse",children:[n.jsx("thead",{children:n.jsxs("tr",{className:"bg-slate-100 border-b-2 border-slate-200",children:[n.jsx("th",{className:"text-left py-1 px-2 text-[10px] font-extrabold text-slate-600 uppercase tracking-widest w-[30%]",children:"Charge"}),n.jsx("th",{className:"text-center py-1 px-1 text-[10px] font-extrabold text-slate-600 uppercase tracking-widest w-[38%]",children:"Type"}),n.jsx("th",{className:"text-right py-1 pr-1 text-[10px] font-extrabold text-slate-600 uppercase tracking-widest w-[18%]",children:"Value"}),n.jsx("th",{className:"text-left py-1 pl-1 text-[10px] font-extrabold text-slate-600 uppercase tracking-widest w-[14%]",children:"Unit"})]})}),n.jsx("tbody",{className:"divide-y divide-slate-50",children:d})]})}),Qs=({label:d,tooltip:l,type:s,value:f,unit:m,onValueChange:g,min:A,max:O,decimals:U,disabled:k,indent:z,prefix:E,required:me,error:ve,onFieldBlur:q})=>n.jsxs(n.Fragment,{children:[n.jsxs("tr",{className:`hover:bg-blue-100/50 transition-colors ${ve?"":"border-b border-slate-100/60"} ${k?"opacity-50":""}`,children:[n.jsx("td",{className:"py-0.5 px-2",children:n.jsxs("span",{className:`flex items-center gap-1 ${z?"pl-4 text-slate-400 text-xs":"text-slate-800 text-xs font-semibold"} leading-tight`,children:[E,n.jsx("span",{className:"truncate",children:d}),me&&n.jsx("span",{className:"text-red-500 font-bold shrink-0",children:"*"}),l&&n.jsxs("span",{className:"group relative cursor-help shrink-0",children:[n.jsxs("svg",{className:"w-3 h-3 text-slate-400",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[n.jsx("circle",{cx:"12",cy:"12",r:"10"}),n.jsx("path",{d:"M12 16v-4M12 8h.01"})]}),n.jsx("span",{className:`absolute left-0 bottom-full mb-1 w-44 p-1.5 bg-slate-800 text-white text-[9px] leading-relaxed
45                rounded shadow-lg opacity-0 invisible group-hover:opacity-100 group-hover:visible transition-all z-20 pointer-events-none whitespace-normal`,children:l})]})]})}),n.jsx("td",{className:"py-0.5 px-1 text-center",children:s??n.jsx("span",{className:"text-[9px] text-slate-400",children:"—"})}),n.jsx("td",{className:"py-0.5 pr-1 text-right",children:n.jsx(nx,{value:f,onChange:g,min:A,max:O,decimals:U,disabled:k,error:ve,onFieldBlur:q})}),n.jsx("td",{className:"py-0.5 pl-1",children:n.jsx("span",{className:"text-[10px] font-bold uppercase tracking-wide text-slate-400",children:m})})]}),ve&&n.jsx("tr",{className:"border-b border-slate-100/60",children:n.jsx("td",{colSpan:4,className:"pb-1 px-2 -mt-0.5",children:n.jsx("span",{className:"text-[10px] text-red-600 font-medium",children:ve})})})]}),rx={rovCharges:1e3,odaCharges:1e3,handlingCharges:1e3,toPayCharges:1e3,codCharges:1e3,greenTax:1e3,hamaliCharges:1e3,miscCharges:1e3,daccCharges:1e3},sx={rovCharges:1e3,odaCharges:1e3,handlingCharges:1e3,toPayCharges:1e3,codCharges:1e3,greenTax:1e3,hamaliCharges:1e3,miscCharges:1e3,daccCharges:1e3},ax=({baseFreight:d,onBaseFreightChange:l,sampleWeight:s,onSampleWeightChange:f,sampleInvoice:m,onSampleInvoiceChange:g,charges:A,consequences:O=[]})=>{const U=d+A.reduce((k,z)=>k+z.value,0);return n.jsxs("div",{className:"bg-white rounded-xl p-4 h-full flex flex-col shadow-sm overflow-hidden border border-slate-200 relative",children:[n.jsx("div",{className:"absolute top-0 left-0 right-0 h-0.5 bg-gradient-to-r from-blue-500 via-indigo-500 to-blue-400 rounded-t-xl"}),n.jsxs("div",{className:"flex flex-col gap-4 flex-1 pt-1",children:[n.jsxs("div",{className:"flex items-center justify-between pb-2 border-b border-slate-100",children:[n.jsx("span",{className:"text-[10px] font-bold text-slate-500 uppercase tracking-widest",children:"Live Estimate"}),n.jsxs("span",{className:"flex items-center gap-1 px-1.5 py-0.5 bg-blue-50 rounded-full border border-blue-100",children:[n.jsx("span",{className:"w-1.5 h-1.5 bg-blue-500 rounded-full animate-pulse"}),n.jsx("span",{className:"text-[8px] font-bold text-blue-600 uppercase tracking-wider",children:"Live"})]})]}),n.jsxs("div",{children:[n.jsx("p",{className:"text-[10px] text-slate-500 font-bold uppercase tracking-widest mb-1.5",children:"Sample Base Freight"}),n.jsxs("div",{className:"flex items-center gap-2 bg-slate-50 border border-slate-200 rounded-lg px-3 py-2 focus-within:border-blue-400 focus-within:ring-1 focus-within:ring-blue-100 transition-all",children:[n.jsx("span",{className:"text-slate-400 text-sm font-medium",children:"₹"}),n.jsx("input",{type:"number",min:0,max:1e6,step:100,value:d,onChange:k=>l(Math.min(1e6,Math.max(0,parseFloat(k.target.value)||0))),className:`flex-1 bg-transparent text-lg font-bold text-slate-800 text-right focus:outline-none
46                [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none`})]})]}),n.jsxs("div",{children:[n.jsx("p",{className:"text-[10px] text-slate-500 font-bold uppercase tracking-widest mb-1.5",children:"Simulation Weight"}),n.jsxs("div",{className:"flex items-center gap-2 bg-slate-50 border border-slate-200 rounded-lg px-3 py-2 focus-within:border-blue-400 focus-within:ring-1 focus-within:ring-blue-100 transition-all",children:[n.jsx("input",{type:"number",min:0,max:1e6,step:1,value:s??10,onChange:k=>f?.(Math.min(1e6,Math.max(0,parseFloat(k.target.value)||0))),className:`flex-1 bg-transparent text-lg font-bold text-slate-800 text-right focus:outline-none
47                [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none`}),n.jsx("span",{className:"text-slate-400 text-sm font-medium",children:"KG"})]})]}),n.jsxs("div",{children:[n.jsx("p",{className:"text-[10px] text-slate-500 font-bold uppercase tracking-widest mb-1.5",children:"Sample Invoice"}),n.jsxs("div",{className:"flex items-center gap-2 bg-slate-50 border border-slate-200 rounded-lg px-3 py-2 focus-within:border-blue-400 focus-within:ring-1 focus-within:ring-blue-100 transition-all",children:[n.jsx("span",{className:"text-slate-400 text-sm font-medium",children:"₹"}),n.jsx("input",{type:"number",min:0,max:1e6,step:100,value:m??0,onChange:k=>g?.(Math.min(1e6,Math.max(0,parseFloat(k.target.value)||0))),className:`flex-1 bg-transparent text-lg font-bold text-slate-800 text-right focus:outline-none
48                [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none`})]})]}),n.jsxs("div",{className:"flex-1 flex flex-col gap-1",children:[n.jsx("p",{className:"text-[10px] text-slate-500 font-bold uppercase tracking-widest",children:"Applied Charges"}),A.length===0?n.jsx("p",{className:"text-[10px] text-slate-400 italic mt-1",children:"No charges entered yet"}):n.jsx("div",{className:"space-y-1.5 mt-1",children:A.map((k,z)=>n.jsxs("div",{className:"flex justify-between items-center py-0.5",children:[n.jsx("span",{className:"text-[10px] text-slate-500 truncate max-w-[55%]",children:k.label}),n.jsxs("span",{className:"text-[10px] font-semibold text-blue-600 shrink-0",children:["+ ₹",k.value.toLocaleStr
48ing()]})]},z))})]}),n.jsxs("div",{className:"border-t border-slate-100 pt-3 mt-auto",children:[n.jsx("p",{className:"text-[8px] font-bold text-slate-400 uppercase tracking-[0.18em] mb-1",children:"Estimated Net Cost"}),n.jsxs("span",{className:"text-2xl font-extrabold text-slate-800 leading-none",children:["₹",U.toLocaleString()]})]}),O.length>0&&n.jsx("div",{className:"space-y-1.5 border-t border-slate-100 pt-3",children:O.map((k,z)=>n.jsxs("div",{className:`text-[9px] leading-relaxed p-2 rounded-lg border flex items-start gap-1.5
49                ${k.type==="warning"?"bg-amber-50 border-amber-200 text-amber-700":k.type==="success"?"bg-emerald-50 border-emerald-200 text-emerald-700":"bg-blue-50 border-blue-200 text-blue-700"}`,children:[n.jsx("div",{className:`w-1.5 h-1.5 rounded-full mt-0.5 shrink-0
50                  ${k.type==="warning"?"bg-amber-400":k.type==="success"?"bg-emerald-400":"bg-blue-400"}`}),k.message]},z))})]})]})},ix=({charges:d,pricingPreview:l,onBaseFreightChange:s,baseFreight:f,sampleWeight:m,onSampleWeightChange:g,sampleInvoice:A,onSampleInvoiceChange:O})=>{const{charges:U,setCharge:k,setCardField:z,validateField:E,validateCardField:me}=d,{getField:ve}=go("add-vendor"),q=(R,N)=>ve(R)?.label??N,[ee,de]=x.useState(!0),[Y,le]=x.useState(!0),[J,G]=x.useState(!1),[ue,V]=x.useState(!1),[he,L]=x.useState(!1),[ce,fe]=x.useState(f??5e3),Ae=f??ce,re=R=>{fe(R),s?.(R)},[I,Ne]=x.useState(m??10),ge=m??I,we=R=>{Ne(R),g?.(R)},[ye,We]=x.useState(A??0),Vt=A??ye,Dn=R=>{We(R),O?.(R)},[xt,Un]=x.useState({toPayCharges:!1,codCharges:!1,daccCharges:!1}),Ye=x.useCallback((R,N)=>{Un(B=>({...B,[R]:N})),N?(z(R,"fixedAmount",null),z(R,"mode","FIXED"),z(R,"currency","INR")):(z(R,"fixedAmount",null),z(R,"variableRange",null))},[z]);x.useEffect(()=>{const R=N=>Number(N?.fixedAmount??0)>0||Number(N?.variableRange??0)>0;Un(N=>({toPayCharges:N.toPayCharges||R(U.toPayCharges),codCharges:N.codCharges||R(U.codCharges),daccCharges:N.daccCharges||R(U.daccCharges)}))},[U.toPayCharges,U.codCharges,U.daccCharges]);const qe=R=>{const N=U[R]||{};return N.mode||(N.currency==="INR"?"FIXED":"VARIABLE")},nt=R=>{const N=U[R]||{};return qe(R)==="FIXED"?N.fixedAmount??"":N.variableRange??""},yn=R=>{const N=U[R]||{};return qe(R)==="FIXED"?N.unit==="per kg"?"₹/KG":"₹":"%"},ut=(R,N)=>{z(R,"mode",N?"FIXED":"VARIABLE"),z(R,"currency",N?"INR":"PERCENT"),setTimeout(()=>me(R,N?"fixedAmount":"variableRange"),0)},He=(R,N)=>{const B=qe(R)==="FIXED"?"fixedAmount":"variableRange";z(R,B,N===""?null:parseFloat(N))},Rt=R=>qe(R)==="FIXED"?rx[R]??1e3:sx[R]??1e3,It=(R,N,B,M=!1,H=!1,pe,se=!1)=>{const Ce=H&&pe?xt[pe]:!0,Ie=qe(N)==="FIXED",Qe=d.errors?.[N],Nt=Qe?Qe.fixedAmount||Qe.variableRange:void 0,nn=Ie?"fixedAmount":"variableRange";return n.jsx(Qs,{label:R,tooltip:B,type:n.jsx(Hd,{isFixed:Ie,onChange:Te=>ut(N,Te),disabled:H&&!Ce}),value:nt(N),unit:yn(N),onValueChange:Te=>He(N,Te),min:0,max:Rt(N),decimals:2,disabled:!1,indent:M,required:se,error:Nt,onFieldBlur:()=>me(N,nn),prefix:H&&pe?n.jsx("input",{type:"checkbox",checked:Ce,onChange:Te=>Ye(pe,Te.target.checked),className:"w-3 h-3 rounded text-indigo-600 border-slate-300 accent-indigo-600 cursor-pointer shrink-0 mr-1"}):void 0},N)},mt="odaCharges",Ke=U.odaCharges?.matrix||[],Mt=(R,N)=>{const B=N===""?null:parseFloat(N),M=Ke.map(H=>{const pe=[...H.bands||[]];return pe[R]&&(pe[R]={...pe[R],minKg:B}),{...H,bands:pe}});z(mt,"matrix",M)},Ct=(R,N)=>{const B=N===""?null:parseFloat(N),M=Ke.map(H=>{const pe=[...H.bands||[]];return pe[R]&&(pe[R]={...pe[R],maxKg:B}),{...H,bands:pe}});z(mt,"matrix",M)},Bt=R=>{const N=Ke.map(B=>{const M=(B.bands||[]).filter((H,pe)=>pe!==R);return{...B,bands:M}});z(mt,"matrix",N)},Fn=()=>{const R=Ke.map(N=>{const B=[...N.bands||[],{minKg:null,maxKg:null,charge:0}];return{...N,bands:B}});z(mt,"matrix",R)},Kt=(R,N)=>{const B=N===""?null:parseFloat(N),M=[...Ke];M[R]&&(M[R]={...M[R],minDist:B}),z(mt,"matrix",M)},nr=(R,N)=>{const B=N===""?null:parseFloat(N),M=[...Ke];M[R]&&(M[R]={...M[R],maxDist:B}),z(mt,"matrix",M)},is=R=>{const N=Ke.filter((B,M)=>M!==R);z(mt,"matrix",N)},jr=()=>{const R=Ke[0]?.bands,N=Array.isArray(R)?R.map(M=>({minKg:M.minKg,maxKg:M.maxKg,charge:0})):[{minKg:0,maxKg:100,charge:0},{minKg:101,maxKg:500,charge:0},{minKg:501,maxKg:null,charge:0}],B=[...Ke,{minDist:null,maxDist:null,bands:N}];z(mt,"matrix",B)},St=(R,N,B)=>
50{const M=B===""?0:parseFloat(B),H=[...Ke];if(H[R]){const pe=[...H[R].bands||[]];pe[N]&&(pe[N]={...pe[N],charge:M}),H[R]={...H[R],bands:pe}}z(mt,"matrix",H)},rr=R=>{if(!R)return"Not configured";const N=R.mode==="FIXED",B=R.billingType??"per_kg";if(!N){const M=R.variableRange??0;return`Variable surcharge of ${typeof M=="number"?M+"%":M} on raw base freight.`}if(B==="per_kg")return`₹${R.fixedAmount??0} per KG rate.`;if(B==="per_shipment")return`Flat charge of ₹${R.fixedAmount??0} per shipment.`;if(B==="per_kg_minimum"){const M=R.perKg??0,H=R.minimum??0;return`₹${M} per KG, with a minimum charge floor of ₹${H}.`}if(B==="per_kg_excess"){const M=R.fixedAmount??0,H=R.thresholdWeight??0,pe=R.variableRange??0;return`₹${M} flat up to ${H}KG, then ₹${pe}/KG for every KG above that.`}if(B==="negotiable")return"Negotiable / Case-by-case (rates to be confirmed upon booking).";if(B==="matrix"){const M=R.matrixType==="2d"||R.matrix&&Array.isArray(R.matrix)&&R.matrix.length>0&&R.matrix[0]?.bands!==void 0,H=R.matrix||[];if(H.length===0)return"Empty pricing matrix configured.";if(M){const pe=[];return H.slice(0,3).forEach(se=>{const Ce=se.minDist??se.minKm??0,Ie=se.maxDist??se.maxKm,Qe=Ie?`${Ce}-${Ie}km`:`${Ce}+ km`,Nt=se.bands||se.matrix||[],nn=Nt.slice(0,2).map(Te=>{const it=Te.minKg??Te.minWeight??0,Et=Te.maxKg??Te.maxWeight,Ot=Et?`${it}-${Et}kg`:`${it}+kg`,Wn=Te.perKg!==void 0?`₹${Te.perKg}/kg`:`₹${Te.charge??Te.rate}`;return`${Ot}: ${Wn}`}).join(", ");pe.push(`• ${Qe}: ${nn}${Nt.length>2?"...":""}`)}),`Distance × Weight pricing matrix:
51${pe.join(`
52`)}`}else return`Weight slab pricing matrix:
53${H.map(se=>{const Ce=se.minWeight??se.minKg??0,Ie=se.maxWeight??se.maxKg,Qe=Ie?`${Ce}-${Ie}kg`:`${Ce}+kg`,Nt=se.rate!==void 0?`₹${se.rate}/kg`:`₹${se.charge??se.rate}`,nn=se.fixedSurcharge?` (min ₹${se.fixedSurcharge})`:"";return`• ${Qe}: ${Nt}${nn}`}).join(`
54`)}`}return"Not configured"},ot=l?.charges??[],yt=l?.consequences??[];return n.jsxs(Zl,{className:"flex flex-row gap-6 min-h-0 items-stretch",children:[n.jsxs("div",{className:"flex-1 min-w-0 flex flex-col gap-0 overflow-y-auto",children:[n.jsx(Tl,{icon:"💰",title:"Basic Charges",open:ee,onToggle:()=>de(R=>!R),first:!0}),n.jsxs(Rl,{open:ee,children:[n.jsx(Qs,{label:q("docketCharges","Docket Charges"),tooltip:"Fixed charge per booking",value:U.docketCharges??"",unit:"₹",required:!0,error:d.errors.docketCharges,onFieldBlur:()=>E("docketCharges"),onValueChange:R=>k("docketCharges",R),min:0,max:1e3,decimals:2}),n.jsx(Qs,{label:q("fuelSurchargePct","Fuel Surcharge"),tooltip:"% of base freight",type:n.jsx("span",{className:"text-[9px] text-slate-400",children:"% on Base"}),value:U.fuelSurchargePct??"",unit:"%",required:!0,error:d.errors.fuelSurchargePct,onFieldBlur:()=>E("fuelSurchargePct"),onValueChange:R=>k("fuelSurchargePct",R),min:0,max:50,decimals:2}),n.jsx(Qs,{label:"Min Chargeable Wt",tooltip:"Minimum billable weight per consignment",value:U.minWeightKg??"",unit:"KG",error:d.errors.minWeightKg,onFieldBlur:()=>E("minWeightKg"),onValueChange:R=>k("minWeightKg",R),min:0,max:1e3,decimals:1}),n.jsx(Qs,{label:q("minimumCharges","Minimum Charges"),tooltip:"Floor charge regardless of weight",value:U.minCharges??"",unit:"₹",error:d.errors.minCharges,onFieldBlur:()=>E("minCharges"),onValueChange:R=>k("minCharges",R),min:0,max:1e3,decimals:2}),n.jsx(Qs,{label:q("gstPct","GST %"),tooltip:"GST percentage applied on final freight",type:n.jsx("span",{className:"text-[9px] text-slate-400",children:"% on Total"}),value:U.gstPct??"",unit:"%",required:!0,error:d.errors.gstPct,onFieldBlur:()=>E("gstPct"),onValueChange:R=>k("gstPct",R),min:0,max:100,decimals:2}),It("ROV / FOV","rovCharges","Risk/Freight of Value — flat rate or % of declared value"),(()=>{const R="odaCharges",N=qe(R)==="FIXED",B=U.odaCharges?.billingType??"per_kg",M="%",H=se=>{const Ce=B||"per_kg";if(se===Ce)return;const Ie=U.odaCharges,Qe={...Ie._draftValues||{}};if(Ce==="per_kg_minimum"?Qe[Ce]={perKg:Ie.perKg,minimum:Ie.minimum}:Ce==="per_kg_excess"?Qe[Ce]={fixedAmount:Ie.fixedAmount,thresholdWeight:Ie.thresholdWeight,variableRange:Ie.variableRange}:Qe[Ce]=Ie.fixedAmount,z(R,"_draftValues",Qe),z(R,"billingType",se),se==="per_kg_minimum"){const Nt=Qe[se]||{};z(R,"perKg",Nt.perKg??null),z(R,"minimum",Nt.minimum??null),z(R,"fixedAmount",null),z(R,"thresholdWeight",null),z(R,"variableRange",null)}else if(se==="per_kg_excess"){const Nt=Qe[se]||{};z(R,"fixedAmount",Nt.fixedAmount??null),z(R,"thresholdWeight",Nt.thresholdWeight??null),z(R,"variableRange",Nt.variableRange??null),z(R,"perKg",null),z(R,"minimum",null)}else z(R,"fixedAmount",Qe[se]??null),z(R,"perKg",null),z(R,"minimum",null),z(R,"thresholdWeight",null),z(R,"variableRange",null)},pe=(()=>{const se=U.odaCharges;switch(B){case"per_kg":return`Per KG · ₹${se?.fixedAmount??0}/kg`;
54case"per_shipment":return`Flat · ₹${se?.fixedAmount??0}`;case"per_kg_minimum":return`+Min · ₹${se?.perKg??0}/kg`;case"per_kg_excess":return`+Extra · ₹${se?.fixedAmount??0} base`;case"matrix":return`Matrix · ${Array.isArray(se?.matrix)?se.matrix.length:0} row(s)`;case"negotiable":return"Negotiable";default:return"Not configured"}})();return n.jsxs(m0.Fragment,{children:[n.jsxs("tr",{className:"hover:bg-blue-100/50 transition-colors",children:[n.jsx("td",{className:"py-0.5 px-2 align-top pt-1.5",children:n.jsxs("div",{className:"flex flex-col gap-1",children:[n.jsxs("span",{className:"flex items-center gap-1 text-slate-700 font-medium leading-tight",children:[n.jsx("span",{className:"truncate",children:"ODA Charges"}),n.jsxs("span",{className:"group relative cursor-help shrink-0",children:[n.jsxs("svg",{className:"w-3 h-3 text-slate-400",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[n.jsx("circle",{cx:"12",cy:"12",r:"10"}),n.jsx("path",{d:"M12 16v-4M12 8h.01"})]}),n.jsx("span",{className:"absolute left-0 bottom-full mb-1 w-48 p-1.5 bg-slate-800 text-white text-[9px] leading-relaxed rounded shadow-lg opacity-0 invisible group-hover:opacity-100 group-hover:visible transition-all z-20 pointer-events-none whitespace-normal",children:"Out of Delivery Area surcharge — fixed per KG, per shipment, matrix, or % of base freight"})]})]}),N&&n.jsx("div",{className:"text-[10px] text-slate-500 font-medium whitespace-pre-line leading-snug pr-2 pt-1 pb-2",children:rr(U.odaCharges)||"No configuration set."})]})}),n.jsx("td",{className:"py-0.5 px-1 text-center align-top pt-1",children:n.jsx("div",{className:"flex flex-col items-center gap-1.5",children:n.jsx(Hd,{isFixed:N,onChange:se=>ut(R,se)})})}),n.jsx("td",{className:"py-0.5 pr-1 text-right align-top pt-1",children:n.jsx("div",{className:"flex items-center gap-1.5 justify-end",children:N?n.jsxs("button",{type:"button",onClick:()=>L(!0),className:"w-[148px] h-[26px] flex items-center justify-between gap-1 text-[10px] font-semibold px-2 rounded border border-slate-200 text-slate-700 bg-slate-50 shadow-sm hover:border-blue-400 hover:bg-white transition-colors",children:[n.jsx("span",{className:"truncate",children:pe}),n.jsx("svg",{className:"w-3 h-3 text-slate-400 shrink-0",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19 9l-7 7-7-7"})})]}):n.jsx("input",{type:"number",className:"w-16 h-[26px] text-right bg-slate-50 border border-slate-200 rounded px-2 py-1 focus:outline-none focus:border-blue-400 focus:bg-white transition-colors [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",value:nt(R),onChange:se=>He(R,se.target.value),min:0,max:100,placeholder:"0"})})}),n.jsx("td",{className:"py-0.5 pl-1 align-top pt-1.5",children:!N&&n.jsx("span",{className:"text-[10px] font-bold uppercase tracking-wide text-slate-400",children:M})})]}),n.jsx(tx,{open:he,onClose:()=>L(!1),billingType:B,odaCard:U.odaCharges,onSelectType:H,onFieldChange:(se,Ce)=>z(R,se,Ce),onOpenMatrix:()=>{L(!1),V(!0)}}),B==="matrix"&&N&&au.createPortal(n.jsx(Nr,{children:ue&&n.jsx(ct.div,{initial:{opacity:0}
54,animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 z-[200] flex items-center justify-center bg-slate-900/60 backdrop-blur-sm p-4",children:n.jsxs(ct.div,{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.95},className:"bg-white rounded-2xl shadow-2xl max-w-4xl w-full max-h-[90vh] flex flex-col overflow-hidden",children:[n.jsxs("div",{className:"flex items-center justify-between px-6 py-4 bg-slate-50 border-b border-slate-200",children:[n.jsxs("div",{children:[n.jsx("h3",{className:"text-base font-bold text-slate-800",children:"ODA Matrix Configuration"}),n.jsx("p",{className:"text-[11px] text-slate-500 mt-0.5",children:"Configure distance and weight bands for Out of Delivery Area charges."})]}),n.jsx("button",{onClick:()=>V(!1),className:"p-2 text-slate-400 hover:text-slate-600 hover:bg-slate-200/50 rounded-full transition-colors",children:n.jsx("svg",{className:"w-5 h-5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:n.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})})]}),n.jsxs("div",{className:"overflow-x-auto overflow-y-auto flex-1 p-6 scrollbar-thin scrollbar-thumb-slate-200",children:[n.jsx("div",{className:"border border-slate-200 rounded-xl overflow-hidden shadow-sm",children:n.jsxs("table",{className:"w-full text-center min-w-[600px] border-collapse bg-white",children:[n.jsx("thead",{className:"bg-slate-50 border-b border-slate-200 text-slate-600 font-bold text-[11px] uppercase tracking-wider",children:n.jsxs("tr",{children:[n.jsx("th",{className:"py-3 px-2 font-semibold w-[160px] text-center border-r border-slate-200",children:"Distance (KM)"}),(Ke[0]?.bands||[]).map((se,Ce)=>n.jsx("th",{className:"py-2 px-2 font-semibold text-center align-middle relative min-w-[120px] border-r border-slate-200 group",children:n.jsxs("div",{className:"flex flex-col items-center gap-1.5 py-1",children:[n.jsxs("div",{className:"flex items-center gap-1 justify-center",children:[n.jsx("input",{type:"number",className:"w-12 text-[11px] text-center bg-white border border-slate-200 font-medium p-1 rounded focus:outline-none focus:border-blue-400 transition-colors shadow-sm",value:se.minKg??"",placeholder:"Min",onChange:Ie=>Mt(Ce,Ie.target.value)}),n.jsx("span",{className:"text-slate-400 text-[10px]",children:"-"}),n.jsx("input",{type:"number",className:"w-12 text-[11px] text-center bg-white border border-slate-200 font-medium p-1 rounded focus:outline-none focus:border-blue-400 transition-colors shadow-sm",value:se.maxKg??"",placeholder:"Max",onChange:Ie=>Ct(Ce,Ie.target.value)})]}),n.jsx("button",{type:"button",onClick:()=>Bt(Ce),className:"absolute top-1 right-1 opacity-0 group-hover:opacity-100 text-[10px] text-red-400 hover:text-red-600 font-bold transition-opacity",title:"Remove weight column",children:"✕"})]})},Ce)),n.jsx("th",{className:"py-2 px-2 text-center align-middle w-[90px]",children:n.jsx("button",{type:"button",onClick:Fn,className:"px-2 py-1.5 text-[10px] bg-blue-50 text-blue-600 hover:bg-blue-100 border border-blue-200 font-bold rounded shadow-sm transition-colors uppercase tracking-wider",children:"+ Col"})})]})}),n.jsx("tbody",{className:"divide-y divide-slate-100",children:(Ke||[]).map((se,Ce)=>n.jsxs("tr",{className:"hover:bg-slate-50/50 transition-colors group",children:[n.jsx("td",{className:"p-2 border-r border-slate-200",children:n.jsxs("div",{className:"flex items-center gap-1.5 justify-center",children:[n.jsx("input",{type:"number",className:"w-14 text-[11px] text-center bg-white border border-slate-200 font-medium p-1 rounded focus:outline-none focus:border-blue-400 shadow-sm transition-colors",value:se.minDist??"",placeholder:"Min",onChange:Ie=>Kt(Ce,Ie.target.value)}),n.jsx("span",{className:"text-slate-400 text-[10px]",children:"-"}),n.jsx("input",{type:"number",className:"w-14 text-[11px] text-center bg-white border border-slate-200 font-medium p-1 rounded focus:outline-none focus:border-blue-400 shadow-sm transition-colors",value:se.maxDist??"",placeholder:"Max",onChange:Ie=>nr(Ce,Ie.target.value)})]})}),(se.bands||[]).map((Ie,Qe)=>n.jsx("td",{className:"p-2 border-r border-slate-100",children:n.jsx("input",{type:"number",className:"w-full bg-slate-50 text-[12px] text-center font-bold text-slate-700 p-1.5 rounded focus:outline-none focus:bg-white focus:ring-1 focus:ring-blue-400 transition-all [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none shadow-inner",value:Ie.charge??"",placeholder:"₹",onCh
54ange:Nt=>St(Ce,Qe,Nt.target.value)})},Qe)),n.jsx("td",{className:"p-2 text-center align-middle",children:n.jsx("button",{type:"button",onClick:()=>is(Ce),className:"px-2 py-1 text-[10px] text-red-400 hover:text-red-600 font-bold opacity-0 group-hover:opacity-100 transition-opacity",children:"✕ Row"})})]},Ce))})]})}),n.jsx("div",{className:"mt-3 text-center",children:n.jsx("button",{type:"button",onClick:jr,className:"inline-flex items-center gap-1 px-4 py-2 bg-blue-50 hover:bg-blue-100 text-blue-600 border border-blue-200 text-[11px] font-bold rounded-lg uppercase tracking-wider transition-colors shadow-sm",children:"+ Add Distance Row"})})]}),n.jsx("div",{className:"px-6 py-4 bg-slate-50 border-t border-slate-200 flex justify-end",children:n.jsx("button",{onClick:()=>V(!1),className:"px-6 py-2.5 bg-blue-600 hover:bg-blue-700 text-white font-bold text-xs uppercase tracking-wider rounded-lg shadow transition-colors",children:"Done"})})]})})}),document.body)]},"odaCharges")})(),It("Handling","handlingCharges","Material handling per KG or flat rate",!1,!1,void 0,!0),n.jsx(Qs,{label:"› Weight Threshold",tooltip:"Weight above which handling charge applies",value:U.handlingCharges?.weightThreshold??"",unit:"KG",error:d.errors.handlingCharges?.weightThreshold,onFieldBlur:()=>me("handlingCharges","weightThreshold"),onValueChange:R=>z("handlingCharges","weightThreshold",R===""?null:parseFloat(R)),min:0,max:1e3,decimals:1,indent:!0})]}),n.jsx(Tl,{icon:"📋",title:"Additional Charges",open:Y,onToggle:()=>le(R=>!R),count:3}),n.jsxs(Rl,{open:Y,children:[It(q("greenTax","Green Tax / NGT"),"greenTax","Environmental surcharge levied by state"),It(q("hamaliCharges","Hamali"),"hamaliCharges","Loading & unloading labour charges"),It(q("miscCharges","MISC / AOC"),"miscCharges","Miscellaneous or airport operations charges")]}),n.jsx(Tl,{icon:"⚙️",title:"Optional Charges",open:J,onToggle:()=>G(R=>!R),count:[xt.toPayCharges,xt.codCharges,xt.daccCharges].filter(Boolean).length,countLabel:"active"}),n.jsxs(Rl,{open:J,children:[It("To-Pay","toPayCharges","Surcharge for consignee-paid shipments",!1,!0,"toPayCharges"),It("COD / DOD","codCharges","Cash/Demand Draft on Delivery fee",!1,!0,"codCharges"),It(q("daccCharges","DACC"),"daccCharges","Delivery Area Congestion Charge",!1,!0,"daccCharges")]})]}),n.jsx("div",{className:"w-60 shrink-0 self-stretch",children:n.jsx(ax,{baseFreight:Ae,onBaseFreightChange:re,sampleWeight:ge,onSampleWeightChange:we,sampleInvoice:Vt,onSampleInvoiceChange:Dn,charges:ot,consequences:yt})})]})},uo={N1:1,N2:2,N3:3,N4:4,C1:5,C2:6,E1:7,E2:8,W1:9,W2:10,S1:11,S2:12,S3:13,S4:14,NE1:15,NE2:16,X1:17,X2:18,X3:19};function Il(d){if(!d)return"Special";const l=d.toUpperCase();return l.startsWith("NE")?"Northeast":l.startsWith("N")?"North":l.startsWith("S")?"South":l.startsWith("E")?"East":l.startsWith("W")?"West":l.startsWith("C")?"Central":"Special"}function fo(d){return d&&d.split(" ").map(l=>l.charAt(0).toUpperCase()+l.slice(1).toLowerCase()).join(" ")}const fi=({state:d,onClick:l,size:s="md"})=>{const f=x.useRef(null);x.useEffect(()=>{f.current&&(f.current.indeterminate=d==="some")},[d]);const m=s==="sm"?"w-3.5 h-3.5":"w-4 h-4";return n.jsx("span",{className:"flex-shrink-0 cursor-pointer",onClick:l,children:n.jsx("input",{ref:f,type:"checkbox",checked:d==="all",readOnly:!0,onChange:()=>{},className:`${m} rounded border-slate-300 text-blue-600 cursor-pointer pointer-events-none
55                    focus:ring-1 focus:ring-blue-400 focus:ring-offset-0`})})},ox=({onComplete:d,blankCellValue:l="",initialSelectedZones:s=[],initialSelectedPincodes:f=[]})=>{const[m,g]=x.useState(!0),[A,O]=x.useState(null),[U,k]=x.useState([]),[z,E]=x.useState(new Map),[me,ve]=x.useState(new Set),[q,ee]=x.useState(new Set),[de,Y]=x.useState(new Set),[le,J]=x.useState(new Set),[G,ue]=x.useState(""),[V,he]=x.useState("North"),[L,ce]=x.useState(null),[fe,Ae]=x.useState(null),[re,I]=x.useState(""),[Ne,ge]=x.useState(""),we=x.useMemo(()=>{const N=new Map;for(const B of U)N.set(B.zoneCode,B.cities.flatMap(M=>M.pincodes));return N},[U]);x.useEffect(()=>{let N=!1;return(async()=>{g(!0),O(null);try{const M=await fetch("/pincodes.json");if(!M.ok)throw new Error(`HTTP ${M.status}`);const H=await M.json();if(N)return;const pe=new Map,se=new Map;for(const Te of H){const it=String(Te.pincode);pe.set(it,Te);const Et=Te.zone||"Uncategorized";se.has(Et)||se.set(Et,[])}const Ce=new Map;for(const Te of H){const it=String(Te.pincode),Et=Te.zone||"Uncategorized",Ot=`${(Te.city??"").toUpperCase()}||${(Te.state??"").toUpperCase()}||${Et}`;Ce.has(Ot)||Ce.set(Ot,{city:(Te.city??"").toUpperCase(),state:(Te.state??"").toUpperCase(),zone:Et,pincodes:[]}),Ce.get(Ot).pincodes.push(it)}const Ie=new Map;for(const[Te,it]of Ce.entries())Ie.has(it.zone)||Ie.set(it.zone,[]),Ie.get(it.zone).push({city:it.city,state:it.state,cityKey:Te,pincodes:it.pincodes.sort(),zone:it.zone});let Qe={};try{const Te=await fetch("/zones_blueprint.json");Te.ok&&(Qe=(await Te.json()).zones||{})}catch(Te){console.warn(Te)}const Nt=[],nn=Array.from(Ie.keys()).sort((Te,it)=>{const Et=uo[Te]??999,Ot=uo[it]??999;return Et-Ot});for(const Te of nn){const it=Ie.get(Te);it.sort((Et,Ot)=>Et.city.localeCompare(Ot.city)),Nt.push({zoneCode:Te,region:Il(Te),description:Qe[Te]?.description||"",cities:it,totalPincodes:it.reduce((Et,Ot)=>Et+Ot.pincodes.length,0)})}if(k(Nt),E(pe),f.length>0){const Te=new Set(f.filter(it=>pe.has(String(it))));if(Te.size>0){ve(Te);const it=new Set;for(const Ot of Te){const Wn=pe.get(Ot)?.zone;Wn&&it.add(Wn)}ee(it);const Et=pe.get(Array.from(Te)[0])?.zone;Et&&he(Il(Et))}}else if(s.length>0){const Te=new Set;for(const[_s,Pt]of Ce.entries())s.includes(Pt.zone)&&Pt.pincodes.forEac
55h(_r=>Te.add(_r));Te.size>0&&ve(Te),ee(new Set(s));const it=s[0],Et={N:"North",C:"Central",E:"East",W:"West",S:"South",X:"Special"},Ot=it?.[0]||"N",Wn=it?.startsWith("NE")?"Northeast":Et[Ot]||"North";he(Wn)}}catch(B){N||(console.error(B),O("Failed to load data."))}finally{N||g(!1)}})(),()=>{N=!0}},[]);const ye=x.useCallback(N=>{const B=we.get(N)??[];if(!B.length)return"none";const M=B.filter(H=>me.has(H)).length;return M===0?"none":M===B.length?"all":"some"},[we,me]),We=x.useCallback(N=>{if(!N.pincodes.length)return"none";const B=N.pincodes.filter(M=>me.has(M)).length;return B===0?"none":B===N.pincodes.length?"all":"some"},[me]),Vt=x.useCallback((N,B)=>{const M=we.get(N)??[];ve(H=>{const pe=new Set(H);return M.forEach(se=>B?pe.add(se):pe.delete(se)),pe})},[we]),Dn=x.useCallback((N,B)=>{ve(M=>{const H=new Set(M);return N.pincodes.forEach(pe=>B?H.add(pe):H.delete(pe)),H})},[]),xt=x.useCallback(N=>{ve(B=>{const M=new Set(B);return M.has(N)?M.delete(N):M.add(N),M})},[]);x.useCallback(N=>{ee(B=>{const M=new Set(B);return M.has(N)?M.delete(N):M.add(N),M})},[]),x.useCallback(N=>{Y(B=>{const M=new Set(B);return M.has(N)?M.delete(N):M.add(N),M})},[]);const Un=x.useCallback(()=>{if(me.size===0){ie.error("Please select at least one pincode");return}const N=new Map;for(const se of me){const Ce=z.get(se);if(!Ce)continue;const Ie=Ce.zone;N.has(Ie)||N.set(Ie,{cities:new Set,states:new Set});const Qe=N.get(Ie);Qe.cities.add(`${Ce.city}||${fo(Ce.state)}`),Qe.states.add(fo(Ce.state))}const B=[];for(const[se,Ce]of N.entries())B.push({zoneCode:se,zoneName:se,region:Il(se),selectedStates:Array.from(Ce.states),selectedCities:Array.from(Ce.cities),isComplete:!0});B.sort((se,Ce)=>{const Ie=uo[se.zoneCode]??999,Qe=uo[Ce.zoneCode]??999;return Ie-Qe});const M=B.map(se=>se.zoneCode),H={};for(const se of M){H[se]={};for(const Ce of M)H[se][Ce]=l}const pe=Array.from(me).map(se=>{const Ce=z.get(se);return{pincode:se,zone:Ce?.zone||"",state:Ce?.state||"",city:Ce?.city||"",isODA:!1,active:!0}}).filter(se=>se.zone);d({zones:B,priceMatrix:H,serviceability:pe}),ie.success(`${me.size.toLocaleString()} pincodes → ${B.length} zones configured!`,{duration:4e3})},[me,z,l,d]),Ye=x.useMemo(()=>{const N=G.trim().toUpperCase();let B=U;return!N&&V!=="All"&&(B=B.filter(M=>M.region===V)),N?B.map(M=>({...M,cities:M.cities.filter(H=>H.city.includes(N)||H.state.includes(N)||H.pincodes.some(pe=>pe.startsWith(N)))})).filter(M=>M.cities.length>0):B},[U,G,V]);x.useEffect(()=>{if(Ye.length===0){ce(null);return}Ye.some(B=>B.zoneCode===L)||ce(Ye[0].zoneCode)},[Ye,L]);const qe=x.useMemo(()=>Ye.find(N=>N.zoneCode===L)||null,[Ye,L]);x.useEffect(()=>{if(!qe||qe.cities.length===0){Ae(null);return}qe.cities.some(B=>B.cityKey===fe)||Ae(qe.cities[0].cityKey)},[qe,fe]);const nt=x.useMemo(()=>qe&&qe.cities.find(N=>N.cityKey===fe)||null,[qe,fe]),yn=x.useMemo(()=>{if(!qe)return[];let N=qe.cities;if(re.trim()){const B=re.trim().toUpperCase();N=N.filter(M=>M.city.includes(B)||M.state.includes(B))}return N},[qe,re]),ut=x.useMemo(()=>{if(!nt)return[];let N=nt.pincodes;if(Ne.trim()){const B=Ne.trim().toUpperCase();N=N.filter(M=>M.startsWith(B))}if(G.trim()){const B=G.trim().toUpperCase();/^\d+$/.test(B)&&(N=N.filter(M=>M.startsWith(B)))}return N},[nt,Ne,G]),[He,Rt]=x.useState(!1),It=x.useRef(null),mt=x.useMemo(()=>{const N=G.trim().toUpperCase();if(!N||z.size===0)return[];const B=[];if(/^\d+$/.test(N)){for(const[M,H]of z)if(M.startsWith(N)&&(B.push({key:M,label:M,sublabel:`${H.city}, ${fo(H.state)}`,pincodes:[M]}),B.length>=8))break}else{const M=new Map;for(const[H,pe]of z){if(pe.city.includes(N)||pe.state.includes(N)){const se=`${pe.city}||${pe.state}`;M.has(se)||M.set(se,{city:pe.city,state:pe.state,pincodes:[]}),M.get(se).pincodes.push(H)}if(M.size>=8)break}for(const{city:H,state:pe,pincodes:se}of M.values())B.push({key:`${H}||${pe}`,label:`${H}, ${fo(pe)}`,sublabel:`${se.length.toLocaleString()} pincode${se.length===1?"":"s"}`,pincodes:se})}return B},[G,z]),Ke=x.useCallback(N=>{ve(B=>{const M=new Set(B);return N.pincodes.forEach(H=>M.add(H)),M}
55),ue(""),Rt(!1),ie.success(`${N.pincodes.length.toLocaleString()} pincode${N.pincodes.length===1?"":"s"} selected from "${N.label}"`)},[]);x.useEffect(()=>{if(!He)return;const N=B=>{It.current&&!It.current.contains(B.target)&&Rt(!1)};return document.addEventListener("mousedown",N),()=>document.removeEventListener("mousedown",N)},[He]),x.useEffect(()=>{I("")},[L]),x.useEffect(()=>{ge("")},[fe]);const Mt=x.useMemo(()=>Ye.length===0?!1:Ye.every(N=>ye(N.zoneCode)==="all"),[Ye,ye]),Ct=x.useMemo(()=>Mt?!1:Ye.some(N=>ye(N.zoneCode)!=="none"),[Ye,ye,Mt]),Bt=Mt?"all":Ct?"some":"none",Fn=x.useCallback(N=>{ve(B=>{const M=new Set(B);return Ye.forEach(H=>{(we.get(H.zoneCode)??[]).forEach(se=>N?M.add(se):M.delete(se))}),M})},[Ye,we]),Kt=x.useMemo(()=>!qe||qe.cities.length===0?!1:qe.cities.every(N=>We(N)==="all"),[qe,We]),nr=x.useMemo(()=>Kt||!qe?!1:qe.cities.some(N=>We(N)!=="none"),[qe,We,Kt]),is=Kt?"all":nr?"some":"none",jr=x.useCallback(N=>{qe&&ve(B=>{const M=new Set(B);return qe.cities.forEach(H=>{H.pincodes.forEach(pe=>N?M.add(pe):M.delete(pe))}),M})},[qe]),St=x.useMemo(()=>!nt||nt.pincodes.length===0?!1:nt.pincodes.every(N=>me.has(N)),[nt,me]),rr=x.useMemo(()=>St||!nt?!1:nt.pincodes.some(N=>me.has(N)),[nt,me,St]),ot=St?"all":rr?"some":"none",yt=x.useCallback(N=>{nt&&ve(B=>{const M=new Set(B);return nt.pincodes.forEach(H=>N?M.add(H):M.delete(H)),M})},[nt]);if(m)return n.jsxs("div",{className:"flex flex-col items-center justify-center p-16 gap-3 text-slate-500",children:[n.jsx(un,{className:"w-8 h-8 animate-spin text-blue-500"}),n.jsx("span",{className:"text-sm",children:"Loading pincode data…"})]});if(A)return n.jsxs("div",{className:"p-4 bg-red-50 border border-red-200 rounded-xl flex items-center gap-3 text-red-700",children:[n.jsx(bi,{className:"w-5 h-5 flex-shrink-0"}),n.jsx("span",{className:"text-sm",children:A})]});const R=me.size;return n.jsxs("div",{className:"w-full space-y-3",children:[n.jsx("div",{className:"sticky top-0 z-20 bg-white/95 backdrop-blur-sm border border-slate-200 rounded-xl px-4 py-3 shadow-sm",children:n.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[n.jsxs("div",{className:"relative flex-1 min-w-40",ref:It,children:[n.jsx(gi,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 w-4 h-4
56                               text-slate-400 pointer-events-none`}),n.jsx("input",{type:"text",value:G,onChange:N=>{const B=N.target.value,M=B.length===0?"":/\d/.test(B[0])?B.replace(/\D/g,"").slice(0,6):B.replace(/[^a-zA-Z]/g,"").slice(0,25);ue(M),Rt(!0)},onFocus:()=>Rt(!0),maxLength:25,placeholder:"Search city, state or pincode…",className:`w-full pl-9 pr-7 py-1.5 text-sm border border-slate-200 rounded-lg
57                         focus:border-blue-400 focus:ring-1 focus:ring-blue-400 outline-none
58                         bg-slate-50 focus:bg-white transition-colors`}),G&&n.jsx("button",{type:"button",onClick:()=>{ue(""),Rt(!1)},className:"absolute right-2 top-1/2 -translate-y-1/2",children:n.jsx(Sr,{className:"w-3.5 h-3.5 text-slate-400 hover:text-slate-600"})}),He&&G.trim()&&mt.length>0&&n.jsx("div",{className:`absolute left-0 right-0 top-full mt-1 bg-white border border-slate-200
59                              rounded-lg shadow-lg z-30 max-h-64 overflow-y-auto`,children:mt.map(N=>n.jsxs("button",{type:"button",onClick:()=>Ke(N),className:`w-full flex items-center justify-between gap-3 px-3 py-2 text-left
60                               hover:bg-blue-50 transition-colors border-b border-slate-100 last:border-b-0`,children:[n.jsx("span",{className:"text-sm font-medium text-slate-700 truncate",children:N.label}),n.jsx("span",{className:"text-xs text-slate-400 whitespace-nowrap",children:N.sublabel})]},N.key))}),He&&G.trim()&&mt.length===0&&n.jsx("div",{className:`absolute left-0 right-0 top-full mt-1 bg-white border border-slate-200
61                              rounded-lg shadow-lg z-30 px-3 py-2 text-sm text-slate-400`,children:"No matching pincode, city or state found."})]}),n.jsxs("div",{className:"flex items-center gap-2 min-w-fit ml-auto",children:[n.jsx(P0,{className:"w-4 h-4 text-blue-500 flex-shrink-0"}),n.jsx("span",{className:"text-xl font-bold text-blue-600 tabular-nums",children:R.toLocaleStr
61ing()}),n.jsx("span",{className:"text-sm text-slate-500",children:"pincodes selected"}),R>0&&n.jsxs("button",{type:"button",onClick:()=>ve(new Set),className:`ml-1 text-xs text-slate-400 hover:text-red-500 transition-colors
62                           flex items-center gap-0.5`,children:[n.jsx(Sr,{className:"w-3 h-3"}),"clear all"]})]}),n.jsxs("button",{type:"button",onClick:Un,disabled:R===0,className:`px-4 py-2 bg-blue-600 text-white text-sm font-semibold
63                       rounded-lg hover:bg-blue-700 active:bg-blue-800 transition-colors
64                       disabled:bg-slate-200 disabled:text-slate-400 disabled:cursor-not-allowed
65                       flex items-center gap-2 whitespace-nowrap shadow-sm`,children:[n.jsx(wr,{className:"w-4 h-4"}),"Apply Selection"]})]})}),n.jsxs("div",{className:"flex items-center gap-2 pb-2 overflow-x-auto no-scrollbar mask-linear-fade",children:[n.jsx("button",{type:"button",onClick:()=>he("All"),className:`px-3 py-1 text-xs font-semibold rounded-full border transition-all whitespace-nowrap
66                ${V==="All"?"bg-slate-800 text-white border-slate-800 shadow-md":"bg-white text-slate-600 border-slate-200 hover:border-slate-400 hover:bg-slate-50"}`,children:"All Zones"}),["North","South","East","West","Central","Northeast","Special"].map(N=>n.jsx("button",{type:"button",onClick:()=>he(N),className:`px-3 py-1 text-xs font-semibold rounded-full border transition-all whitespace-nowrap
67                    ${V===N?"bg-blue-600 text-white border-blue-600 shadow-md":"bg-white text-slate-600 border-slate-200 hover:border-blue-300 hover:bg-blue-50"}`,children:N},N))]}),n.jsxs("div",{className:"flex flex-col lg:grid lg:grid-cols-3 gap-4 lg:h-[600px] w-full",children:[n.jsxs("div",{className:"bg-white border border-slate-200 rounded-xl flex flex-col overflow-hidden shadow-sm h-[380px] lg:h-full",children:[n.jsxs("div",{className:"px-3.5 py-3 bg-slate-50 border-b border-slate-200 flex items-center justify-between shrink-0",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(fi,{state:Bt,onClick:()=>Fn(Bt!=="all")}),n.jsxs("span",{className:"text-xs font-bold text-slate-700 uppercase tracking-wider",children:["Zones (",Ye.length,")"]})]}),n.jsx("span",{className:"text-[10px] bg-slate-200 text-slate-700 font-semibold px-2 py-0.5 rounded-full shrink-0",children:V})]}),n.jsx("div",{className:"flex-1 overflow-y-auto divide-y divide-slate-100",children:Ye.length===0?n.jsxs("div",{className:"text-center py-14 text-slate-400",children:[n.jsx($l,{className:"w-8 h-8 mx-auto mb-3 opacity-30"}),n.jsx("p",{className:"text-sm",children:"No zones found"})]}):Ye.map(N=>{const B=L===N.zoneCode,M=ye(N.zoneCode),H=we.get(N.zoneCode)?.filter(se=>me.has(se)).length||0,pe=we.get(N.zoneCode)?.length||0;return n.jsxs("div",{onClick:()=>ce(N.zoneCode),className:`flex items-center justify-between px-3.5 py-3 cursor-pointer transition-all
68                      ${M!=="none"?`bg-blue-100/70 hover:bg-blue-100 ${B?"border-r-2 border-blue-600":""}`:B?"bg-blue-50/40 border-r-2 border-blue-600":"hover:bg-slate-50/80"}`,children:[n.jsxs("div",{className:"flex items-center gap-2.5 min-w-0",children:[n.jsx(fi,{state:M,onClick:se=>{se.stopPropagation(),Vt(N.zoneCode,M!=="all")}}),n.jsxs("div",{className:"flex flex-col min-w-0",children:[n.jsxs("div",{className:"flex items-baseline gap-1.5",children:[n.jsx("span",{className:"text-sm font-extrabold text-slate-800 shrink-0",children:N.zoneCode}),N.description&&n.jsx("span",{className:"text-xs text-slate-400 font-medium truncate max-w-[120px]",children:N.description})]}),n.jsxs("span",{className:"text-[10px] text-slate-400 font-medium",children:[N.cities.length," Cities • ",pe," Pincodes"]})]})]}),n.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[H>0&&n.jsx("span",{className:`text-[10px] font-bold px-1.5 py-0.5 rounded-full ${H===pe?"bg-emerald-100 text-emerald-800":"bg-blue-100 text-blue-800"}`,children:H}),n.jsx(Cr,{className:`w-4 h-4 transition-transform ${B?"text-blue-500 translate-x-0.5":"text-slate-300"}`})]})]},N.zoneCode)})})]}),n.jsxs("div",{className:"bg-white border border-slate-200 rounded-xl flex flex-col overflow-hidden shadow-sm h-[380px] lg:h-full",children:[n.jsxs("div",{className:"px-3.5 py-3 bg-slate-50 border-b border-slate-200 flex flex-col gap-2 shrink-0",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(fi,{state:is,onClick:()=>jr(is!=="all")}),n.jsxs("span",{className:"text-xs font-bold text-slate-700 uppercase tracking-wider",children:["Cities (",qe?.cities.length||0,")"]})]}),L&&n.jsxs("span",{className:"text-[10px] bg-blue-50 text-blue-700 font-extrabold px-2 py-0.5 rounded-md shrink-0",children:["Zone ",L]})]}),n.jsxs("div",{className:"relative",children:[n.jsx(gi,{className:"absolute left-2.5 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-slate-400"}),n.jsx("input",{type:"text",placeholder:"Search cities in this zone...",value:re,onChange:N=>I(N.target.value.replace(/[^a-zA-Z]/g,"").slice(0,25)),maxLength:25,className:"w-full pl-8 pr-6 py-1 text-xs border border-slate-200 rounded-md bg-white focus:outline-none focus:border-blue-400 focus:ring-1 focus:ring-blue-400"}),re&&n.jsx("button",{type:"button",onClick:()=>I(""),className:"absolute right-2 top-1/2 -translate-y-1/2",children:n.jsx(Sr,{className:"w-3 h-3 text-slate-400 hover:text-slate-600"})})]})]}),n.jsx("div",{className:"flex-1 overflow-y-auto divide-y divide-slate-100",children:qe?yn.length===0?n.jsx("div",{className:"text-center py-12 text-slate-400 text-xs",children:"No matching cities found"}):yn.map(N=>{const B=fe===N.cityKey,M=We(N),H=N.pincodes.filter(se=>me.has(se)).length,pe=N.pincodes.length;return n.jsxs("div",{onClick:()=>Ae(N.cityKey),className:`flex items-center justify-between px-3.5 py-2.5 cursor-pointer transition-all
69                      ${M!=="none"?`bg-blue-100/70 hover:bg-blue-100 ${B?"border-r-2 border-blue-600":""}`:B?"bg-blue-50/40 border-r-2 border-blue-600":"hover:bg-slate-50/80"}`,children:[n.jsxs("div",{className:"flex items-center gap-2.5 min-w-0",children:[n.jsx(fi,{state:M,size:"sm",onClick:se=>{se.stopPropagation(),Dn(N,M!=="all")}}),n.jsxs("div",{className:"flex flex-col min-w-0",children:[n.jsx("span",{className:"text-sm font-semibold text-slate-700 truncate",children:N.city}),n.jsxs("span",{className:"text-[10px] text-slate-400 truncate",children:[N.state," • ",pe," Pincodes"]})]})]}),n.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[H>0&&n.jsx("span",{className:`text-[10px] font-bold px-1.5 py-0.5 rounded-full ${H===pe?"bg-emerald-100 text-emerald-800":"bg-blue-100 text-blue-800"}`,children:H}),n.jsx(Cr,{className:`w-3.5 h-3.5 transition-transform ${B?"text-blue-500 translate-x-0.5":"text-slate-300"}`})]})]},N.cityKey)}):n.jsx("div",{className:"text-center py-12 text-slate-400 text-xs",children:"Select a zone to view cities"})})]}),n.jsxs("div",{className:"bg-slate-50/40 border border-slate-200 rounded-xl flex flex-col overflow-hidden shadow-sm h-[380px] lg:h-full",children:[n.jsxs("div",{className:"px-3.5 py-3 bg-slate-50 border-b border-slate-200 flex flex-col gap-2 shrink-0",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(fi,{state:ot,onClick:()=>yt(ot!=="all")}),n.jsxs("span",{className:"text-xs font-bold text-slate-700 uppercase tracking-wider",children:["Pincodes (",nt?.pincodes.length||0,")"]})]}),nt&&n.jsx("span",{className:"text-[10px] bg-slate-200 text-slate-700 font-bold px-2 py-0.5 rounded-md truncate max-w-[120px] shrink-0",children:nt.city})]}),n.jsxs("div",{className:"relative",children:[n.jsx(gi,{className:"absolute left-2.5 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-slate-400"}),n.jsx("input",{type:"text",placeholder:"Filter pincodes...",value:Ne,onChange:N=>ge(N.target.value.replace(/\D/g,"").slice(0,6)),inputMode:"numeric",maxLength:6,className:"w-full pl-8 pr-6 py-1 text-xs border border-slate-200 rounded-md bg-white focus:outline-none focus:border-blue-400 focus:ring-1 focus:ring-blue-400"}),Ne&&n.jsx("button",{type:"button",onClick:()=>ge(""),className:"absolute right-2 top-1/2 -translate-y-1/2",children:n.jsx(Sr,{className:"w-3 h-3 text-slate-400 hover:text-slate-600"})})]})]}),n.jsx("div",{className:"flex-1 overflow-y-auto p-3.5",children:nt?ut.length===0?n.jsx("div",{className:"text-center py-12 text-slate-400 text-xs",children:"No pincodes match the filter"}):n.jsxs("div",{className:"flex flex-col gap-3",children:[n.jsx("div",{className:"flex flex-wrap gap-1.5 shrink-0",children:n.jsx("button",{type:"button",onClick:()=>yt(ot!=="all"),className:`text-xs font-bold px-3 py-1.5 rounded-lg border transition-all flex items-center gap-1.5 shadow-sm select-none
70                      ${ot==="all"?"bg-blue-100 border-blue-300 text-blue-800 hover:bg-blue-200":"bg-white border-blue-200 text-blue-600 hover:bg-blue-50"}`,children:ot==="all"?n.jsxs(n.Fragment,{children:[n.jsx(Sr,{className:"w-3.5 h-3.5 text-blue-600"}),"Deselect All Pincodes"]}):n.jsxs(n.Fragment,{children:[n.jsx(wr,{className:"w-3.5 h-3.5 text-blue-600 fill-blue-50"}),"Select All Pincodes"]})})}),n.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-1.5",children:ut.map(N=>{const B=me.has(N);return n.jsxs("button",{type:"button",onClick:()=>xt(N),className:`text-xs font-semibold py-2 rounded-lg border transition-all text-center flex items-center justify-between px-3.5 shadow-sm select-none
71                          ${B?"bg-blue-600 border-blue-600 text-white font-extrabold ring-1 ring-blue-600":"bg-white border-slate-200 text-slate-700 hover:border-blue-400 hover:text-blue-600 hover:bg-blue-50/20"}`,children:[n.jsx("span",{children:N}),B&&n.jsx(wr,{className:"w-3 h-3 text-white fill-white/10 shrink-0"})]},N)})})]}):n.jsx("div",{className:"text-center py-12 text-slate-400 text-xs",children:"Select a city to view pincodes"})})]})]})]})},lx=({logs:d})=>!(typeof window<"u"&&localStorage.getItem("debug")==="1")||!d||d.length===0?null:n.jsxs("div",{className:"fixed bottom-4 right-4 z-50 bg-black/90 text-white p-4 rounded-lg shadow-xl max-w-sm max-h-80 overflow-y-auto text-xs font-mono backdrop-blur-md border border-slate-700",children:[n.jsx("div",{className:"flex justify-between items-center mb-2 border-b border-slate-700 pb-2 sticky top-0 bg-black/90",children:n.jsxs("span",{className:"font-bold text-blue-400",children:["Debug Stream (",d.length,")"]})}),n.jsx("div",{className:"flex flex-col gap-1.5",children:d.slice().reverse().map((s,f)=>n.jsxs("div",{className:"break-words border-l-2 border-slate-700 pl-2",children:[n.jsx("span",{className:"text-slate-500 text-[10px] mr-2",children:d.length-f}),n.jsx("span",{className:s.includes("ERROR")?"text-red-400":"text-slate-300",children:s})]},f))})]}),hu=d=>{if(d==null||d==="")return null;let l=String(d).trim();if(l.includes("e")||l.includes("E"))try{const f=parseFloat(l);!isNaN(f)&&isFinite(f)&&(l=Math.round(f).toString())}catch{}if(l.includes(".")){const f=parseFloat(l);!isNaN(f)&&isFinite(f)&&(l=Math.round(f).toString())}const s=l.replace(/[^0-9]/g,"");if(s.length===6&&/^[1-8]/.test(s))return s;if(s.length>6){const f=s.slice(0,6);if(/^[1-8]/.test(f))return f}return null},cx=d=>
71{if(d==null||d==="")return!1;const l=String(d).toLowerCase().trim();return["true","yes","1","y","oda","remote"].includes(l)},dx=d=>{const s=[...d].sort((m,g)=>m.pincode.localeCompare(g.pincode)).map(m=>`${m.pincode}:${m.zone}:${m.isODA}`).join("|");let f=0;for(let m=0;m<s.length;m++){const g=s.charCodeAt(m);f=(f<<5)-f+g,f=f&f}return Math.abs(f).toString(16).padStart(8,"0")},ux=d=>{const l=[],s=d[0]?.length||0;for(let g=0;g<s;g++){let A=0;const O=Math.min(100,d.length);for(let U=0;U<O;U++){const k=d[U]?.[g];hu(k)!==null&&A++}l[g]=A/O}let f=0,m=0;for(let g=0;g<l.length;g++)l[g]>m&&(m=l[g],f=g);return m>.3?f:-1},fx=(d,l)=>{for(let m=0;m<d.length;m++)if((d[m]||"").toLowerCase()==="isoda")return m;const s=["true","false","yes","no","1","0","y","n"],f=l[0]?.length||0;for(let m=0;m<f;m++){let g=0;const A=Math.min(50,l.length);for(let O=0;O<A;O++){const U=String(l[O]?.[m]||"").toLowerCase().trim();s.includes(U)&&g++}if(g/A>.7)return m}return-1},mx=d=>{if(!d||d.length===0)return!1;const l=["pincode","pin","postal","zip","code","oda","remote","zone","state","city"];let s=0;for(const f of d){const m=String(f||"").toLowerCase();(l.some(g=>m.includes(g))||/^[a-z\s]+$/i.test(m))&&s++}return s/d.length>.3},hx=d=>d.startsWith("NE")?"Northeast":d.startsWith("N")?"North":d.startsWith("S")?"South":d.startsWith("E")?"East":d.startsWith("W")?"West":d.startsWith("C")?"Central":d.startsWith("X")?"Special":"Other",Jd=[".pdf",".docx",".doc"],px=({onServiceabilityReady:d,onError:l,onDocumentFile:s,onFileCaptured:f})=>{const[m,g]=x.useState(null),[A,O]=x.useState(!1),[U,k]=x.useState(!1),[z,E]=x.useState(!0),[me,ve]=x.useState(new Map),[q,ee]=x.useState(null),[de,Y]=x.useState(!1),le=
71x.useRef(null);x.useEffect(()=>{(async()=>{try{const ge=await fetch("/pincodes.json");if(!ge.ok)throw new Error(`Failed to load blueprint: ${ge.status}`);const we=await ge.json();if(!Array.isArray(we))throw new Error("Invalid blueprint format");const ye=new Map;for(const We of we)We.pincode&&We.zone&&ye.set(String(We.pincode),We);ve(ye),console.log(`[ServiceabilityUpload] Loaded ${ye.size} pincodes from blueprint`)}catch(Ne){console.error("[ServiceabilityUpload] Failed to load blueprint:",Ne),ie.error("Failed to load pincode database. Please refresh the page."),l?.(["Failed to load pincode database"])}finally{E(!1)}})()},[l]);const J=I=>{I.preventDefault(),I.stopPropagation(),O(!0)},G=I=>{I.preventDefault(),I.stopPropagation(),O(!1)},ue=I=>{I.preventDefault(),I.stopPropagation()},V=async I=>{I.preventDefault(),I.stopPropagation(),O(!1);const Ne=Array.from(I.dataTransfer.files);if(!Ne.length)return;const ge=Ne.reduce((we,ye)=>we+ye.size,0);if(ge>10*1024*1024){ie.error(`Total size ${(ge/1024/1024).toFixed(1)} MB exceeds the 10 MB limit`);return}for(const we of Ne)await L(we)},he=async I=>{const Ne=Array.from(I.target.files||[]);if(!Ne.length)return;const ge=Ne.reduce((we,ye)=>we+ye.size,0);if(ge>10*1024*1024){ie.error(`Total size ${(ge/1024/1024).toFixed(1)} MB exceeds the 10 MB limit`),I.target.value="";return}for(const we of Ne)await L(we);I.target.value=""},L=async I=>{f?.(I);const Ne="."+I.name.split(".").pop()?.toLowerCase();if(Jd.includes(Ne)){if(!s){ie.error("PDF/Word upload is not available here. Please use a CSV or Excel file.");return}g(I),k(!0),ee(null);try{await s(I)}finally{k(!1)}return}if(me.size===0){ie.error("Pincode database not loaded. Please wait and try again.");return}if(![".csv",".xlsx",".xls",".xlsm",".txt",".tsv"].includes(Ne)){ie.error("Please upload a CSV, Excel, PDF, or Word file");return}g(I),k(!0),ee(null);try{const we=await ce(I),ye=fe(we);if(ee(ye),ye.valid.length===0)ie.error("No valid pincodes found in file"),l?.(["No valid pincodes found"]);else{const We=`Processed ${ye.valid.length} valid pincodes across ${ye.zoneSummary.length} zones`;ye.invalid.length>0?ie(`${We}. ${ye.invalid.length} invalid entries excluded.`,{icon:"⚠️",duration:5e3}):ie.success(We,{duration:4e3}),d({serviceability:ye.valid,zoneSummary:ye.zoneSummary,checksum:ye.checksum,source:"excel",rawRows:we})}}catch(we){console.error("[ServiceabilityUpload] Processing error:",we),ie.error(we.message||"Failed to process file"),l?.([we.message||"Processing failed"])}finally{k(!1)}},ce=I=>new Promise((Ne,ge)=>{const we=new FileReader;we.onload=ye=>{try{const We=ye.target?.result,Vt=Ul(We,{type:"binary",cellText:!1,cellDates:!0}),Dn=Vt.Sheets[Vt.SheetNames[0]],xt=Wl.sheet_to_json(Dn,{header:1,raw:!0,defval:""});Ne(xt)}catch{ge(new Error("Failed to parse file. Please check the format."))}},we.onerror=()=>ge(new Error("Failed to read file")),we.readAsBinaryString(I)}),fe=I=>{const Ne=[],ge=[],we=[],ye=new Set;if(!I||I.length===0)throw new Error("File is empty");const We=I.filter(ut=>ut&&ut.some(He=>He!=null&&String(He).trim()));if(We.length===0)throw new Error("No data found in file");const Vt=mx(We[0]),Dn=Vt?We[0].map((ut,He)=>String(ut||`Col${He+1}`)):We[0].map((ut,He)=>`Col${He+1}`),xt=Vt?We.slice(1):We;if(xt.length===0)throw new Error("No data rows found (only header?)");const Un=ux(xt);if(Un===-1)throw new Error(`Could not detect pincode column.
72Ensure your file contains a column with 6-digit Indian pincodes.
73Example: 110001, 400001, 560001`);const Ye=fx(Dn,xt);console.log("[ServiceabilityUpload] Column detection:",{pincodeCol:Un,odaCol:Ye,hasHeader:Vt,totalRows:xt.length});for(let ut=0;ut<xt.length;ut++){const He=xt[ut],Rt=Vt?ut+2:ut+1;if(!He||He.every(Bt=>Bt==null||String(Bt).trim()===""))continue;const It=He[Un],mt=Ye>=0?He[Ye]:void 0,Ke=hu(It);if(!Ke){ge.push({row:Rt,pincode:String(It||""),reason:"Invalid pincode format (must be 6 digits)"});continue}if(ye.has(Ke)){we.push({row:Rt,pincode:Ke});continue}ye.add(Ke);const Mt=me.get(Ke);if(!Mt){ge.push({row:Rt,pincode:Ke,reason:"Pincode not found in database (not serviceable)"});continue}const Ct={pincode:Ke,zone:Mt.zone,state:Mt.state,city:Mt.city,isODA:cx(mt),active:!0};Ne.push(Ct)}const qe=new Map;for(const ut of Ne)qe.has(ut.zone)||qe.set(ut.zone,{entries:[]}),qe.get(ut.zone).entries.push(ut);const nt=[];for(const[ut,He]of qe.entries()){const Rt=[...new Set(He.entries.map(Ke=>Ke.state))],It=[...new Set(He.entries.map(Ke=>Ke.city))],mt=He.entries.filter(Ke=>Ke.isODA).length;nt.push({zoneCode:ut,region:hx(ut),pincodeCount:He.entries.length,states:Rt,cities:It,odaCount:mt})}nt.sort((ut,He)=>ut.zoneCode.localeCompare(He.zoneCode));const yn=dx(Ne);return{valid:Ne,invalid:ge,duplicates:we,zoneSummary:nt,checksum:yn}},Ae=()=>{const I=`pincode,isOda
74110001,false
75110002,false
76110003,false
77400001,false
78400002,true
79560001,false
80700001,false
81226001,false
82302001,false
83
84Notes:
85- Only "pincode" column is required
86- isOda is optional (true/false, yes/no, 1/0)
87- Zone, state, city are auto-assigned from our database
88- Pincodes not in our database will be rejected`,Ne=new Blob([I],{type:"text/csv"}),ge=document.createElement("a");ge.href=URL.createObjectURL(Ne),ge.download="serviceability_template.csv",ge.click(),URL.revokeObjectURL(ge.href),ie.success("Template downloaded")},re=()=>{g(null),ee(null),le.current&&(le.current.value="")};return z?n.jsx("div",{className:"p-6 rounded-xl border border-slate-200 bg-white",children:n.jsxs("div",{className:"flex items-center justify-center gap-3 py-8",children:[n.jsx(un,{className:"w-5 h-5 animate-spin text-blue-600"}),n.jsx("span",{className:"text-slate-600",children:"Loading pincode database..."})]})}):n.jsxs("div",{className:"space-y-4",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{children:[n.jsx("h3",{className:"text-lg font-semibold text-slate-900",children:"Upload Serviceability"}),n.jsxs("p",{className:"text-sm text-slate-500 mt-0.5",children:["Upload your pincode list. Zones are auto-assigned from our database.",s&&" PDF/Word files are read with AI extraction."]})]}),n.jsxs("button",{onClick:Ae,className:"inline-flex items-center gap-2 px-4 py-2.5 text-sm font-semibold text-white bg-green-600 hover:bg-green-700 rounded-xl transition-colors shadow-sm",children:[n.jsx(Vl,{className:"w-4 h-4"}),"Download Sample Template"]})]}),n.jsxs("div",{className:`
89          relative rounded-xl border-2 border-dashed p-8 text-center transition-all
90          ${A?"border-blue-400 bg-blue-50":m?"border-green-300 bg-green-50":"border-slate-300 bg-slate-50 hover:border-blue-300 hover:bg-blue-50"}
91        `,onDragEnter:J,onDragLeave:G,onDragOver:ue,onDrop:V,children:[n.jsx("input",{ref:le,type:"file",accept:s?".csv,.xlsx,.xls,.xlsm,.txt,.tsv,.pdf,.docx,.doc":".csv,.xlsx,.xls,.xlsm,.txt,.tsv",multiple:!0,onChange:he,className:"absolute inset-0 w-full h-full opacity-0 cursor-pointer"}),U?n.jsxs("div",{className:"flex flex-col items-center gap-3",children:[n.jsx(un,{className:"w-10 h-10 text-blue-600 animate-spin"}),n.jsx("p",{className:"text-slate-600 font-medium",children:m&&Jd.includes("."+(m.name.split(".").pop()?.toLowerCase()??""))?"Analysing with AI — this can take up to 2 minutes...":"Processing file..."})]}):m?n.jsxs("div",{className:"flex flex-col items-center gap-3",children:[n.jsx(po,{className:"w-10 h-10 text-green-600"}),n.jsxs("div",{children:[n.jsx("p",{className:"font-medium text-green-900",children:m.name}),n.jsxs("p",{className:"text-sm text-green-600",children:[(m.size/1024).toFixed(1)," KB"]}
91)]}),n.jsxs("button",{onClick:I=>{I.stopPropagation(),re()},className:"mt-2 inline-flex items-center gap-1.5 px-3 py-1.5 text-sm text-red-600 hover:bg-red-100 rounded-lg transition-colors",children:[n.jsx(D0,{className:"w-4 h-4"}),"Remove"]})]}):n.jsxs("div",{className:"flex flex-col items-center gap-3",children:[n.jsx(ho,{className:"w-10 h-10 text-slate-400"}),n.jsxs("div",{children:[n.jsx("p",{className:"font-medium text-slate-700",children:"Drop your file here or click to browse"}),n.jsxs("p",{className:"text-sm text-slate-500 mt-1",children:["CSV, Excel (.xlsx, .xls)",s?", PDF, Word":""]})]})]})]}),n.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:[n.jsxs("div",{className:"flex items-start gap-3 p-4 rounded-lg bg-blue-50 border border-blue-100",children:[n.jsx(du,{className:"w-5 h-5 text-blue-600 flex-shrink-0 mt-0.5"}),n.jsxs("div",{className:"text-sm text-blue-800",children:[n.jsx("p",{className:"font-medium",children:"How it works:"}),n.jsxs("ul",{className:"mt-1 space-y-0.5 text-blue-700",children:[n.jsx("li",{children:"• Your file should contain a column with 6-digit pincodes"}),n.jsx("li",{children:'• Optional: Include an "isOda" column (true/false)'}),n.jsx("li",{children:"• Zones, states, and cities are auto-assigned from our database"}),n.jsx("li",{children:"• Pincodes not in our database will be rejected"})]})]})]}),n.jsxs("div",{className:"p-4 rounded-lg bg-gradient-to-br from-emerald-50 to-green-50 border border-green-200",children:[n.jsxs("p",{className:"text-xs font-semibold text-green-800 mb-2 flex items-center gap-1.5",children:[n.jsx(po,{className:"w-3.5 h-3.5"}),"Sample Format"]}),n.jsx("div",{className:"bg-white rounded-lg border border-green-200 overflow-hidden shadow-sm",children:n.jsxs("table",{className:"w-full text-xs",children:[n.jsx("thead",{className:"bg-slate-100 border-b border-slate-200",children:n.jsxs("tr",{children:[n.jsx("th",{className:"px-3 py-1.5 text-left font-semibold text-slate-700",children:"pincode"}),n.jsx("th",{className:"px-3 py-1.5 text-left font-semibold text-slate-700",children:"isOda"})]})}),n.jsxs("tbody",{className:"divide-y divide-slate-100",children:[n.jsxs("tr",{className:"hover:bg-slate-50",children:[n.jsx("td",{className:"px-3 py-1.5 font-mono text-slate-900",children:"110001"}),n.jsx("td",{className:"px-3 py-1.5 text-slate-600",children:"FALSE"})]}),n.jsxs("tr",{className:"hover:bg-slate-50",children:[n.jsx("td",{className:"px-3 py-1.5 font-mono text-slate-900",children:"110002"}),n.jsx("td",{className:"px-3 py-1.5 text-slate-600",children:"FALSE"})]}),n.jsxs("tr",{className:"hover:bg-slate-50",children:[n.jsx("td",{className:"px-3 py-1.5 font-mono text-slate-900",children:"110003"}),n.jsx("td",{className:"px-3 py-1.5 text-slate-600",children:"FALSE"})]}),n.jsxs("tr",{className:"hover:bg-slate-50",children:[n.jsx("td",{className:"px-3 py-1.5 font-mono text-slate-900",children:"400001"}),n.jsx("td",{className:"px-3 py-1.5 text-slate-600",children:"FALSE"})]}),n.jsxs("tr",{className:"hover:bg-slate-50",children:[n.jsx("td",{className:"px-3 py-1.5 font-mono text-slate-900",children:"400002"}),n.jsx("td",{className:"px-3 py-1.5 text-slate-600 font-medium",children:"TRUE"})]}),n.jsxs("tr",{className:"hover:bg-slate-50",children:[n.jsx("td",{className:"px-3 py-1.5 font-mono text-slate-900",children:"560001"}),n.jsx("td",{className:"px-3 py-1.5 text-slate-600",children:"FALSE"})]}),n.jsxs("tr",{className:"hover:bg-slate-50",children:[n.jsx("td",{className:"px-3 py-1.5 font-mono text-slate-900",children:"700001"}),n.jsx("td",{className:"px-3 py-1.5 text-slate-600",children:"FALSE"})]}),n.jsxs("tr",{className:"hover:bg-slate-50",children:[n.jsx("td",{className:"px-3 py-1.5 font-mono text-slate-900",children:"226001"}),n.jsx("td",{className:"px-3 py-1.5 text-slate-600",children:"FALSE"})]}),n.jsxs("tr",{className:"hover:bg-slate-50",children:[n.jsx("td",{className:"px-3 py-1.5 font-mono text-slate-900",children:"302001"}),n.jsx("td",{className:"px-3 py-1.5 text-slate-600",children:"FALSE"})]}),n.jsxs("tr",{className:"hover:bg-slate-50",children:[n.jsx("td",{className:"px-3 py-1.5 font-mono text-slate-900",children:"110020"}),n.jsx("td",{className:"px-3 py-1.5 text-slate-600",children:"FALSE"})]})]})]})})]})]}),q&&n.jsxs("div",{className:"space-y-4",children:[n.jsx("div",{className:`
92            rounded-xl border-2 p-4
93            ${q.valid.length>0?"border-green-300 bg-green-50":"border-red-300 bg-red-50"}
94          `,children:n.jsxs("div",{className:"flex items-center gap-3",children:[q.valid.length>0?n.jsx(wr,{className:"w-6 h-6 text-green-600"}):n.jsx(F0,{className:"w-6 h-6 text-red-600"}),n.jsxs("div",{className:"flex-1",children:[n.jsx("p",{className:`font-semibold ${q.valid.length>0?"text-green-900":"text-red-900"}`,children:q.valid.length>0?`${q.valid.length} valid pincodes processed`:"No valid pincodes found"}),n.jsxs("p",{className:`text-sm ${q.valid.length>0?"text-green-700":"text-red-700"}
94`,children:[q.zoneSummary.length," zones •",q.invalid.length>0&&` ${q.invalid.length} invalid • `,q.duplicates.length>0&&` ${q.duplicates.length} duplicates`]})]}),n.jsx("button",{onClick:()=>Y(!de),className:"p-2 hover:bg-white/50 rounded-lg transition-colors",children:de?n.jsx(T0,{className:"w-5 h-5 text-slate-600"}):n.jsx(iu,{className:"w-5 h-5 text-slate-600"})})]})}),de&&n.jsxs("div",{className:"space-y-4",children:[q.zoneSummary.length>0&&n.jsxs("div",{className:"rounded-xl border border-slate-200 bg-white overflow-hidden",children:[n.jsx("div",{className:"px-4 py-3 bg-slate-50 border-b border-slate-200",children:n.jsx("h4",{className:"font-medium text-slate-900",children:"Zone Summary"})}),n.jsx("div",{className:"divide-y divide-slate-100",children:q.zoneSummary.map(I=>n.jsxs("div",{className:"px-4 py-3 flex items-center justify-between",children:[n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx("span",{className:"inline-flex items-center justify-center w-10 h-10 rounded-lg bg-blue-100 text-blue-700 font-semibold",children:I.zoneCode}),n.jsxs("div",{children:[n.jsx("p",{className:"font-medium text-slate-900",children:I.region}),n.jsxs("p",{className:"text-sm text-slate-500",children:[I.states.slice(0,3).join(", "),I.states.length>3&&` +${I.states.length-3} more`]})]})]}),n.jsxs("div",{className:"text-right",children:[n.jsxs("p",{className:"font-medium text-slate-900",children:[I.pincodeCount," pincodes"]}),I.odaCount>0&&n.jsxs("p",{className:"text-sm text-orange-600",children:[I.odaCount," ODA"]})]})]},I.zoneCode))})]}),q.invalid.length>0&&n.jsxs("div",{className:"rounded-xl border border-red-200 bg-red-50 overflow-hidden",children:[n.jsx("div",{className:"px-4 py-3 bg-red-100 border-b border-red-200",children:n.jsxs("h4",{className:"font-medium text-red-900 flex items-center gap-2",children:[n.jsx(Fa,{className:"w-4 h-4"}),"Invalid Entries (",q.invalid.length,")"]})}),n.jsxs("div",{className:"max-h-48 overflow-y-auto",children:[n.jsxs("table",{className:"w-full text-sm",children:[n.jsx("thead",{className:"bg-red-100/50",children:n.jsxs("tr",{children:[n.jsx("th",{className:"px-4 py-2 text-left font-medium text-red-800",children:"Row"}),n.jsx("th",{className:"px-4 py-2 text-left font-medium text-red-800",children:"Pincode"}),n.jsx("th",{className:"px-4 py-2 text-left font-medium text-red-800",children:"Reason"})]})}),n.jsx("tbody",{className:"divide-y divide-red-100",children:q.invalid.slice(0,50).map((I,Ne)=>n.jsxs("tr",{className:"hover:bg-red-100/30",children:[n.jsx("td",{className:"px-4 py-2 text-red-700",children:I.row}),n.jsx("td",{className:"px-4 py-2 font-mono text-red-900",children:I.pincode}),n.jsx("td",{className:"px-4 py-2 text-red-700",children:I.reason})]},Ne))})]}),q.invalid.length>50&&n.jsxs("div",{className:"px-4 py-2 text-sm text-red-600 bg-red-100/50",children:["... and ",q.invalid.length-50," more"]})]})]}),q.valid.length>0&&n.jsxs("div",{className:"flex items-center justify-between px-4 py-3 rounded-lg bg-slate-100 text-sm",children:[n.jsx("span",{className:"text-slate-600",children:"Checksum:"}),n.jsx("code",{className:"font-mono text-slate-700",children:q.checksum})]})]})]})]})};function gx({targetRef:d,when:l,offset:s=80,containerRef:f}){return x.useEffect(()=>{const m=d.current;if(!m)return;const g=f?.current,A=requestAnimationFrame(()=>{if(g){const U=m.getBoundingClientRect().top-g.getBoundingClientRect().top+g.scrollTop-s;g.scrollTo({top:U,behavior:"smooth"})}else{const O=m.getBoundingClientRect().top+window.pageYOffset-s;window.scrollTo({top:O,behavior:"smooth"})}});return()=>cancelAnimationFrame(A)},[l,d,s,f]),null}const xx=({drafts:d,loading:l,onClose:s,onContinue:f,onDelete:m})=>n.jsxs("div",{className:"w-full h-fit bg-white rounded-2xl border border-slate-200/80 shadow-2xl flex flex-col overflow-hidden",children:[n.jsxs("div",{className:"px-4 py-3 bg-slate-800 flex items-center justify-between shrink-0",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(Kl,{className:"w-4 h-4 text-white"}),n.jsx("span",{className:"text-sm font-extrabold text-white",children:"Drafts"}),d.length>0&&n.jsx("span",{className:"text-[10px] font-bold text-white bg-white/15 border border-white/20 rounded-full px-2 py-0.5",children:d.length})]}),n.jsx("button",{type:"button",onClick:s,className:"text-slate-300 hover:text-white transition-colors","aria-label":"Close drafts panel",children:n.jsx(Sr,{className:"w-4 h-4"})})]}),n.jsx("div",{className:"flex flex-col divide-y divide-slate-100 max-h-[60vh] overflow-y-auto",children:l&&d.length===0?n.jsxs("div",{className:"py-6 px-4 flex items-center justify-center gap-2 text-xs font-semibold text-slate-400",children:[n.jsx(un,{className:"w-4 h-4 animate-spin"})," Loading drafts..."]}):d.length===0?n.jsx("div",{className:"py-6 px-4 text-center text-xs font-semibold text-slate-400",children:"No drafts saved yet"}):d.map(g=>n.jsxs("div",{className:"px-4 py-3 hover:bg-slate-50 transition-colors flex items-center gap-2 group/draft cursor-pointer",onClick:()=>f(g),children:[n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("p",{className:"text-sm font-semibold text-slate-800 truncate",children:g.draftName||"Unnamed Draft"}),n.jsxs("p",{className:"text-[11px] text-slate-400 mt-0.5",children:["Last saved ",new Date(g.updatedAt).toLocaleDateString()," at"," ",new Date(g.updatedAt).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})]})]}),n.jsx("button",{type:"button",onClick:A=>{A.stopPropagation(),m(g._id)},className:"p-1.5 rounded-lg text-slate-300 hover:text-red-500 hover:bg-red-50 transition-colors shrink-0",title:"Delete draft",children:n.jsx(Sr,{className:"w-3.5 h-3.5"})}),n.jsx(Cr,{className:"w-4 h-4 text-slate-300 group-hover/draft:text-blue-500 transition-colors shrink-0"})]},g._id))})]}),bx=({open:d,isSavingDraft:l,onSaveDraft:s,onDiscard:f,onCancel:m})=>d?n.jsx("div",{className:"fixed inset-0 z-[300] flex items-center justify-center bg-black/50 backdrop-blur-sm",onClick:g=>{g.target===g.currentTarget&&m()},children:n.jsxs("div",{className:"bg-white rounded-2xl shadow-2xl w-full max-w-sm mx-4 overflow-hidden animate-in fade-in zoom-in-95 duration-150",children:[n.jsxs("div",{className:"flex items-start gap-3 p-5 border-b border-slate-100",children:[n.jsx("div",{className:"p-2 bg-amber-100 rounded-xl shrink-0 mt-0.5",children:n.jsx(Fa,{className:"w-5 h-5 text-amber-600"})}),n.jsxs("div",{className:"flex-1",children:[n.jsx("h2",{className:"text-base font-bold text-slate-900",children:"Unsaved Progress"}),n.jsx("p",{className:"text-sm text-slate-500 mt-1 leading-relaxed",children:"You have unsaved changes to this vendor. What would you like to do?"})]}),n.jsx("button",{type:"button",onClick:m,className:"p-1 rounded-lg text-slate-400 hover:text-slate-600 hover:bg-slate-100 transition-colors shrink-0",children:n.jsx(Sr,{className:"w-4 h-4"})})]}),n.jsxs("div",{className:"flex flex-col gap-2 p-4",children:[n.jsx("button",{type:"button",onClick:s,disabled:l,className:"w-full py-2.5 rounded-xl bg-blue-600 hover:bg-blue-700 active:scale-[0.98] text-white font-semibold text-sm transition-all flex items-center justify-center gap-2 disabled:opacity-60 disabled:cursor-not-allowed shadow-sm",children:l?n.jsxs(n.Fragment,{children:[n.jsx(un,{className:"w-4 h-4 animate-spin"})," Saving draft..."]}):n.jsxs(n.Fragment,{children:[n.jsx(Kl,{className:"w-4 h-4"})," Save as Draft"]})}),n.jsx("button",{type:"button",onClick:f,className:"w-full py-2.5 rounded-xl bg-red-50 hover:bg-red-100 active:scale-[0.98] text-red-600 font-semibold text-sm transition-all border border-red-200",children:"Discard & Leave"}),n.jsx("button",{type:"button",onClick:m,className:"w-full py-2 rounded-xl text-slate-500 hover:text-slate-800 hover:bg-slate-50 font-medium text-sm transition-colors",children:"Cancel — Keep Editing"})]})]})}):null;var hi={exports:{}};/**
95 * @license
96 * Lodash <https://lodash.com/>
97 * Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
98 * Released under MIT license <https://lodash.com/license>
99 * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
100 * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
101 */var vx=hi.exports,Yd;function yx(){return Yd||(Yd=1,(function(d,l){(function(){var s,f="4.17.21",m=200,g="Unsupported core-js use. Try https://npms.io/search?q=ponyfill.",A="Expected a function",O="Invalid `variable` option passed into `_.template`",U="__lodash_hash_undefined__",k=500,z="__lodash_placeholder__",E=1,me=2,ve=4,q=1,ee=2,de=1,Y=2,le=4,J=8,G=16,ue=32,V=64,he=128,L=256,ce=512,fe=30,Ae="...",re=800,I=16,Ne=1,ge=2,we=3,ye=1/0,We=9007199254740991,Vt=17976931348623157e292,Dn=NaN,xt=4294967295,Un=xt-1,Ye=xt>>>1,qe=[["ary",he],["bind",de],["bindKey",Y],["curry",J],["curryRight",G],["flip",ce],["partial",ue],["partialRight",V],["rearg",L]],nt="[object Arguments]",yn="[object Array]",ut="[object AsyncFunction]",He="[object Boolean]",Rt="[object Date]",It="[object DOMException]",mt="[object Error]",Ke="[object Function]",Mt="[object GeneratorFunction]",Ct="[object Map]",Bt="[object Number]",Fn="[object Null]",Kt="[object Object]",nr="[object Promise]",is="[object Proxy]",jr="[object RegExp]",St="[object Set]",rr="[object String]",ot="[object Symbol]",yt="[object Undefined]",R="[object WeakMap]",N="[object WeakSet]",B="[object ArrayBuffer]",M="[object DataView]",H="[object Float32Array]",pe="[object Float64Array]",se="[object Int8Array]",Ce="[object Int16Array]",Ie="[object Int32Array]",Qe="[object Uint8Array]",Nt="[object Uint8ClampedArray]",nn="[object Uint16Array]",Te="[object Uint32Array]",it=/\b__p \+= '';/g,Et=/\b(__p \+=) '' \+/g,Ot=/(__e\(.*?\)|\b__t\)) \+\n'';/g,Wn=/&(?:amp|lt|gt|quot|#39);/g,_s=/[&<>"']/g,Pt=RegExp(Wn.source),_r=RegExp(_s.source),kr=/<%-([\s\S]+?)%>/g,yi=/<%([\s\S]+?)%>/g,sr=/<%=([\s\S]+?)%>/g,ks=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,ht=/^\w*$/,Nn=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,rn=/[\\^$.*+?()[\]{}|]/g,ar=RegExp(rn.source),Ni=/^\s+/,$r=/\s/,ta=/\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/,Ta=/\{\n\/\* \[wrapped with (.+)\] \*/,Yl=/,? & /,As=/[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g,na=/[()=,{}\[\]\/\s]/,ra=/\\(\\)?/g,wi=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,sa=/\w*$/,os=/^[-+]0x[0-9a-f]+$/i,Es=/^0b[01]+$/i,Ur=/^\[object .+?Constructor\]$/,Ps=/^0o[0-7]+$/i,xo=/^(?:0|[1-9]\d*)$/,Ci=/[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u01
vendor: 12,907 bytes, line 101
1017f]/g,Ds=/($^)/,bo=/['\n\r\u2028\u2029\\]/g,Bn="\\ud800-\\udfff",vo="\\u0300-\\u036f",Ra="\\ufe20-\\ufe2f",aa="\\u20d0-\\u20ff",Si=vo+Ra+aa,Ia="\\u2700-\\u27bf",Fs="a-z\\xdf-\\xf6\\xf8-\\xff",ji="\\xac\\xb1\\xd7\\xf7",Ts="\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf",Ma="\\u2000-\\u206f",ia=" \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000",Ge="A-Z\\xc0-\\xd6\\xd8-\\xde",Ar="\\ufe0e\\ufe0f",ir=ji+Ts+Ma+ia,Oa="['’]",_i="["+Bn+"]",La="["+ir+"]",Rs="["+Si+"]",ki="\\d+",ls="["+Ia+"]",oa="["+Fs+"]",Lt="[^"+Bn+ir+ki+Ia+Fs+Ge+"]",Gt="\\ud83c[\\udffb-\\udfff]",Zt="(?:"+Rs+"|"+Gt+")",Tn="[^"+Bn+"]",cs="(?:\\ud83c[\\udde6-\\uddff]){2}",Is="[\\ud800-\\udbff][\\udc00-\\udfff]",ds="["+Ge+"]",za="\\u200d",Wr="(?:"+oa+"|"+Lt+")",Vn="(?:"+ds+"|"+Lt+")",Ms="(?:"+Oa+"(?:d|ll|m|re|s|t|ve))?",Kn="(?:"+Oa+"(?:D|LL|M|RE|S|T|VE))?",$a=Zt+"?",Os="["+Ar+"]?",Br="(?:"+za+"(?:"+[Tn,cs,Is].join("|")+")"+Os+$a+")*",Gn="\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])",Ai="\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])",us=Os+$a+Br,Ua="(?:"+[ls,cs,Is].join("|")+")"+us,Rn="(?:"+[Tn+Rs+"?",Rs,cs,Is,_i].join("|")+")",Ls=RegExp(Oa,"g"),zs=RegExp(Rs,"g"),or=RegExp(Gt+"(?="+Gt+")|"+Rn+us,"g"),fn=RegExp([ds+"?"+oa+"+"+Ms+"(?="+[La,ds,"$"].join("|")+")",Vn+"+"+Kn+"(?="+[La,ds+Wr,"$"].join("|")+")",ds+"?"+Wr+"+"+Ms,ds+"+"+Kn,Ai,Gn,ki,Ua].join("|"),"g"),yo=RegExp("["+za+Bn+Si+Ar+"]"),la=/[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/,No=["Array","Buffer","DataView","Date","Error","Float32Array","Float64Array","Function","Int8Array","Int16Array","Int32Array","Map","Math","Object","Promise","RegExp","Set","String","Symbol","TypeError","Uint8Array","Uint8ClampedArray","Uint16Array","Uint32Array","WeakMap","_","clearTimeout","isFinite","parseInt","setTimeout"],lr=-1,bt={};bt[H]=bt[pe]=bt[se]=bt[Ce]=bt[Ie]=bt[Qe]=bt[Nt]=bt[nn]=bt[Te]=!0,bt[nt]=bt[yn]=bt[B]=bt[He]=bt[M]=bt[Rt]=bt[mt]=bt[Ke]=bt[Ct]=bt[Bt]=bt[Kt]=bt[jr]=bt[St]=bt[rr]=bt[R]=!1;var rt={};rt[nt]=rt[yn]=rt[B]=rt[M]=rt[He]=rt[Rt]=rt[H]=rt[pe]=rt[se]=rt[Ce]=rt[Ie]=rt[Ct]=rt[Bt]=rt[Kt]=rt[jr]=rt[St]=rt[rr]=rt[ot]=rt[Qe]=rt[Nt]=rt[nn]=rt[Te]=!0,rt[mt]=rt[Ke]=rt[R]=!1;var sn={À:"A",Á:"A",Â:"A",Ã:"A",Ä:"A",Å:"A",à:"a",á:"a",â:"a",ã:"a",ä:"a",å:"a",Ç:"C",ç:"c",Ð:"D",ð:"d",È:"E",É:"E",Ê:"E",Ë:"E",è:"e",é:"e",ê:"e",ë:"e",Ì:"I",Í:"I",Î:"I",Ï:"I",ì:"i",í:"i",î:"i",ï:"i",Ñ:"N",ñ:"n",Ò:"O",Ó:"O",Ô:"O",Õ:"O",Ö:"O",Ø:"O",ò:"o",ó:"o",ô:"o",õ:"o",ö:"o",ø:"o",Ù:"U",Ú:"U",Û:"U",Ü:"U",ù:"u",ú:"u",û:"u",ü:"u",Ý:"Y",ý:"y",ÿ:"y",Æ:"Ae",æ:"ae",Þ:"Th",þ:"th",ß:"ss",Ā:"A",Ă:"A",Ą:"A",ā:"a",ă:"a",ą:"a",Ć:"C",Ĉ:"C",Ċ:"C",Č:"C",ć:"c",ĉ:"c",ċ:"c",č:"c",Ď:"D",Đ:"D",ď:"d",đ:"d",Ē:"E",Ĕ:"E",Ė:"E",Ę:"E",Ě:"E",ē:"e",ĕ:"e",ė:"e",ę:"e",ě:"e",Ĝ:"G",Ğ:"G",Ġ:"G",Ģ:"G",ĝ:"g",ğ:"g",ġ:"g",ģ:"g",Ĥ:"H",Ħ:"H",ĥ:"h",ħ:"h",Ĩ:"I",Ī:"I",Ĭ:"I",Į:"I",İ:"I",ĩ:"i",ī:"i",ĭ:"i",į:"i",ı:"i",Ĵ:"J",ĵ:"j",Ķ:"K",ķ:"k",ĸ:"k",Ĺ:"L",Ļ:"L",Ľ:"L",Ŀ:"L",Ł:"L",ĺ:"l",ļ:"l",ľ:"l",ŀ:"l",ł:"l",Ń:"N",Ņ:"N",Ň:"N",Ŋ:"N",ń:"n",ņ:"n",ň:"n",ŋ:"n",Ō:"O",Ŏ:"O",Ő:"O",ō:"o",ŏ:"o",ő:"o",Ŕ:"R",Ŗ:"R",Ř:"R",ŕ:"r",ŗ:"r",ř:"r",Ś:"S",Ŝ:"S",Ş:"S",Š:"S",ś:"s",ŝ:"s",ş:"s",š:"s",Ţ:"T",Ť:"T",Ŧ:"T",ţ:"t",ť:"t",ŧ:"t",Ũ:"U",Ū:"U",Ŭ:"U",Ů:"U",Ű:"U",Ų:"U",ũ:"u",ū:"u",ŭ:"u",ů:"u",ű:"u",ų:"u",Ŵ:"W",ŵ:"w",Ŷ:"Y",ŷ:"y",Ÿ:"Y",Ź:"Z",Ż:"Z",Ž:"Z",ź:"z",ż:"z",ž:"z",IJ:"IJ",ij:"ij",Œ:"Oe",œ:"oe",ʼn:"'n",ſ:"s"},ca={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},wo={"&amp;":"&","&lt;":"<","&gt;":">","&quot;":'"',"&#39;":"'"},Co={"\\":"\\","'":"'","\n":"n","\r":"r","\u2028":"u2028","\u2029":"u2029"},Ei=parseFloat,Wa=parseInt,wn=typeof lo=="object"&&lo&&lo.Object===Object&&lo,Ql=typeof self=="object"&&self&&self.Object===Object&&self,jt=wn||Ql||Function("return this")(),da=l&&!l.nodeType&&l,In=da&&!0&&d&&!d.nodeType&&d,gt=In&&In.exports===da,Xt=gt&&wn.process,Cn=(function(){try{var j=In&&In.require&&In.require("util").types;return j||Xt&&Xt.binding&&Xt.binding("util")}catch{}})(),$s=Cn&&Cn.isArrayBuffer,So=Cn&&Cn.isDate,Ba=Cn&&Cn.isMap,ua=Cn&&Cn.isRegExp,cr=Cn&&Cn.isSet,Va=Cn&&Cn.isTypedArray;function qt(j,a,o){switch(o.length){case 0:return j.call(a);case 1:return j.call(a,o[0]);case 2:return j.call(a,o[0],o[1]);case 3:return j.call(a,o[0],o[1],o[2])}return j.apply(a,o)}function Vr(j,a,o,p){for(var v=-1,T=j==null?0:j.length;++v<T;){var P=j[v];a(p,P,o(P),j)}return p}function mn(j,a){for(var o=-1,p=j==null?0:j.length;++o<p&&a(j[o],o,j)!==!1;);return j}function Kr(j,a){for(var o=j==null?0:j.length;o--&&a(j[o],o,j)!==!1;);return j}function Ka(j,a){for(var o=-1,p=j==null?0:j.length;++o<p;)if(!a(j[o],o,j))return!1;return!0}function dr(j,a){for(var o=-1,p=j==null?0:j.length,v=0,T=[];++o<p;){var P=j[o];a(P,o,j)&&(T[v++]=P)}return T}function hn(j,a){var o=j==null?0:j.length;return!!o&&hr(j,a,0)>-1}function Er(j,a,o){for(var p=-1,v=j==null?0:j.length;++p<v;)if(o(a,j[p]))return!0;return!1}function vt(j,a){for(var o=-1,p=j==null?0:j.length,v=Array(p);++o<p;)v[o]=a(j[o],o,j);return v}function ur(j,a){for(var o=-1,p=a.length,v=j.length;++o<p;)j[v+o]=a[o];return j}function fr(j,a,o,p){var v=-1,T=j==null?0:j.length;for(p&&T&&(o=j[++v]);++v<T;)o=a(o,j[v],v,j);return o}function jo(j,a,o,p){var v=j==null?0:j.length;for(p&&v&&(o=j[--v]);v--;)o=a(o,j[v],v,j);return o}function mr(j,a){for(var o=-1,p=j==null?0:j.length;++o<p;)if(a(j[o],o,j))return!0;return!1}var Us=ha("length");function Ga(j){return j.split("")}function _o(j){return j.match(As)||[]}function Mn(j,a,o){var p;return o(j,function(v,T,P){if(a(v,T,P))return p=T,!1}),p}function fa(j,a,o,p){for(var v=j.length,T=o+(p?1:-1);p?T--:++T<v;)if(a(j[T],T,j))return T;return-1}function hr(j,a,o){return a===a?gs(j,a,o):fa(j,Pi,o)}function ma(j,a,o,p){for(var v=o-1,T=j.length;++v<T;)if(p(j[v],a))return v;return-1}function Pi(j){return j!==j}function Za(j,a){var o=j==null?0:j.length;return o?fs(j,a)/o:Dn}function ha(j){return function(a){return a==null?s:a[j]}}function Pr(j){return function(a){return j==null?s:j[a]}}function Ws(j,a,o,p,v){return v(j,function(T,P,C){o=p?(p=!1,T):a(o,T,P,C)}),o}function Dr(j,a){var o=j.length;for(j.sort(a);o--;)j[o]=j[o].value;return j}function fs(j,a){for(var o,p=-1,v=j.length;++p<v;){var T=a(j[p]);T!==s&&(o=o===s?T:o+T)}return o}function ms(j,a){for(var o=-1,p=Array(j);++o<j;)p[o]=a(o);return p}function Di(j,a){return vt(a,function(o){return[o,j[o]]})}function Xa(j){return j&&j.slice(0,Ii(j)+1).replace(Ni,"")}function an(j){return function(a){return j(a)}}function hs(j,a){return vt(a,function(o){return j[o]})}function Fr(j,a){return j.has(a)}function qa(j,a){for(var o=-1,p=j.length;++o<p&&hr(a,j[o],0)>-1;);return o}function pa(j,a){for(var o=j.length;o--&&hr(a,j[o],0)>-1;);return o}function ko(j,a){for(var o=j.length,p=0;o--;)j[o]===a&&++p;return p}var Fi=Pr(sn),Ao=Pr(ca);function Eo(j){return"\\"+Co[j]}function ga(j,a){return j==null?s:j[a]}function ps(j){return yo.test(j)}function xa(j){return la.test(j)}function Ti(j){for(var a,o=[];!(a=j.next()).done;)o.push(a.value);return o}function Gr(j){var a=-1,o=Array(j.size);return j.forEach(function(p,v){o[++a]=[v,p]}),o}function Ha(j,a){return function(o){return j(a(o))}}function Tr(j,a){for(var o=-1,p=j.length,v=0,T=[];++o<p;){var P=j[o];(P===a||P===z)&&(j[o]=z,T[v++]=o)}return T}function ba(j){var a=-1,o=Array(j.size);return j.forEach(function(p){o[++a]=p}),o}function Ri(j){var a=-1,o=Array(j.size);return j.forEach(function(p){o[++a]=[p,p]}),o}function gs(j,a,o){for(var p=o-1,v=j.length;++p<v;)if(j[p]===a)return p;return-1}function on(j,a,o){for(var p=o+1;p--;)if(j[p]===a)return p;return p}function Qt(j){return ps(j)?xs(j):Us(j)}function Sn(j){return ps(j)?Po(j):Ga(j)}function Ii(j){for(var a=j.length;a--&&$r.test(j.charAt(a)););return a}var pn=Pr(wo);function xs(j){for(var a=or.lastIndex=0;or.test(j);)++a;return a}function Po(j){return j.match(or)||[]}function Do(j){return j.match(fn)||[]}var Fo=(function j(a){a=a==null?jt:bs.defaults(jt.Object(),a,bs.pick(jt,No));var o=a.Array,p=a.Date,v=a.Error,T=a.Function,P=a.Math,C=a.Object,D=a.RegExp,S=a.String,K=a.TypeError,F=o.prototype,te=T.prototype,w=C.prototype,oe=a["__core-js_shared__"],Q=te.toString,$=w.hasOwnProperty,Ee=0,Fe=(function(){var e=/[^.]+$/.exec(oe&&oe.keys&&oe.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""})(),Le=w.toString,_t=Q.call(C),ke=jt._,kt=D("^"+Q.call($).replace(rn,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Pe=gt?a.Buffer:s,ze=a.Symbol,ft=a.Uint8Array,ln=Pe?Pe.allocUnsafe:s,ae=Ha(C.getPrototypeOf,C),xe=C.create,W=w.propertyIsEnumerable,je=F.splice,Se=ze?ze.isConcatSpreadable:s,$e=ze?ze.iterator:s,Ue=ze?ze.toStringTag:s,lt=(function(){try{var e=Xs(C,"defineProperty");return e({},"",{}),e}catch{}})(),en=a.clearTimeout!==jt.clearTimeout&&a.clearTimeout,pr=p&&p.now!==jt.Date.now&&p.now,gr=a.setTimeout!==jt.setTimeout&&a.setTimeout,et=P.ceil,jn=P.floor,At=C.getOwnPropertySymbols,Ft=Pe?Pe.isBuffer:s,Bs=a.isFinite,Mi=F.join,To=Ha(C.keys,C),zt=P.max,Ht=P.min,Ro=p.now,Io=a.parseInt,va=P.random,ya=F.reverse,vs=Xs(a,"DataView"),Na=Xs(a,"Map"),De=Xs(a,"Promise"),_n=Xs(a,"Set"),Rr=Xs(a,"WeakMap"),xr=Xs(C,"create"),Zn=Rr&&new Rr,Xn={},Ja=qs(vs),wt=qs(Na),wa=qs(De),Oi=qs(_n),Cu=qs(Rr),Li=ze?ze.prototype:s,Ya=Li?Li.valueOf:s,ec=Li?Li.toString:s;function u(e){if(Tt(e)&&!Be(e)&&!(e instanceof st)){if(e instanceof qn)return e;if($.call(e,"__wrapped__"))return td(e)}return new qn(e)}var Ca=(function(){function e(){}return function(t){if(!Dt(t))return{};if(xe)return xe(t);e.prototype=t;var r=new e;return e.prototype=s,r}})();function zi(){}function qn(e,t){this.__wrapped__=e,this.__actions__=[],this.__chain__=!!t,this.__index__=0,this.__values__=s}u.templateSettings={escape:kr,evaluate:yi,interpolate:sr,variable:"",imports:{_:u}},u.prototype=zi.prototype,u.prototype.constructor=u,qn.prototype=Ca(zi.prototype),qn.prototype.constructor=qn;function st(e){this.__wrapped__=e,this.__actions__=[],this.__dir__=1,this.__filtered__=!1,this.__iteratees__=[],this.__takeCount__=xt,this.__views__=[]}function Su(){var e=new st(this.__wrapped__);return e.__actions__=kn(this.__actions__),e.__dir__=this.__dir__,e.__filtered__=this.__filtered__,e.__iteratees__=kn(this.__iteratees__),e.__takeCount__=this.__takeCount__,e.__views__=kn(this.__views__),e}function ju(){if(this.__filtered__){var e=new st(this);e.__dir__=-1,e.__filtered__=!0}else e=this.clone(),e.__dir__*=-1;return e}function _u(){var e=this.__wrapped__.value(),t=this.__dir__,r=Be(e),i=t<0,c=r?e.length:0,h=zf(0,c,this.__views__),b=h.start,y=h.end,_=y-b,Z=i?y:b-1,X=this.__iteratees__,ne=X.length,be=0,_e=Ht(_,this.__takeCount__);if(!r||!i&&c==_&&_e==_)return Sc(e,this.__actions__);var Me=[];e:for(;_--&&be<_e;){Z+=t;for(var Ze=-1,Oe=e[Z];++Ze<ne;){var tt=X[Ze],at=tt.iteratee,zn=tt.type,bn=at(Oe);if(zn==ge)Oe=bn;else if(!bn){if(zn==Ne)continue e;break e}}Me[be++]=Oe}return Me}st.prototype=Ca(zi.prototype),st.prototype.constructor=st;function Vs(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var i=e[t];this.set(i[0],i[1])}}function ku(){this.__data__=xr?xr(null):{},this.size=0}function Au(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}function Eu(e){var t=this.__data__;if(xr){var r=t[e];return r===U?s:r}return $.call(t,e)?t[e]:s}function Pu(e){var t=this.__data__;return xr?t[e]!==s:$.call(t,e)}function Du(e,t){var r=this.__data__;return this.size+=this.has(e)?0:1,r[e]=xr&&t===s?U:t,this}Vs.prototype.clear=ku,Vs.prototype.delete=Au,Vs.prototype.get=Eu,Vs.prototype.has=Pu,Vs.prototype.set=Du;function Zr(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var i=e[t];this.set(i[0],i[1])}}function Fu(){this.__data__=[],this.size=0}function Tu(e){var t=this.__data__,r=$i(t,e);if(r<0)return!1;var i=t.length-1;return r==i?t.pop():je.call(t,r,1),--this.size,!0}function Ru(e){var t=this.__data__,r=$i(t,e);return r<0?s:t[r][1]}function Iu(e){return $i(this.__data__,e)>-1}function Mu(e,t){var r=this.__data__,i=$i(r,e);return i<0?(++this.size,r.push([e,t])):r[i][1]=t,this}Zr.prototype.clear=Fu,Zr.prototype.delete=Tu,Zr.prototype.get=Ru,Zr.prototype.has=Iu,Zr.prototype.set=Mu;function Xr(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var i=e[t];this.set(i[0],i[1])}}function Ou(){this.size=0,this.__data__={hash:new Vs,map:new(Na||Zr),string:new Vs}}function Lu(e){var t=Yi(this,e).delete(e);return this.size-=t?1:0,t}function zu(e){return Yi(this,e).get(e)}function $u(e){return Yi(this,e).has(e)}function Uu(e,t){var r=Yi(this,e),i=r.size;return r.set(e,t),this.size+=r.size==i?0:1,this}Xr.prototype.clear=Ou,Xr.prototype.delete=Lu,Xr.prototype.get=zu,Xr.prototype.has=$u,Xr.prototype.set=Uu;function Ks(e){var t=-1,r=e==null?0:e.length;for(this.__data__=new Xr;
vendor: 4,675 bytes, line 101
101++t<r;)this.add(e[t])}function Wu(e){return this.__data__.set(e,U),this}function Bu(e){return this.__data__.has(e)}Ks.prototype.add=Ks.prototype.push=Wu,Ks.prototype.has=Bu;function br(e){var t=this.__data__=new Zr(e);this.size=t.size}function Vu(){this.__data__=new Zr,this.size=0}function Ku(e){var t=this.__data__,r=t.delete(e);return this.size=t.size,r}function Gu(e){return this.__data__.get(e)}function Zu(e){return this.__data__.has(e)}function Xu(e,t){var r=this.__data__;if(r instanceof Zr){var i=r.__data__;if(!Na||i.length<m-1)return i.push([e,t]),this.size=++r.size,this;r=this.__data__=new Xr(i)}return r.set(e,t),this.size=r.size,this}br.prototype.clear=Vu,br.prototype.delete=Ku,br.prototype.get=Gu,br.prototype.has=Zu,br.prototype.set=Xu;function tc(e,t){var r=Be(e),i=!r&&Hs(e),c=!r&&!i&&Ss(e),h=!r&&!i&&!c&&ka(e),b=r||i||c||h,y=b?ms(e.length,S):[],_=y.length;for(var Z in e)(t||$.call(e,Z))&&!(b&&(Z=="length"||c&&(Z=="offset"||Z=="parent")||h&&(Z=="buffer"||Z=="byteLength"||Z=="byteOffset")||Yr(Z,_)))&&y.push(Z);return y}function nc(e){var t=e.length;return t?e[Go(0,t-1)]:s}function qu(e,t){return Qi(kn(e),Gs(t,0,e.length))}function Hu(e){return Qi(kn(e))}function Mo(e,t,r){(r!==s&&!vr(e[t],r)||r===s&&!(t in e))&&qr(e,t,r)}function Qa(e,t,r){var i=e[t];(!($.call(e,t)&&vr(i,r))||r===s&&!(t in e))&&qr(e,t,r)}function $i(e,t){for(var r=e.length;r--;)if(vr(e[r][0],t))return r;return-1}function Ju(e,t,r,i){return ys(e,function(c,h,b){t(i,c,r(c),b)}),i}function rc(e,t){return e&&Mr(t,Jt(t),e)}function Yu(e,t){return e&&Mr(t,En(t),e)}function qr(e,t,r){t=="__proto__"&&lt?lt(e,t,{configurable:!0,enumerable:!0,value:r,writable:!0}):e[t]=r}function Oo(e,t){for(var r=-1,i=t.length,c=o(i),h=e==null;++r<i;)c[r]=h?s:xl(e,t[r]);return c}function Gs(e,t,r){return e===e&&(r!==s&&(e=e<=r?e:r),t!==s&&(e=e>=t?e:t)),e}function Hn(e,t,r,i,c,h){var b,y=t&E,_=t&me,Z=t&ve;if(r&&(b=c?r(e,i,c,h):r(e)),b!==s)return b;if(!Dt(e))return e;var X=Be(e);if(X){if(b=Uf(e),!y)return kn(e,b)}else{var ne=cn(e),be=ne==Ke||ne==Mt;if(Ss(e))return kc(e,y);if(ne==Kt||ne==nt||be&&!c){if(b=_||be?{}:Gc(e),!y)return _?Pf(e,Yu(b,e)):Ef(e,rc(b,e))}else{if(!rt[ne])return c?e:{};b=Wf(e,ne,y)}}h||(h=new br);var _e=h.get(e);if(_e)return _e;h.set(e,b),Nd(e)?e.forEach(function(Oe){b.add(Hn(Oe,t,r,Oe,e,h))}):vd(e)&&e.forEach(function(Oe,tt){b.set(tt,Hn(Oe,t,r,tt,e,h))});var Me=Z?_?rl:nl:_?En:Jt,Ze=X?s:Me(e);return mn(Ze||e,function(Oe,tt){Ze&&(tt=Oe,Oe=e[tt]),Qa(b,tt,Hn(Oe,t,r,tt,e,h))}),b}function Qu(e){var t=Jt(e);return function(r){return sc(r,e,t)}}function sc(e,t,r){var i=r.length;if(e==null)return!i;for(e=C(e);i--;){var c=r[i],h=t[c],b=e[c];if(b===s&&!(c in e)||!h(b))return!1}return!0}function ac(e,t,r){if(typeof e!="function")throw new K(A);return ii(function(){e.apply(s,r)},t)}function ei(e,t,r,i){var c=-1,h=hn,b=!0,y=e.length,_=[],Z=t.length;if(!y)return _;r&&(t=vt(t,an(r))),i?(h=Er,b=!1):t.length>=m&&(h=Fr,b=!1,t=new Ks(t));e:for(;++c<y;){var X=e[c],ne=r==null?X:r(X);if(X=i||X!==0?X:0,b&&ne===ne){for(var be=Z;be--;)if(t[be]===ne)continue e;_.push(X)}else h(t,ne,i)||_.push(X)}return _}var ys=Fc(Ir),ic=Fc(zo,!0);function ef(e,t){var r=!0;return ys(e,function(i,c,h){return r=!!t(i,c,h),r}),r}function Ui(e,t,r){for(var i=-1,c=e.length;++i<c;){var h=e[i],b=t(h);if(b!=null&&(y===s?b===b&&!Ln(b):r(b,y)))var y=b,_=h}return _}function tf(e,t,r,i){var c=e.length;for(r=Ve(r),r<0&&(r=-r>c?0:c+r),i=i===s||i>c?c:Ve(i),i<0&&(i+=c),i=r>i?0:Cd(i);r<i;)e[r++]=t;return e}function oc(e,t){var r=[];return ys(e,function(i,c,h){t(i,c,h)&&r.push(i)}),r}function tn(e,t,r,i,c){var h=-1,b=e.length;for(r||(r=Vf),c||(c=[]);++h<b;){var y=e[h];t>0&&r(y)?t>1?tn(y,t-1,r,i,c):ur(c,y):i||(c[c.length]=y)}return c}var Lo=Tc(),lc=Tc(!0);function Ir(e,t){return e&&Lo(e,t,Jt)}function zo(e,t){return e&&lc(e,t,Jt)}function Wi(e,t){return dr(t,function(r){return Qr(e[r])})}function Zs(e,t){t=ws(t,e);for(var r=0,i=t.length;e!=null&&r<i;)e=e[Or(t[r++])];return r&&r==i?e:s}function cc(e,t,r){var i=t(e);return Be(e)?i:ur(i,r(e))}function gn(e){return e==null?e===s?yt:Fn:Ue&&Ue in C(e)?Lf(e):Jf(e)}function $o(e,t){return e>t}function nf(e,t){return e!=null&&$.call(e,t)}function rf(e,t){return e!=null&&t in C(e)}function sf(e,t,r){return e>=Ht(t,r)&&e<zt(t,r)}function Uo(e,t,r){for(var i=r?Er:hn,c=e[0].length,h=e.length,b=h,y=o(h),_=1/0,Z=[];b--;){var X=e[b];b&&t&&(X=vt(X,an(t))),_=Ht(X.length,_),y[b]=!r&&(t||c>=120&&X.length>=120)?new Ks(b&&X):s}X=e[0];var ne=-1,be=y[0];e:for(;++ne<c&&Z.length<_;){var _e=X[ne],Me=t?t(_e):_e;if(_e=r||_e!==0?_e:0,!(be?Fr(be,Me):i(Z,Me,r))){for(b=h;--b;){var Ze=y[b];if(!(Ze?Fr(Ze,Me):i(e[b],Me,r)))continue e}be&&be.push(Me),Z.push(_e)}}return Z}
vendor: 5,603 bytes, line 101
101function af(e,t,r,i){return Ir(e,function(c,h,b){t(i,r(c),h,b)}),i}function ti(e,t,r){t=ws(t,e),e=Hc(e,t);var i=e==null?e:e[Or(Yn(t))];return i==null?s:qt(i,e,r)}function dc(e){return Tt(e)&&gn(e)==nt}function of(e){return Tt(e)&&gn(e)==B}function lf(e){return Tt(e)&&gn(e)==Rt}function ni(e,t,r,i,c){return e===t?!0:e==null||t==null||!Tt(e)&&!Tt(t)?e!==e&&t!==t:cf(e,t,r,i,ni,c)}function cf(e,t,r,i,c,h){var b=Be(e),y=Be(t),_=b?yn:cn(e),Z=y?yn:cn(t);_=_==nt?Kt:_,Z=Z==nt?Kt:Z;var X=_==Kt,ne=Z==Kt,be=_==Z;if(be&&Ss(e)){if(!Ss(t))return!1;b=!0,X=!1}if(be&&!X)return h||(h=new br),b||ka(e)?Bc(e,t,r,i,c,h):Mf(e,t,_,r,i,c,h);if(!(r&q)){var _e=X&&$.call(e,"__wrapped__"),Me=ne&&$.call(t,"__wrapped__");if(_e||Me){var Ze=_e?e.value():e,Oe=Me?t.value():t;return h||(h=new br),c(Ze,Oe,r,i,h)}}return be?(h||(h=new br),Of(e,t,r,i,c,h)):!1}function df(e){return Tt(e)&&cn(e)==Ct}function Wo(e,t,r,i){var c=r.length,h=c,b=!i;if(e==null)return!h;for(e=C(e);c--;){var y=r[c];if(b&&y[2]?y[1]!==e[y[0]]:!(y[0]in e))return!1}for(;++c<h;){y=r[c];var _=y[0],Z=e[_],X=y[1];if(b&&y[2]){if(Z===s&&!(_ in e))return!1}else{var ne=new br;if(i)var be=i(Z,X,_,e,t,ne);if(!(be===s?ni(X,Z,q|ee,i,ne):be))return!1}}return!0}function uc(e){if(!Dt(e)||Gf(e))return!1;var t=Qr(e)?kt:Ur;return t.test(qs(e))}function uf(e){return Tt(e)&&gn(e)==jr}function ff(e){return Tt(e)&&cn(e)==St}function mf(e){return Tt(e)&&ao(e.length)&&!!bt[gn(e)]}function fc(e){return typeof e=="function"?e:e==null?Pn:typeof e=="object"?Be(e)?pc(e[0],e[1]):hc(e):Rd(e)}function Bo(e){if(!ai(e))return To(e);var t=[];for(var r in C(e))$.call(e,r)&&r!="constructor"&&t.push(r);return t}function hf(e){if(!Dt(e))return Hf(e);var t=ai(e),r=[];for(var i in e)i=="constructor"&&(t||!$.call(e,i))||r.push(i);return r}function Vo(e,t){return e<t}function mc(e,t){var r=-1,i=An(e)?o(e.length):[];return ys(e,function(c,h,b){i[++r]=t(c,h,b)}),i}function hc(e){var t=al(e);return t.length==1&&t[0][2]?Xc(t[0][0],t[0][1]):function(r){return r===e||Wo(r,e,t)}}function pc(e,t){return ol(e)&&Zc(t)?Xc(Or(e),t):function(r){var i=xl(r,e);return i===s&&i===t?bl(r,e):ni(t,i,q|ee)}}function Bi(e,t,r,i,c){e!==t&&Lo(t,function(h,b){if(c||(c=new br),Dt(h))pf(e,t,b,r,Bi,i,c);else{var y=i?i(cl(e,b),h,b+"",e,t,c):s;y===s&&(y=h),Mo(e,b,y)}},En)}function pf(e,t,r,i,c,h,b){var y=cl(e,r),_=cl(t,r),Z=b.get(_);if(Z){Mo(e,r,Z);return}var X=h?h(y,_,r+"",e,t,b):s,ne=X===s;if(ne){var be=Be(_),_e=!be&&Ss(_),Me=!be&&!_e&&ka(_);X=_,be||_e||Me?Be(y)?X=y:$t(y)?X=kn(y):_e?(ne=!1,X=kc(_,!0)):Me?(ne=!1,X=Ac(_,!0)):X=[]:oi(_)||Hs(_)?(X=y,Hs(y)?X=Sd(y):(!Dt(y)||Qr(y))&&(X=Gc(_))):ne=!1}ne&&(b.set(_,X),c(X,_,i,h,b),b.delete(_)),Mo(e,r,X)}function gc(e,t){var r=e.length;if(r)return t+=t<0?r:0,Yr(t,r)?e[t]:s}function xc(e,t,r){t.length?t=vt(t,function(h){return Be(h)?function(b){return Zs(b,h.length===1?h[0]:h)}:h}):t=[Pn];var i=-1;t=vt(t,an(Re()));var c=mc(e,function(h,b,y){var _=vt(t,function(Z){return Z(h)});return{criteria:_,index:++i,value:h}});return Dr(c,function(h,b){return Af(h,b,r)})}function gf(e,t){return bc(e,t,function(r,i){return bl(e,i)})}function bc(e,t,r){for(var i=-1,c=t.length,h={};++i<c;){var b=t[i],y=Zs(e,b);r(y,b)&&ri(h,ws(b,e),y)}return h}function xf(e){return function(t){return Zs(t,e)}}function Ko(e,t,r,i){var c=i?ma:hr,h=-1,b=t.length,y=e;for(e===t&&(t=kn(t)),r&&(y=vt(e,an(r)));++h<b;)for(var _=0,Z=t[h],X=r?r(Z):Z;(_=c(y,X,_,i))>-1;)y!==e&&je.call(y,_,1),je.call(e,_,1);return e}function vc(e,t){for(var r=e?t.length:0,i=r-1;r--;){var c=t[r];if(r==i||c!==h){var h=c;Yr(c)?je.call(e,c,1):qo(e,c)}}return e}function Go(e,t){return e+jn(va()*(t-e+1))}function bf(e,t,r,i){for(var c=-1,h=zt(et((t-e)/(r||1)),0),b=o(h);h--;)b[i?h:++c]=e,e+=r;return b}function Zo(e,t){var r="";if(!e||t<1||t>We)return r;do t%2&&(r+=e),t=jn(t/2),t&&(e+=e);while(t);return r}function Je(e,t){return dl(qc(e,t,Pn),e+"")}function vf(e){return nc(Aa(e))}function yf(e,t){var r=Aa(e);return Qi(r,Gs(t,0,r.length))}function ri(e,t,r,i){if(!Dt(e))return e;t=ws(t,e);for(var c=-1,h=t.length,b=h-1,y=e;y!=null&&++c<h;){var _=Or(t[c]),Z=r;if(_==="__proto__"||_==="constructor"||_==="prototype")return e;if(c!=b){var X=y[_];Z=i?i(X,_,y):s,Z===s&&(Z=Dt(X)?X:Yr(t[c+1])?[]:{})}Qa(y,_,Z),y=y[_]}return e}var yc=Zn?function(e,t){return Zn.set(e,t),e}:Pn,Nf=lt?function(e,t){return lt(e,"toString",{configurable:!0,enumerable:!1,value:yl(t),writable:!0})}:Pn;function wf(e){return Qi(Aa(e))}function Jn(e,t,r){var i=-1,c=e.length;t<0&&(t=-t>c?0:c+t),r=r>c?c:r,r<0&&(r+=c),c=t>r?0:r-t>>>0,t>>>=0;for(var h=o(c);++i<c;)h[i]=e[i+t];return h}function Cf(e,t){var r;return ys(e,function(i,c,h){return r=t(i,c,h),!r}),!!r}function Vi(e,t,r){var i=0,c=e==null?i:e.length;if(typeof t=="number"&&t===t&&c<=Ye){for(;i<c;){var h=i+c>>>1,b=e[h];b!==null&&!Ln(b)&&(r?b<=t:b<t)?i=h+1:c=h}return c}return Xo(e,t,Pn,r)}function Xo(e,t,r,i){var c=0,h=e==null?0:e.length;if(h===0)return 0;t=r(t);for(var b=t!==t,y=t===null,_=Ln(t),Z=t===s;c<h;){var X=jn((c+h)/2),ne=r(e[X]),be=ne!==s,_e=ne===null,Me=ne===ne,Ze=Ln(ne);if(b)var Oe=i||Me;else Z?Oe=Me&&(i||be):y?Oe=Me&&be&&(i||!_e):_?Oe=Me&&be&&!_e&&(i||!Ze):_e||Ze?Oe=!1:Oe=i?ne<=t:ne<t;Oe?c=X+1:h=X}return Ht(h,Un)}function Nc(e,t){for(var r=-1,i=e.length,c=0,h=[];++r<i;){var b=e[r],y=t?t(b):b;if(!r||!vr(y,_)){var _=y;h[c++]=b===0?0:b}}return h}function wc(e){return typeof e=="number"?e:Ln(e)?Dn:+e}function On(e){if(typeof e=="string")return e;if(Be(e))return vt(e,On)+"";if(Ln(e))return ec?ec.call(e):"";var t=e+"";return t=="0"&&1/e==-ye?"-0":t}function Ns(e,t,r){var i=-1,c=hn,h=e.length,b=!0,y=[],_=y;if(r)b=!1,c=Er;else if(h>=m){var Z=t?null:Rf(e);
vendor: 5,103 bytes, line 101
101if(Z)return ba(Z);b=!1,c=Fr,_=new Ks}else _=t?[]:y;e:for(;++i<h;){var X=e[i],ne=t?t(X):X;if(X=r||X!==0?X:0,b&&ne===ne){for(var be=_.length;be--;)if(_[be]===ne)continue e;t&&_.push(ne),y.push(X)}else c(_,ne,r)||(_!==y&&_.push(ne),y.push(X))}return y}function qo(e,t){return t=ws(t,e),e=Hc(e,t),e==null||delete e[Or(Yn(t))]}function Cc(e,t,r,i){return ri(e,t,r(Zs(e,t)),i)}function Ki(e,t,r,i){for(var c=e.length,h=i?c:-1;(i?h--:++h<c)&&t(e[h],h,e););return r?Jn(e,i?0:h,i?h+1:c):Jn(e,i?h+1:0,i?c:h)}function Sc(e,t){var r=e;return r instanceof st&&(r=r.value()),fr(t,function(i,c){return c.func.apply(c.thisArg,ur([i],c.args))},r)}function Ho(e,t,r){var i=e.length;if(i<2)return i?Ns(e[0]):[];for(var c=-1,h=o(i);++c<i;)for(var b=e[c],y=-1;++y<i;)y!=c&&(h[c]=ei(h[c]||b,e[y],t,r));return Ns(tn(h,1),t,r)}function jc(e,t,r){for(var i=-1,c=e.length,h=t.length,b={};++i<c;){var y=i<h?t[i]:s;r(b,e[i],y)}return b}function Jo(e){return $t(e)?e:[]}function Yo(e){return typeof e=="function"?e:Pn}function ws(e,t){return Be(e)?e:ol(e,t)?[e]:ed(pt(e))}var Sf=Je;function Cs(e,t,r){var i=e.length;return r=r===s?i:r,!t&&r>=i?e:Jn(e,t,r)}var _c=en||function(e){return jt.clearTimeout(e)};function kc(e,t){if(t)return e.slice();var r=e.length,i=ln?ln(r):new e.constructor(r);return e.copy(i),i}function Qo(e){var t=new e.constructor(e.byteLength);return new ft(t).set(new ft(e)),t}function jf(e,t){var r=t?Qo(e.buffer):e.buffer;return new e.constructor(r,e.byteOffset,e.byteLength)}function _f(e){var t=new e.constructor(e.source,sa.exec(e));return t.lastIndex=e.lastIndex,t}function kf(e){return Ya?C(Ya.call(e)):{}}function Ac(e,t){var r=t?Qo(e.buffer):e.buffer;return new e.constructor(r,e.byteOffset,e.length)}function Ec(e,t){if(e!==t){var r=e!==s,i=e===null,c=e===e,h=Ln(e),b=t!==s,y=t===null,_=t===t,Z=Ln(t);if(!y&&!Z&&!h&&e>t||h&&b&&_&&!y&&!Z||i&&b&&_||!r&&_||!c)return 1;if(!i&&!h&&!Z&&e<t||Z&&r&&c&&!i&&!h||y&&r&&c||!b&&c||!_)return-1}return 0}function Af(e,t,r){for(var i=-1,c=e.criteria,h=t.criteria,b=c.length,y=r.length;++i<b;){var _=Ec(c[i],h[i]);if(_){if(i>=y)return _;var Z=r[i];return _*(Z=="desc"?-1:1)}}return e.index-t.index}function Pc(e,t,r,i){for(var c=-1,h=e.length,b=r.length,y=-1,_=t.length,Z=zt(h-b,0),X=o(_+Z),ne=!i;++y<_;)X[y]=t[y];for(;++c<b;)(ne||c<h)&&(X[r[c]]=e[c]);for(;Z--;)X[y++]=e[c++];return X}function Dc(e,t,r,i){for(var c=-1,h=e.length,b=-1,y=r.length,_=-1,Z=t.length,X=zt(h-y,0),ne=o(X+Z),be=!i;++c<X;)ne[c]=e[c];for(var _e=c;++_<Z;)ne[_e+_]=t[_];for(;++b<y;)(be||c<h)&&(ne[_e+r[b]]=e[c++]);return ne}function kn(e,t){var r=-1,i=e.length;for(t||(t=o(i));++r<i;)t[r]=e[r];return t}function Mr(e,t,r,i){var c=!r;r||(r={});for(var h=-1,b=t.length;++h<b;){var y=t[h],_=i?i(r[y],e[y],y,r,e):s;_===s&&(_=e[y]),c?qr(r,y,_):Qa(r,y,_)}return r}function Ef(e,t){return Mr(e,il(e),t)}function Pf(e,t){return Mr(e,Vc(e),t)}function Gi(e,t){return function(r,i){var c=Be(r)?Vr:Ju,h=t?t():{};return c(r,e,Re(i,2),h)}}function Sa(e){return Je(function(t,r){var i=-1,c=r.length,h=c>1?r[c-1]:s,b=c>2?r[2]:s;for(h=e.length>3&&typeof h=="function"?(c--,h):s,b&&xn(r[0],r[1],b)&&(h=c<3?s:h,c=1),t=C(t);++i<c;){var y=r[i];y&&e(t,y,i,h)}return t})}function Fc(e,t){return function(r,i){if(r==null)return r;if(!An(r))return e(r,i);for(var c=r.length,h=t?c:-1,b=C(r);(t?h--:++h<c)&&i(b[h],h,b)!==!1;);return r}}function Tc(e){return function(t,r,i){for(var c=-1,h=C(t),b=i(t),y=b.length;y--;){var _=b[e?y:++c];if(r(h[_],_,h)===!1)break}return t}}function Df(e,t,r){var i=t&de,c=si(e);function h(){var b=this&&this!==jt&&this instanceof h?c:e;return b.apply(i?r:this,arguments)}return h}function Rc(e){return function(t){t=pt(t);var r=ps(t)?Sn(t):s,i=r?r[0]:t.charAt(0),c=r?Cs(r,1).join(""):t.slice(1);return i[e]()+c}}function ja(e){return function(t){return fr(Fd(Dd(t).replace(Ls,"")),e,"")}}function si(e){return function(){var t=arguments;switch(t.length){case 0:return new e;case 1:return new e(t[0]);case 2:return new e(t[0],t[1]);case 3:return new e(t[0],t[1],t[2]);case 4:return new e(t[0],t[1],t[2],t[3]);case 5:return new e(t[0],t[1],t[2],t[3],t[4]);case 6:return new e(t[0],t[1],t[2],t[3],t[4],t[5]);case 7:return new e(t[0],t[1],t[2],t[3],t[4],t[5],t[6])}var r=Ca(e.prototype),i=e.apply(r,t);return Dt(i)?i:r}}function Ff(e,t,r){var i=si(e);function c(){for(var h=arguments.length,b=o(h),y=h,_=_a(c);y--;)b[y]=arguments[y];var Z=h<3&&b[0]!==_&&b[h-1]!==_?[]:Tr(b,_);if(h-=Z.length,h<r)return zc(e,t,Zi,c.placeholder,s,b,Z,s,s,r-h);var X=this&&this!==jt&&this instanceof c?i:e;return qt(X,this,b)}return c}function Ic(e){return function(t,r,i){var c=C(t);if(!An(t)){var h=Re(r,3);t=Jt(t),r=function(y){return h(c[y],y,c)}}var b=e(t,r,i);return b>-1?c[h?t[b]:b]:s}}function Mc(e){return Jr(function(t){var r=t.length,i=r,c=qn.prototype.thru;for(e&&t.reverse();i--;){var h=t[i];if(typeof h!="function")throw new K(A);if(c&&!b&&Ji(h)=="wrapper")var b=new qn([],!0)}for(i=b?i:r;++i<r;){h=t[i];var y=Ji(h),_=y=="wrapper"?sl(h):s;_&&ll(_[0])&&_[1]==(he|J|ue|L)&&!_[4].length&&_[9]==1?b=b[Ji(_[0])].apply(b,_[3]):b=h.length==1&&ll(h)?b[y]():b.thru(h)}return function(){var Z=arguments,X=Z[0];
vendor: 1,064 bytes, line 101
101if(b&&Z.length==1&&Be(X))return b.plant(X).value();for(var ne=0,be=r?t[ne].apply(this,Z):X;++ne<r;)be=t[ne].call(this,be);return be}})}function Zi(e,t,r,i,c,h,b,y,_,Z){var X=t&he,ne=t&de,be=t&Y,_e=t&(J|G),Me=t&ce,Ze=be?s:si(e);function Oe(){for(var tt=arguments.length,at=o(tt),zn=tt;zn--;)at[zn]=arguments[zn];if(_e)var bn=_a(Oe),$n=ko(at,bn);if(i&&(at=Pc(at,i,c,_e)),h&&(at=Dc(at,h,b,_e)),tt-=$n,_e&&tt<Z){var Ut=Tr(at,bn);return zc(e,t,Zi,Oe.placeholder,r,at,Ut,y,_,Z-tt)}var yr=ne?r:this,ts=be?yr[e]:e;return tt=at.length,y?at=Yf(at,y):Me&&tt>1&&at.reverse(),X&&_<tt&&(at.length=_),this&&this!==jt&&this instanceof Oe&&(ts=Ze||si(ts)),ts.apply(yr,at)}return Oe}function Oc(e,t){return function(r,i){return af(r,e,t(i),{})}}function Xi(e,t){return function(r,i){var c;if(r===s&&i===s)return t;if(r!==s&&(c=r),i!==s){if(c===s)return i;typeof r=="string"||typeof i=="string"?(r=On(r),i=On(i)):(r=wc(r),i=wc(i)),c=e(r,i)}return c}}function el(e){return Jr(function(t){return t=vt(t,an(Re())),Je(function(r){var i=this;return e(t,function(c){return qt(c,i,r)})})})}
vendor: 5,571 bytes, line 101
101function qi(e,t){t=t===s?" ":On(t);var r=t.length;if(r<2)return r?Zo(t,e):t;var i=Zo(t,et(e/Qt(t)));return ps(t)?Cs(Sn(i),0,e).join(""):i.slice(0,e)}function Tf(e,t,r,i){var c=t&de,h=si(e);function b(){for(var y=-1,_=arguments.length,Z=-1,X=i.length,ne=o(X+_),be=this&&this!==jt&&this instanceof b?h:e;++Z<X;)ne[Z]=i[Z];for(;_--;)ne[Z++]=arguments[++y];return qt(be,c?r:this,ne)}return b}function Lc(e){return function(t,r,i){return i&&typeof i!="number"&&xn(t,r,i)&&(r=i=s),t=es(t),r===s?(r=t,t=0):r=es(r),i=i===s?t<r?1:-1:es(i),bf(t,r,i,e)}}function Hi(e){return function(t,r){return typeof t=="string"&&typeof r=="string"||(t=Qn(t),r=Qn(r)),e(t,r)}}function zc(e,t,r,i,c,h,b,y,_,Z){var X=t&J,ne=X?b:s,be=X?s:b,_e=X?h:s,Me=X?s:h;t|=X?ue:V,t&=~(X?V:ue),t&le||(t&=-4);var Ze=[e,t,c,_e,ne,Me,be,y,_,Z],Oe=r.apply(s,Ze);return ll(e)&&Jc(Oe,Ze),Oe.placeholder=i,Yc(Oe,e,t)}function tl(e){var t=P[e];return function(r,i){if(r=Qn(r),i=i==null?0:Ht(Ve(i),292),i&&Bs(r)){var c=(pt(r)+"e").split("e"),h=t(c[0]+"e"+(+c[1]+i));return c=(pt(h)+"e").split("e"),+(c[0]+"e"+(+c[1]-i))}return t(r)}}var Rf=_n&&1/ba(new _n([,-0]))[1]==ye?function(e){return new _n(e)}:Cl;function $c(e){return function(t){var r=cn(t);return r==Ct?Gr(t):r==St?Ri(t):Di(t,e(t))}}function Hr(e,t,r,i,c,h,b,y){var _=t&Y;if(!_&&typeof e!="function")throw new K(A);var Z=i?i.length:0;if(Z||(t&=-97,i=c=s),b=b===s?b:zt(Ve(b),0),y=y===s?y:Ve(y),Z-=c?c.length:0,t&V){var X=i,ne=c;i=c=s}var be=_?s:sl(e),_e=[e,t,r,i,c,X,ne,h,b,y];if(be&&qf(_e,be),e=_e[0],t=_e[1],r=_e[2],i=_e[3],c=_e[4],y=_e[9]=_e[9]===s?_?0:e.length:zt(_e[9]-Z,0),!y&&t&(J|G)&&(t&=-25),!t||t==de)var Me=Df(e,t,r);else t==J||t==G?Me=Ff(e,t,y):(t==ue||t==(de|ue))&&!c.length?Me=Tf(e,t,r,i):Me=Zi.apply(s,_e);var Ze=be?yc:Jc;return Yc(Ze(Me,_e),e,t)}function Uc(e,t,r,i){return e===s||vr(e,w[r])&&!$.call(i,r)?t:e}function Wc(e,t,r,i,c,h){return Dt(e)&&Dt(t)&&(h.set(t,e),Bi(e,t,s,Wc,h),h.delete(t)),e}function If(e){return oi(e)?s:e}function Bc(e,t,r,i,c,h){var b=r&q,y=e.length,_=t.length;if(y!=_&&!(b&&_>y))return!1;var Z=h.get(e),X=h.get(t);if(Z&&X)return Z==t&&X==e;var ne=-1,be=!0,_e=r&ee?new Ks:s;for(h.set(e,t),h.set(t,e);++ne<y;){var Me=e[ne],Ze=t[ne];if(i)var Oe=b?i(Ze,Me,ne,t,e,h):i(Me,Ze,ne,e,t,h);if(Oe!==s){if(Oe)continue;be=!1;break}if(_e){if(!mr(t,function(tt,at){if(!Fr(_e,at)&&(Me===tt||c(Me,tt,r,i,h)))return _e.push(at)})){be=!1;break}}else if(!(Me===Ze||c(Me,Ze,r,i,h))){be=!1;break}}return h.delete(e),h.delete(t),be}function Mf(e,t,r,i,c,h,b){switch(r){case M:if(e.byteLength!=t.byteLength||e.byteOffset!=t.byteOffset)return!1;e=e.buffer,t=t.buffer;case B:return!(e.byteLength!=t.byteLength||!h(new ft(e),new ft(t)));case He:case Rt:case Bt:return vr(+e,+t);case mt:return e.name==t.name&&e.message==t.message;case jr:case rr:return e==t+"";case Ct:var y=Gr;case St:var _=i&q;if(y||(y=ba),e.size!=t.size&&!_)return!1;var Z=b.get(e);if(Z)return Z==t;i|=ee,b.set(e,t);var X=Bc(y(e),y(t),i,c,h,b);return b.delete(e),X;case ot:if(Ya)return Ya.call(e)==Ya.call(t)}return!1}function Of(e,t,r,i,c,h){var b=r&q,y=nl(e),_=y.length,Z=nl(t),X=Z.length;if(_!=X&&!b)return!1;for(var ne=_;ne--;){var be=y[ne];if(!(b?be in t:$.call(t,be)))return!1}var _e=h.get(e),Me=h.get(t);if(_e&&Me)return _e==t&&Me==e;var Ze=!0;h.set(e,t),h.set(t,e);for(var Oe=b;++ne<_;){be=y[ne];var tt=e[be],at=t[be];if(i)var zn=b?i(at,tt,be,t,e,h):i(tt,at,be,e,t,h);if(!(zn===s?tt===at||c(tt,at,r,i,h):zn)){Ze=!1;break}Oe||(Oe=be=="constructor")}if(Ze&&!Oe){var bn=e.constructor,$n=t.constructor;bn!=$n&&"constructor"in e&&"constructor"in t&&!(typeof bn=="function"&&bn instanceof bn&&typeof $n=="function"&&$n instanceof $n)&&(Ze=!1)}return h.delete(e),h.delete(t),Ze}function Jr(e){return dl(qc(e,s,sd),e+"")}function nl(e){return cc(e,Jt,il)}function rl(e){return cc(e,En,Vc)}var sl=Zn?function(e){return Zn.get(e)}:Cl;function Ji(e){for(var t=e.name+"",r=Xn[t],i=$.call(Xn,t)?r.length:0;i--;){var c=r[i],h=c.func;if(h==null||h==e)return c.name}return t}function _a(e){var t=$.call(u,"placeholder")?u:e;return t.placeholder}function Re(){var e=u.iteratee||Nl;return e=e===Nl?fc:e,arguments.length?e(arguments[0],arguments[1]):e}function Yi(e,t){var r=e.__data__;return Kf(t)?r[typeof t=="string"?"string":"hash"]:r.map}function al(e){for(var t=Jt(e),r=t.length;r--;){var i=t[r],c=e[i];t[r]=[i,c,Zc(c)]}return t}function Xs(e,t){var r=ga(e,t);return uc(r)?r:s}function Lf(e){var t=$.call(e,Ue),r=e[Ue];try{e[Ue]=s;var i=!0}catch{}var c=Le.call(e);return i&&(t?e[Ue]=r:delete e[Ue]),c}var il=At?function(e){return e==null?[]:(e=C(e),dr(At(e),function(t){return W.call(e,t)}))}:Sl,Vc=At?function(e){for(var t=[];e;)ur(t,il(e)),e=ae(e);return t}:Sl,cn=gn;(vs&&cn(new vs(new ArrayBuffer(1)))!=M||Na&&cn(new Na)!=Ct||De&&cn(De.resolve())!=nr||_n&&cn(new _n)!=St||Rr&&cn(new Rr)!=R)&&(cn=function(e){var t=gn(e),r=t==Kt?e.constructor:s,i=r?qs(r):"";if(i)switch(i){case Ja:return M;case wt:return Ct;case wa:return nr;case Oi:return St;case Cu:return R}return t});function zf(e,t,r){for(var i=-1,c=r.length;++i<c;){var h=r[i],b=h.size;switch(h.type){case"drop":e+=b;break;case"dropRight":t-=b;break;case"take":t=Ht(t,e+b);break;case"takeRight":e=zt(e,t-b);break}}return{start:e,end:t}}function $f(e){var t=e.match(Ta);return t?t[1].split(Yl):[]}function Kc(e,t,r){t=ws(t,e);for(var i=-1,c=t.length,h=!1;++i<c;){var b=Or(t[i]);if(!(h=e!=null&&r(e,b)))break;e=e[b]}return h||++i!=c?h:(c=e==null?0:e.length,!!c&&ao(c)&&Yr(b,c)&&(Be(e)||Hs(e)))}function Uf(e){var t=e.length,r=new e.constructor(t);return t&&typeof e[0]=="string"&&$.call(e,"index")&&(r.index=e.index,r.input
vendor: 7,296 bytes, lines 101-103
101=e.input),r}function Gc(e){return typeof e.constructor=="function"&&!ai(e)?Ca(ae(e)):{}}function Wf(e,t,r){var i=e.constructor;switch(t){case B:return Qo(e);case He:case Rt:return new i(+e);case M:return jf(e,r);case H:case pe:case se:case Ce:case Ie:case Qe:case Nt:case nn:case Te:return Ac(e,r);case Ct:return new i;case Bt:case rr:return new i(e);case jr:return _f(e);case St:return new i;case ot:return kf(e)}}function Bf(e,t){var r=t.length;if(!r)return e;var i=r-1;return t[i]=(r>1?"& ":"")+t[i],t=t.join(r>2?", ":" "),e.replace(ta,`{
102/* [wrapped with `+t+`] */
103`)}function Vf(e){return Be(e)||Hs(e)||!!(Se&&e&&e[Se])}function Yr(e,t){var r=typeof e;return t=t??We,!!t&&(r=="number"||r!="symbol"&&xo.test(e))&&e>-1&&e%1==0&&e<t}function xn(e,t,r){if(!Dt(r))return!1;var i=typeof t;return(i=="number"?An(r)&&Yr(t,r.length):i=="string"&&t in r)?vr(r[t],e):!1}function ol(e,t){if(Be(e))return!1;var r=typeof e;return r=="number"||r=="symbol"||r=="boolean"||e==null||Ln(e)?!0:ht.test(e)||!ks.test(e)||t!=null&&e in C(t)}function Kf(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}function ll(e){var t=Ji(e),r=u[t];if(typeof r!="function"||!(t in st.prototype))return!1;if(e===r)return!0;var i=sl(r);return!!i&&e===i[0]}function Gf(e){return!!Fe&&Fe in e}var Zf=oe?Qr:jl;function ai(e){var t=e&&e.constructor,r=typeof t=="function"&&t.prototype||w;return e===r}function Zc(e){return e===e&&!Dt(e)}function Xc(e,t){return function(r){return r==null?!1:r[e]===t&&(t!==s||e in C(r))}}function Xf(e){var t=ro(e,function(i){return r.size===k&&r.clear(),i}),r=t.cache;return t}function qf(e,t){var r=e[1],i=t[1],c=r|i,h=c<(de|Y|he),b=i==he&&r==J||i==he&&r==L&&e[7].length<=t[8]||i==(he|L)&&t[7].length<=t[8]&&r==J;if(!(h||b))return e;i&de&&(e[2]=t[2],c|=r&de?0:le);var y=t[3];if(y){var _=e[3];e[3]=_?Pc(_,y,t[4]):y,e[4]=_?Tr(e[3],z):t[4]}return y=t[5],y&&(_=e[5],e[5]=_?Dc(_,y,t[6]):y,e[6]=_?Tr(e[5],z):t[6]),y=t[7],y&&(e[7]=y),i&he&&(e[8]=e[8]==null?t[8]:Ht(e[8],t[8])),e[9]==null&&(e[9]=t[9]),e[0]=t[0],e[1]=c,e}function Hf(e){var t=[];if(e!=null)for(var r in C(e))t.push(r);return t}function Jf(e){return Le.call(e)}function qc(e,t,r){return t=zt(t===s?e.length-1:t,0),function(){for(var i=arguments,c=-1,h=zt(i.length-t,0),b=o(h);++c<h;)b[c]=i[t+c];c=-1;for(var y=o(t+1);++c<t;)y[c]=i[c];return y[t]=r(b),qt(e,this,y)}}function Hc(e,t){return t.length<2?e:Zs(e,Jn(t,0,-1))}function Yf(e,t){for(var r=e.length,i=Ht(t.length,r),c=kn(e);i--;){var h=t[i];e[i]=Yr(h,r)?c[h]:s}return e}function cl(e,t){if(!(t==="constructor"&&typeof e[t]=="function")&&t!="__proto__")return e[t]}var Jc=Qc(yc),ii=gr||function(e,t){return jt.setTimeout(e,t)},dl=Qc(Nf);function Yc(e,t,r){var i=t+"";return dl(e,Bf(i,Qf($f(i),r)))}function Qc(e){var t=0,r=0;return function(){var i=Ro(),c=I-(i-r);if(r=i,c>0){if(++t>=re)return arguments[0]}else t=0;return e.apply(s,arguments)}}function Qi(e,t){var r=-1,i=e.length,c=i-1;for(t=t===s?i:t;++r<t;){var h=Go(r,c),b=e[h];e[h]=e[r],e[r]=b}return e.length=t,e}var ed=Xf(function(e){var t=[];return e.charCodeAt(0)===46&&t.push(""),e.replace(Nn,function(r,i,c,h){t.push(c?h.replace(ra,"$1"):i||r)}),t});function Or(e){if(typeof e=="string"||Ln(e))return e;var t=e+"";return t=="0"&&1/e==-ye?"-0":t}function qs(e){if(e!=null){try{return Q.call(e)}catch{}try{return e+""}catch{}}return""}function Qf(e,t){return mn(qe,function(r){var i="_."+r[0];t&r[1]&&!hn(e,i)&&e.push(i)}),e.sort()}function td(e){if(e instanceof st)return e.clone();var t=new qn(e.__wrapped__,e.__chain__);return t.__actions__=kn(e.__actions__),t.__index__=e.__index__,t.__values__=e.__values__,t}function em(e,t,r){(r?xn(e,t,r):t===s)?t=1:t=zt(Ve(t),0);var i=e==null?0:e.length;if(!i||t<1)return[];for(var c=0,h=0,b=o(et(i/t));c<i;)b[h++]=Jn(e,c,c+=t);return b}function tm(e){for(var t=-1,r=e==null?0:e.length,i=0,c=[];++t<r;){var h=e[t];h&&(c[i++]=h)}return c}function nm(){var e=arguments.length;if(!e)return[];for(var t=o(e-1),r=arguments[0],i=e;i--;)t[i-1]=arguments[i];return ur(Be(r)?kn(r):[r],tn(t,1))}var rm=Je(function(e,t){return $t(e)?ei(e,tn(t,1,$t,!0)):[]}),sm=Je(function(e,t){var r=Yn(t);return $t(r)&&(r=s),$t(e)?ei(e,tn(t,1,$t,!0),Re(r,2)):[]}),am=Je(function(e,t){var r=Yn(t);return $t(r)&&(r=s),$t(e)?ei(e,tn(t,1,$t,!0),s,r):[]});function im(e,t,r){var i=e==null?0:e.length;return i?(t=r||t===s?1:Ve(t),Jn(e,t<0?0:t,i)):[]}function om(e,t,r){var i=e==null?0:e.length;return i?(t=r||t===s?1:Ve(t),t=i-t,Jn(e,0,t<0?0:t)):[]}function lm(e,t){return e&&e.length?Ki(e,Re(t,3),!0,!0):[]}function cm(e,t){return e&&e.length?Ki(e,Re(t,3),!0):[]}function dm(e,t,r,i){var c=e==null?0:e.length;return c?(r&&typeof r!="number"&&xn(e,t,r)&&(r=0,i=c),tf(e,t,r,i)):[]}function nd(e,t,r){var i=e==null?0:e.length;if(!i)return-1;var c=r==null?0:Ve(r);return c<0&&(c=zt(i+c,0)),fa(e,Re(t,3),c)}function rd(e,t,r){var i=e==null?0:e.length;if(!i)return-1;var c=i-1;return r!==s&&(c=Ve(r),c=r<0?zt(i+c,0):Ht(c,i-1)),fa(e,Re(t,3),c,!0)}function sd(e){var t=e==null?0:e.length;return t?tn(e,1):[]}function um(e){var t=e==null?0:e.length;return t?tn(e,ye):[]}function fm(e,t){var r=e==null?0:e.length;return r?(t=t===s?1:Ve(t),tn(e,t)):[]}function mm(e){for(var t=-1,r=e==null?0:e.length,i={};++t<r;){var c=e[t];i[c[0]]=c[1]}return i}function ad(e){return e&&e.length?e[0]:s}function hm(e,t,r){var i=e==null?0:e.length;if(!i)return-1;var c=r==null?0:Ve(r);return c<0&&(c=zt(i+c,0)),hr(e,t,c)}function pm(e){var t=e==null?0:e.length;return t?Jn(e,0,-1):[]}var gm=Je(function(e){var t=vt(e,Jo);return t.length&&t[0]===e[0]?Uo(t):[]}),xm=Je(function(e){var t=Yn(e),r=vt(e,Jo);return t===Yn(r)?t=s:r.pop(),r.length&&r[0]===e[0]?Uo(r,Re(t,2)):[]}),bm=Je(function(e){var t=Yn(e),r=vt(e,Jo);return t=typeof t=="function"?t:s,t&&r.pop(),r.length&&r[0]===e[0]?Uo(r,s,t):[]});function vm(e,t){return e==null?"":Mi.call(e,t)}function Yn(e){var t=e==null?0:e.length;return t?e[t-1]:s}function ym(e,t,r){var i=e==null?0:e.length;if(!i)return-1;var c=i;return r!==s&&(c=Ve(r),c=c<0?zt(i+c,0):Ht(c,i-1)),t===t?on(e,t,c):fa(e,Pi,c,!0)}function Nm(e,t){return e&&e.length?gc(e,Ve(t)):s}var wm=Je(id);function id(e,t){return e&&e.length&&t&&t.length?Ko(e,t):e}function Cm(e,t,r){return e&&e.length&&t&&t.length?Ko(e,t,Re(r,2)):e}function Sm(e,t,r){return e&&e.length&&t&&t.length?Ko(e,t,s,r):e}var jm=Jr(function(e,t){var r=e==null?0:e.length,i=Oo(e,t);return vc(e,vt(t,function(c){return Yr(c,r)?+c:c}).sort(Ec)),i});function _m(e,t){var r=[];if(!(e&&e.length))return r;var i=-1,c=[],h=e.length;for(t=Re(t,3);++i<h;){var b=e[i];t(b,i,e)&&(r.push(b),c.push(i))}return vc(e,c),r}function ul(e){return e==null?e:ya.call(e)}function km(e,t,r){var i=e==null?0:e.length;return i?(r&&typeof r!="number"&&xn(e,t,r)?(t=0,r=i):(t=t==null?0:Ve(t),r=r===s?i:Ve(r)),Jn(e,t,r)):[]}function Am(e,t){return Vi(e,t)}function Em(e,t,r){return Xo(e,t,Re(r,2))}function Pm(e,t){var r=e==null?0:e.length;if(r){var i=Vi(e,t);if(i<r&&vr(e[i],t))return i}return-1}function Dm(e,t){return Vi(e,t,!0)}function Fm(e,t,r){return Xo(e,t,Re(r,2),!0)}function Tm(e,t){var r=e==null?0:e.length;if(r){var i=Vi(e,t,!0)-1;if(vr(e[i],t))return i}return-1}function Rm(e){return e&&e.length?Nc(e):[]}function Im(e,t){return e&&e.length?Nc(e,Re(t,2)):[]}function Mm(e){var t=e==null?0:e.length;return t?Jn(e,1,t):[]}
vendor: 6,945 bytes, line 103
103function Om(e,t,r){return e&&e.length?(t=r||t===s?1:Ve(t),Jn(e,0,t<0?0:t)):[]}function Lm(e,t,r){var i=e==null?0:e.length;return i?(t=r||t===s?1:Ve(t),t=i-t,Jn(e,t<0?0:t,i)):[]}function zm(e,t){return e&&e.length?Ki(e,Re(t,3),!1,!0):[]}function $m(e,t){return e&&e.length?Ki(e,Re(t,3)):[]}var Um=Je(function(e){return Ns(tn(e,1,$t,!0))}),Wm=Je(function(e){var t=Yn(e);return $t(t)&&(t=s),Ns(tn(e,1,$t,!0),Re(t,2))}),Bm=Je(function(e){var t=Yn(e);return t=typeof t=="function"?t:s,Ns(tn(e,1,$t,!0),s,t)});function Vm(e){return e&&e.length?Ns(e):[]}function Km(e,t){return e&&e.length?Ns(e,Re(t,2)):[]}function Gm(e,t){return t=typeof t=="function"?t:s,e&&e.length?Ns(e,s,t):[]}function fl(e){if(!(e&&e.length))return[];var t=0;return e=dr(e,function(r){if($t(r))return t=zt(r.length,t),!0}),ms(t,function(r){return vt(e,ha(r))})}function od(e,t){if(!(e&&e.length))return[];var r=fl(e);return t==null?r:vt(r,function(i){return qt(t,s,i)})}var Zm=Je(function(e,t){return $t(e)?ei(e,t):[]}),Xm=Je(function(e){return Ho(dr(e,$t))}),qm=Je(function(e){var t=Yn(e);return $t(t)&&(t=s),Ho(dr(e,$t),Re(t,2))}),Hm=Je(function(e){var t=Yn(e);return t=typeof t=="function"?t:s,Ho(dr(e,$t),s,t)}),Jm=Je(fl);function Ym(e,t){return jc(e||[],t||[],Qa)}function Qm(e,t){return jc(e||[],t||[],ri)}var eh=Je(function(e){var t=e.length,r=t>1?e[t-1]:s;return r=typeof r=="function"?(e.pop(),r):s,od(e,r)});function ld(e){var t=u(e);return t.__chain__=!0,t}function th(e,t){return t(e),e}function eo(e,t){return t(e)}var nh=Jr(function(e){var t=e.length,r=t?e[0]:0,i=this.__wrapped__,c=function(h){return Oo(h,e)};return t>1||this.__actions__.length||!(i instanceof st)||!Yr(r)?this.thru(c):(i=i.slice(r,+r+(t?1:0)),i.__actions__.push({func:eo,args:[c],thisArg:s}),new qn(i,this.__chain__).thru(function(h){return t&&!h.length&&h.push(s),h}))});function rh(){return ld(this)}function sh(){return new qn(this.value(),this.__chain__)}function ah(){this.__values__===s&&(this.__values__=wd(this.value()));var e=this.__index__>=this.__values__.length,t=e?s:this.__values__[this.__index__++];return{done:e,value:t}}function ih(){return this}function oh(e){for(var t,r=this;r instanceof zi;){var i=td(r);i.__index__=0,i.__values__=s,t?c.__wrapped__=i:t=i;var c=i;r=r.__wrapped__}return c.__wrapped__=e,t}function lh(){var e=this.__wrapped__;if(e instanceof st){var t=e;return this.__actions__.length&&(t=new st(this)),t=t.reverse(),t.__actions__.push({func:eo,args:[ul],thisArg:s}),new qn(t,this.__chain__)}return this.thru(ul)}function ch(){return Sc(this.__wrapped__,this.__actions__)}var dh=Gi(function(e,t,r){$.call(e,r)?++e[r]:qr(e,r,1)});function uh(e,t,r){var i=Be(e)?Ka:ef;return r&&xn(e,t,r)&&(t=s),i(e,Re(t,3))}function fh(e,t){var r=Be(e)?dr:oc;return r(e,Re(t,3))}var mh=Ic(nd),hh=Ic(rd);function ph(e,t){return tn(to(e,t),1)}function gh(e,t){return tn(to(e,t),ye)}function xh(e,t,r){return r=r===s?1:Ve(r),tn(to(e,t),r)}function cd(e,t){var r=Be(e)?mn:ys;return r(e,Re(t,3))}function dd(e,t){var r=Be(e)?Kr:ic;return r(e,Re(t,3))}var bh=Gi(function(e,t,r){$.call(e,r)?e[r].push(t):qr(e,r,[t])});function vh(e,t,r,i){e=An(e)?e:Aa(e),r=r&&!i?Ve(r):0;var c=e.length;return r<0&&(r=zt(c+r,0)),io(e)?r<=c&&e.indexOf(t,r)>-1:!!c&&hr(e,t,r)>-1}var yh=Je(function(e,t,r){var i=-1,c=typeof t=="function",h=An(e)?o(e.length):[];return ys(e,function(b){h[++i]=c?qt(t,b,r):ti(b,t,r)}),h}),Nh=Gi(function(e,t,r){qr(e,r,t)});function to(e,t){var r=Be(e)?vt:mc;return r(e,Re(t,3))}function wh(e,t,r,i){return e==null?[]:(Be(t)||(t=t==null?[]:[t]),r=i?s:r,Be(r)||(r=r==null?[]:[r]),xc(e,t,r))}var Ch=Gi(function(e,t,r){e[r?0:1].push(t)},function(){return[[],[]]});function Sh(e,t,r){var i=Be(e)?fr:Ws,c=arguments.length<3;return i(e,Re(t,4),r,c,ys)}function jh(e,t,r){var i=Be(e)?jo:Ws,c=arguments.length<3;return i(e,Re(t,4),r,c,ic)}function _h(e,t){var r=Be(e)?dr:oc;return r(e,so(Re(t,3)))}function kh(e){var t=Be(e)?nc:vf;return t(e)}function Ah(e,t,r){(r?xn(e,t,r):t===s)?t=1:t=Ve(t);var i=Be(e)?qu:yf;return i(e,t)}function Eh(e){var t=Be(e)?Hu:wf;return t(e)}function Ph(e){if(e==null)return 0;if(An(e))return io(e)?Qt(e):e.length;var t=cn(e);return t==Ct||t==St?e.size:Bo(e).length}function Dh(e,t,r){var i=Be(e)?mr:Cf;return r&&xn(e,t,r)&&(t=s),i(e,Re(t,3))}var Fh=Je(function(e,t){if(e==null)return[];var r=t.length;return r>1&&xn(e,t[0],t[1])?t=[]:r>2&&xn(t[0],t[1],t[2])&&(t=[t[0]]),xc(e,tn(t,1),[])}),no=pr||function(){return jt.Date.now()};function Th(e,t){if(typeof t!="function")throw new K(A);return e=Ve(e),function(){if(--e<1)return t.apply(this,arguments)}}function ud(e,t,r){return t=r?s:t,t=e&&t==null?e.length:t,Hr(e,he,s,s,s,s,t)}function fd(e,t){var r;if(typeof t!="function")throw new K(A);return e=Ve(e),function(){return--e>0&&(r=t.apply(this,arguments)),e<=1&&(t=s),r}}var ml=Je(function(e,t,r){var i=de;if(r.length){var c=Tr(r,_a(ml));i|=ue}return Hr(e,i,t,r,c)}),md=Je(function(e,t,r){var i=de|Y;if(r.length){var c=Tr(r,_a(md));i|=ue}return Hr(t,i,e,r,c)});function hd(e,t,r){t=r?s:t;var i=Hr(e,J,s,s,s,s,s,t);return i.placeholder=hd.placeholder,i}function pd(e,t,r){t=r?s:t;var i=Hr(e,G,s,s,s,s,s,t);return i.placeholder=pd.placeholder,i}function gd(e,t,r){var i,c,h,b,y,_,Z=0,X=!1,ne=!1,be=!0;if(typeof e!="function")throw new K(A);t=Qn(t)||0,Dt(r)&&(X=!!r.leading,ne="maxWait"in r,h=ne?zt(Qn(r.maxWait)||0,t):h,be="trailing"in r?!!r.trailing:be);function _e(Ut){var yr=i,ts=c;return i=c=s,Z=Ut,b=e.apply(ts,yr),b}function Me(Ut){return Z=Ut,y=ii(tt,t),X?_e(Ut):b}function Ze(Ut){var yr=Ut-_,ts=Ut-Z,Id=t-yr;return ne?Ht(Id,h-ts):Id}function Oe(Ut){var yr=Ut-_,ts=Ut-Z;return _===s||yr>=t||yr<0||ne&&ts>=h}function tt(){var Ut=no();if(Oe(Ut))return at(Ut);y=ii(tt,Ze(Ut))}function at(Ut){return y=s,be&&i?_e(Ut):(i=c=s,b)}function zn(){y!==s&&_c(y),Z=0,i=_=c=y=s}function bn(){return y===s?b:at(no())}function $n(){var Ut=no(),yr=Oe(Ut);if(i=arguments,c=this,_=Ut,yr){if(y===s)return Me(_);if(ne)return _c(y),y=ii(tt,t),_e(_)}return y===s&&(y=ii(tt,t)),b}return $n.cancel=zn,$n.flush=bn,$n}var Rh=Je(function(e,t){return ac(e,1,t)}),Ih=Je(function(e,t,r){return ac(e,Qn(t)||0,r)});function Mh(e){return Hr(e,ce)}function ro(e,t){if(typeof e!="function"||t!=null&&typeof t!="function")throw new K(A);var r=function(){var i=arguments,c=t?t.apply(this,i):i[0],h=r.cache;if(h.has(c))return h.get(c);var b=e.apply(this,i);return r.cache=h.set(c,b)||h,b};return r.cache=new(ro.Cache||Xr),r}ro.Cache=Xr;function so(e){if(typeof e!="function")throw new K(A);return function(){var t=arguments;switch(t.length){case 0:return!e.call(this);case 1:return!e.call(this,t[0]);case 2:return!e.call(this,t[0],t[1]);case 3:return!e.call(this,t[0],t[1],t[2])}return!e.apply(this,t)}}function Oh(e){return fd(2,e)}var Lh=Sf(function(e,t){t=t.length==1&&Be(t[0])?vt(t[0],an(Re())):vt(tn(t,1),an(Re()));var r=t.length;return Je(function(i){for(var c=-1,h=Ht(i.length,r);++c<h;)i[c]=t[c].call(this,i[c]);return qt(e,this,i)})}),hl=Je(function(e,t){var r=Tr(t,_a(hl));
vendor: 8,810 bytes, line 103
103return Hr(e,ue,s,t,r)}),xd=Je(function(e,t){var r=Tr(t,_a(xd));return Hr(e,V,s,t,r)}),zh=Jr(function(e,t){return Hr(e,L,s,s,s,t)});function $h(e,t){if(typeof e!="function")throw new K(A);return t=t===s?t:Ve(t),Je(e,t)}function Uh(e,t){if(typeof e!="function")throw new K(A);return t=t==null?0:zt(Ve(t),0),Je(function(r){var i=r[t],c=Cs(r,0,t);return i&&ur(c,i),qt(e,this,c)})}function Wh(e,t,r){var i=!0,c=!0;if(typeof e!="function")throw new K(A);return Dt(r)&&(i="leading"in r?!!r.leading:i,c="trailing"in r?!!r.trailing:c),gd(e,t,{leading:i,maxWait:t,trailing:c})}function Bh(e){return ud(e,1)}function Vh(e,t){return hl(Yo(t),e)}function Kh(){if(!arguments.length)return[];var e=arguments[0];return Be(e)?e:[e]}function Gh(e){return Hn(e,ve)}function Zh(e,t){return t=typeof t=="function"?t:s,Hn(e,ve,t)}function Xh(e){return Hn(e,E|ve)}function qh(e,t){return t=typeof t=="function"?t:s,Hn(e,E|ve,t)}function Hh(e,t){return t==null||sc(e,t,Jt(t))}function vr(e,t){return e===t||e!==e&&t!==t}var Jh=Hi($o),Yh=Hi(function(e,t){return e>=t}),Hs=dc((function(){return arguments})())?dc:function(e){return Tt(e)&&$.call(e,"callee")&&!W.call(e,"callee")},Be=o.isArray,Qh=$s?an($s):of;function An(e){return e!=null&&ao(e.length)&&!Qr(e)}function $t(e){return Tt(e)&&An(e)}function ep(e){return e===!0||e===!1||Tt(e)&&gn(e)==He}var Ss=Ft||jl,tp=So?an(So):lf;function np(e){return Tt(e)&&e.nodeType===1&&!oi(e)}function rp(e){if(e==null)return!0;if(An(e)&&(Be(e)||typeof e=="string"||typeof e.splice=="function"||Ss(e)||ka(e)||Hs(e)))return!e.length;var t=cn(e);if(t==Ct||t==St)return!e.size;if(ai(e))return!Bo(e).length;for(var r in e)if($.call(e,r))return!1;return!0}function sp(e,t){return ni(e,t)}function ap(e,t,r){r=typeof r=="function"?r:s;var i=r?r(e,t):s;return i===s?ni(e,t,s,r):!!i}function pl(e){if(!Tt(e))return!1;var t=gn(e);return t==mt||t==It||typeof e.message=="string"&&typeof e.name=="string"&&!oi(e)}function ip(e){return typeof e=="number"&&Bs(e)}function Qr(e){if(!Dt(e))return!1;var t=gn(e);return t==Ke||t==Mt||t==ut||t==is}function bd(e){return typeof e=="number"&&e==Ve(e)}function ao(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=We}function Dt(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}function Tt(e){return e!=null&&typeof e=="object"}var vd=Ba?an(Ba):df;function op(e,t){return e===t||Wo(e,t,al(t))}function lp(e,t,r){return r=typeof r=="function"?r:s,Wo(e,t,al(t),r)}function cp(e){return yd(e)&&e!=+e}function dp(e){if(Zf(e))throw new v(g);return uc(e)}function up(e){return e===null}function fp(e){return e==null}function yd(e){return typeof e=="number"||Tt(e)&&gn(e)==Bt}function oi(e){if(!Tt(e)||gn(e)!=Kt)return!1;var t=ae(e);if(t===null)return!0;var r=$.call(t,"constructor")&&t.constructor;return typeof r=="function"&&r instanceof r&&Q.call(r)==_t}var gl=ua?an(ua):uf;function mp(e){return bd(e)&&e>=-We&&e<=We}var Nd=cr?an(cr):ff;function io(e){return typeof e=="string"||!Be(e)&&Tt(e)&&gn(e)==rr}function Ln(e){return typeof e=="symbol"||Tt(e)&&gn(e)==ot}var ka=Va?an(Va):mf;function hp(e){return e===s}function pp(e){return Tt(e)&&cn(e)==R}function gp(e){return Tt(e)&&gn(e)==N}var xp=Hi(Vo),bp=Hi(function(e,t){return e<=t});function wd(e){if(!e)return[];if(An(e))return io(e)?Sn(e):kn(e);if($e&&e[$e])return Ti(e[$e]());var t=cn(e),r=t==Ct?Gr:t==St?ba:Aa;return r(e)}function es(e){if(!e)return e===0?e:0;if(e=Qn(e),e===ye||e===-ye){var t=e<0?-1:1;return t*Vt}return e===e?e:0}function Ve(e){var t=es(e),r=t%1;return t===t?r?t-r:t:0}function Cd(e){return e?Gs(Ve(e),0,xt):0}function Qn(e){if(typeof e=="number")return e;if(Ln(e))return Dn;if(Dt(e)){var t=typeof e.valueOf=="function"?e.valueOf():e;e=Dt(t)?t+"":t}if(typeof e!="string")return e===0?e:+e;e=Xa(e);var r=Es.test(e);return r||Ps.test(e)?Wa(e.slice(2),r?2:8):os.test(e)?Dn:+e}function Sd(e){return Mr(e,En(e))}function vp(e){return e?Gs(Ve(e),-We,We):e===0?e:0}function pt(e){return e==null?"":On(e)}var yp=Sa(function(e,t){if(ai(t)||An(t)){Mr(t,Jt(t),e);return}for(var r in t)$.call(t,r)&&Qa(e,r,t[r])}),jd=Sa(function(e,t){Mr(t,En(t),e)}),oo=Sa(function(e,t,r,i){Mr(t,En(t),e,i)}),Np=Sa(function(e,t,r,i){Mr(t,Jt(t),e,i)}),wp=Jr(Oo);function Cp(e,t){var r=Ca(e);return t==null?r:rc(r,t)}var Sp=Je(function(e,t){e=C(e);var r=-1,i=t.length,c=i>2?t[2]:s;for(c&&xn(t[0],t[1],c)&&(i=1);++r<i;)for(var h=t[r],b=En(h),y=-1,_=b.length;++y<_;){var Z=b[y],X=e[Z];(X===s||vr(X,w[Z])&&!$.call(e,Z))&&(e[Z]=h[Z])}return e}),jp=Je(function(e){return e.push(s,Wc),qt(_d,s,e)});function _p(e,t){return Mn(e,Re(t,3),Ir)}function kp(e,t){return Mn(e,Re(t,3),zo)}function Ap(e,t){return e==null?e:Lo(e,Re(t,3),En)}function Ep(e,t){return e==null?e:lc(e,Re(t,3),En)}function Pp(e,t){return e&&Ir(e,Re(t,3))}function Dp(e,t){return e&&zo(e,Re(t,3))}function Fp(e){return e==null?[]:Wi(e,Jt(e))}function Tp(e){return e==null?[]:Wi(e,En(e))}function xl(e,t,r){var i=e==null?s:Zs(e,t);return i===s?r:i}function Rp(e,t){return e!=null&&Kc(e,t,nf)}function bl(e,t){return e!=null&&Kc(e,t,rf)}var Ip=Oc(function(e,t,r){t!=null&&typeof t.toString!="function"&&(t=Le.call(t)),e[t]=r},yl(Pn)),Mp=Oc(function(e,t,r){t!=null&&typeof t.toString!="function"&&(t=Le.call(t)),$.call(e,t)?e[t].push(r):e[t]=[r]},Re),Op=Je(ti);function Jt(e){return An(e)?tc(e):Bo(e)}function En(e){return An(e)?tc(e,!0):hf(e)}function Lp(e,t){var r={};return t=Re(t,3),Ir(e,function(i,c,h){qr(r,t(i,c,h),i)}),r}function zp(e,t){var r={};return t=Re(t,3),Ir(e,function(i,c,h){qr(r,c,t(i,c,h))}),r}var $p=Sa(function(e,t,r){Bi(e,t,r)}),_d=Sa(function(e,t,r,i){Bi(e,t,r,i)}),Up=Jr(function(e,t){var r={};if(e==null)return r;var i=!1;t=vt(t,function(h){return h=ws(h,e),i||(i=h.length>1),h}),Mr(e,rl(e),r),i&&(r=Hn(r,E|me|ve,If));for(var c=t.length;c--;)qo(r,t[c]);return r});function Wp(e,t){return kd(e,so(Re(t)))}var Bp=Jr(function(e,t){return e==null?{}:gf(e,t)});function kd(e,t){if(e==null)return{};var r=vt(rl(e),function(i){return[i]});return t=Re(t),bc(e,r,function(i,c){return t(i,c[0])})}function Vp(e,t,r){t=ws(t,e);var i=-1,c=t.length;for(c||(c=1,e=s);++i<c;){var h=e==null?s:e[Or(t[i])];h===s&&(i=c,h=r),e=Qr(h)?h.call(e):h}return e}function Kp(e,t,r){return e==null?e:ri(e,t,r)}function Gp(e,t,r,i){return i=typeof i=="function"?i:s,e==null?e:ri(e,t,r,i)}var Ad=$c(Jt),Ed=$c(En);function Zp(e,t,r){var i=Be(e),c=i||Ss(e)||ka(e);if(t=Re(t,4),r==null){var h=e&&e.constructor;c?r=i?new h:[]:Dt(e)?r=Qr(h)?Ca(ae(e)):{}:r={}}return(c?mn:Ir)(e,function(b,y,_){return t(r,b,y,_)}),r}function Xp(e,t){return e==null?!0:qo(e,t)}function qp(e,t,r){return e==null?e:Cc(e,t,Yo(r))}function Hp(e,t,r,i){return i=typeof i=="function"?i:s,e==null?e:Cc(e,t,Yo(r),i)}function Aa(e){return e==null?[]:hs(e,Jt(e))}function Jp(e){return e==null?[]:hs(e,En(e))}function Yp(e,t,r){return r===s&&(r=t,t=s),r!==s&&(r=Qn(r),r=r===r?r:0),t!==s&&(t=Qn(t),t=t===t?t:0),Gs(Qn(e),t,r)}function Qp(e,t,r){return t=es(t),r===s?(r=t,t=0):r=es(r),e=Qn(e),sf(e,t,r)}function eg(e,t,r){if(r&&typeof r!="boolean"&&xn(e,t,r)&&(t=r=s),r===s&&(typeof t=="boolean"?(r=t,t=s):typeof e=="boolean"&&(r=e,e=s)),e===s&&t===s?(e=0,t=1):(e=es(e),t===s?(t=e,e=0):t=es(t)),e>t){var i=e;e=t,t=i}if(r||e%1||t%1){var c=va();return Ht(e+c*(t-e+Ei("1e-"+((c+"").length-1))),t)}return Go(e,t)}var tg=ja(function(e,t,r){return t=t.toLowerCase(),e+(r?Pd(t):t)});function Pd(e){return vl(pt(e).toLowerCase())}function Dd(e){return e=pt(e),e&&e.replace(Ci,Fi).replace(zs,"")}function ng(e,t,r){e=pt(e),t=On(t);var i=e.length;r=r===s?i:Gs(Ve(r),0,i);var c=r;return r-=t.length,r>=0&&e.slice(r,c)==t}function rg(e){return e=pt(e),e&&_r.test(e)?e.replace(_s,Ao):e}function sg(e){return e=pt(e),e&&ar.test(e)?e.replace(rn,"\\$&"):e}var ag=ja(function(e,t,r){return e+(r?"-":"")+t.toLowerCase()}),ig=ja(function(e,t,r){return e+(r?" ":"")+t.toLowerCase()}),og=Rc("toLowerCase");function lg(e,t,r){e=pt(e),t=Ve(t);var i=t?Qt(e):0;if(!t||i>=t)return e;var c=(t-i)/2;return qi(jn(c),r)+e+qi(et(c),r)}function cg(e,t,r){e=pt(e),t=Ve(t);var i=t?Qt(e):0;return t&&i<t?e+qi(t-i,r):e}function dg(e,t,r){e=pt(e),t=Ve(t);var i=t?Qt(e):0;return t&&i<t?qi(t-i,r)+e:e}function ug(e,t,r){return r||t==null?t=0:t&&(t=+t),Io(pt(e).replace(Ni,""),t||0)}function fg(e,t,r){return(r?xn(e,t,r):t===s)?t=1:t=Ve(t),Zo(pt(e),t)}function mg(){var e=arguments,t=pt(e[0]);return e.length<3?t:t.replace(e[1],e[2])}var hg=ja(function(e,t,r){return e+(r?"_":"")+t.toLowerCase()});function pg(e,t,r){return r&&typeof r!="number"&&xn(e,t,r)&&(t=r=s),r=r===s?xt:r>>>0,r?(e=pt(e),e&&(typeof t=="string"||t!=null&&!gl(t))&&(t=On(t),!t&&ps(e))?Cs(Sn(e),0,r):e.split(t,r)):[]}var gg=ja(function(e,t,r){return e+(r?" ":"")+vl(t)});function xg(e,t,r){return e=pt(e),r=r==null?0:Gs(Ve(r),0,e.length),t=On(t),e.slice(r,r+t.length)==t}function bg(e,t,r){var i=u.templateSettings;r&&xn(e,t,r)&&(t=s),e=pt(e),t=oo({},t,i,Uc);var c=oo({}
vendor: 5,412 bytes, lines 103-120
103,t.imports,i.imports,Uc),h=Jt(c),b=hs(c,h),y,_,Z=0,X=t.interpolate||Ds,ne="__p += '",be=D((t.escape||Ds).source+"|"+X.source+"|"+(X===sr?wi:Ds).source+"|"+(t.evaluate||Ds).source+"|$","g"),_e="//# sourceURL="+($.call(t,"sourceURL")?(t.sourceURL+"").replace(/\s/g," "):"lodash.templateSources["+ ++lr+"]")+`
104`;e.replace(be,function(Oe,tt,at,zn,bn,$n){return at||(at=zn),ne+=e.slice(Z,$n).replace(bo,Eo),tt&&(y=!0,ne+=`' +
105__e(`+tt+`) +
106'`),bn&&(_=!0,ne+=`';
107`+bn+`;
108__p += '`),at&&(ne+=`' +
109((__t = (`+at+`)) == null ? '' : __t) +
110'`),Z=$n+Oe.length,Oe}),ne+=`';
111`;var Me=$.call(t,"variable")&&t.variable;if(!Me)ne=`with (obj) {
112`+ne+`
113}
114`;else if(na.test(Me))throw new v(O);ne=(_?ne.replace(it,""):ne).replace(Et,"$1").replace(Ot,"$1;"),ne="function("+(Me||"obj")+`) {
115`+(Me?"":`obj || (obj = {});
116`)+"var __t, __p = ''"+(y?", __e = _.escape":"")+(_?`, __j = Array.prototype.join;
117function print() { __p += __j.call(arguments, '') }
118`:`;
119`)+ne+`return __p
120}`;var Ze=Td(function(){return T(h,_e+"return "+ne).apply(s,b)});if(Ze.source=ne,pl(Ze))throw Ze;return Ze}function vg(e){return pt(e).toLowerCase()}function yg(e){return pt(e).toUpperCase()}function Ng(e,t,r){if(e=pt(e),e&&(r||t===s))return Xa(e);if(!e||!(t=On(t)))return e;var i=Sn(e),c=Sn(t),h=qa(i,c),b=pa(i,c)+1;return Cs(i,h,b).join("")}function wg(e,t,r){if(e=pt(e),e&&(r||t===s))return e.slice(0,Ii(e)+1);if(!e||!(t=On(t)))return e;var i=Sn(e),c=pa(i,Sn(t))+1;return Cs(i,0,c).join("")}function Cg(e,t,r){if(e=pt(e),e&&(r||t===s))return e.replace(Ni,"");if(!e||!(t=On(t)))return e;var i=Sn(e),c=qa(i,Sn(t));return Cs(i,c).join("")}function Sg(e,t){var r=fe,i=Ae;if(Dt(t)){var c="separator"in t?t.separator:c;r="length"in t?Ve(t.length):r,i="omission"in t?On(t.omission):i}e=pt(e);var h=e.length;if(ps(e)){var b=Sn(e);h=b.length}if(r>=h)return e;var y=r-Qt(i);if(y<1)return i;var _=b?Cs(b,0,y).join(""):e.slice(0,y);if(c===s)return _+i;if(b&&(y+=_.length-y),gl(c)){if(e.slice(y).search(c)){var Z,X=_;for(c.global||(c=D(c.source,pt(sa.exec(c))+"g")),c.lastIndex=0;Z=c.exec(X);)var ne=Z.index;_=_.slice(0,ne===s?y:ne)}}else if(e.indexOf(On(c),y)!=y){var be=_.lastIndexOf(c);be>-1&&(_=_.slice(0,be))}return _+i}function jg(e){return e=pt(e),e&&Pt.test(e)?e.replace(Wn,pn):e}var _g=ja(function(e,t,r){return e+(r?" ":"")+t.toUpperCase()}),vl=Rc("toUpperCase");function Fd(e,t,r){return e=pt(e),t=r?s:t,t===s?xa(e)?Do(e):_o(e):e.match(t)||[]}var Td=Je(function(e,t){try{return qt(e,s,t)}catch(r){return pl(r)?r:new v(r)}}),kg=Jr(function(e,t){return mn(t,function(r){r=Or(r),qr(e,r,ml(e[r],e))}),e});function Ag(e){var t=e==null?0:e.length,r=Re();return e=t?vt(e,function(i){if(typeof i[1]!="function")throw new K(A);return[r(i[0]),i[1]]}):[],Je(function(i){for(var c=-1;++c<t;){var h=e[c];if(qt(h[0],this,i))return qt(h[1],this,i)}})}function Eg(e){return Qu(Hn(e,E))}function yl(e){return function(){return e}}function Pg(e,t){return e==null||e!==e?t:e}var Dg=Mc(),Fg=Mc(!0);function Pn(e){return e}function Nl(e){return fc(typeof e=="function"?e:Hn(e,E))}function Tg(e){return hc(Hn(e,E))}function Rg(e,t){return pc(e,Hn(t,E))}var Ig=Je(function(e,t){return function(r){return ti(r,e,t)}}),Mg=Je(function(e,t){return function(r){return ti(e,r,t)}});function wl(e,t,r){var i=Jt(t),c=Wi(t,i);r==null&&!(Dt(t)&&(c.length||!i.length))&&(r=t,t=e,e=this,c=Wi(t,Jt(t)));var h=!(Dt(r)&&"chain"in r)||!!r.chain,b=Qr(e);return mn(c,function(y){var _=t[y];e[y]=_,b&&(e.prototype[y]=function(){var Z=this.__chain__;if(h||Z){var X=e(this.__wrapped__),ne=X.__actions__=kn(this.__actions__);return ne.push({func:_,args:arguments,thisArg:e}),X.__chain__=Z,X}return _.apply(e,ur([this.value()],arguments))})}),e}function Og(){return jt._===this&&(jt._=ke),this}function Cl(){}function Lg(e){return e=Ve(e),Je(function(t){return gc(t,e)})}var zg=el(vt),$g=el(Ka),Ug=el(mr);function Rd(e){return ol(e)?ha(Or(e)):xf(e)}function Wg(e){return function(t){return e==null?s:Zs(e,t)}}var Bg=Lc(),Vg=Lc(!0);function Sl(){return[]}function jl(){return!1}function Kg(){return{}}function Gg(){return""}function Zg(){return!0}function Xg(e,t){if(e=Ve(e),e<1||e>We)return[];var r=xt,i=Ht(e,xt);t=Re(t),e-=xt;for(var c=ms(i,t);++r<e;)t(r);return c}function qg(e){return Be(e)?vt(e,Or):Ln(e)?[e]:kn(ed(pt(e)))}function Hg(e){var t=++Ee;return pt(e)+t}var Jg=Xi(function(e,t){return e+t},0),Yg=tl("ceil"),Qg=Xi(function(e,t){return e/t},1),e0=tl("floor");function t0(e){return e&&e.length?Ui(e,Pn,$o):s}function n0(e,t){return e&&e.length?Ui(e,Re(t,2),$o):s}function r0(e){return Za(e,Pn)}function s0(e,t){return Za(e,Re(t,2))}function a0(e){return e&&e.length?Ui(e,Pn,Vo):s}function i0(e,t){return e&&e.length?Ui(e,Re(t,2),Vo):s}var o0=Xi(function(e,t){return e*t},1),l0=tl("round"),c0=Xi(function(e,t){return e-t},0);function d0(e){return e&&e.length?fs(e,Pn):0}function u0(e,t){return e&&e.length?fs(e,Re(t,2)):0}return u.after=Th,u.ary=ud,u.assign=yp,u.assignIn=jd,u.assignInWith=oo,u.assignWith=Np,u.at=wp,u.before=fd,u.bind=ml,u.bindAll=kg,u.bindKey=md,u.castArray=Kh,u.chain=ld,u.chunk=em,u.compact=tm,u.concat=nm,u.cond=Ag,u.conforms=Eg,u.constant=yl,u.countBy=dh,u.create=Cp,u.curry=hd,u.curryRight=pd,u.debounce=gd,u.defaults=Sp,u.defaultsDeep=jp,u.defer=Rh,u.delay=Ih,u.difference=rm,u.differenceBy=sm,u.differenceWith=am,u.drop=im,u.dropRight=om,u.dropRightWhile=lm,u.dropWhile=cm,u.fill=dm,u.filter=fh,u.flatMap=ph,u.flatMapDeep=gh,u.flatMapDepth=xh,u.flatten=sd,u.flatten
vendor: 4,402 bytes, line 120
120Deep=um,u.flattenDepth=fm,u.flip=Mh,u.flow=Dg,u.flowRight=Fg,u.fromPairs=mm,u.functions=Fp,u.functionsIn=Tp,u.groupBy=bh,u.initial=pm,u.intersection=gm,u.intersectionBy=xm,u.intersectionWith=bm,u.invert=Ip,u.invertBy=Mp,u.invokeMap=yh,u.iteratee=Nl,u.keyBy=Nh,u.keys=Jt,u.keysIn=En,u.map=to,u.mapKeys=Lp,u.mapValues=zp,u.matches=Tg,u.matchesProperty=Rg,u.memoize=ro,u.merge=$p,u.mergeWith=_d,u.method=Ig,u.methodOf=Mg,u.mixin=wl,u.negate=so,u.nthArg=Lg,u.omit=Up,u.omitBy=Wp,u.once=Oh,u.orderBy=wh,u.over=zg,u.overArgs=Lh,u.overEvery=$g,u.overSome=Ug,u.partial=hl,u.partialRight=xd,u.partition=Ch,u.pick=Bp,u.pickBy=kd,u.property=Rd,u.propertyOf=Wg,u.pull=wm,u.pullAll=id,u.pullAllBy=Cm,u.pullAllWith=Sm,u.pullAt=jm,u.range=Bg,u.rangeRight=Vg,u.rearg=zh,u.reject=_h,u.remove=_m,u.rest=$h,u.reverse=ul,u.sampleSize=Ah,u.set=Kp,u.setWith=Gp,u.shuffle=Eh,u.slice=km,u.sortBy=Fh,u.sortedUniq=Rm,u.sortedUniqBy=Im,u.split=pg,u.spread=Uh,u.tail=Mm,u.take=Om,u.takeRight=Lm,u.takeRightWhile=zm,u.takeWhile=$m,u.tap=th,u.throttle=Wh,u.thru=eo,u.toArray=wd,u.toPairs=Ad,u.toPairsIn=Ed,u.toPath=qg,u.toPlainObject=Sd,u.transform=Zp,u.unary=Bh,u.union=Um,u.unionBy=Wm,u.unionWith=Bm,u.uniq=Vm,u.uniqBy=Km,u.uniqWith=Gm,u.unset=Xp,u.unzip=fl,u.unzipWith=od,u.update=qp,u.updateWith=Hp,u.values=Aa,u.valuesIn=Jp,u.without=Zm,u.words=Fd,u.wrap=Vh,u.xor=Xm,u.xorBy=qm,u.xorWith=Hm,u.zip=Jm,u.zipObject=Ym,u.zipObjectDeep=Qm,u.zipWith=eh,u.entries=Ad,u.entriesIn=Ed,u.extend=jd,u.extendWith=oo,wl(u,u),u.add=Jg,u.attempt=Td,u.camelCase=tg,u.capitalize=Pd,u.ceil=Yg,u.clamp=Yp,u.clone=Gh,u.cloneDeep=Xh,u.cloneDeepWith=qh,u.cloneWith=Zh,u.conformsTo=Hh,u.deburr=Dd,u.defaultTo=Pg,u.divide=Qg,u.endsWith=ng,u.eq=vr,u.escape=rg,u.escapeRegExp=sg,u.every=uh,u.find=mh,u.findIndex=nd,u.findKey=_p,u.findLast=hh,u.findLastIndex=rd,u.findLastKey=kp,u.floor=e0,u.forEach=cd,u.forEachRight=dd,u.forIn=Ap,u.forInRight=Ep,u.forOwn=Pp,u.forOwnRight=Dp,u.get=xl,u.gt=Jh,u.gte=Yh,u.has=Rp,u.hasIn=bl,u.head=ad,u.identity=Pn,u.includes=vh,u.indexOf=hm,u.inRange=Qp,u.invoke=Op,u.isArguments=Hs,u.isArray=Be,u.isArrayBuffer=Qh,u.isArrayLike=An,u.isArrayLikeObject=$t,u.isBoolean=ep,u.isBuffer=Ss,u.isDate=tp,u.isElement=np,u.isEmpty=rp,u.isEqual=sp,u.isEqualWith=ap,u.isError=pl,u.isFinite=ip,u.isFunction=Qr,u.isInteger=bd,u.isLength=ao,u.isMap=vd,u.isMatch=op,u.isMatchWith=lp,u.isNaN=cp,u.isNative=dp,u.isNil=fp,u.isNull=up,u.isNumber=yd,u.isObject=Dt,u.isObjectLike=Tt,u.isPlainObject=oi,u.isRegExp=gl,u.isSafeInteger=mp,u.isSet=Nd,u.isString=io,u.isSymbol=Ln,u.isTypedArray=ka,u.isUndefined=hp,u.isWeakMap=pp,u.isWeakSet=gp,u.join=vm,u.kebabCase=ag,u.last=Yn,u.lastIndexOf=ym,u.lowerCase=ig,u.lowerFirst=og,u.lt=xp,u.lte=bp,u.max=t0,u.maxBy=n0,u.mean=r0,u.meanBy=s0,u.min=a0,u.minBy=i0,u.stubArray=Sl,u.stubFalse=jl,u.stubObject=Kg,u.stubString=Gg,u.stubTrue=Zg,u.multiply=o0,u.nth=Nm,u.noConflict=Og,u.noop=Cl,u.now=no,u.pad=lg,u.padEnd=cg,u.padStart=dg,u.parseInt=ug,u.random=eg,u.reduce=Sh,u.reduceRight=jh,u.repeat=fg,u.replace=mg,u.result=Vp,u.round=l0,u.runInContext=j,u.sample=kh,u.size=Ph,u.snakeCase=hg,u.some=Dh,u.sortedIndex=Am,u.sortedIndexBy=Em,u.sortedIndexOf=Pm,u.sortedLastIndex=Dm,u.sortedLastIndexBy=Fm,u.sortedLastIndexOf=Tm,u.startCase=gg,u.startsWith=xg,u.subtract=c0,u.sum=d0,u.sumBy=u0,u.template=bg,u.times=Xg,u.toFinite=es,u.toInteger=Ve,u.toLength=Cd,u.toLower=vg,u.toNumber=Qn,u.toSafeInteger=vp,u.toString=pt,u.toUpper=yg,u.trim=Ng,u.trimEnd=wg,u.trimStart=Cg,u.truncate=Sg,u.unescape=jg,u.uniqueId=Hg,u.upperCase=_g,u.upperFirst=vl,u.each=cd,u.eachRight=dd,u.first=ad,wl(u,(function(){var e={};return Ir(u,function(t,r){$.call(u.prototype,r)||(e[r]=t)}),e})(),{chain:!1}),u.VERSION=f,mn(["bind","bindKey","curry","curryRight","partial","partialRight"],function(e){u[e].placeholder=u}),mn(["drop","take"],function(e,t){st.prototype[e]=function(r){r=r===s?1:zt(Ve(r),0);var i=this.__filtered__&&!t?new st(this):this.clone();return i.__filtered__?i.__takeCount__=Ht(r,i.__takeCount__):i.__views__.push({size:Ht(r,xt),type:e+(i.__dir__<0?"Right":"")}),i},st.prototype[e+"Right"]=function(r){return this.reverse()[e](r).reverse()}}),mn(["filter","map","takeWhile"],function(e,t){var r=t+1,i=r==Ne||r==we;st.prototype[e]=function(c){var h=this.clone();return h.__iteratees__.push({iteratee:Re(c,3),type:r}),h.__filtered__=h.__filtered__||i,h}}),mn(["head","last"],function(e,t){var r="take"+(t?"Right":"");
120st.prototype[e]=function(){return this[r](1).value()[0]}}),mn(["initial","tail"],function(e,t){var r="drop"+(t?"":"Right");st.prototype[e]=function(){return this.__filtered__?new st(this):this[r](1)}}),st.prototype.compact=function(){return this.filter(Pn)},st.prototype.find=function(e){return this.filter(e).head()},st.prototype.findLast=function(e){return this.reverse().find(e)},st.prototype.invokeMap=Je(function(e,t){return typeof e=="function"?new st(this):this.map(function(r){return ti(r,e,t)})}),st.prototype.reject=function(e){return this.filter(so(Re(e)))},st.prototype.slice=function(e,t){e=Ve(e);var r=this;return r.__filtered__&&(e>0||t<0)?new st(r):(e<0?r=r.takeRight(-e):e&&(r=r.drop(e)),t!==s&&(t=Ve(t),r=t<0?r.dropRight(-t):r.take(t-e)),r)},st.prototype.takeRightWhile=function(e){return this.reverse().takeWhile(e).reverse()},st.prototype.toArray=function(){return this.take(xt)},Ir(st.prototype,function(e,t){var r=/^(?:filter|find|map|reject)|While$/.test(t),i=/^(?:head|last)$/.test(t),c=u[i?"take"+(t=="last"?"Right":""):t],h=i||/^find/.test(t);c&&(u.prototype[t]=function(){var b=this.__wrapped__,y=i?[1]:arguments,_=b instanceof st,Z=y[0],X=_||Be(b),ne=function(tt){var at=c.apply(u,ur([tt],y));return i&&be?at[0]:at};X&&r&&typeof Z=="function"&&Z.length!=1&&(_=X=!1);var be=this.__chain__,_e=!!this.__actions__.length,Me=h&&!be,Ze=_&&!_e;if(!h&&X){b=Ze?b:new st(this);var Oe=e.apply(b,y);return Oe.__actions__.push({func:eo,args:[ne],thisArg:s}),new qn(Oe,be)}return Me&&Ze?e.apply(this,y):(Oe=this.thru(ne),Me?i?Oe.value()[0]:Oe.value():Oe)})}),mn(["pop","push","shift","sort","splice","unshift"],function(e){var t=F[e],r=/^(?:push|sort|unshift)$/.test(e)?"tap":"thru",i=/^(?:pop|shift)$/.test(e);u.prototype[e]=function(){var c=arguments;if(i&&!this.__chain__){var h=this.value();return t.apply(Be(h)?h:[],c)}return this[r](function(b){return t.apply(Be(b)?b:[],c)})}}),Ir(st.prototype,function(e,t){var r=u[t];if(r){var i=r.name+"";$.call(Xn,i)||(Xn[i]=[]),Xn[i].push({name:t,func:r})}}),Xn[Zi(s,Y).name]=[{name:"wrapper",func:s}],st.prototype.clone=Su,st.prototype.reverse=ju,st.prototype.value=_u,u.prototype.at=nh,u.prototype.chain=rh,u.prototype.commit=sh,u.prototype.next=ah,u.prototype.plant=oh,u.prototype.reverse=lh,u.prototype.toJSON=u.prototype.valueOf=u.prototype.value=ch,u.prototype.first=u.prototype.head,$e&&(u.prototype[$e]=ih),u}),bs=Fo();In?((In.exports=bs)._=bs,da._=bs):jt._=bs}).call(vx)})(hi,hi.exports)),hi.exports}var Nx=yx(),mi={};const Da=2147483647,Lr=36,Xl=1,vi=26,wx=38,Cx=700,pu=72,gu=128,xu="-",Sx=/^xn--/,jx=/[^\0-\x7F]/,_x=/[\x2E\u3002\uFF0E\uFF61]/g,kx={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},Ml=Lr-Xl,zr=Math.floor,Ol=String.fromCharCode;function js(d){throw new RangeError(kx[d])}function Ax(d,l){const s=[];let f=d.length;for(;f--;)s[f]=l(d[f]);return s}function bu(d,l){const s=d.split("@");let f="";s.length>1&&(f=s[0]+"@",d=s[1]),d=d.replace(_x,".");const m=d.split("."),g=Ax(m,l).join(".");return f+g}function ql(d){const l=[];let s=0;const f=d.length;for(;s<f;){const m=d.charCodeAt(s++);if(m>
120=55296&&m<=56319&&s<f){const g=d.charCodeAt(s++);(g&64512)==56320?l.push(((m&1023)<<10)+(g&1023)+65536):(l.push(m),s--)}else l.push(m)}return l}const vu=d=>String.fromCodePoint(...d),Ex=function(d){return d>=48&&d<58?26+(d-48):d>=65&&d<91?d-65:d>=97&&d<123?d-97:Lr},Qd=function(d,l){return d+22+75*(d<26)-((l!=0)<<5)},yu=function(d,l,s){let f=0;for(d=s?zr(d/Cx):d>>1,d+=zr(d/l);d>Ml*vi>>1;f+=Lr)d=zr(d/Ml);return zr(f+(Ml+1)*d/(d+wx))},Hl=function(d){const l=[],s=d.length;let f=0,m=gu,g=pu,A=d.lastIndexOf(xu);A<0&&(A=0);for(let O=0;O<A;++O)d.charCodeAt(O)>=128&&js("not-basic"),l.push(d.charCodeAt(O));for(let O=A>0?A+1:0;O<s;){const U=f;for(let z=1,E=Lr;;E+=Lr){O>=s&&js("invalid-input");const me=Ex(d.charCodeAt(O++));me>=Lr&&js("invalid-input"),me>zr((Da-f)/z)&&js("overflow"),f+=me*z;const ve=E<=g?Xl:E>=g+vi?vi:E-g;if(me<ve)break;const q=Lr-ve;z>zr(Da/q)&&js("overflow"),z*=q}const k=l.length+1;g=yu(f-U,k,U==0),zr(f/k)>Da-m&&js("overflow"),m+=zr(f/k),f%=k,l.splice(f++,0,m)}return String.fromCodePoint(...l)},Jl=function(d){const l=[];d=ql(d);const s=d.length;let f=gu,m=0,g=pu;for(const U of d)U<128&&l.push(Ol(U));const A=l.length;let O=A;for(A&&l.push(xu);O<s;){let U=Da;for(const z of d)z>=f&&z<U&&(U=z);const k=O+1;U-f>zr((Da-m)/k)&&js("overflow"),m+=(U-f)*k,f=U;for(const z of d)if(z<f&&++m>Da&&js("overflow"),z===f){let E=m;for(let me=Lr;;me+=Lr){const ve=me<=g?Xl:me>=g+vi?vi:me-g;if(E<ve)break;const q=E-ve,ee=Lr-ve;l.push(Ol(Qd(ve+q%ee,0))),E=zr(q/ee)}l.push(Ol(Qd(E,0))),g=yu(m,k,O===A),m=0,++O}++m,++f}return l.join("")},Nu=function(d){return bu(d,function(l){return Sx.test(l)?Hl(l.slice(4).toLowerCase()):l})},wu=function(d){return bu(d,function(l){return jx.test(l)?"xn--"+Jl(l):l})},Px={version:"2.3.1",ucs2:{decode:ql,encode:vu},decode:Hl,encode:Jl,toASCII:wu,toUnicode:Nu},Dx=Object.freeze(Object.defineProperty({__proto__:null,decode:Hl,default:Px,encode:Jl,toASCII:wu,toUnicode:Nu,ucs2decode:ql,ucs2encode:vu},Symbol.toStringTag,{value:"Module"})),Fx=ou(Dx),Tx={},Rx=Object.freeze(Object.defineProperty({__proto__:null,default:Tx},Symbol.toStringTag,{value:"Module"})),Ix=ou(Rx);var eu;function Mx(){if(eu)return mi;eu=1;const d=Fx,l=Ix,s={hasOwn:Object.prototype.hasOwnProperty,indexOf:Array.prototype.indexOf,defaultThreshold:16,maxIPv6Groups:8,categories:{valid:1,dnsWarn:7,rfc5321:15,cfws:31,deprecated:63,rfc5322:127,error:255},diagnoses:{valid:0,rfc5321TLD:9,rfc5321TLDNumeric:10,rfc5321QuotedString:11,rfc5321AddressLiteral:12,cfwsComment:17,cfwsFWS:18,undesiredNonAscii:25,deprecatedLocalPart:33,deprecatedFWS:34,deprecatedQTEXT:35,deprecatedQP:36,deprecatedComment:37,deprecatedCTEXT:38,deprecatedIPv6:39,deprecatedCFWSNearAt:49,rfc5322Domain:65,rfc5322TooLong:66,rfc5322LocalTooLong:67,rfc5322DomainTooLong:68,rfc5322LabelTooLong:69,rfc5322DomainLiteral:70,rfc5322DomainLiteralOBSDText:71,rfc5322IPv6GroupCount:72,rfc5322IPv62x2xColon:73,rfc5322IPv6BadCharacter:74,rfc5322IPv6MaxGroups:75,rfc5322IPv6ColonStart:76,rfc5322IPv6ColonEnd:77,errExpectingDTEXT:129,errNoLocalPart:130,errNoDomain:131,errConsecutiveDots:132,errATEXTAfterCFWS:133,errATEXTAfterQS:134,errATEXTAfterDomainLiteral:135,errExpectingQPair:136,errExpectingATEXT:137,errExpectingQTEXT:138,errExpectingCTEXT:139,errBackslashEnd:140,errDotStart:141,errDotEnd:142,errDomainHyphenStart:143,errDomainHyphenEnd:144,errUnclosedQuotedString:145,errUnclosedComment:146,errUnclosedDomainLiteral:147,errFWSCRLFx2:148,errFWSCRLFEnd:149,errCRNoLF:150,errUnknownTLD:160,errDomainTooShort:161,errDotAfterDomainLiteral:162},components:{localpart:0,domain:1,literal:2,contextComment:3,contextFWS:4,contextQuotedString:5,contextQuotedPair:6}};return s.specials=(function(){const f='()<>[]:;@\\,."',m=new Array(256);m.fill(!1);for(let g=0;g<f.length;++g)m[f.codePointAt(g)]=!0;return function(g){return m[g]}})(),s.c0Controls=(function(){const f=new Array(256);f.fill(!1);for(let m=0;m<33;++m)f[m]=!0;return function(m){return f[m]}})(),s.c1Controls=(function(){const f=new Array(256);f.fill(!1);for(let m=127;m<160;++m)f[m]=!0;return function(m){return f[m]}})(),s.regex={ipV4:/\b(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/,ipV6:/^[a-fA-F\d]{0,4}$/},s.normalizeSupportsNul="\0".normalize("NFC")==="\0",s.nulNormalize=function(f){return f.split("\0").map(m=>m.normalize("NFC")).join("\0")},s.normalize=function(f){return f.normalize("NFC")},s.normalizeSupportsNul||(s.normalize=function(f){return f.indexOf("\0")>=0?s.nulNormalize(f):f.normalize("NFC")}),s.checkIpV6=function(f){return f.every(m=>s.regex.ipV6.test(m))},s.isIterable=Array.isArray,typeof Symbol<"u"&&(s.isIterable=f=>Array.isArray(f)||!!f&&typeof f=="object"&&typeof f[Symbol.iterator]=="function"),s._isSet=f=>f instanceof Set,s._isMap=f=>f instanceof Map,s.isSet=l.types&&l.types.isSet||s._isSet,s.isMap=l.types&&l.types.isMap||s._isMap,s.normalizeTable=function(f){return s.isSet(f)||Array.isArray(f)?f:s.isMap(f)?f.keys():Object.keys(f)},s.canonicalizeAtom=function(f){return d.toASCII(f).toLowerCase()},s.includesMapped=function(f,m,g){for(const A of f)if(g===m(A))return!0;return!1}
120,s.validDomain=function(f,m){const g=s.canonicalizeAtom(f);return m.tldBlacklist?!s.includesMapped(s.normalizeTable(m.tldBlacklist),s.canonicalizeAtom,g):s.includesMapped(s.normalizeTable(m.tldWhitelist),s.canonicalizeAtom,g)},s.hasDomainLiteralThenAtom=function(f){let m=!1;for(let g=0;g<f.length;++g)if(f[g][0]==="[")m=!0;else if(m)return!0;return!1},mi.validate=s.validate=function(f,m,g){if(m=m||{},typeof f!="string")throw new TypeError("expected string email");f=s.normalize(f),typeof m=="function"&&(g=m,m={}),typeof g!="function"&&(g=null);let A,O;if(typeof m.errorLevel=="number"?(A=!0,O=m.errorLevel):(A=!!m.errorLevel,O=s.diagnoses.valid),m.tldWhitelist){if(typeof m.tldWhitelist=="string")m.tldWhitelist=[m.tldWhitelist];else if(typeof m.tldWhitelist!="object")throw new TypeError("expected array or object tldWhitelist")}if(m.tldBlacklist){if(typeof m.tldBlacklist=="string")m.tldBlacklist=[m.tldBlacklist];else if(typeof m.tldBlacklist!="object")throw new TypeError("expected array or object tldBlacklist")}if(m.minDomainAtoms&&(m.minDomainAtoms!==(+m.minDomainAtoms|0)||m.minDomainAtoms<0))throw new TypeError("expected positive integer minDomainAtoms");if(m.excludeDiagnoses){if(!s.isIterable(m.excludeDiagnoses))throw new TypeError("expected iterable excludeDiagnoses");s.isSet(m.excludeDiagnoses)||(m.excludeDiagnoses=new Set(m.excludeDiagnoses))}let U=s.diagnoses.valid;const k=L=>{L>U&&(!m.excludeDiagnoses||!m.excludeDiagnoses.has(L))&&(U=L)};!(m.allowUnicode===void 0||!!m.allowUnicode)&&/[^\x00-\x7f]/.test(f)&&k(s.diagnoses.undesiredNonAscii);const E={now:s.components.localpart,prev:s.components.localpart,stack:[s.components.localpart]};let me="";const ve={local:"",domain:""},q={locals:[""],domains:[""]};let ee=0,de=0,Y=0,le,J=!1,G=!1;const ue=f.length;let V;for(let L=0;L<ue;L+=V.length){switch(V=String.fromCodePoint(f.codePointAt(L)),E.now){case s.components.localpart:switch(V){case"(":de===0?k(ee===0?s.diagnoses.cfwsComment:s.diagnoses.deprecatedComment):(k(s.diagnoses.cfwsComment),G=!0),E.stack.push(E.now),E.now=s.components.contextComment;break;case".":de===0?k(ee===0?s.diagnoses.errDotStart:s.diagnoses.errConsecutiveDots):(G&&k(s.diagnoses.deprecatedLocalPart),G=!1,de=0,++ee,ve.local+=V,q.locals[ee]="");break;case'"':de===0?(k(ee===0?s.diagnoses.rfc5321QuotedString:s.diagnoses.deprecatedLocalPart),ve.local+=V,q.locals[ee]+=V,de+=Buffer.byteLength(V,"utf8"),G=!0,E.stack.push(E.now),E.now=s.components.contextQuotedString):k(s.diagnoses.errExpectingATEXT);break;case"\r":if(ue===++L||f[L]!==`
121`){k(s.diagnoses.errCRNoLF);break}case" ":case"	":de===0?k(ee===0?s.diagnoses.cfwsFWS:s.diagnoses.deprecatedFWS):G=!0,E.stack.push(E.now),E.now=s.components.contextFWS,me=V;break;case"@":if(E.stack.length!==1)throw new Error("unexpected item on context stack");ve.local.length===0?k(s.diagnoses.errNoLocalPart):de===0?k(s.diagnoses.errDotEnd):Buffer.byteLength(ve.local,"utf8")>64?k(s.diagnoses.rfc5322LocalTooLong):(E.prev===s.components.contextComment||E.prev===s.components.contextFWS)&&k(s.diagnoses.deprecatedCFWSNearAt),E.now=s.components.domain,E.stack[0]=s.components.domain,ee=0,de=0,G=!1;break;default:if(G)switch(E.prev){case s.components.contextComment:case s.components.contextFWS:k(s.diagnoses.errATEXTAfterCFWS);break;case s.components.contextQuotedString:k(s.diagnoses.errATEXTAfterQS);break;default:throw new Error("more atext found where none is allowed, but unrecognized prev context: "+E.prev)}else E.prev=E.now,le=V.codePointAt(0),(s.specials(le)||s.c0Controls(le)||s.c1Controls(le))&&k(s.diagnoses.errExpectingATEXT),ve.local+=V,q.locals[ee]+=V,de+=Buffer.byteLength(V,"utf8")}break;case s.components.domain:switch(V){case"(":de===0?k(ee===0?s.diagnoses.deprecatedCFWSNearAt:s.diagnoses.deprecatedComment):(G=!0,k(s.diagnoses.cfwsComment)),E.stack.push(E.now),E.now=s.components.contextComment;break;case".":const fe=d.toASCII(q.domains[ee]).length;de===0?k(ee===0?s.diagnoses.errDotStart:s.diagnoses.errConsecutiveDots):J?k(s.diagnoses.errDomainHyphenEnd):fe>63&&k(s.diagnoses.rfc5322LabelTooLong),G=!1,de=0,++ee,q.domains[ee]="",ve.domain+=V;break;case"[":q.domains[ee].length===0?(ve.domain.length&&k(s.diagnoses.errDotAfterDomainLiteral),G=!0,de+=Buffer.byteLength(V,"utf8"),E.stack.push(E.now),E.now=s.components.literal,ve.domain+=V,q.domains[ee]+=V,ve.literal=""):k(s.diagnoses.errExpectingATEXT);break;case"\r":if(ue===++L||f[L]!==`
122`){k(s.diagnoses.errCRNoLF);break}case" ":case"	":de===0?k(ee===0?s.diagnoses.deprecatedCFWSNearAt:s.diagnoses.deprecatedFWS):(k(s.diagnoses.cfwsFWS),G=!0),E.stack.push(E.now),E.now=s.components.c
122ontextFWS,me=V;break;default:if(G)switch(E.prev){case s.components.contextComment:case s.components.contextFWS:k(s.diagnoses.errATEXTAfterCFWS);break;case s.components.literal:k(s.diagnoses.errATEXTAfterDomainLiteral);break;default:throw new Error("more atext found where none is allowed, but unrecognized prev context: "+E.prev)}le=V.codePointAt(0),J=!1,s.specials(le)||s.c0Controls(le)||s.c1Controls(le)?k(s.diagnoses.errExpectingATEXT):V==="-"?(de===0&&k(s.diagnoses.errDomainHyphenStart),J=!0):(le<48||le>122&&le<192||le>57&&le<65||le>90&&le<97)&&k(s.diagnoses.rfc5322Domain),ve.domain+=V,q.domains[ee]+=V,de+=Buffer.byteLength(V,"utf8")}break;case s.components.literal:switch(V){case"]":if(U<s.categories.deprecated){let fe=-1,Ae=ve.literal;const re=s.regex.ipV4.exec(Ae);if(re&&(fe=re.index,fe!==0&&(Ae=Ae.slice(0,fe)+"0:0")),fe===0)k(s.diagnoses.rfc5321AddressLiteral);else if(Ae.slice(0,5).toLowerCase()!=="ipv6:")k(s.diagnoses.rfc5322DomainLiteral);else{const I=Ae.slice(5);let Ne=s.maxIPv6Groups;const ge=I.split(":");fe=I.indexOf("::"),~fe?fe!==I.lastIndexOf("::")?k(s.diagnoses.rfc5322IPv62x2xColon):((fe===0||fe===I.length-2)&&++Ne,ge.length>Ne?k(s.diagnoses.rfc5322IPv6MaxGroups):ge.length===Ne&&k(s.diagnoses.deprecatedIPv6)):ge.length!==Ne&&k(s.diagnoses.rfc5322IPv6GroupCount),I[0]===":"&&I[1]!==":"?k(s.diagnoses.rfc5322IPv6ColonStart):I[I.length-1]===":"&&I[I.length-2]!==":"?k(s.diagnoses.rfc5322IPv6ColonEnd):s.checkIpV6(ge)?k(s.diagnoses.rfc5321AddressLiteral):k(s.diagnoses.rfc5322IPv6BadCharacter)}}else k(s.diagnoses.rfc5322DomainLiteral);ve.domain+=V,q.domains[ee]+=V,de+=Buffer.byteLength(V,"utf8"),E.prev=E.now,E.now=E.stack.pop();break;case"\\":k(s.diagnoses.rfc5322DomainLiteralOBSDText),E.stack.push(E.now),E.now=s.components.contextQuotedPair;break;case"\r":if(ue===++L||f[L]!==`
123`){k(s.diagnoses.errCRNoLF);break}case" ":case"	":k(s.diagnoses.cfwsFWS),E.stack.push(E.now),E.now=s.components.contextFWS,me=V;break;default:if(le=V.codePointAt(0),le!==127&&s.c1Controls(le)||le===0||V==="["){k(s.diagnoses.errExpectingDTEXT);break}else(s.c0Controls(le)||le===127)&&k(s.diagnoses.rfc5322DomainLiteralOBSDText);ve.literal+=V,ve.domain+=V,q.domains[ee]+=V,de+=Buffer.byteLength(V,"utf8")}break;case s.components.contextQuotedString:switch(V){case"\\":E.stack.push(E.now),E.now=s.components.contextQuotedPair;break;case"\r":if(ue===++L||f[L]!==`
124`){k(s.diagnoses.errCRNoLF);break}case"	":ve.local+=" ",q.locals[ee]+=" ",de+=Buffer.byteLength(V,"utf8"),k(s.diagnoses.cfwsFWS),E.stack.push(E.now),E.now=s.components.contextFWS,me=V;break;case'"':ve.local+=V,q.locals[ee]+=V,de+=Buffer.byteLength(V,"utf8"),E.prev=E.now,E.now=E.stack.pop();break;default:le=V.codePointAt(0),le!==127&&s.c1Controls(le)||le===0||le===10?k(s.diagnoses.errExpectingQTEXT):(s.c0Controls(le)||le===127)&&k(s.diagnoses.deprecatedQTEXT),ve.local+=V,q.locals[ee]+=V,de+=Buffer.byteLength(V,"utf8")}break;case s.components.contextQuotedPair:le=V.codePointAt(0),le!==127&&s.c1Controls(le)?k(s.diagnoses.errExpectingQPair):(le<31&&le!==9||le===127)&&k(s.diagnoses.deprecatedQP),E.prev=E.now,E.now=E.stack.pop();const ce="\\"+V;switch(E.now){case s.components.contextComment:break;case s.components.contextQuotedString:ve.local+=ce,q.locals[ee]+=ce,de+=2;break;case s.components.literal:ve.domain+=ce,q.domains[ee]+=ce,de+=2;break;default:throw new Error("quoted pair logic invoked in an invalid context: "+E.now)}break;case s.components.contextComment:switch(V){case"(":E.stack.push(E.now),E.now=s.components.contextComment;break;case")":E.prev=E.now,E.now=E.stack.pop();break;case"\\":E.stack.push(E.now),E.now=s.components.contextQuotedPair;break;case"\r":if(ue===++L||f[L]!==`
125`){k(s.diagnoses.errCRNoLF);break}case" ":case"	":k(s.diagnoses.cfwsFWS),E.stack.push(E.now),E.now=s.components.contextFWS,me=V;break;default:if(le=V.codePointAt(0),le===0||le===10||le!==127&&s.c1Controls(le)){k(s.diagnoses.errExpectingCTEXT);break}else(s.c0Controls(le)||le===127)&&k(s.diagnoses.deprecatedCTEXT)}break;case s.components.contextFWS:if(me==="\r"){if(V==="\r"){k(s.diagnoses.errFWSCRLFx2);break}++Y>1?k(s.diagnoses.deprecatedFWS):Y=1}switch(V){case"\r":(ue===++L||f[L]!==`
126`)&&k(s.diagnoses.errCRNoLF);break;case" ":case"	":break;default:me==="\r"&&k(s.diagnoses.errFWSCRLFEnd),Y=0,E.prev=E.now,E.now=E.stack.pop(),--L}me=V;break;default:throw new Error("unknown context: "+E.now)}if(U>s.categories.rfc5322)break}if(U<s.categories.rfc5322){const L=d.toASCII(ve.domain).length;
126if(E.now===s.components.contextQuotedString)k(s.diagnoses.errUnclosedQuotedString);else if(E.now===s.components.contextQuotedPair)k(s.diagnoses.errBackslashEnd);else if(E.now===s.components.contextComment)k(s.diagnoses.errUnclosedComment);else if(E.now===s.components.literal)k(s.diagnoses.errUnclosedDomainLiteral);else if(V==="\r")k(s.diagnoses.errFWSCRLFEnd);else if(ve.domain.length===0)k(s.diagnoses.errNoDomain);else if(de===0)k(s.diagnoses.errDotEnd);else if(J)k(s.diagnoses.errDomainHyphenEnd);else if(L>255)k(s.diagnoses.rfc5322DomainTooLong);else if(Buffer.byteLength(ve.local,"utf8")+L+1>254)k(s.diagnoses.rfc5322TooLong);else if(de>63)k(s.diagnoses.rfc5322LabelTooLong);else if(m.minDomainAtoms&&q.domains.length<m.minDomainAtoms&&(q.domains.length!==1||q.domains[0][0]!=="["))k(s.diagnoses.errDomainTooShort);else if(s.hasDomainLiteralThenAtom(q.domains))k(s.diagnoses.errDotAfterDomainLiteral);else if(m.tldWhitelist||m.tldBlacklist){const ce=q.domains[ee];s.validDomain(ce,m)||k(s.diagnoses.errUnknownTLD)}}U<s.categories.dnsWarn&&q.domains[ee].codePointAt(0)<=57&&k(s.diagnoses.rfc5321TLDNumeric),U<O&&(U=s.diagnoses.valid);const he=A?U:U<s.defaultThreshold;return g&&g(he),he},mi.diagnoses=s.validate.diagnoses=(function(){const f={},m=Object.keys(s.diagnoses);for(let g=0;g<m.length;++g){const A=m[g];f[A]=s.diagnoses[A]}return f})(),mi.normalize=s.normalize,mi}var Ox=Mx();const tu=h0(Ox);function pi(d){return d.replace(/\D+/g,"")}function Lx(d,l,s,f){const m=pi(d);if(m==="")return"";const g=m.slice(0,f),A=Number(g);if(Number.isNaN(A))return"";const O=Math.min(Math.max(A,l),s);return String(O)}const zx=(d,l)=>{const s=[],f=[];if(!d||typeof d!="object")return s.push("Price matrix is missing or invalid"),{isValid:!1,errors:s,warnings:f};const m=l?new Set(l.filter(A=>!!A).map(A=>A.toUpperCase())):null,g=Object.keys(d).filter(A=>!m||m.has(A.toUpperCase()));return g.length===0?(s.push("Price matrix is empty - no zones configured"),{isValid:!1,errors:s,warnings:f}):(g.forEach(A=>{const O=d[A];if(!O||typeof O!="object"){s.push(`Invalid price data for zone ${A}`);return}Object.keys(O).filter(k=>!m||m.has(k.toUpperCase())).forEach(k=>{const z=O[k];let E=null;if(typeof z=="number")E=z;else if(typeof z=="string"&&z.trim()!==""){if(E=parseFloat(z),isNaN(E)){s.push(`Invalid price for ${A} → ${k}: must be a number`);return}}else if(z==null||typeof z=="string"&&z.trim()===""){s.push(`Missing price for ${A} → ${k}`);return}if(E===null){s.push(`Missing price for ${A} → ${k}`);return}E<0?s.push(`Invalid price for ${A} → ${k}: cannot be negative`):E>999999&&s.push(`Invalid price for ${A} → ${k}: exceeds maximum (999999)`),E===0&&f.push(`Price for ${A} → ${k} is zero`)})}),{isValid:s.length===0,errors:s,warnings:f})},$x=d=>{const l=[],s=[];if(!d.zones||!Array.isArray(d.zones))return l.push("Zones configuration is missing or invalid"),{isValid:!1,errors:l,warnings:s};if(d.zones.length===0)return l.push("No zones configured - please configure at least one zone"),{isValid:!1,errors:l,warnings:s};d.zones.forEach(g=>{(!g.zoneCode||typeof g.zoneCode!="string")&&l.push(`Zone ${g.zoneName||"unknown"} has invalid zone code`),(!g.selectedCities||g.selectedCities.length===0)&&s.push(`Zone ${g.zoneCode} has no cities mapped (coverage uses zone-wide defaults)`),!g.isComplete&&g.selectedCities&&g.selectedCities.length>0&&s.push(`Zone ${g.zoneCode} is marked as incomplete`)});const f=d.zones.map(g=>g.zoneCode),m=f.filter((g,A)=>f.indexOf(g)!==A);return m.length>0&&l.push(`Duplicate zone codes found: ${m.join(", ")}`),{isValid:l.length===0,errors:l,warnings:s}},Ux=d=>{const l=[],s=[];return d.oda?(d.oda.enabled&&((!d.oda.pincodes||d.oda.pincodes.length===0)&&s.push("ODA is enabled but no pincodes are configured"),(d.oda.surcharge.fixed<0||d.oda.surcharge.variable<0)&&l.push("ODA surcharge values cannot be negative")),{isValid:l.length===0,errors:l,warnings:s}):(s.push("ODA configuration is missing"),{isValid:!0,errors:l,warnings:s})},Wx=d=>{const l=[],s=[];if(!d.other)return{isValid:!0,errors:l,warnings:s};const f=d.other;return["minWeight","docketCharges","fuel","minCharges","greenTax","daccCharges","miscellanousCharges"].forEach(A=>{const O=f[A];typeof O=="number"&&O<0&&l.push(`${A} cannot be negative`)}),f.divisor!==null&&f.cftFactor!==null&&s.push("Both divisor and cftFactor are set - they should be mutually exclusive"),["rovCharges","codCharges","topayCharges","handlingCharges","appointmentCharges","insuaranceCharges","odaCharges","prepaidCharges","fmCharges"].forEach(A=>{const O=f[A];typeof O=="object"&&O!==null&&("variable"in O&&typeof O.variable=="number"&&O.variable<0&&l.push(`${A}
126.variable cannot be negative`),"fixed"in O&&typeof O.fixed=="number"&&O.fixed<0&&l.push(`${A}.fixed cannot be negative`))}),{isValid:l.length===0,errors:l,warnings:s}},rs=d=>{const l=[],s=[];if(!d)return l.push("Wizard data is missing - please configure zones and pricing"),{isValid:!1,errors:l,warnings:s};const f=$x(d);l.push(...f.errors),s.push(...f.warnings);const m=d.zones?.map(U=>U.zoneCode).filter(U=>!!U)||[],g=zx(d.priceMatrix,m.length>0?m:void 0);l.push(...g.errors),s.push(...g.warnings);const A=Ux(d);l.push(...A.errors),s.push(...A.warnings);const O=Wx(d);return l.push(...O.errors),s.push(...O.warnings),{isValid:l.length===0,errors:l,warnings:s}},ss=d=>{if(!d)return{hasZones:!1,hasPriceMatrix:!1,hasODA:!1,hasOtherCharges:!1,zoneCount:0,matrixDimension:"0×0",completionPercentage:0};const l=Array.isArray(d.zones)&&d.zones.length>0,s=l&&d.zones.every(E=>E&&E.isComplete===!0),f=!!d.priceMatrix&&typeof d.priceMatrix=="object"&&Object.keys(d.priceMatrix).length>0,m=f&&Object.values(d.priceMatrix).some(E=>E&&typeof E=="object"?Object.values(E).some(me=>typeof me=="number"&&me>0):!1),g=!!d.oda&&d.oda.enabled===!0,A=d.other!=null,O=l?d.zones.length:0,k=`${f?Object.keys(d.priceMatrix).length:0}×${O}`;let z=0;return l&&(z+=25),s&&(z+=25),f&&(z+=25),m&&(z+=25),{hasZones:l,hasPriceMatrix:f,hasODA:g,hasOtherCharges:A,zoneCount:O,matrixDimension:k,completionPercentage:z}},nu=["N1","N2","N3","N4","S1","S2","S3","S4","E1","E2","W1","W2","W3","C1","C2","NE1","NE2","X1","X2","X3"],ru={FULL_MINUS_EXCEPTIONS:"FULL_MINUS_EXCEPT",ONLY_SERVED:"ONLY_SERVED"};function mo(d,l){const s=new Set;for(const f of d)for(let m=f.s;m<=f.e;m++)s.add(m);for(const f of l)s.add(f);return Array.from(s).sort((f,m)=>f-m)}function Bx(d){const l=[];d.version||l.push("Missing version field");const s=["meta","pricing","serviceability","stats"];for(const f of s)d[f]||l.push(`Missing required section: ${f}`);if(d.meta){const f=["companyName","transporterType"];for(const m of f)d.meta[m]||l.push(`Meta missing required field: ${m}`)}if(d.pricing&&(d.pricing.priceRate||l.push("Pricing missing priceRate"),d.pricing.zoneRates||l.push("Pricing missing zoneRates")),d.serviceability)for(const[f,m]of Object.entries(d.serviceability))if(!m.mode)l.push(`Zone ${f} missing coverage mode`);else{const g=m.mode;g===ru.FULL_MINUS_EXCEPTIONS?!m.exceptRanges&&!m.exceptSingles&&l.push(`Zone ${f} FULL_MINUS mode but no exceptions`):g===ru.ONLY_SERVED&&!m.servedRanges&&!m.servedSingles&&l.push(`Zone ${f} ONLY_SERVED mode but no served data`)}return{isValid:l.length===0,errors:l}}const Ll=[{upTo:20,label:"Reading your documents…",icon:R0},{upTo:45,label:"Scanning rate cards & charges…",icon:I0},{upTo:75,label:"Mapping zones & pincodes…",icon:M0},{upTo:100,label:"Putting it all together…",icon:xi}],Vx=({className:d})=>n.jsxs("svg",{viewBox:"0 0 64 40",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:d,children:[n.jsx("rect",{x:"2",y:"6",width:"36",height:"20",rx:"2",fill:"#2563eb"}),n.jsx("rect",{x:"5",y:"9",width:"30",height:"6",rx:"1",fill:"#bfdbfe",opacity:"0.9"}),n.jsx("path",{d:"M38 14 H50 C52 14 53 15 54 17 L58 23 C58.6 24 58 25 57 25 H38 Z",fill:"#1d4ed8"}),n.jsx("path",{d:"M50 16 L53.5 16 L56.2 21 H50 Z",fill:"#dbeafe"}),n.jsx("rect",{x:"2",y:"26",width:"58",height:"2.5",fill:"#1e3a8a"}),n.jsxs("g",{className:"origin-center",style:{transformOrigin:"13px 32px"},children:[n.jsx("circle",{cx:"13",cy:"32",r:"5.5",fill:"#0f172a"}),n.jsx("circle",{cx:"13",cy:"32",r:"2.4",fill:"#cbd5e1"}),n.jsx("rect",{x:"12.4",y:"27",width:"1.2",height:"2",fill:"#cbd5e1"}),n.jsx("rect",{x:"12.4",y:"35",width:"1.2",height:"2",fill:"#cbd5e1"})]}),n.jsxs("g",{style:{transformOrigin:"48px 32px"},children:[n.jsx("circle",{cx:"48",cy:"32",r:"5.5",fill:"#0f172a"}),n.jsx("circle",{cx:"48",cy:"32",r:"2.4",fill:"#cbd5e1"}),n.jsx("rect",{x:"47.4",y:"27",width:"1.2",height:"2",fill:"#cbd5e1"}),n.jsx("rect",{x:"47.4",y:"35",width:"1.2",height:"2",fill:"#cbd5e1"})]})]}),Kx=({progress:d})=>{const l=Ll.find(A=>d<=A.upTo)||Ll[Ll.length-1],s=l.icon,f=Math.round(d),m=26,g=2*Math.PI*m;return n.jsxs("div",{className:"relative rounded-2xl border border-blue-100 bg-gradient-to-br from-white via-blue-50 to-white p-6 overflow-hidden shadow-lg shadow-blue-900/5",children:[n.jsx(ct.div,{className:"absolute -top-10 -left-10 w-40 h-40 rounded-full bg-blue-200/40 blur-3xl",animate:{x:[0,30,0],y:[0,20,0]},transition:{duration:8,repeat:1/0,ease:"easeInOut"}}),n.jsx(ct.div,{className:"absolute -bottom-12 -right-10 w-48 h-48 rounded-full bg-blue-200/35 blur-3xl",animate:{x:[0,-25,0],y:[0,-15,0]},transition:{duration:9,repeat:1/0,ease:"easeInOut"}}),[...Array(10)].map((A,O)=>n.jsx(ct.span,{className:"absolute w-1 h-1 rounded-full bg-blue-400/60",style:{left:`${O*9.7%100}%`,top:`${O*23%70+5}%`}
126,animate:{opacity:[.15,.8,.15]},transition:{duration:2+O%4,repeat:1/0,ease:"easeInOut",delay:O*.3}},O)),n.jsxs("div",{className:"relative z-10 flex items-center gap-5",children:[n.jsxs("div",{className:"relative w-20 h-20 shrink-0",children:[n.jsxs("svg",{viewBox:"0 0 60 60",className:"w-20 h-20 -rotate-90",children:[n.jsx("circle",{cx:"30",cy:"30",r:m,fill:"none",stroke:"rgba(37,99,235,0.15)",strokeWidth:"5"}),n.jsx(ct.circle,{cx:"30",cy:"30",r:m,fill:"none",stroke:"#2563eb",strokeWidth:"5",strokeLinecap:"round",strokeDasharray:g,animate:{strokeDashoffset:g-f/100*g},transition:{duration:.4,ease:"easeOut"}})]}),n.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:n.jsxs("span",{className:"text-lg font-black text-blue-600 tabular-nums",children:[f,"%"]})})]}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx(Nr,{mode:"wait",children:n.jsxs(ct.div,{initial:{opacity:0,y:8},animate:{opacity:1,y:0},exit:{opacity:0,y:-8},transition:{duration:.3},className:"flex items-center gap-2 text-sm font-bold text-slate-700",children:[n.jsx(s,{className:"w-4 h-4 text-blue-500 shrink-0"}),n.jsx("span",{className:"truncate",children:l.label})]},l.label)}),n.jsxs("div",{className:"relative h-9 mt-3",children:[n.jsx("div",{className:"absolute bottom-2 left-0 right-0 h-2 rounded-full bg-blue-100 overflow-hidden",children:n.jsx(ct.div,{className:"h-full bg-gradient-to-r from-blue-400 via-blue-600 to-blue-700 relative",animate:{width:`${f}%`},transition:{duration:.4,ease:"easeOut"},children:n.jsx(ct.div,{className:"absolute inset-y-0 w-12 bg-gradient-to-r from-transparent via-white/70 to-transparent",animate:{left:["-20%","120%"]},transition:{duration:1.4,repeat:1/0,ease:"linear"}})})}),n.jsx("div",{className:"absolute bottom-[11px] left-0 right-0 h-px border-t-2 border-dashed border-blue-200"}),n.jsx(ct.div,{className:"absolute bottom-1",animate:{left:`calc(${f}% - 18px)`},transition:{duration:.4,ease:"easeOut"},children:n.jsx(ct.div,{animate:{y:[0,-1.5,0]},transition:{duration:.5,repeat:1/0,ease:"easeInOut"},children:n.jsx(Vx,{className:"w-11 h-7 drop-shadow-lg"})})})]})]})]}),n.jsx("p",{className:"relative z-10 mt-4 text-xs text-slate-400",children:"This usually takes around 2 minutes per transporter — feel free to keep this tab open while we get everything ready."})]})};function tr(d){if(!d)return{fixed:0,variable:0};const l=(d.mode||d.chargeMode||"").toString().toUpperCase(),s=d.fixedAmount??d.fixedRate??d.fixed??d.amount??0,f=d.variableRange??d.variablePct??d.variablePercent??d.variable??0,m=Number(s)||0,g=Number(f)||0,A=d.unit||"per kg";return l==="FIXED"?{fixed:m,variable:0,unit:A}:l==="VARIABLE"?{fixed:0,variable:g,unit:A}:{fixed:m,variable:g,unit:A}}const Yt=lu,dn="zonePriceMatrixData",Gx={"Company Details":3,Company:3,Charges:4,"Serviceability & Pricing":2,Serviceability:2,Pricing:2},Zx=({isOpen:d,onClose:l,onGoToStep:s,errors:f})=>{if(!d)return null;const m=f.reduce((g,A)=>(g[A.step]||(g[A.step]=[]),g[A.step].push(A),g),{});return n.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-slate-900/60 backdrop-blur-sm p-4",children:n.jsxs(ct.div,{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.95},className:"bg-white rounded-2xl shadow-2xl max-w-lg w-full overflow-hidden flex flex-col max-h-[80vh]",children:[n.jsxs("div",{className:"bg-red-50 p-6 border-b border-red-100 flex items-center gap-4",children:[n.jsx("div",{className:"p-3 bg-red-100 rounded-full text-red-600",children:n.jsx(Fa,{className:"w-6 h-6"})}),n.jsxs("div",{children:[n.jsx("h3",{className:"text-xl font-bold text-red-900",children:"Validation Errors"}),n.jsxs("p",{className:"text-red-700 text-sm mt-1",children:["Please fix the following ",f.length," error",f.length!==1?"s":""," to proceed."]})]})]}),n.jsx("div",{className:"p-6 overflow-y-auto flex-1 space-y-6",children:Object.entries(m).map(([g,A])=>{const O=Gx[g];return n.jsxs("div",{className:"space-y-3",children:[n.jsxs("div",{className:"flex items-center justify-between border-b border-slate-100 pb-1",children:[n.jsx("h4",{className:"text-xs font-bold text-slate-400 uppercase tracking-wider",children:g}),O&&n.jsxs("button",{onClick:()=>{l(),s(O)},className:"text-xs font-semibold text-blue-600 hover:text-blue-800 flex items-center gap-1 transition-colors",children:["Go to Step ",O," →"]})]}),n.jsx("div",{className:"space-y-2",children:A.map((U,k)=>n.jsxs("div",{className:"flex items-start gap-3 p-3 rounded-lg bg-slate-50 border border-slate-100",children:[n.jsx(bi,{className:"w-5 h-5 text-red-500 shrink-0 mt-0.5"}),n.jsxs("div",{children:[n.jsx("p",{className:"text-sm font-semibold text-slate-700",children:U.field}),n.jsx("p",{className:"text-xs text-slate-500",children:U.message})]})]},k))})]},g)})}),n.jsx("div",{className:"p-4 bg-slate-50 border-t border-slate-100 flex justify-end",children:n.jsx("button",{onClick:l,className:"px-6 py-2 bg-slate-200 hover:bg-slate-300 text-slate-800 font-semibold rounded-lg transition-colors",children:"Close"})})]})})},zl=({onBack:d,onNext:l,backLabel:s="Back",nextLabel:f="Next",isNextDisabled:m=!1,isSubmitting:g=!1,showNext:A=!0,showBack:O=!0})=>{const U=f.toLowerCase().includes("submit")||f.toLowerCase()==="save";return n.jsxs("div",{className:"flex items-center justify-between mb-2 transition-all",children:[n.jsx("div",{className:"flex-1",children:O&&d&&n.jsxs("button",{type:"button",onClick:d,className:"group flex items-center gap-1.5 text-slate-500 hover:text-slate-800 font-bold text-[11px] uppercase tracking-wider transition-all px-3 py-1.5 rounded-lg hover:bg-slate-100/80 active:scale-95",children:[n.jsx(Cr,{className:"w-3.5 h-3.5 rotate-180 group-hover:-translate-x-1 transition-transform"}),s]})}),n.jsx("div",{className:"flex-1 flex justify-end",children:A&&l&&n.jsxs("button",{type:"button",onClick:l,disabled:m||g,className:`
127              relative overflow-hidden flex items-center gap-2 px-5 py-2 rounded-lg font-bold text-xs shadow-md transition-all active:scale-95
128              ${m||g?"bg-slate-100 text-slate-300 cursor-not-allowed shadow-none":U?"bg-gradient-to-r from-slate-900 to-slate-800 text-white hover:from-black hover:to-slate-900":"bg-gradient-to-r from-blue-600 to-indigo-600 text-white hover:from-blue-700 hover:to-indigo-700"}
129            `,children:[g?n.jsxs(n.Fragment,{children:[n.jsx(un,{className:"w-4 h-4 animate-spin"}),n.jsx("span",{children:"Processing..."})]}):n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"relative z-10",children:f}),U?n.jsx(xi,{className:"w-4 h-4 text-amber-300 animate-pulse"}):n.jsx(Cr,{className:"w-4 h-4 group-hover:translate-x-1 transition-transform"})]}),!m&&!g&&n.jsx("div",{className:"absolute inset-0 bg-gradient-to-tr from-white/0 via-white/10 to-white/0 -translate-x-full group-hover:translate-x-full transition-transform duration-1000 ease-in-out"})]})})]})};function Xx(){return cu.get("authToken")||localStorage.getItem("authToken")||localStorage.getItem("token")||""}function qx(d){try{const l=d.replace(/-/g,"+").replace(/_/g,"/").padEnd(Math.ceil(d.length/4)*4,"="),s=atob(l);return JSON.parse(s)}catch{return null}}function Hx(){const d=Xx();if(d&&d.split(".").length>=2){const l=qx(d.split(".")[1])||{}
129,s=l?.customer?._id||l?.user?._id||l?._id||l?.id||l?.customerId||l?.customerID||"";if(s)return s}try{const l=JSON.parse(localStorage.getItem("authUser")||"{}");return l?.customer?._id||l?._id||""}catch{return""}}function as(d){return d.split(/\s+/).map(l=>l.length?l[0].toUpperCase()+l.slice(1):"").join(" ").trim()}const Jx=/^[^\s@]+@[^\s@]+\.[^\s@]+$/;function Wt(d,...l){if(!d)return"";for(const s of l){const f=d[s];if(f!=null)return String(f)}return""}function Yx(d,l,...s){if(!d)return l;for(const f of s){const m=d[f];if(m!=null){const g=Number(m);if(!isNaN(g))return g}}return l}function su(){try{const d=localStorage.getItem(dn);if(!d)return null;const l=JSON.parse(d);if(!l?.priceMatrix||typeof l.priceMatrix!="object")return null;const s=l.priceMatrix;if(Array.isArray(s))return console.warn("[safeLoadZPM] priceMatrix is an array — discarding corrupted ZPM entry"),null;const f=Object.keys(s);return f.length>0&&f.every(m=>!isNaN(Number(m)))?(console.warn("[safeLoadZPM] priceMatrix has numeric-only keys — discarding corrupted ZPM entry"),null):l}catch{return null}}const jb=()=>{const{user:d}=p0(),l=U0(),s=C0(),f=W0(),m=q0(),{wizardData:g,isLoaded:A,clearWizard:O,setWizardData:U,writeWizard:k}=A0(),[z,E]=x.useState("road"),[me,ve]=x.useState(null);x.useEffect(()=>{l.setField("transportMode",z)},[z,l.setField]);const[q,ee]=x.useState(null),[de,Y]=x.useState([]),[le,J]=x.useState(!1),[G,ue]=x.useState(!1),[V,he]=x.useState(!1),[L,ce]=x.useState(0),[fe,Ae]=x.useState(5e3),[re,I]=x.useState(10),[Ne,ge]=x.useState(0),[we,ye]=x.useState("cloud"),[We,Vt]=x.useState(!1),[Dn,xt]=x.useState(null),[Un,Ye]=x.useState(!1),[qe,nt]=x.useState("loading"),yn=x.useRef(null),[ut,He]=x.useState(0),Rt=x.useRef(null),[It]=x.useState([]),[mt,Ke]=x.useState(""),[Mt,Ct]=x.useState(""),[Bt,Fn]=x.useState(!1),[Kt,nr]=x.useState(!1),[is,jr]=x.useState(!1),[St,rr]=x.useState("active"),[ot,yt]=x.useState(null),[R,N]=x.useState(null),[B,M]=x.useState("pincode"),[H,pe]=x.useState(null),[se,Ce]=x.use
129State(null),[Ie,Qe]=x.useState(null),[Nt,nn]=x.useState(!1),[Te,it]=x.useState(!1),[Et,Ot]=x.useState([]),[Wn,_s]=x.useState(!1),Pt=g0(),[_r]=x0(),[kr,yi]=x.useState(!1),[sr,ks]=x.useState("idle");x.useEffect(()=>{if(sr==="start"){const a=setTimeout(()=>ks("button1"),150);return()=>clearTimeout(a)}if(sr==="button1"){const a=setTimeout(()=>ks("button2"),750);return()=>clearTimeout(a)}if(sr==="button2"){const a=setTimeout(()=>ks("idle"),750);return()=>clearTimeout(a)}},[sr]);const[ht,Nn]=x.useState("idle"),[rn,ar]=x.useState([]),[Ni,$r]=x.useState([]),[ta,Ta]=x.useState(""),[Yl,As]=x.useState(null),[na,ra]=x.useState(null),[wi,sa]=x.useState(!1),[os,Es]=x.useState(null),[Ur,Ps]=x.useState(null),xo=x.useRef(null),Ci=x.useRef(null),Ds=x.useRef(null),[bo,Bn]=x.useState(0);x.useEffect(()=>{if(ht==="generating"){const o=Date.now();Bn(2);const p=setInterval(()=>{const v=Date.now()-o,T=1-Math.exp(-v/12e4),P=Math.min(99,T*97+v/12e4*2);Bn(C=>Math.max(C,P))},250);return()=>clearInterval(p)}ht==="done"&&Bn(100),(ht==="idle"||ht==="files")&&Bn(0)},[ht]),x.useEffect(()=>{if(rn.length>0&&ht==="files"){const a=setTimeout(()=>{Ds.current?.scrollIntoView({behavior:"smooth",block:"nearest"})},100);return()=>clearTimeout(a)}},[rn,ht]);const[vo,Ra]=x.useState(!1),[aa,Si]=x.useState([]),[Ia,Fs]=x.useState({}),[ji,Ts]=x.useState({}),[Ma,ia]=x.useState(!1),Ge=a=>{$r(o=>[...o,a]),setTimeout(()=>xo.current?.scrollTo({top:9999,behavior:"smooth"}),50)};function Ar(){return cu.get("authToken")||localStorage.getItem("authToken")||localStorage.getItem("token")||""}function ir(a={}){const o=Ar();return{...o?{Authorization:`Bearer ${o}`}:{},...a}}function Oa(a){const o=a.toLowerCase().replace(/[_\-. ]/g," "),p=new Set(o.split(/\s+/));if(/proposal|agreement|contract|quotat|letter\s*of|loi\b|mou\b|kyc|onboard/i.test(o))return"company_details";if(["pincode","pincodes","serviceable","serviceability","coverage","network"].some(K=>o.includes(K))||/rate\s*card|rate\s*sheet|cade\s*rate|out\s*card|rate\s*book|ratebook|ratecard|ratesheet/.test(o)||p.has("book")&&p.has("rate")||p.has("rate")||p.has("rates"))return"zone_data";const v=["company","vendor","transporter","profile","info","details","contact","gst","pan","kyc","overview","about"],T=["charge","charges","price","pricing","tariff","fuel","docket","oda","rov","insurance","surcharge","fee","cost","billing"],P=["zone","zones","pincode","pincodes","serviceability","service","coverage","matrix","area","delivery","served","network"],C=K=>K.filter(F=>o.includes(F)).length,D={company_details:C(v),charges:C(T),zone_data:C(P)},S=Object.keys(D).sort((K,F)=>D[F]-D[K]);return D[S[0]]>0?S[0]:"charges"}const _i=40*1024*1024,La=_i/3,Rs=a=>{const o=Array.from(a),p=new Set([".xlsx",".xls",".csv",".pdf",".png",".jpg",".jpeg",".docx",".doc",".pptx",".ppt",".json",".tiff",".bmp",".webp"]),v=[];let T=rn.reduce((P,C)=>P+C.file.size,0);for(const P of o){const C="."+P.name.split(".").pop().toLowerCase();if(!p.has(C)){ie.error(`${P.name}: unsupported format`);continue}if(P.size>La){ie.error(`${P.name}: exceeds ${(La/(1024*1024)).toFixed(1)} MB per-file limit`);continue}if(T+P.size>_i){ie.error(`${P.name}: would exceed the 40 MB total limit for these documents`);continue}T+=P.size,v.push({file:P,id:Math.random().toString(36).slice(2),category:Oa(P.name)})}ar(P=>[...P,...v])},ki=async()=>{if(rn.length===0){ie.error("Drop at least one file first");return}const a=gt.trim()||"new_vendor",o=a.toLowerCase().replace(/\s+/g,"_").replace(/[^a-z0-9_]/g,"").slice(0,40)||"new_vendor";Ta(o),Nn("generating"),$r([]),As(null),Ge(`[START] Creating vendor profile for "${a}"…`);try{if(!(await(await fetch(`${Yt}/api/utsf-generator/transporter`,{method:"POST",credentials:"include",headers:ir({"Content-Type":"application/json"}),body:JSON.stringify({name:o})})).json()).success)throw new Error("Failed to create transporter slot");Ge("[OK] Vendor slot ready — uploading files…");for(const ae of rn){const xe=new FormData;xe.append("files",ae.file),xe.append("subfolder",ae.category),(await fetch(`${Yt}/api/utsf-generator/transporter/${o}/upload`,{method:"POST",credentials:"include",headers:ir(),body:xe})).ok?Ge(`[OK] ${ae.file.name} → ${ae.category.replace(/_/g," ")}`):Ge(`[WARN] ${ae.file.name}: upload failed`)}Ge("[AI] Analysing files and extracting vendor data…");const v=await fetch(`${Yt}/api/utsf-generator/transporter/${o}/stream`,{credentials:"include",headers:ir()});if(!v.ok||!v.body)throw new Error(`Stream error: ${v.status}`);const T=v.body.getReader(),P=new TextDecoder;let C="",D=null;for(;;){const{done:ae,value:xe}=await T.read();if(ae)break;C+=P.decode(xe,{stream:!0});const W=C.split(`
130`);C=W.pop()??"";for(const je of W)if(je.startsWith("data: "))try{const Se=JSON.parse(je.slice(6));if(typeof Se=="string")Ge(Se);else if(Se.__done__)if(Se.exitCode===0)D=Se.downloadToken??null,Ge("[DONE] Vendor profile generated!");else throw new Error("Generation failed");else Se.companyName&&Ge(`[INFO] Detected: "${Se.companyName}"`)}catch{}}if(!D)throw new Error("No download token returned");As(D),Ge("[IMPORT] Saving to your vendor account…");let S=null;try{const ae=await fetch(`${Yt}/api/utsf-generator/output/file/${D}`);if(!ae.ok)Ge(`[WARN] UTSF fetch failed (HTTP ${ae.status}) — autofill skipped`);else{const xe=await ae.text();if(!xe||!xe.trim())Ge("[WARN] UTSF data is empty — autofill skipped");else try{const W=JSON.parse(xe);let je=W?.diagnosticLogs;W&&W.utsf?(S=W.utsf,je||(je=W.diagnosticLogs)):S=W,je&&Array.isArray(je)&&(console.log("[UTSF Diagnostic]",je),window.__utsfDiagnostics=je),ra(JSON.stringify(S,null,2))}catch{Ge("[WARN] UTSF JSON parse failed — autofill skipped")}}}catch(ae){Ge(`[WARN] UTSF fetch error: ${ae?.message||ae} — autofill skipped`)}let K=!1;try{const ae=new AbortController,xe=setTimeout(()=>ae.abort(),9e4),W=await fetch(`${Yt}/api/utsf-generator/output/${o}/import`,{method:"POST",credentials:"include",signal:ae.signal,headers:ir({"Content-Type":"application/json"}),body:JSON.stringify({downloadToken:D})}).finally(()=>clearTimeout(xe));if(W.ok){const je=await W.json().catch(()=>({}));je.success?(K=!0,Ge(`[OK] Vendor linked to your account (${je.transporter?.totalPincodes??"?"} pincodes, approved)`)):(Ge(`[ERROR] Could not link vendor to your account: ${je.message||"unknown error"}. Please contact support.`),console.error("[AddVendor] UTSF import returned failure:",je))}else{const je=await W.text().catch(()=>"");Ge(`[ERROR] Could not link vendor to your account (HTTP ${W.status}: ${je.slice(0,120)}). Please contact support.`),console.error("[AddVendor] UTSF import failed:",W.status,je)}}catch(ae){ae?.name==="AbortError"?Ge("[WARN] Import timed out after 90 s. The vendor was generated but could not be linked to your account automatically — please try again or c
130ontact support."):Ge(`[ERROR] Could not link vendor to your account: ${ae?.message||ae}. Please contact support.`),console.error("[AddVendor] UTSF import exception:",ae)}K||Ge("[INFO] You can still fill the form below — but the vendor may not show in calculation results until re-imported.");const F=S?.meta||{},te=S?.pricing?.priceRate||{};if(S?.serviceability&&Object.keys(S.serviceability).length>0){Ge("[IMPORT] Reconstructing serviceability + ODA coverage…");const ae=await ma(S);Ge(ae?"[OK] Serviceability + ODA coverage loaded from UTSF":"[WARN] Could not reconstruct serviceability from UTSF — configure it on the next step.")}let w=S?.pricing?.zoneRates||{};if(Object.keys(w).length===0&&rn.length>0){Ge("[RATE] Scanning uploaded files for zone rate matrix…");const ae=await li(F?.pincode||Gr()).catch(()=>null)||void 0,xe=await Ea().catch(()=>null),W=xe?new Map(xe.map(Se=>[Se.pincode,Se.zone])):void 0,je=[...rn.filter(Se=>Se.category==="zone_data"),...rn.filter(Se=>Se.category==="charges"),...rn.filter(Se=>Se.category==="company_details")];for(const Se of je){if(Object.keys(w).length>0)break;const $e=(Se.file.name.split(".").pop()??"").toLowerCase();if(["xlsx","xls","csv"].includes($e))try{const Ue=await Se.file.arrayBuffer(),lt=Ul(new Uint8Array(Ue),{type:"array"});let en={},pr=0,gr=null;for(const et of lt.SheetNames){const jn=lt.Sheets[et],At=Wl.sheet_to_json(jn,{header:1,defval:""});if(At.length<2)continue;const Ft=_l(At,[],ae,W);Ft.confidence>pr&&Object.keys(Ft.matrix).length>=1&&(en=Ft.matrix,pr=Ft.confidence,gr=Ft)}if(Object.keys(en).length>0){w=en,Ge(`[OK] Zone matrix from ${Se.file.name} (Excel, ${pr}% confidence)`);const et=gr?.metadata;if(et&&typeof et=="object"){Ge(`[META] Extracted vendor metadata from file comments: ${Object.keys(et).join(", ")}`),et.company&&(l.setField("companyName",et.company),Xt(et.company)),et["vendor code"]&&l.setField("vendorCode",et["vendor code"]),(et["gst no."]||et.gstin||et.gst)&&l.setField("gstin",et["gst no."]||et.gstin||et.gst);const jn=At=>{const Ft=At.replace(/[₹$,Rs.rskgKG %]+/gi,"").trim(),Bs=parseFloat(Ft);return isNaN(Bs)?null:Bs};if(et["fuel surcharge"]){const At=jn(et["fuel surcharge"]);At!==null&&setCharges(Ft=>({...Ft,fuelSurchargePct:At}))}if(et["docket charge"]||et["docket charges"]){const At=jn(et["docket charge"]||et["docket charges"]);At!==null&&setCharges(Ft=>({...Ft,docketCharges:{...Ft.docketCharges||{},mode:"FIXED",fixedAmount:At,currency:"INR"}}))}if(et["min charges"]||et["minimum charges"]){const At=jn(et["min charges"]||et["minimum charges"]);At!==null&&setCharges(Ft=>({...Ft,minCharges:At}))}if(et["min weight"]||et["minimum weight"]){const At=jn(et["min weight"]||et["minimum weight"]);At!==null&&setCharges(Ft=>({...Ft,minWeightKg:At}))}}continue}}catch{}Ge(`[AI] Extracting rates from ${Se.file.name} (${$e.toUpperCase()})…`);try{const Ue=await ls(Se.file);Ue&&Object.keys(Ue).length>0&&(w=Ue,Ge(`[OK] Zone matrix from ${Se.file.name} (AI extraction — ${Object.keys(Ue).length} origin zones)`))}catch{}}Object.keys(w).length===0&&Ge("[WARN] No zone rate matrix found in any uploaded file — you can add rates manually on the next step")}const oe=!!S&&!!S.meta;if(oe){if(F.companyName&&(l.setField("companyName",F.companyName),Xt(F.companyName)),(F.gstNo||F.gstin)&&l.setField("gstin",F.gstNo||F.gstin),F.address&&l.setField("address",F.address),F.contactPhone&&l.setField("vendorPhoneNumber",F.contactPhone),F.contactEmail&&l.setField("vendorEmailAddress",F.contactEmail),F.contactPersonName&&l.setField("contactPersonName",F.contactPersonName),F.displayName&&l.setField("displayName",F.displayName),F.vendorCode&&l.setField("vendorCode",F.vendorCode),F.transportMode){const W=String(F.transportMode).toUpperCase();W==="FTL"?l.setField("serviceMode","FTL"):(W==="LTL"||W==="PTL"||W==="COURIER")&&l.setField("serviceMode","PTL")}{const W=F.pincode!=null?String(F.pincode).trim():"";if(/^\d{6}$/.test(W))try{await s.setPincode(W)}catch{}}if(F.maxShipmentLengthFt!=null&&ve(Number(F.maxShipmentLengthFt)),te.divisor!=null&&Number(te.divisor)>0&&typeof f.loadFromDraft=="function"&&((String(te.volumetricUnit||"cm").toLowerCase().startsWith("in")?"in":"cm")==="cm"?f.loadFromDraft({unit:"cm",volumetricDivisor:Number(te.divisor)}):f.loadFromDraft({unit:"in",cftFactor:Number(te.divisor)})),Object.keys(w).length>0){const W=[...new Set([...Object.keys(w),...Object.values(w).flatMap(Se=>
130Object.keys(Se))])],je={zones:W,priceMatrix:w,timestamp:new Date().toISOString()};yt(je),localStorage.setItem(dn,JSON.stringify(je)),U(Se=>({...Se||{},zones:W.map($e=>({zoneCode:$e,zoneName:$e})),selectedZones:W.map($e=>({zoneCode:$e,zoneName:$e})),priceMatrix:w,lastUpdated:new Date().toISOString()}))}const ae=(W,je="per kg")=>{const Se={...Xe(),unit:je};if(W==null)return Se;if(typeof W=="number")return W>0?{...Se,mode:"FIXED",fixedAmount:W,variableRange:0}:Se;if(typeof W=="object"){if(W.v>0)return{...Se,mode:"VARIABLE",variableRange:W.v,fixedAmount:W.f??0};if(W.f>0)return{...Se,mode:"FIXED",fixedAmount:W.f,variableRange:0}}return Se},xe=W=>{const je=Xe();if(!W)return{...je,billingType:"per_kg"};if(je._autofilled=Date.now(),W.type==="distance_weight_matrix"||W.billingType==="distance_weight_matrix"||W.matrix&&Array.isArray(W.matrix)&&W.matrix.length>0&&W.matrix[0]?.bands!==void 0){const Se=(W.matrix||[]).filter(Ue=>(Ue.bands||[]).length>0&&(Ue.bands||[]).every(lt=>lt.note==="Negotiable"||Ue.note==="Negotiable"));let $e;return Se.length>0&&($e=`>${Math.min(...Se.map(lt=>lt.minDist??lt.minKm??0))}km: Negotiable`),{...je,mode:"FIXED",billingType:"matrix",matrixType:"2d",matrix:(W.matrix||[]).map(Ue=>({minDist:Ue.minDist??Ue.minKm??0,maxDist:Ue.maxDist??Ue.maxKm??null,bands:(Ue.bands||[]).map(lt=>({minKg:lt.minKg??lt.minWeight??0,maxKg:lt.maxKg??lt.maxWeight??null,charge:lt.charge??lt.perKg??lt.rate??0}))})),...$e?{note:$e}:{}}}if(W.type==="weight_band"||W.billingType==="weight_band"||W.bands&&Array.isArray(W.bands)&&W.bands.length>0||W.matrix&&Array.isArray(W.matrix)&&W.matrix.length>0&&!W.matrix[0]?.bands){const Se=W.bands||W.matrix||[];return{...je,mode:"FIXED",billingType:"matrix",matrixType:"1d",matrix:Se.map($e=>({minWeight:$e.minKg??$e.minWeight??null,maxWeight:$e.maxKg??$e.maxWeight??null,rate:$e.perKg??$e.charge??$e.rate??null,fixedSurcharge:$e.minimum??$e.fixedSurcharge??null}))}}if(W.type==="per_shipment"||W.billingType==="per_shipment"){const Se=W.fixed??W.f??0;return{...je,mode:"FIXED",billingType:"per_shipment",fixedAmount:Se,variableRange:0,perKg:0,minimum:Se}}if(W.type==="per_kg_minimum"||W.billingType==="per_kg_minimum")return{...je,mode:"VARIABLE",billingType:"per_kg_minimum",perKg:W.perKg??W.v??0,minimum:W.minimum??W.f??0};if(W.billingType==="per_kg_excess")return{...je,mode:"FIXED",billingType:"per_kg_excess",fixedAmount:W.fixedAmount??W.f??0,thresholdWeight:W.thresholdWeight??0,variableRange:W.variableRange??W.v??0};if(W.type==="negotiable"||W.billingType==="negotiable")return{...je,mode:"FIXED",billingType:"negotiable",note:W.note||"Negotiable"};if(W.f!==void 0||W.fixed!==void 0){const Se=W.fixed??W.f??0,$e=W.variable??W.v??0;if(Se>0&&$e===0)return{...je,mode:"FIXED",billingType:"per_shipment",fixedAmount:Se,variableRange:0,perKg:0,minimum:Se};if(Se>0&&$e>0)return{...je,mode:"VARIABLE",billingType:"per_kg_minimum",perKg:$e,minimum:Se};if(Se===0&&$e>0)return{...je,mode:"VARIABLE",billingType:"per_kg",variableRange:$e,fixedAmount:0,perKg:$e,minimum:0}}if(typeof W=="number")return W>0?{...je,mode:"FIXED",billingType:"per_shipment",fixedAmount:W,variableRange:0,perKg:0,minimum:W}:{...je,billingType:"per_kg"};if(typeof W=="object"){if(W.v>0)return{...je,mode:"VARIABLE",billingType:"per_kg",variableRange:W.v,fixedAmount:W.f??0,perKg:W.v,minimum:0};if(W.f>0)return{...je,mode:"FIXED",billingType:"per_shipment",fixedAmount:W.f,variableRange:0,perKg:0,minimum:W.f}}return{...je,billingType:"per_kg"}};if(Object.keys(te).length>0){const W=te.fuel!=null?te.fuel:0,je=te.gstPct!=null?te.gstPct:te.gst!=null?te.gst:18,Se=te.handlingCharges!=null?ae(te.handlingCharges):{...Xe(),mode:"FIXED",fixedAmount:0,variableRange:0};m.loadFromDraft({minWeightKg:te.minWeight??null,minCharges:te.minCharges??null,docketCharges:te.docketCharges??null,fuelSurchargePct:W,gstPct:je,rovCharges:ae(te.rovCharges),codCharges:ae(te.codCharges),toPayCharges:ae(te.topayCharges),odaCharges:(()=>{const $e=Array.isArray(te.odaMatrix?.matrix)&&te.odaMatrix.matrix.length>0,Ue=xe($e?te.odaMatrix:te.odaCharges);if($e&&te.odaCharges){Ue.genericOda=te.odaCharges;const lt=xe(te.odaCharges);Ue.perKg=lt.perKg,Ue.minimum=lt.minimum,Ue.fixedAmount=lt.fixedAmount??Ue.fixedAmount,Ue.variableRange=lt.variableRange??Ue.variableRange,Ue.note=lt.note??Ue.note}return console.log("[ODA-DEBUG][prefill]",{"pr.odaCharges":te.odaCharges,"pr.odaMatrix":te.odaMatrix,hasMatrix:$e,card:Ue}),Ge(`[ODA-DEBUG][prefill] pr.odaCharges=${JSON.stringify(te.odaCharges)} pr.odaMatrix=${JSON.stringify(te.odaMatrix)} hasMatrix=${$e} card=${JSON.stringify(Ue)}`),Ue})(),handlingCharges:Se,appointmentCharges:ae(te.appointmentCharges),greenTax:ae(te.greenTax,"per shipment"),hamaliCharges:ae(te.hamaliCharges),miscCharges:ae(te.miscCharges),daccCharges:ae(te.daccCharges,"per shipment")})}try{const W="vendorWizard.v1";let je={};const Se=localStorage.getItem(W);if(Se)try{je=JSON.parse(Se)}catch{}if(Object.keys(w).length>0){const lt=[...new Set([...Object.keys(w),...Object.values(w).flatMap(en=>Object.keys(en))])];je={...je,zones:lt.map(en=>({zoneCode:en,zoneName:en})),selectedZones:lt.map(en=>({zoneCode:en,zoneName:en}
130)),priceMatrix:w,lastUpdated:new Date().toISOString()},localStorage.setItem(W,JSON.stringify(je))}const $e=rs(je),Ue=ss(je);Ce($e),Qe(Ue)}catch(W){console.warn("[InlineGen] wizard validation refresh failed",W)}}const Q=S?.dataQuality??null;Q!==null&&Es(Math.round(Q));const $=S?.stats||{},Ee=["fuel","rovCharges","odaCharges","docketCharges","insuranceCharges","handlingCharges","codCharges"].filter(ae=>{const xe=te[ae];return xe&&(typeof xe=="number"?xe>0:xe.v>0||xe.f>0)}).map(ae=>ae.replace("Charges","").replace(/([A-Z])/g," $1").trim());Ps({zones:$.zonesServed??Object.keys(w).length,pincodes:$.totalPincodes??$.totalServedPincodes??0,charges:Ee}),Tn("existing"),Vn("manual"),Object.keys(w).length>0?M("matrix"):Ge("[WARN] No zone rate matrix found — upload your rate card Excel on the next step to add rates."),fn(!0),wn(F.companyName||o),Ge(oe?"[READY] Review the pre-filled details below and click Add Vendor.":"[READY] Vendor created — UTSF data unavailable, please fill the form manually.");const Fe=l.basics,Le=(ae,xe)=>ae!=null&&String(ae).trim()!==""||xe!=null&&String(xe).trim()!=="",_t=!!F.companyName&&F.companyName.toLowerCase().replace(/[^a-z0-9]/g,"")===o.replace(/[^a-z0-9]/g,""),ke=[];(!Le(F.companyName,Fe.companyName)||_t)&&ke.push({id:"companyName",label:"Legal Company Name",type:"text",required:!0,placeholder:"Full registered company name",helper:_t?`Detected "${F.companyName}" from folder name — enter the real company name`:void 0}),Le(F.contactPersonName,Fe.contactPersonName)||ke.push({id:"contactPersonName",label:"Contact Person Name",type:"text",required:!0,placeholder:"Full name"}),Le(F.contactPhone,Fe.vendorPhoneNumber)||ke.push({id:"vendorPhoneNumber",label:"Phone Number",type:"tel",required:!0,placeholder:"10-digit mobile",helper:"Exactly 10 digits"}),Le(F.contactEmail,Fe.vendorEmailAddress)||ke.push({id:"vendorEmailAddress",label:"Email Address",type:"email",required:!1,placeholder:"[email protected]"}),Le(F.address,Fe.address)||ke.push({id:"address",label:"Address",type:"text",required:!0,placeholder:"Registered/operating address"}),Le(F.vendorCode,Fe.vendorCode)||ke.push({id:"vendorCode",label:"Vendor Code",type:"text",required:!1,placeholder:"Internal vendor code"});const kt=(()=>{const ae=F.transportMode?String(F.transportMode).toUpperCase():"";return ae==="FTL"?"FTL":ae==="LTL"||ae==="PTL"||ae==="COURIER"?"PTL":Fe.serviceMode||""})();ke.push({id:"serviceMode",label:"Service Mode",type:"select",options:["FTL","PTL"],required:!0,helper:kt?`Auto-detected: ${kt} — confirm or change`:void 0});const Pe=F.pincode!=null?String(F.pincode).trim():"",ze=/^\d{6}$/.test(Pe),ft=s.geo.pincode||"",ln=/^\d{6}$/.test(ft);if(!ze&&!ln&&ke.push({id:"pincode",label:"Pincode",type:"pincode",required:!0,placeholder:"6-digit pincode",helper:"State and city auto-resolve from pincode"}),ke.length>0){Ge(`[INFO] ${ke.length} required field${ke.length===1?"":"s"} need attention.`);const ae={};F.companyName&&ke.find(xe=>xe.id==="companyName")&&(ae.companyName=String(F.companyName)),F.contactPersonName&&ke.find(xe=>xe.id==="contactPersonName")&&(ae.contactPersonName=String(F.contactPersonName)),F.contactPhone&&ke.find(xe=>xe.id==="vendorPhoneNumber")&&(ae.vendorPhoneNumber=String(F.contactPhone).replace(/\D/g,"").slice(0,10)),F.contactEmail&&ke.find(xe=>xe.id==="vendorEmailAddress")&&(ae.vendorEmailAddress=String(F.contactEmail)),F.address&&ke.find(xe=>xe.id==="address")&&(ae.address=String(F.address)),F.vendorCode&&ke.find(xe=>xe.id==="vendorCode")&&(ae.vendorCode=String(F.vendorCode)),kt&&ke.find(xe=>xe.id==="serviceMode")&&(ae.serviceMode=kt),Si(ke),Fs(ae),Ts({}),ia(!1),Nn("done"),Ra(!0)}else Nn("done")}catch(p){Ge(`[ERROR] ${p.message}`),Nn("error")}},ls=x.useCallback(async a=>{console.log(`[FC:extractPrices] → POST /api/utsf-generator/extract-prices  file="${a.name}" size=${(a.size/1024).toFixed(1)}KB type="${a.type}"`);const o=performance.now(),p=new FormData;p.append("file",a);try{const v=await fetch(`${Yt}/api/utsf-generator/extract-prices`,{method:"POST",credentials:"include",headers:ir(),body:p}),T=(performance.now()-o).toFixed(0);if(!v.ok)return console.error(`[FC:extractPrices] HTTP ${v.status} after ${T}ms`),null;const P=await v.json();return P&&P.diagnosticLogs&&Array.isArray(P.diagnosticLogs)&&(console.log("[UTSF Diagnostic]",P.diagnosticLogs),window.__utsfDiagnostics=C=>P.diagnosticLogs,window.__utsfDiagnostics=P.diagnosticLogs),console.log(`[FC:extractPrices] Response in ${T}ms — success=${P.success}
130 zonesFound=${P.zonesFound} confidence=${P.confidence} source="${P.source}" message="${P.message}"`),P.success&&P.zoneRates&&Object.keys(P.zoneRates).length>0?(console.log("[FC:extractPrices] Zone rate keys:",Object.keys(P.zoneRates)),P.zoneRates):(console.warn("[FC:extractPrices] No zoneRates returned. Full response:",P),null)}catch(v){return console.error("[FC:extractPrices] Network/parse error:",v),null}},[]),oa=x.useCallback(async(a,o=!1)=>{const p=a.name.split(".").pop()?.toLowerCase()||"",v=["xlsx","xls","csv"].includes(p);console.log(`[FC:handlePricingFileUpload] File selected: name="${a.name}" ext="${p}" size=${(a.size/1024).toFixed(1)}KB type="${a.type}" isExcel=${v}`),Y(C=>[...C,{file:a,category:"charges"}]);const T=g?.priceMatrix?Object.keys(g.priceMatrix):[];if(!o&&T.length>0){console.log(`[FC:handlePricingFileUpload] Clearing existing matrix (${T.join(", ")}) before fresh extraction from "${a.name}"`),U(C=>({...C||{},priceMatrix:{},zones:[],selectedZones:[]}));try{localStorage.removeItem(dn)}catch{}la(!1)}yi(!0);const P=ie.loading("Extracting zone rates from file…");try{let C=null,D=0,S=[];const K=await li(Gr()).catch(()=>null)||void 0,F=await Ea().catch(()=>null),te=F?new Map(F.map(w=>[w.pincode,w.zone])):void 0;if(v)try{const w=await a.arrayBuffer(),oe=Ul(new Uint8Array(w),{type:"array"});for(const Q of oe.SheetNames){const $=oe.Sheets[Q],Ee=Wl.sheet_to_json($,{header:1,defval:""});if(Ee.length<2)continue;const Fe=_l(Ee,[],K,te);Fe.confidence>D&&Object.keys(Fe.matrix).length>=1&&(C=Fe.matrix,D=Fe.confidence,S=Fe.discoveredZones)}}catch{}if(!C||D<50){console.log(`[FC:handlePricingFileUpload] Client-side parse insufficient (matrix=${C?Object.keys(C).length:0} zones, conf=${D}) — calling microservice`);const w=await ls(a);w&&Object.keys(w).length>Object.keys(C??{}).length?(C=w,S=[...new Set([...Object.keys(w),...Object.values(w).flatMap(oe=>Object.keys(oe))])],console.log(`[FC:handlePricingFileUpload] Microservice matrix accepted — ${Object.keys(w).length} origin zones, ${S.length} total zone codes`)):console.warn("[FC:handlePricingFileUpload] Microservice returned no better matrix")}if(console.log(`[FC:handlePricingFileUpload] Final matrix: ${C?Object.keys(C).length:0} origin zones, ${S.length} discoveredZones`),C&&Object.keys(C).length>0){const w=S.length>0?S:[...new Set([...Object.keys(C),...Object.values(C).flatMap(ke=>Object.keys(ke))])],oe=w.map(ke=>({zoneCode:ke,zoneName:ke}));let Q=C,$=w;U(ke=>{if(o&&ke?.priceMatrix&&Object.keys(ke.priceMatrix).length>0){const kt={...ke.priceMatrix};for(const[ft,ln]of Object.entries(C))kt[ft]={...kt[ft]||{},...ln};const Pe=(ke.zones||[]).map(ft=>ft.zoneCode),ze=[...new Set([...Pe,...w])];return Q=kt,$=ze,{...ke||{},priceMatrix:kt,zones:ze.map(ft=>({zoneCode:ft,zoneName:ft})),selectedZones:ze.map(ft=>({zoneCode:ft,zoneName:ft})),lastUpdated:new Date().toISOString()}}return{...ke||{},priceMatrix:C,zones:oe,selectedZones:oe,lastUpdated:new Date().toISOString()}});const Ee={zones:$,priceMatrix:Q,timestamp:new Date().toISOString()};yt(Ee),localStorage.setItem(dn,JSON.stringify(Ee)),la(!0),M("matrix"),Vn("manual");const Fe=Object.keys(Q).length,Le=$.length,_t=D>=80?"high confidence":D>=55?"good confidence":"low confidence — review rates";ie.success(o?`Merged rates from ${a.name} — ${Fe} origins × ${Le} zones total`:`Extracted ${Fe} origin × ${Le} zone matrix (${_t})`,{id:P,duration:4e3})}else ie.error("Could not find a zone rate matrix. Make sure the Excel has zone codes (N1, NORTH, W1…) as row and column headers.",{id:P})}catch(C){console.error("[PricingUpload] Error:",C),ie.error("Upload failed — please try again.",{id:P})}finally{yi(!1)}},[g.zones,U,ls,s]),[Lt,Gt]=x.useState(1),[Zt,Tn]=x.useState(null),[cs,Is]=x.useState("transporter"),[ds,za]=x.useState(null),[Wr,Vn]=x.useState("selection"),Ms=x.useCallback(a=>
130{if(a>Lt){const o=Ie?.hasPriceMatrix||(H?.serviceability?.length??0)>0;if(a>=3&&!o){ie.error("Complete pricing setup before going to Details or Charges.");return}if(a>=4){const p=$a();if(p.length>0){Ot(p),nn(!0);return}}}Gt(a),window.scrollTo({top:0,behavior:"smooth"})},[Lt,Ie,H,l,s,f]),Kn=x.useCallback(()=>{if(Lt===1&&Zt===null){ie.error("Search and select a vendor before continuing.");return}if(Lt===2&&!(Ie?.hasPriceMatrix||(H?.serviceability?.length??0)>0)){ie.error("Configure at least one zone and fill in the price matrix before continuing.");return}if(Lt===3){const a=$a();if(a.length>0){Ot(a),nn(!0);return}}Gt(a=>Math.min(a+1,4)),window.scrollTo({top:0,behavior:"smooth"})},[Lt,Zt,l,Ie,H,s,f]),$a=x.useCallback(()=>{it(!0);const a=[],o=(C,D,S)=>a.push({step:C,field:D,message:S,severity:"error"});try{const C=Ha();C.ok||C.errs.forEach(D=>o("Company Details","General",D))}catch{o("Company Details","System","Error checking specific company details.")}const p=l.validateAll();p.isValid||Object.entries(p.errors).forEach(([C,D])=>{const S=C.replace(/([A-Z])/g," $1").replace(/^./,K=>K.toUpperCase());o("Company Details",S,D)}),(typeof s.validateGeo=="function"?s.validateGeo():!0)||o("Company Details","Location","Pincode or State information is missing/invalid."),(typeof f.validateVolumetric=="function"?f.validateVolumetric():!0)||o("Company Details","Volumetric Config","Volumetric configuration is invalid.");const P=l.basics;return(!P.vendorCode||P.vendorCode.trim()==="")&&o("Company","Transporter Code","Transporter Code is required."),a},[l,s,f]),Os=x.useCallback(()=>{Gt(a=>{const o=Math.max(a-1,1);return o===1&&a!==1&&(Nn("idle"),ar([]),$r([]),As(null),ra(null),Es(null),Ps(null),Bn(0)),o}),window.scrollTo({top:0,behavior:"smooth"})},[]),[Br,Gn]=x.useState([]),[Ai,us]=x.useState(!1),[Ua,Rn]=x.useState(!1),[Ls,zs]=x.useState(-1),[or,fn]=x.useState(!1),[yo,la]=x.useState(!1),[No,lr]=x.useState(!1),[bt,rt]=x.useState(!1),[sn,ca]=x.useState([]),wo=x.useCallback(a=>{ca(o=>o.some(p=>p.type==="search"&&p.result.id===a.id)?o:[...o,{key:`search-${a.id}`,type:"search",result:a}])},[]),Co=x.useCallback(a=>{const o=a.trim();o&&ca(p=>p.some(v=>v.type==="custom"&&v.name.toLowerCase()===o.toLowerCase())?p:[...p,{key:`custom-${o}-${Date.now()}`,type:"custom",name:o}])},[]),Ei=x.useCallback(a=>{ca(o=>o.filter(p=>p.key!==a))},[]),[Wa,wn]=x.useState(null),[Ql,jt]=x.useState(null),[da,In]=x.useState(null),[gt,Xt]=x.useState(""),Cn=x.useRef(null),$s=x.useRef(null),[So,Ba]=x.useState(!1),ua=x.useRef(null),cr=x.useRef("");x.useEffect(()=>{const a=d?.customer?._id||"";if(a){cr.current=a;return}try{const o=JSON.parse(localStorage.getItem("authUser")||"{}");cr.current=o?.customer?._id||o?._id||""}catch{cr.current=""}},[d]);const{applyVendorAutofill:Va}=z0({vendorBasics:l,pincodeLookup:s,volumetric:f,charges:m,setWizardData:U,setZpm:yt,setIsAutoFilled:fn,setAutoFilledFromName:wn,setAutoFilledFromId:jt,setWizardValidation:Ce,setWizardStatus:Qe,validateWizardData:rs,getWizardStatus:ss,setServiceabilityData:pe}),[qt,Vr]=x.useState([]),[mn,Kr]=x.useState(!1),[Ka,dr]=x.useState(!1),[hn,Er]=x.useState(null),[vt,ur]=x.useState(!1),fr=x.useCallback(a=>hn||qt.find(p=>(p.draftName||"").trim().toLowerCase()===a.trim().toLowerCase())?._id,[hn,qt]),[jo,mr]=x.useState(!1),[Us,Ga]=x.useState(""),[_o,Mn]=x.useState(!1),fa=x.useCallback(async()=>{const a=new AbortController,o=setTimeout(()=>a.abort(),15e3);try{dr(!0);const v=(await ns.getVendorDrafts(a.signal))?.data||[];Vr(v),v.length>0?Kr(!0):ie.error("No saved drafts found.",{duration:2e3})}catch(p){p?.name==="AbortError"?ie.error("Request timed out. Check your connection and try again."):ie.error("Failed to load drafts. Please try again.")}finally{clearTimeout(o),dr(!1)}},[]),hr="fc_vendor_drafts_cache";x.useEffect(()=>{try{const o=localStorage.getItem(hr);o&&Vr(JSON.parse(o))}catch{}const a=new AbortController;return(async()=>{try{const p=(await ns.getVendorDrafts(a.signal))?.data||[];Vr(p),localStorage.setItem(hr,JSON.stringify(p))}catch{}})(),()=>a.abort()},[]);const ma=x.useCallback(async a=>{const o=a?.serviceability||{},p=a?.oda||{};if(Object.keys(o).length===0)return null;const v={N1:"North",N2:"North",N3:"North",N4:"North",S1:"South",S2:"South",S3:"South",S4:"South",E1:"East",E2:"East",W1:"West",W2:"West",C1:"Central",C2:"Central",NE1:"North East",NE2:"North East",X1:"Special",X2:"Special",X3:"Special"};try{const T=await Ea().catch(()=>null);if(!Array.isArray(T))return null;const P=T,C=new Set(nu),D=new Map,S=new Map;for(const oe of P){if(!oe||typeof oe!="object")continue;const Q=String(oe.zone||"").toUpperCase().trim(),$=Number(oe.pincode);!Q||!Number.isFinite($)||(D.set($,{zone:Q,state:oe.state,city:oe.city}),S.has(Q)||S.set(Q,[]),S.get(Q).push($))}const K=[],F=[],te=new Set;let w=0;for(const[oe,Q]of Object.entries(o)){const $=String(oe||"").toUpperCase().trim();if(!$||!C.has($)){$&&console.warn(`[UTSF Import] Skipping unknown serviceability zone "${$}" — not in master zone list`);continue}if(!Q||typeof Q!="object")continue;const Ee=S.get($)||[],Fe=String(Q.mode||"").toUpperCase().trim();let Le=[];if(Fe==="FULL_ZONE")Le=[...Ee];else if(Fe==="FULL_MINUS_EXCEPT"){const ae=new Set(mo(Q.exceptRanges||[],Q.exceptSingles||[]));Le=Ee.filter(xe=>!ae.has(xe))}else if(Fe==="ONLY_SERVED"){const ae=new Set(Ee),xe=mo(Q.servedRanges||[],Q.servedSingles||[]);Le=xe.filter(W=>ae.has(W)),w+=xe.length-Le.length}const _t=mo(Q.crossZoneRanges||[],Q.crossZoneSingles||[]);if(_t.length>0&&(Le=Le.concat(_t)),Le.length===0)continue;
130const ke=p[$]||p[oe]||{},kt=ke&&typeof ke=="object"?new Set(mo(ke.odaRanges||[],ke.odaSingles||[])):new Set,Pe=new Set,ze=new Set;let ft=0;for(const ae of Le){const xe=D.get(ae);if(!xe)continue;const W=String(ae);te.has(W)||(te.add(W),Pe.add(xe.state),ze.add(xe.city),ft++,K.push({pincode:W,zone:$,state:xe.state,city:xe.city,isODA:kt.has(ae),active:!0}))}const ln=Array.isArray(Q.pinOverrides)?Q.pinOverrides:[];for(const ae of ln){const xe=Number(ae.pincode);if(!Number.isFinite(xe)||!ae.city||!ae.state)continue;const W=String(xe);te.has(W)||(te.add(W),Pe.add(ae.state),ze.add(ae.city),ft++,K.push({pincode:W,zone:$,state:ae.state,city:ae.city,isODA:kt.has(xe),active:!0}))}ft!==0&&F.push({zoneCode:$,region:v[$]||"Other",pincodeCount:ft,states:Array.from(Pe),cities:Array.from(ze)})}return K.length>0?(pe({serviceability:K,zoneSummary:F,checksum:`utsf-import-${Date.now()}`,source:"autofill"}),w>0&&(console.warn(`[UTSF Import] Dropped ${w} pincode(s) the source claims to serve but that aren't in our master pincode list — coverage was trimmed silently.`),ie(`${w} pincode(s) from the source data aren't in our master pincode list and were excluded from serviceability — review coverage on the next step.`)),{entries:K,zoneSummary:F}):null}catch(T){return console.warn("[UTSF Import] Serviceability reconstruction skipped:",T),null}},[pe]),Pi=x.useCallback(async a=>{const o=a.target.files?.[0];if(!o)return;a.target.value="";const p=ie.loading("Reading UTSF file…");lr(!0);try{const v=await o.text();let T;try{T=JSON.parse(v)}catch{ie.error("Invalid UTSF file — not valid JSON",{id:p});return}const{isValid:P,errors:C}=Bx(T);if(!P){ie.error(`UTSF validation failed: ${C[0]}`,{id:p});return}ie.loading("Applying vendor data…",{id:p});const D=T.meta||{};D.companyName&&(l.setField("companyName",D.companyName),Xt(D.companyName)),D.vendorCode&&l.setField("vendorCode",D.vendorCode),D.gstNo&&l.setField("gstNo",D.gstNo),D.address&&l.setField("address",D.address),D.state&&l.setField("state",D.state),D.city&&l.setField("city",D.city),D.pincode&&l.setField("pincode",String(D.pincode)),D.contactPersonName&&l.setField("contactPersonName",D.contactPersonName),D.vendorPhone&&l.setField("vendorPhone",String(D.vendorPhone)),D.vendorEmail&&l.setField("vendorEmail",D.vendorEmail);const S=(D.transportMode||"").toLowerCase();["road","air","rail","ship"].includes(S)&&E(S);const F=(T.pricing||{}).zoneRates||{};if(Object.keys(F).length>0){const w=Array.from(new Set([...Object.keys(F),...Object.values(F).flatMap($=>Object.keys($))])),oe={};for(const[$,Ee]of Object.entries(F)){oe[$]={};for(const[Fe,Le]of Object.entries(Ee))oe[$][Fe]=Number(Le)}const Q={zones:w,priceMatrix:oe,timestamp:new Date().toISOString()};yt(Q),localStorage.setItem(dn,JSON.stringify(Q))}ie.loading("Reconstructing serviceability…",{id:p}),!await ma(T)&&T?.serviceability&&Object.keys(T.serviceability).length>0&&ie("Serviceability data could not be reconstructed — configure it on the next step."),Tn("new_with_pincodes"),M("pincode"),Mn(!0),ie.success(`Imported: ${D.companyName||o.name}`,{id:p}),Kn()}catch(v){console.error("[UTSF Import] Error:",v),ie.error("Failed to import UTSF file",{id:p})}finally{lr(!1)}},[l,yt,pe,E,Kn,Mn]),Za=x.useCallback(a=>{try{const o=a.payload||a;if(a._id&&Er(a._id),o.basics&&l.loadFromDraft&&l.loadFromDraft(o.basics),o.geo&&s.loadFromDraft&&s.loadFromDraft(o.geo),o.volumetric&&f.loadFromDraft&&f.loadFromDraft(o.volumetric),o.charges&&m.loadFromDraft){const S=o.charges;m.loadFromDraft({...S,rovCharges:S.rovCharges||Xe(),codCharges:S.codCharges||Xe(),toPayCharges:S.toPayCharges||Xe(),handlingCharges:S.handlingCharges||Xe(),appointmentCharges:S.appointmentCharges||Xe()})}o.transportMode&&E(o.transportMode),o.maxShipmentLengthFt!==void 0&&ve(o.maxShipmentLengthFt??null),o.zoneConfigMode&&M(o.zoneConfigMode),o.invoicePercentage&&Ke(o.invoicePercentage),o.invoiceMinAmount&&Ct(o.invoiceMinAmount),o.invoiceUseMax!=null&&Fn(o.invoiceUseMax),o.serviceabilityData&&pe(o.serviceabilityData),o.zpm&&(yt(o.zpm),localStorage.setItem(dn,JSON.stringify(o.zpm))),o.wizardData&&typeof k=="function"?k({zones:o.wizardData.zones||[],priceMatr
130ix:o.wizardData.priceMatrix||{},serviceability:o.wizardData.serviceability||[],serviceabilityChecksum:o.wizardData.serviceabilityChecksum||"",serviceabilitySource:o.wizardData.serviceabilitySource||""}):o.zpm?.priceMatrix&&typeof k=="function"&&k({zones:Array.isArray(o.zpm.zones)?o.zpm.zones:[],priceMatrix:o.zpm.priceMatrix||{}}),Kr(!1),Mn(!0);const p=[1,2,3,4].includes(o.currentStep)?o.currentStep:1,v=!!(o.wizardData?.priceMatrix&&Object.keys(o.wizardData.priceMatrix).length||o.wizardData?.serviceability?.length||o.zpm?.priceMatrix&&Object.keys(o.zpm.priceMatrix).length||o.serviceabilityData?.serviceability?.length),T=!!((o.basics?.companyName||o.basics?.legalCompanyName)&&(o.basics?.gstin||o.basics?.gst||o.basics?.gstNo)),P=o.charges?.docketCharges!=null||o.charges?.fuelSurchargePct!=null||o.charges?.gstPct!=null;let C=1;v&&(C=2),T&&(C=3),P&&(C=4);const D=Math.max(p,C,2);Gt(D),window.scrollTo({top:0,behavior:"smooth"}),ie.success("Draft restored successfully!",{duration:2e3})}catch(o){console.error("Failed parsing draft payload",o),ie.error("Failed to parse draft data.")}},[l,s,f,m,k]),ha=x.useCallback(async a=>{try{await ns.deleteVendorDraft(a),Vr(o=>{const p=o.filter(v=>v._id!==a);return localStorage.setItem("fc_vendor_drafts_cache",JSON.stringify(p)),p}),hn===a&&(Er(null),Dr.current=!0),ie.success("Draft deleted.")}catch{ie.error("Failed to delete draft.")}},[hn]);x.useEffect(()=>{const a=()=>Kr(!0);return window.addEventListener("fc:open-drafts-panel",a),sessionStorage.getItem("fc_open_drafts_on_mount")&&(sessionStorage.removeItem("fc_open_drafts_on_mount"),Kr(!0)),()=>window.removeEventListener("fc:open-drafts-panel",a)},[]);const Pr=x.useCallback(a=>({basics:{...l.basics,companyName:a},geo:{state:s.geo.state,city:s.geo.city,pincode:s.geo.pincode},volumetric:{...f.state},charges:{...m.charges},transportMode:z,zoneConfigMode:B,serviceabilityData:H?{serviceability:H.serviceability,zoneSummary:H.zoneSummary,checksum:H.checksum,source:H.source}:null,zpm:ot?{zones:ot.zones,priceMatrix:ot.priceMatrix}:null,wizardData:g?{zones:g.zones,priceMatrix:g.priceMatrix,serviceability:g.serviceability,serviceabilityChecksum:g.serviceabilityChecksum,serviceabilitySource:g.serviceabilitySource}:null,invoicePercentage:mt,invoiceMinAmount:Mt,invoiceUseMax:Bt,currentStep:Lt}),[l.basics,s.geo,f.state,m.charges,z,B,H,ot,g,mt,Mt,Bt,Lt]),Ws=x.useCallback(()=>{const a=l.basics,o=!!(a?.companyName||a?.legalCompanyName||a?.contactPersonName||a?.gstin||a?.gst),p=Object.values(m.charges||{}).some(P=>{if(P!==null&&typeof P=="object"){const C=P.fixedAmount,D=P.variableRange;return C!=null&&C!==0||D!=null&&D!==""&&D!=="0%"&&D!==0}return P!=null&&P!==""&&P!==0}),v=!!(H?.serviceability?.length||g?.serviceability?.length),T=!!(ot?.priceMatrix&&Object.keys(ot.priceMatrix).length)||!!(g?.priceMatrix&&Object.keys(g.priceMatrix).length);return o||p||v||T},[l.basics,m.charges,H,g,ot]),Dr=x.useRef(!1),fs=x.useCallback(async a=>{const o=(a||l.basics.companyName||gt||"").trim();if(!o)return Ga(""),mr(!0),!1;ur(!0);try{const p=Pr(o),T=(await ns.saveVendorDraft(o,p,fr(o)))?.data?._id;T&&Er(T),Dr.current=!0;try{const C=(await ns.getVendorDrafts())?.data||[];Vr(C),localStorage.setItem("fc_vendor_drafts_cache",JSON.stringify(C))}catch{}return a&&l.setField("companyName",a),ie.success("Draft saved to cloud!",{duration:2e3}),!0}catch(p){return p?.code==="DRAFT_LIMIT_REACHED"?ie.error(p.message||"Draft limit reached. Finish or delete an existing draft first.",{duration:4e3}):ie.error("Failed to save draft. Please try again."),!1}finally{ur(!1)}},[l,gt,Pr,fr]),ms=x.useCallback(async a=>{if(Dr.current||!Ws())return;const p=(l.basics.companyName||gt||"").trim()||`Untitled Draft — ${new Date().toLocaleString([],{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}`;try{const v=Pr(p),P=(await ns.saveVendorDraft(p,v,fr(p)))?.data?._id;P&&Er(P);try{const D=(await ns.getVendorDrafts())?.data||[];Vr(D),localStorage.setItem("fc_vendor_drafts_cache",JSON.stringify(D))}catch{}a==="validation-failed"&&ie.success("Your progress was saved as a draft — pick it up anytime from Drafts.",{duration:4e3})}catch(v){console.error("[AutoSaveDraft] failed",v)}},[l.basics,gt,Pr,fr,Ws]),Di=x.useCallback(()=>
130{if(Dr.current||!Ws())return;const o=(l.basics.companyName||gt||"").trim()||`Untitled Draft — ${new Date().toLocaleString([],{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}`;try{const p=Pr(o),v={draftName:o,payload:p},T=fr(o);T&&(v.draftId=T);const P=new Blob([JSON.stringify(v)],{type:"application/json"}),C=`${lu}/api/drafts/vendor`;navigator.sendBeacon?.(C,P)}catch{}},[l.basics,gt,Pr,fr,Ws]),Xa=x.useRef(Di);Xa.current=Di;const an=x.useRef(ms);an.current=ms,x.useEffect(()=>{const a=()=>Xa.current();return window.addEventListener("beforeunload",a),()=>window.removeEventListener("beforeunload",a)},[]),x.useEffect(()=>()=>{an.current("abandon")},[]);const hs=x.useMemo(()=>Nx.debounce(async a=>{if(!a||a.length<2){Gn([]),rt(!1),Nn("idle"),ar([]),us(!1);return}$s.current&&$s.current.abort(),$s.current=new AbortController,us(!0);try{const o=cr.current,p=Ar(),v=o?`&customerID=${encodeURIComponent(o)}`:"",T=`${Yt}/api/transporter/search-transporters?query=${encodeURIComponent(a)}${v}&limit=10`;console.time("[Search] API call");const P=await fetch(T,{method:"GET",headers:{Authorization:`Bearer ${p}`,"Content-Type":"application/json"},credentials:"include",signal:$s.current.signal});if(console.timeEnd("[Search] API call"),!P.ok)throw new Error(`Search failed: ${P.status}`);const C=await P.json(),D=["india","post","indiapost","india post","postal"],S=a.toLowerCase(),K=D.some(w=>w.includes(S)||S.includes(w)),F={id:"indiapost-transporter",source:"system",isTemporary:!1,isSystemVendor:!0,systemVendorId:"indiapost-transporter",companyName:"IndiaPost",legalCompanyName:"India Post (Department of Posts)",displayName:"IndiaPost",vendorCode:"INDIAPOST",rating:4.2,zones:[]},te=C.success&&C.data?.length>0?C.data:[];if(K){const w=te.filter(oe=>oe.id!=="indiapost-transporter");Gn([F,...w])}else Gn(te);Rn(!0),rt(te.length===0&&!K)}catch(o){o.name!=="AbortError"&&(console.error("[Autocomplete] Search error:",o),Gn([]),Rn(!0))}finally{us(!1)}},200),[]),Fr=x.useCallback(a=>
130{if(Rn(!1),zs(-1),a.isSystemVendor&&a.systemVendorId){lr(!0),(async()=>{try{const o=Ar(),p=cr.current;if(!p){ie.error("Please log in to add vendors.");return}const v=await fetch(`${Yt}/api/transporter/add-system-vendor`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${o}`},credentials:"include",body:JSON.stringify({customerId:p,systemVendorId:a.systemVendorId})}),T=await v.json().catch(()=>({}));v.ok&&T.success?T.alreadyExists?ie.success(`${a.companyName} is already in your vendors! View it in My Vendors.`,{duration:4e3}):(ie.success(`${a.companyName} added to Your Vendors! Quotes will now appear in your dashboard.`,{duration:5e3}),Pt("/my-vendors")):ie.error(T.message||"Failed to add vendor. Please try again.")}catch(o){console.error("[SystemVendor] Add failed:",o),ie.error("Failed to add vendor. Please check your connection.")}finally{lr(!1)}})();return}if(a.source==="individualFtl"){lr(!0),(async()=>{try{const o=Ar(),p=cr.current,v=`${Yt}/api/transporter/search-transporters/${a.id}?source=individualFtl&customerID=${encodeURIComponent(p)}`,T=await fetch(v,{method:"GET",headers:{Authorization:`Bearer ${o}`,"Content-Type":"application/json"},credentials:"include"});if(!T.ok)throw new Error(`Detail fetch failed: ${T.status}`);const P=await T.json();if(!P.success||!P.data)throw new Error("No detail data returned");Is("individual_ftl"),za(P.data),Gn([]),ie.success(`Loaded "${P.data.transporterName}" — ${P.data.existingLanes?.length||0} existing lane(s). Add more below, or edit and save as your own.`,{duration:6e3})}catch(o){console.error("[AutoFill] Individual FTL detail fetch failed",o),ie.error("Failed to load this transporter. Please try again.")}finally{lr(!1)}})();return}lr(!0),(async()=>{try{const o=Ar(),p=cr.current,v=`${Yt}/api/transporter/search-transporters/${a.id}?source=${encodeURIComponent(a.source)}&customerID=${encodeURIComponent(p)}`;console.time("[AutoFill] detail-fetch");const T=await fetch(v,{method:"GET",headers:{Authorization:`Bearer ${o}`,"Content-Type":"application/json"},credentials:"include"});if(console.timeEnd("[AutoFill] detail-fetch"),!T.ok)throw new Error(`Detail fetch failed: ${T.status}`);const P=await T.json();if(!P.success||!P.data)throw new Error("No detail data returned");const C=P.data,D=!!a.isMyVendor;await Va(C,{blankCellValue:"",overwriteZones:!0,overwritePriceMatrix:D,overwriteCharges:D}),fn(!0),wn(C.displayName||C.companyName||C.legalCompanyName||""),jt(C.id||null),In(a.source==="public"?a.id:null),Gn([]),Vn("selection"),M("matrix"),Tn("existing"),Mn(!0),Ms(2),ie.success(a.isMyVendor?`Editing "${C.displayName||C.companyName}" — Pricing, Details & Charges are autofilled. Change what you need.`:`Auto-filled from "${C.displayName||C.companyName}". Please configure your own pricing and zones.`,{duration:5e3})}catch(o){console.error("[AutoFill] Auto-fill failed",o),ie.error(o?.message?.includes("404")?"Vendor not found — it may have been deleted.":"Failed to auto-fill vendor. Please try again.")}finally{lr(!1)}})()},[Va,fn,lr,wn,jt,Rn,Gn,zs,Ms,Pt]),qa=x.useCallback(a=>{a.type==="search"?Fr(a.result):(Xt(a.name),Rn(!1),rt(!0),ks("start"))},[Fr]),pa=x.useCallback(()=>{if(sn.length===0)return;const[a,...o]=sn;ca(o),qa(a)},[sn,qa]),ko=x.useCallback(()=>{fn(!1),wn(null),jt(null),In(null),Vn("selection"),M("matrix")},[]),Fi=x.useRef(!1),Ao=x.useCallback(()=>{const a=su();yt(a),dt("ZPM_LOADED",{hasData:!!a,data:a}),a&&M("matrix")},[g]);x.useEffect(()=>{or&&g.zones&&g.zones.length>0&&B!=="matrix"&&M("matrix")},[or,g.zones,B]),x.useCallback(a=>{const o=a.zones.map(p=>p.zoneCode);try{const p="vendorWizard.v1";let v={};const T=localStorage.getItem(p);if(T)try{v=JSON.parse(T)}catch{v={}}v={...v,selectedZones:o.map(S=>({zoneCode:S,zoneName:S})),zones:a.zones,priceMatrix:a.priceMatrix,step:3,lastUpdated:new Date().toISOString(),uploadedFromCSV:!0},localStorage.setItem(p,JSON.stringify(v));const P={zones:o,priceMatrix:a.priceMatrix,timestamp:new Date().toISOString()};localStorage.setItem(dn,JSON.stringify(P)),yt(P),typeof U=="function"&&U(S=>({...S||{},selectedZones:o.map(K=>({zoneCode:K,zoneName:K}
130)),zones:a.zones,priceMatrix:a.priceMatrix}));const C=rs(v),D=ss(v);Ce(C),Qe(D),fn(!0),wn("CSV/Excel Upload"),ie.success(`Zone mapping applied! ${a.zones.length} zones configured. Now fill in prices.`,{duration:5e3})}catch(p){console.error("[ZoneMapping] Failed to save:",p),ie.error("Failed to apply zone mapping")}},[U,rs,ss]);const Eo=x.useCallback(a=>{const o=a.zones.map(p=>p.zoneCode);try{const p="vendorWizard.v1";let v={};const T=localStorage.getItem(p);if(T)try{v=JSON.parse(T)}catch{v={}}v={...v,selectedZones:o.map(K=>({zoneCode:K,zoneName:K})),zones:a.zones,priceMatrix:a.priceMatrix,serviceability:a.serviceability||[],step:3,lastUpdated:new Date().toISOString(),autoAssigned:!0},localStorage.setItem(p,JSON.stringify(v));const P={zones:o,priceMatrix:a.priceMatrix,timestamp:new Date().toISOString()};localStorage.setItem(dn,JSON.stringify(P)),yt(P),typeof U=="function"&&U(K=>({...K||{},selectedZones:o.map(F=>({zoneCode:F,zoneName:F})),zones:a.zones,priceMatrix:a.priceMatrix,serviceability:a.serviceability||[],serviceabilityChecksum:""}));const C=rs(v),D=ss(v);Ce(C),Qe(D),fn(!0),wn("Auto Zone Assignment");const S=a.zones.reduce((K,F)=>K+F.selectedCities.length,0);ie.success(`Auto-assigned ${a.zones.length} zones with ${S} cities! Now fill in prices.`,{duration:5e3}),M("matrix")}catch(p){console.error("[ZoneSelection] Failed to save:",p),ie.error("Failed to apply zone selection")}},[U,rs,ss]),ga=x.useCallback(async a=>{pe(a),Pa({serviceability:a.serviceability}),a.source==="excel"&&In(null),typeof U=="function"&&U(w=>({...w||{},serviceability:a.serviceability,serviceabilityChecksum:a.checksum,serviceabilitySource:a.source}));const o=a.zoneSummary.map(w=>({zoneCode:w.zoneCode,zoneName:w.zoneCode,region:w.region,selectedStates:w.states,selectedCities:w.cities.map(oe=>`${oe}||${w.states[0]||"UNKNOWN"}`),isComplete:!0})),p=a.zoneSummary.map(w=>w.zoneCode);let v={},T=!1,P=[],C={};if(a.prebuiltPriceMatrix&&Object.keys(a.prebuiltPriceMatrix).length>0){const w=new Set(p),oe={},Q=new Set;for(const[$,Ee]of Object.entries(a.prebuiltPriceMatrix)){if(!w.has($)){Q.add($);continue}oe[$]={};for(const[Fe,Le]of Object.entries(Ee)){if(!w.has(Fe)){Q.add(Fe);continue}oe[$][Fe]=Le}}Object.keys(oe).length>0&&(v=oe,T=!0),P=[...Q]}else if(a.rawRows&&a.rawRows.length>1)try{const w=await li(Gr()).catch(()=>null)||void 0,oe=await Ea().catch(()=>null),Q=oe?new Map(oe.map(Ee=>[Ee.pincode,Ee.zone])):void 0,$=_l(a.rawRows,p,w,Q);Object.keys($.matrix).length>0&&(v=$.matrix,T=!0),P=$.droppedZones||[],C=$.rateOverrides||{}}catch(w){console.warn("[handleServiceabilityReady] Rate extraction from serviceability file failed:",w)}const D="vendorWizard.v1",S={selectedZones:p.map(w=>({zoneCode:w,zoneName:w})),zones:o,priceMatrix:v,rateOverrides:C,step:3,lastUpdated:new Date().toISOString(),pincodeAuthoritative:!0,serviceabilityChecksum:a.checksum,serviceability:a.serviceability,meta:{version:1,updatedAt:new Date().toISOString()},oda:{enabled:!1,pincodes:[],surcharge:{fixed:0,variable:0}},other:{minWeight:0,docketCharges:0,fuel:0,rovCharges:{variable:0,fixed:0},codCharges:{variable:0,fixed:0},topayCharges:{variable:0,fixed:0},handlingCharges:{variable:0,fixed:0,threshholdweight:0},appointmentCharges:{variable:0,fixed:0},divisor:2800,cftFactor:6,minCharges:0,greenTax:0,daccCharges:0,miscellanousCharges:0,insuaranceCharges:{variable:0,fixed:0},odaCharges:{variable:0,fixed:0},prepaidCharges:{variable:0,fixed:0},fmCharges:{variable:0,fixed:0}}};localStorage.setItem(D,JSON.stringify(S));const K={zones:p,priceMatrix:v,timestamp:new Date().toISOString()};localStorage.setItem(dn,JSON.stringify(K)),yt(K),typeof U=="function"&&U(w=>({...w||{},...S}));const F=rs(S),te=ss(S);if(Ce(F),Qe(te),fn(!0),wn("Pincode Upload"),rr("cloud_utsf"),T){la(!0);const w=Object.keys(v).length;ie.success(`Serviceability loaded: ${a.serviceability.length} pincodes across ${a.zoneSummary.length} zones. Also found a rate table — ${w} origin${w!==1?"s":""} × ${p.length} zones imported.`,{duration:6e3})}else ie.success(`Serviceability loaded: ${a.serviceability.length} pincodes across ${a.zoneSummary.length}
130 zones`,{duration:5e3});P.length>0&&ie(`${P.length} zone${P.length!==1?"s":""} in the rate table (${P.join(", ")}) ${P.length!==1?"have":"has"} no pincode coverage in this file — those rates were skipped, not imported.`,{icon:"⚠️",duration:7e3})},[U,rs,ss]),ps=x.useCallback(async a=>{const o=ie.loading(`Analysing ${a.name} with AI — this can take up to 2 minutes…`),v=(gt.trim()||l.basics.companyName||"pincode_upload").toLowerCase().replace(/\s+/g,"_").replace(/[^a-z0-9_]/g,"").slice(0,32)+"_"+Math.random().toString(36).slice(2,8)||`doc_${Date.now()}`;try{if(!(await(await fetch(`${Yt}/api/utsf-generator/transporter`,{method:"POST",credentials:"include",headers:ir({"Content-Type":"application/json"}),body:JSON.stringify({name:v})})).json()).success)throw new Error("Failed to create extraction slot");const P=new FormData;if(P.append("files",a),P.append("subfolder","zone_data"),!(await fetch(`${Yt}/api/utsf-generator/transporter/${v}/upload`,{method:"POST",credentials:"include",headers:ir(),body:P})).ok)throw new Error("File upload to extraction service failed");const D=await fetch(`${Yt}/api/utsf-generator/transporter/${v}/stream`,{credentials:"include",headers:ir()});if(!D.ok||!D.body)throw new Error(`Stream error: ${D.status}`);const S=D.body.getReader(),K=new TextDecoder;let F="",te=null;for(;;){const{done:Le,value:_t}=await S.read();if(Le)break;F+=K.decode(_t,{stream:!0});const ke=F.split(`
131`);F=ke.pop()??"";for(const kt of ke)if(kt.startsWith("data: "))try{const Pe=JSON.parse(kt.slice(6));if(Pe?.__done__)if(Pe.exitCode===0)te=Pe.downloadToken??null;else throw new Error("Extraction failed")}catch{}}if(!te)throw new Error("Extraction produced no result");const w=await fetch(`${Yt}/api/utsf-generator/output/file/${te}`);if(!w.ok)throw new Error(`Could not fetch extraction result (HTTP ${w.status})`);const oe=await w.text();if(!oe||!oe.trim())throw new Error("Extraction result was empty");const Q=JSON.parse(oe),$=Q?.utsf||Q,Ee=await ma($);if(!Ee||Ee.entries.length===0){const Le=$?.pricing?.zoneRates||{},_t=new Set;for(const ke of Object.values(Le))for(const kt of Object.keys(ke)){const Pe=kt.toUpperCase().trim();Pe&&Pe!=="X3"&&_t.add(Pe)}if(_t.size>0)try{const ke=await Ea().catch(()=>null);if(ke&&Array.isArray(ke)){const kt=ke,Pe={N1:"North",N2:"North",N3:"North",N4:"North",S1:"South",S2:"South",S3:"South",S4:"South",E1:"East",E2:"East",W1:"West",W2:"West",W3:"West",C1:"Central",C2:"Central",NE1:"North East",NE2:"North East",X1:"Special",X2:"Special"},ze=new Map;for(const ae of _t)ze.set(ae,[]);for(const ae of kt){if(!ae||typeof ae!="object")continue;const xe=String(ae.zone||"").toUpperCase().trim();if(!_t.has(xe))continue;const W=Number(ae.pincode);Number.isFinite(W)&&ze.get(xe).push({pincode:String(W),zone:xe,state:ae.state||"",city:ae.city||"",isODA:!1,active:!0})}const ft=[],ln=[];for(const[ae,xe]of ze.entries())xe.length!==0&&(ft.push(...xe),ln.push({zoneCode:ae,region:Pe[ae]||"Other",pincodeCount:xe.length,states:[...new Set(xe.map(W=>W.state))],cities:[...new Set(xe.map(W=>W.city))],odaCount:0}));if(ft.length>0){let ae=$?.pricing?.zoneRates||{};if(Object.keys(ae).length===0)try{const xe=await ls(a);xe&&Object.keys(xe).length>0&&(ae=xe)}catch{}ie.dismiss(o),ie.success(`Extracted ${ln.length} zones and ${ft.length.toLocaleString()} pincodes from ${a.name} via zone rate table`),await ga({serviceability:ft,zoneSummary:ln,checksum:`doc-zone-${Date.now()}`,source:"document",prebuiltPriceMatrix:ae});return}}}catch{}ie.error(`No pincode/zone coverage found in ${a.name}. Try a file with a clearer pincode list, or use "Upload Your Files" on the previous step.`,{id:o,duration:6e3});return}let Fe=$?.pricing?.zoneRates||{};if(Object.keys(Fe).length===0)try{const Le=await ls(a);Le&&Object.keys(Le).length>0&&(Fe=Le)}catch{}ie.dismiss(o),await ga({serviceability:Ee.entries,zoneSummary:Ee.zoneSummary,checksum:`doc-${Date.now()}`,source:"document",prebuiltPriceMatrix:Fe})}catch(T){console.error("[handleServiceabilityDocumentUpload] Extraction failed:",T),ie.error(T?.message||"Failed to extract data from document",{id:o,duration:6e3})}},[gt,l.basics.companyName,ma,ls,ga]);x.useEffect(()=>{if(A&&g){const a=rs(g),o=ss(g);Ce(a),Qe(o),dt("WIZARD_VALIDATION",{validation:a,status:o})}},[A,g]);const xa=x.useMemo(()=>
131{const a=g?.priceMatrix||ot?.priceMatrix||{},o=Object.keys(a).length,p=o?Object.keys(Object.values(a)[0]??{}).length:0;return{rows:o,cols:p}},[ot,g]);x.useEffect(()=>{if(Fi.current)return;Fi.current=!0;const a=_r.get("draftId");if(a)b0(a).then(C=>{if(!C){ie.error("Draft not found");return}try{const D=C;l.loadFromDraft({companyName:D.companyName||"",contactPersonName:D.contactPersonName||"",vendorPhoneNumber:D.vendorPhone||"",vendorEmailAddress:D.vendorEmail||"",gstin:D.gstNo||"",transportMode:D.transportMode||"road",subVendor:D.subVendor||"",vendorCode:D.vendorCode||"",address:D.address||"",serviceMode:D.serviceMode||"PTL",companyRating:D.rating??null,vendorRatings:D.vendorRatings}),D.transportMode&&E(D.transportMode),(D.pincode||D.state)&&s.loadFromDraft({pincode:String(D.pincode||""),state:D.state||"",city:D.city||""}),(D.volumetricUnit||D.cftFactor!=null)&&f.loadFromDraft({unit:D.volumetricUnit||"cm",cftFactor:D.cftFactor??null});const S=D.prices?.priceRate;S&&(m.loadFromDraft({docketCharges:S.docketCharges??null,minWeightKg:S.minWeight??null,minCharges:S.minCharges??null,greenTax:S.greenTax??null,fuelSurchargePct:S.fuel??null,gstPct:S.gst??null,daccCharges:S.daccCharges??null,miscCharges:S.miscellanousCharges??null,hamaliCharges:S.hamaliCharges??null,rovCharges:S.rovCharges||Xe(),codCharges:S.codCharges||Xe(),toPayCharges:S.topayCharges||Xe(),handlingCharges:S.handlingCharges||Xe(),appointmentCharges:S.appointmentCharges||Xe(),odaCharges:S.odaCharges||Xe(),insuranceCharges:S.insuranceCharges||S.insuaranceCharges||Xe()}),Array.isArray(S.surcharges)&&S.surcharges.length>0&&m.loadSurchargesFromDraft(S.surcharges));const K=D.prices?.priceChart;if(K&&Object.keys(K).length>
1310){const F={zones:D.selectedZones||[],priceMatrix:K,timestamp:new Date().toISOString()};localStorage.setItem(dn,JSON.stringify(F)),yt(F)}dt("CLOUD_DRAFT_LOADED",{id:a,companyName:C.companyName})}catch(D){vn("CLOUD_DRAFT_LOAD_ERROR",{err:D}),ie.error("Failed to restore cloud draft")}});else{const C=uu();if(C){dt("DRAFT_LOADED_ON_MOUNT",C);try{if(C.basics&&typeof l.loadFromDraft=="function"&&(l.loadFromDraft(C.basics),C.basics.transportMode&&E(C.basics.transportMode)),C.geo&&typeof s.loadFromDraft=="function"&&s.loadFromDraft(C.geo),C.volumetric&&typeof f.loadFromDraft=="function"&&f.loadFromDraft(C.volumetric),C.charges&&typeof m.loadFromDraft=="function"){const D=C.charges;m.loadFromDraft({...D,rovCharges:D.rovCharges||Xe(),codCharges:D.codCharges||Xe(),toPayCharges:D.toPayCharges||Xe(),handlingCharges:D.handlingCharges||Xe(),appointmentCharges:D.appointmentCharges||Xe(),odaCharges:D.odaCharges||Xe(),greenTax:D.greenTax||Xe(),hamaliCharges:D.hamaliCharges||Xe(),miscCharges:D.miscCharges||Xe(),daccCharges:D.daccCharges||Xe()})}C.surcharges&&Array.isArray(C.surcharges)&&typeof m.loadSurchargesFromDraft=="function"&&m.loadSurchargesFromDraft(C.surcharges)}catch(D){vn("DRAFT_LOAD_ERROR",{err:D}),ie.error("Failed to restore draft completely")}}}Ao();const o=su();o?.priceMatrix&&Object.keys(o.priceMatrix).length>0&&k({zones:o.zones,priceMatrix:o.priceMatrix});const p=_r.get("manual")==="true",v=_r.get("vendorName");if(p&&v){const C=decodeURIComponent(v);l.setField("companyName",C),Xt(C),rt(!0)}const T=_r.get("imported"),P=_r.get("fromUtsf")==="1";if(T&&P&&!p){const C=decodeURIComponent(T);try{const D=sessionStorage.getItem("utsf_addvendor_prefill"),S=D?JSON.parse(D):null,K=S?.companyName||C;if(Xt(K),l.setField("companyName",K),S?.gstNo&&l.setField("gstin",S.gstNo),S?.address&&l.setField("address",S.address),S?.contactPhone&&l.setField("vendorPhoneNumber",S.contactPhone),S?.contactEmail&&l.setField("vendorEmailAddress",S.contactEmail),S?.serviceabilityStats?.hasServiceability&&N({totalPincodes:S.serviceabilityStats.totalPincodes,zonesServed:S.serviceabilityStats.zonesServed,utsfName:S.serviceabilityStats.utsfName||K}),S?.zoneRates&&Object.keys(S.zoneRates).length>0){const oe={zones:Object.keys(S.zoneRates),priceMatrix:S.zoneRates,timestamp:new Date().toISOString()};yt(oe),localStorage.setItem(dn,JSON.stringify(oe))}const F=w=>{const oe=Xe();if(!w)return{...oe,billingType:"per_kg"};if(oe._autofilled=Date.now(),w.type==="distance_weight_matrix"||w.billingType==="distance_weight_matrix"||w.matrix&&Array.isArray(w.matrix)&&w.matrix.length>0&&w.matrix[0]?.bands!==void 0){const Q=(w.matrix||[]).filter(Ee=>(Ee.bands||[]).length>0&&(Ee.bands||[]).every(Fe=>Fe.note==="Negotiable"||Ee.note==="Negotiable"));let $;return Q.length>0&&($=`>${Math.min(...Q.map(Fe=>Fe.minDist??Fe.minKm??0))}km: Negotiable`),{...oe,mode:"FIXED",billingType:"matrix",matrixType:"2d",matrix:(w.matrix||[]).map(Ee=>({minDist:Ee.minDist??Ee.minKm??0,maxDist:Ee.maxDist??Ee.maxKm??null,bands:(Ee.bands||[]).map(Fe=>({minKg:Fe.minKg??Fe.minWeight??0,maxKg:Fe.maxKg??Fe.maxWeight??null,charge:Fe.charge??Fe.perKg??Fe.rate??0}))})),...$?{note:$}:{}}}if(w.type==="weight_band"||w.billingType==="weight_band"||w.bands&&Array.isArray(w.bands)&&w.bands.length>0||w.matrix&&Array.isArray(w.matrix)&&w.matrix.length>0&&!w.matrix[0]?.bands){const Q=w.bands||w.matrix||[];return{...oe,mode:"FIXED",billingType:"matrix",matrixType:"1d",matrix:Q.map($=>({minWeight:$.minKg??$.minWeight??null,maxWeight:$.maxKg??$.maxWeight??null,rate:$.perKg??$.charge??$.rate??null,fixedSurcharge:$.minimum??$.fixedSurcharge??null}))}}if(w.type==="per_shipment"||w.billingType==="per_shipment"){const Q=w.fixed??w.f??0;return{...oe,mode:"FIXED",billingType:"per_shipment",fixedAmount:Q,variableRange:0,perKg:0,minimum:Q}}if(w.type==="per_kg_minimum"||w.billingType==="per_kg_minimum")return{...oe,mode:"VARIABLE",billingType:"per_kg_minimum",perKg:w.perKg??w.v??0,minimum:w.minimum??w.f??0};if(w.billingType==="per_kg_excess")return{...oe,mode:"FIXED",billingType:"per_kg_excess",fixedAmount:w.fixedAmount??w.f??0,thresholdWeight:w.thresholdWeight??0,variableRange:w.variableRange??w.v??0};if(w.type==="negotiable"||w.billingType==="negotiable")return{...oe,mode:"FIXED",billingType:"negotiable",note:w.note||"Negotiable"};if(w.f!==void 0||w.fixed!==void 0){const Q=w.fixed??w.f??0,$=w.variable??w.v??0;if(Q>0&&$===0)return{...oe,mode:"FIXED",billingType:"per_shipment",fixedAmount:Q,variableRange:0,perKg:0,minimum:Q};if(Q>0&&$>0)return{...oe,mode:"VARIABLE",billingType:"per_kg_minimum",perKg:$,minimum:Q};if(Q===0&&$>0)return{...oe,mode:"VARIABLE",billingType:"per_kg",variableRange:$,fixedAmount:0,perKg:$,minimum:0}}if(typeof w=="number")return w>0?{...oe,mode:"FIXED",billingType:"per_shipment",fixedAmount:w,variableRange:0,perKg:0,minimum:w}:{...oe,billingType:"per_kg"};if(typeof w=="object"){if(w.v>0)return{...oe,mode:"VARIABLE",billingType:"per_kg",variableRange:w.v,fixedAmount:w.f??0,per
131Kg:w.v,minimum:0};if(w.f>0)return{...oe,mode:"FIXED",billingType:"per_shipment",fixedAmount:w.f,variableRange:0,perKg:0,minimum:w.f}}return{...oe,billingType:"per_kg"}},te=w=>w?(w.v??0)>0?{...Xe(),mode:"VARIABLE",variableRange:w.v,fixedAmount:w.f}:(w.f??0)>0?{...Xe(),mode:"FIXED",fixedAmount:w.f,variableRange:0}:Xe():Xe();if(S?.pricing){const w=S.pricing;m.loadFromDraft({minWeightKg:w.minWeight??null,minCharges:w.minCharges??null,docketCharges:w.docketCharges??null,fuelSurchargePct:w.fuel??null,greenTax:w.greenTax??null,daccCharges:w.daccCharges??null,miscCharges:w.miscCharges??null,rovCharges:te(w.rovCharges),codCharges:te(w.codCharges),toPayCharges:te(w.topayCharges),odaCharges:(()=>{const oe=Array.isArray(w.odaMatrix?.matrix)&&w.odaMatrix.matrix.length>0,Q=F(oe?w.odaMatrix:w.odaCharges);if(oe&&w.odaCharges){Q.genericOda=w.odaCharges;const $=F(w.odaCharges);Q.perKg=$.perKg,Q.minimum=$.minimum,Q.fixedAmount=$.fixedAmount??Q.fixedAmount,Q.variableRange=$.variableRange??Q.variableRange,Q.note=$.note??Q.note}return Q})(),insuranceCharges:te(w.insuranceCharges),handlingCharges:te(w.handlingCharges),appointmentCharges:te(w.appointmentCharges)})}Tn("existing"),Vn("selection"),M("matrix"),fn(!0),wn(K),Ms(2),ie.success('Vendor details pre-filled from UTSF — review each step and click "Add Vendor"',{id:"utsf-imported",duration:5e3}),sessionStorage.removeItem("utsf_addvendor_prefill"),Pt("/addvendor",{replace:!0})}catch{Xt(C),ie.success(`Vendor "${C}" ready — review details and submit`,{id:"utsf-imported",duration:4e3})}setTimeout(()=>window.scrollTo({top:0,behavior:"smooth"}),300)}else if(T&&!p){const C=decodeURIComponent(T);Xt(C),Rn(!0),us(!0),hs(C),ie.success(`Vendor "${C}" imported — select it below to continue`,{duration:4e3,id:"utsf-imported"})}},[]),x.useEffect(()=>{if(Kt)return;const a=(m&&(m.charges||m))?.rovCharges||m&&m?.rov||null;if(!a)return;const o=(a.mode||(a.currency==="INR"?"FIXED":a.currency==="PERCENT"?"VARIABLE":"")||"").toString().toUpperCase(),p=v=>v==null?"":String(v);if(o==="FIXED"){const v=a.fixedAmount??a.fixed??a.fixedRate??0,T=String(Number(v)||0);Ct(T),Ke("0.0001"),Fn(!0)}else if(o==="VARIABLE"){const v=a.variableRange??a.variable??a.variablePct??a.variablePercent??"",T=p(v);Ke(T),Ct("0"),Fn(!0)}},[m?.charges?.rovCharges,Kt]),x.useEffect(()=>{s?.geo?.pincode&&Pa({geo:{pincode:s.geo.pincode,state:s.geo.state,city:s.geo.city}})},[s?.geo?.pincode,s?.geo?.state,s?.geo?.city]);const Ti=x.useCallback(a=>a&&a[kl]?a[kl]:null,[]),Gr=x.useCallback(()=>{const a=s?.geo?.pincode;if(a&&String(a).length===6)return String(a);const o=d?.customer?.pincode??d?.pincode;if(o)return String(o);try{const p=JSON.parse(localStorage.getItem("authUser")||"{}"),v=p?.customer?.pincode??p?.pincode;if(v)return String(v)}catch{}return null},[s?.geo?.pincode,d]);x.useEffect(()=>{const a=Ti(g?.priceMatrix);if(!a)return;const o=Gr();o&&(async()=>{const p=await li(o).catch(()=>null);if(!p)return;const v={[p]:{...a}};U(T=>({...T||{},priceMatrix:v,lastUpdated:new Date().toISOString()})),yt({zones:Object.keys(a),priceMatrix:v});try{localStorage.setItem(dn,JSON.stringify({zones:Object.keys(a),priceMatrix:v,timestamp:new Date().toISOString()}))}catch{}})()},[g?.priceMatrix,Ti,Gr,U,yt]),x.useEffect(()=>{const a=s?.geo?.pincode;if(!a||String(a).length!==6)return;const o=g?.priceMatrix;if(!o)return;const p=Object.keys(o);if(p.length!==1||p[0]===kl)return;const v=p[0];(async()=>{const T=await li(a).catch(()=>null);if(!T||T===v)return;const P=o[v],C={[T]:{...P}};U(D=>({...D||{},priceMatrix:C,lastUpdated:new Date().toISOString()}
131)),yt({zones:Object.keys(P),priceMatrix:C});try{localStorage.setItem(dn,JSON.stringify({zones:Object.keys(P),priceMatrix:C,timestamp:new Date().toISOString()}))}catch{}})()},[s?.geo?.pincode,g?.priceMatrix,U,yt]),x.useEffect(()=>{f?.state&&Pa({volumetric:{unit:f.state.unit,volumetricDivisor:f.state.volumetricDivisor??void 0,cftFactor:f.state.cftFactor??void 0},maxShipmentLengthFt:me??void 0})},[f?.state?.unit,f?.state?.volumetricDivisor,f?.state?.cftFactor]);function Ha(){const a=[],o=l.basics||{},p=s.geo||{},v=as(Wt(o,"legalCompanyName","name","companyName","company")).slice(0,60),T=as(Wt(o,"contactPersonName")).slice(0,30),P=as(Wt(o,"subVendor","sub_vendor")).slice(0,20),C=Wt(o,"vendorCode","vendor_code").toUpperCase().replace(/[^A-Z0-9]/g,"").slice(0,9),D=pi(Wt(o,"vendorPhoneNumber","vendorPhone","primaryContactPhone")).slice(0,10),S=Wt(o,"vendorEmailAddress","vendorEmail","primaryContactEmail").trim(),K=Wt(o,"gstin","gst","gstNo").toUpperCase().replace(/\s+/g,"").slice(0,15);if(K){const oe=Bl(K);oe&&a.push(oe)}const F=Wt(o,"address").trim().slice(0,150);if((!v||v.trim().length===0)&&a.push("Legal Transporter name is required (max 60 chars)."),v.trim().length>60&&a.push("Legal Transporter name must be at most 60 characters."),(!T||T.trim().length===0)&&a.push("Contact person is required (max 30 chars)."),T.trim().length>30&&a.push("Contact person must be at most 30 characters."),P&&P.trim().length>20&&a.push("Sub vendor must be at most 20 characters."),/^[A-Za-z0-9]{1,9}$/.test(C)||a.push("Vendor code must be 1 to 9 characters, letters and digits only."),/^[1-9][0-9]{9}$/.test(D)||a.push("Contact number must be 10 digits and cannot start with 0."),S.length>0)if(S.length>30)a.push("Email must be at most 30 characters.");else if(/\s/.test(S))a.push("Email address must not contain spaces.");else{const oe=/\.[a-zA-Z]{2,}$/.test(S);let Q=!1;try{Q=!!(tu.validate(S)&&oe)}catch{Q=Jx.test(S)&&oe}Q||a.push("Invalid email address (must include a valid domain like .com or .in).")}(!F||F.trim().length===0)&&a.push("Address is required (max 150 chars)."),F.trim().length>150&&a.push("Address must be at most 150 characters.");try{const oe=m.charges||{},Q=Yx(oe,0,"fuelSurcharge","fuel");(!Number.isFinite(Q)||Q<0||Q>50)&&a.push("Fuel surcharge must be between 0 and 50.")}catch{}const te=String(p.pincode??"").replace(/\D+/g,"").slice(0,6);te&&te.length!==6&&a.push("Pincode looks invalid (must be exactly 6 digits).");const w=o.serviceMode;return(!w||w!=="FTL"&&w!=="PTL")&&a.push("Please select a service mode."),{ok:a.length===0,errs:a}}const Tr=()=>{console.debug("[VALIDATION] Starting exact validation checks"),it(!0);const a=[],o=(Q,$,Ee)=>{a.push({step:Q,field:$,message:Ee,severity:"error"})};try{const Q=Ha();Q.ok||Q.errs.forEach($=>o("Company Details","General",$))}catch(Q){console.error("[VALIDATION] validateVendorBasicsLocal threw",Q),o("Company Details","System","Error checking specific company details.")}const p=l.validateAll();p.isValid||Object.entries(p.errors).forEach(([Q,$])=>{const Ee=Q.replace(/([A-Z])/g," $1").replace(/^./,Fe=>Fe.toUpperCase());o("Company Details",Ee,$)}),g&&!se?.isValid&&(se?.errors&&se.errors.length>0?se.errors.forEach(Q=>o("Serviceability & Pricing","Zone Configuration",Q)):o("Serviceability & Pricing","Zone Configuration","Manual configuration is invalid.")),(typeof s.validateGeo=="function"?s.validateGeo():!0)||o("Company Details","Location","Pincode or State information is missing/invalid."),(typeof f.validateVolumetric=="function"?f.validateVolumetric():!0)||o("Company Details","Volumetric Config","Volumetric configuration is invalid.");const P={docketCharges:"Docket Charges",fuelSurchargePct:"Fuel Surcharge",gstPct:"GST %",minWeightKg:"Min Chargeable Wt",minCharges:"Minimum Charges",invoiceValueSurcharge:"Invoice Value Surcharge",handlingCharges:"Handling",rovCharges:"ROV / FOV",odaCharges:"ODA Charges",codCharges:"COD Charges",toPayCharges:"To Pay Charges",appointmentCharges:"Appointment Charges",greenTax:"Green Tax",hamaliCharges:"Hamali Charges",miscCharges:"Misc Charges",daccCharges:"DACC Charges"},C=Q=>P[Q]||Q.replace(/([A-Z])/g," $1").replace(/^./,$=>$.toUpperCase()),D=m.validateAll();
131D.isValid||Object.entries(D.errors).forEach(([Q,$])=>{if(typeof $=="string")o("Charges",C(Q),$);else if(typeof $=="object"&&$!==null){const Ee=C(Q);Object.values($).forEach(Fe=>{o("Charges",Ee,Fe)})}});const S=g?.priceMatrix&&Object.keys(g.priceMatrix).length>0,K=ot?.priceMatrix&&Object.keys(ot.priceMatrix).length>0,F=H?.serviceability&&H.serviceability.length>0;return!S&&!K&&!F&&!!!R&&o("Serviceability & Pricing","Data Missing","Zone/Serviceability data is missing. Upload pincodes or configure zones manually."),new URLSearchParams(window.location.search).get("bypassValidation")==="1"&&a.length>0?(console.warn("[VALIDATION] Bypassing errors:",a),ie.success("Validation bypassed (Dev Mode)",{icon:"⚠️"}),!0):a.length>0?(Ot(a),nn(!0),vn("VALIDATION_FAILED",{errs:a}),!1):!0},ba=()=>{const a=l.basics||{},o=s.geo||{},p=as(Wt(a,"name","companyName")).slice(0,60),v=as(Wt(a,"displayName","display_name")).slice(0,30),T=as(Wt(a,"companyName","company_name")).slice(0,60),P=as(Wt(a,"primaryCompanyName","primaryCompany")).slice(0,25),C=as(Wt(a,"subVendor","sub_vendor")).slice(0,20),D=as(Wt(a,"contactPersonName","primaryContactName")).slice(0,100),S=Wt(a,"vendorCode","vendor_code").toUpperCase().replace(/[^A-Z0-9]/g,"").slice(0,9),K=pi(Wt(a,"vendorPhoneNumber","vendorPhone","primaryContactPhone")).slice(0,10),F=Number(Lx(K,1e9,9999999999,10)||0),te=pi(Wt(a,"whatsappNumber","whatsapp")).slice(0,10),w=te?Number(te):null,oe=Wt(a,"vendorEmailAddress","vendorEmail","primaryContactEmail").trim(),Q=Wt(a,"gstin","gstNo","gst").toUpperCase().replace(/\s+/g,"").slice(0,15),$=Wt(a,"address").trim().slice(0,150),Ee=String(o.city??"").trim().slice(0,50),Fe=Number(a.companyRating)||4,Le=Wt(a,"serviceMode","service_mode")||"PTL",_t=f.state||{},ke=_t.unit||"cm";dt("VOLUMETRIC_DATA_DEBUG",{volState:_t,volUnit:ke,fullVolumetricHook:f});const kt=ke==="cm"?{divisor:_t.volumetricDivisor||null,cftFactor:null}:{divisor:null,cftFactor:_t.cftFactor||null};dt("VOLUMETRIC_BITS_MAPPED",kt);const Pe=(De,_n=0,Rr=1e3,xr)=>{if(De==null||De==="")return 0;const Zn=Number(De);if(isNaN(Zn))return 0;const Xn=Math.min(Math.max(Zn,_n),Rr);return Math.round(Xn*100)/100},ze=m.charges||{};console.log("[ODA-DEBUG][submit] c.odaCharges =",JSON.parse(JSON.stringify(ze.odaCharges||null))),Ge(`[ODA-DEBUG][submit] c.odaCharges=${JSON.stringify(ze.odaCharges||null)}`);const ft=tr(ze.rovCharges),ln=tr(ze.codCharges),ae=tr(ze.toPayCharges),xe=tr(ze.handlingCharges),W=tr(ze.appointmentCharges),je=tr(ze.insuranceCharges||ze.insuaranceCharges);tr(ze.odaCharges);const Se=tr(ze.prepaidCharges||ze.codCharges),$e=tr(ze.greenTax),Ue=tr(ze.hamaliCharges),lt=tr(ze.miscCharges),en=tr(ze.daccCharges),pr={serviceMode:Le,volumetricUnit:ke,gst:Pe(ze.gstPct,0,100),minWeight:Pe(ze.minWeightKg,0,1e3),docketCharges:Pe(ze.docketCharges,0,1e3),fuel:Pe(ze.fuelSurchargePct,0,50),invoiceValueSurcharge:Pe(ze.invoiceValueSurcharge,0,100),minCharges:Pe(ze.minCharges,0,1e3),rovCharges:{fixed:Pe(ft.fixed,0,1e3),variable:Pe(ft.variable,0,1e3),unit:ft.unit||"per kg"},codCharges:{fixed:Pe(ln.fixed,0,1e3),variable:Pe(ln.variable,0,1e3),unit:ln.unit||"per kg"},topayCharges:{fixed:Pe(ae.fixed,0,1e3),variable:Pe(ae.variable,0,1e3),unit:ae.unit||"per kg"},handlingCharges:{fixed:Pe(xe.fixed,0,1e3),variable:Pe(xe.variable,0,1e3),unit:xe.unit||"per kg",thresholdWeight:Pe(ze.handlingCharges?.weightThreshold,0,1e3)},appointmentCharges:{fixed:Pe(W.fixed,0,1e3),variable:Pe(W.variable,0,1e3),unit:W.unit||"per kg"},insuranceCharges:{fixed:Pe(je.fixed,0,1e3),variable:Pe(je.variable,0,1e3),unit:je.unit||"per kg"},odaCharges:(()=>{const De=ze.odaCharges,_n=De?.billingType??"per_kg",Rr=(De?.mode||"FIXED")==="FIXED";if(_n==="matrix"){const wt=De?.genericOda;if(wt&&(wt.type||wt.perKg!==void 0||Number(wt.v)||Number(wt.f)||Number(wt.fixed)||Number(wt.variable)))return{fixed:Number(wt.minimum??wt.f??wt.fixed??0),variable:Number(wt.perKg??wt.v??wt.variable??0),perKg:wt.perKg!==void 0?Number(wt.perKg):void 0,minimum:wt.minimum!==void 0?Number(wt.minimum):void 0,type:wt.type||"legacy",billingType:wt.billingType||wt.type||"per_kg",matrix:[],unit:"per kg"};const wa=De?.matrixType==="2d"||Array.isArray(De?.matrix)&&De.matrix.length>0&&Array.isArray(De.matrix[0]?.bands);return{fixed:0,variable:0,type:wa?"distance_weight_matrix":"weight_band",billingType:"matrix",matrixType:wa?"2d":"1d",matrix:De?.matrix||[],unit:"per kg"}}if(_n==="negotiable")return{fixed:0,variable:0,type:"negotiable",billingType:"negotiable",note:De?.note||"Negotiable",matrix:[],unit:"per kg"};if(_n==="per_kg_excess"){const wt=Number(De?.fixedAmount||0),wa=Number(De?.thresholdWeight||0),Oi=Number(De?.variableRange||0);return{fixed:wt,variable:Oi,fixedAmount:wt,thresholdWeight:wa,variableRange:Oi,type:"per_kg_excess",billingType:"per_kg_excess",matrix:[],unit:"per kg"}}const xr=Number(De?.perKg!==void 0?De.perKg:_n==="per_kg"&&!Rr&&De?.variableRange||0)||0,Zn=Number(De?.minimum!==void 0?De.minimum:_n==="per_shipment"&&Rr&&De?.fixedAmount||0)||0;let Xn="legacy",Ja="per_kg";return xr>0&&Zn>0?(Xn="per_kg_minimum",Ja="per_kg_minimum"):Zn>0&&xr===0&&(Xn="per_shipment",Ja="per_shipment"),{fixed:Zn,variable:xr,perKg:xr,minimum:Zn,type:Xn,billingType:Ja,matrix:[],unit:"per kg"}})(),odaMatrix:(()=>{const De=ze.odaCharges;if(Array.isArray(De?.matrix)&&De.matrix.length>0&&(De?.matrixType==="2d"||Array.isArray(De.matrix[0]?.bands)))return{type:"distance_weight_matrix",matrix:De.matrix}})(),prepaidCharges:{fixed:Pe(Se.fixed,0,1e3),variable:Pe(Se.variable,0,1e3),unit:Se.unit||"per kg"},greenTax:{fixed:Pe($e.fixed,0,1e3),variable:Pe($e.variable,0,1e3),unit:$e.unit||"per kg"},hamaliCharges:{fixed:Pe(Ue.fixed,0,1e3),variable:Pe(Ue.variable,0,1e3),unit:Ue.unit||"per kg"},miscellanousCharges:{fixed:Pe(lt.fixed,0,1e3),variable:Pe(lt.variable,0,1e3),unit:lt.unit||"per kg"},daccCharges:{fixed:Pe(en.fixed,0,1e3),variable:Pe(en.variable,0,1e3),unit:en.unit||"per kg"},surcharges:(m.surcharges||[]).filter(De=>De.enabled!==!1&&De.label&&De.label.trim()).map(De=>({id:De.id,label:De.label.trim(),formula:De.formula,value:Number(De.value)||0,value2:Number(De.value2)||0,order:De.order??99,enabled:!0}))};console.log("[ODA-DEBUG][submit] priceRate.odaCharges =",pr.odaCharges,"priceRate.odaMatrix =",pr.odaMatrix),Ge(`[ODA-DEBUG][submit] priceRate.odaCharges=${JSON.stringify(pr.odaCharges)} priceRate.odaMatrix=${JSON.stringify(pr.odaMatrix)}`);
131const gr=g?.priceMatrix||ot?.priceMatrix||{},et=gr&&typeof gr=="object"&&!Array.isArray(gr)&&Object.keys(gr).length>0&&!Object.keys(gr).every(De=>!isNaN(Number(De)))?gr:{},jn=g?.zones?.map(De=>De.zoneCode)||ot?.zones?.map(De=>De.zoneCode)||[],At=new Set(nu),Ft=jn.filter(De=>!At.has(De)),Bs=jn.filter(De=>At.has(De));Ft.length>0&&(console.warn(`[AddVendor] Dropping unknown zone code(s) from selectedZones: ${Ft.join(", ")}`),ie(`Ignored unknown zone code(s): ${Ft.join(", ")} — not part of the master zone list.`));const Mi=(g?.zones||ot?.zones||[]).filter(De=>At.has(De?.zoneCode)),To=String(o.pincode??"").replace(/\D+/g,"").slice(0,6),zt=Number(To||0),Ht=mt&&Number(mt)>0,Ro=Mt&&Number(Mt)>0,Io=Ht||Ro;let va=[],ya="",vs="";return H?.serviceability&&Array.isArray(H.serviceability)&&H.serviceability.length>0?(va=H.serviceability,ya=H.checksum||"",vs=H.source||"excel"):g?.serviceability&&Array.isArray(g.serviceability)&&g.serviceability.length>0?(va=g.serviceability,ya=g.serviceabilityChecksum||"",vs="wizard"):(ya="",vs=""),{customerID:cr.current,companyName:T.trim(),contactPersonName:D,vendorCode:S,vendorPhone:F,vendorWhatsapp:w,vendorEmail:oe,gstNo:
131Q,transportMode:z||"road",serviceMode:Le,address:$,state:String(o.state??"").toUpperCase(),pincode:zt,city:Ee,rating:Fe,vendorRatings:a.vendorRatings||{priceSupport:0,deliveryTime:0,tracking:0,salesSupport:0,damageLoss:0},subVendor:C,selectedZones:Bs,zoneConfigurations:Mi,human:{name:p,displayName:v,primaryCompanyName:P},prices:{priceRate:pr,priceChart:et,rateOverrides:g?.rateOverrides||{}},zones:Mi,serviceability:va,serviceabilityChecksum:ya,serviceabilitySource:vs,invoiceValueCharges:{enabled:Io,percentage:Number(mt||0),minimumAmount:Number(Mt||0),description:"Invoice Value Handling Charges"},isDraft:St==="draft"}},Ri=async a=>{a&&a.preventDefault(),dt("SUBMIT_STARTED");const o=g?.priceMatrix||ot?.priceMatrix||{},p=St==="draft";if(p){const S=l.basics.companyName?.trim();if(!S){ie.error("Company Name is required to save a draft.",{duration:3e3});return}J(!0),Ye(!0),nt("loading");try{const K={basics:{...l.basics},geo:{state:s.geo.state,city:s.geo.city,pincode:s.geo.pincode},volumetric:{...f.state},charges:{...m.charges},transportMode:z,zoneConfigMode:B,serviceabilityData:H?{serviceability:H.serviceability,zoneSummary:H.zoneSummary,checksum:H.checksum,source:H.source}:null,zpm:ot?{zones:ot.zones,priceMatrix:ot.priceMatrix}:null,wizardData:g?{zones:g.zones,priceMatrix:g.priceMatrix,serviceability:g.serviceability,serviceabilityChecksum:g.serviceabilityChecksum,serviceabilitySource:g.serviceabilitySource}:null,invoicePercentage:mt,invoiceMinAmount:Mt,invoiceUseMax:Bt,currentStep:Lt},te=(await ns.saveVendorDraft(S,K,fr(S)))?.data?._id;te&&Er(te),ie.success("Draft saved!",{duration:800}),nt("success"),Pa({basics:K.basics,charges:K.charges})}catch(K){ie.error(K instanceof Error?K.message:"Failed to save draft.",{duration:3e3}),Ye(!1)}finally{J(!1)}return}const v=H?.serviceability&&Array.isArray(H.serviceability)&&H.serviceability.length>0,T=g?.serviceability&&Array.isArray(g.serviceability)&&g.serviceability.length>0,P=o&&typeof o=="object"&&Object.keys(o).length>0,C=ot?.priceMatrix&&Object.keys(ot.priceMatrix).length>0;if(!v&&!T&&!P&&!C){ie.error("Please add pricing or serviceability data before saving.",{duration:5e3}),ms("validation-failed");return}if(!Tr()){vn("VALIDATION_FAILED_ON_SUBMIT"),ie.error("Please fix the highlighted errors before saving.",{duration:5e3}),ms("validation-failed");return}J(!0),Ye(!0),nt("loading");try{const S=ba();if(dt("SUBMIT_PAYLOAD_FOR_API",S),["cloud","cloud_utsf","active","draft"].includes(St)){const F=new FormData;F.append("customerID",String(S.customerID||"")),F.append("companyName",S.companyName),F.append("contactPersonName",S.contactPersonName),F.append("vendorCode",S.vendorCode),F.append("vendorPhone",String(S.vendorPhone)),S.vendorWhatsapp&&F.append("vendorWhatsapp",String(S.vendorWhatsapp)),F.append("vendorEmail",S.vendorEmail),F.append("gstNo",S.gstNo),F.append("transportMode",S.transportMode),F.append("serviceMode",S.serviceMode||""),F.append("address",S.address),F.append("state",S.state),F.append("pincode",String(S.pincode)),F.append("city",S.city),F.append("rating",String(S.rating)),F.append("vendorRatings",JSON.stringify(S.vendorRatings)),F.append("subVendor",S.subVendor||"");const te=f.state.unit||"cm";F.append("volumetricUnit",te),F.append("volumetricDivisor",te==="cm"?String(f.state.volumetricDivisor||""):""),F.append("cftFactor",te==="in"?String(f.state.cftFactor||""):""),me!==null&&F.append("maxShipmentLengthFt",String(me)),F.append("selectedZones",JSON.stringify(S.selectedZones)),F.append("zoneConfigurations",JSON.stringify(S.zoneConfigurations)),F.append("priceRate",JSON.stringify(S.prices.priceRate)),F.append("priceChart",JSON.stringify(S.prices.priceChart)),Object.keys(S.prices.rateOverrides||{}).length>0&&F.append("rateOverrides",JSON.stringify(S.prices.rateOverrides)),q&&F.append("priceChartFile",q),S.serviceability&&S.serviceability.length>0&&(F.append("serviceability",JSON.stringify(S.serviceability)),F.append("serviceabilityChecksum",S.serviceabilityChecksum||""),F.append("serviceabilitySource",S.serviceabilitySource||"excel")),da&&F.append("sourceTransporterId",da),F.append("vendorJson",JSON.stringify(S)),p&&F.append("isDraft","true");const w=Ar(),oe=`${Yt}/api/transporter/addtiedupcompanies`;dt("SUBMITTING_TO_API",{url:oe,hasToken:!!w});const Q=()=>fetch(oe,{method:"POST",headers:{Authorization:`Bearer ${w}`},credentials:"include",body:F});let $=await Q(),Ee=await $.json().catch(()=>({}));if(dt("API_RESPONSE",{status:$.status,json:Ee}),$.status===503&&Ee?.code==="AUTH_DB_UNAVAILABLE"&&(dt("AUTH_DB_UNAVAILABLE_RETRY",{attempt:2}),await new Promise(Le=>setTimeout(Le,1500)),$=await Q(),Ee=await $.json().catch(()=>({})),dt("API_RESPONSE_RETRY",{status:$.status,json:Ee})),!$.ok||!Ee?.success){vn("SUBMIT_ERROR",{status:$.status,json:Ee});const Le=$.status===503&&Ee?.code==="AUTH_DB_UNAVAILABLE"?"Server is temporarily unavailable. Please wait a moment and try again.":Ee?.message||`Cloud save failed (${$.status})`;throw new Error(Le)}const Fe=[...de,...q?[{file:q,category:"charges"}]:[]];if(Fe.length>
1310&&Ee.data?._id)for(const{file:Le,category:_t}of Fe)try{const ke=new FormData;ke.append("file",Le),ke.append("vendorId",Ee.data._id),ke.append("category",_t);const Pe=await(await fetch(`${Yt}/api/uploads/vendor-file`,{method:"POST",headers:{Authorization:`Bearer ${w}`},body:ke})).json().catch(()=>({}));Pe.success?dt("GRIDFS_UPLOAD_SUCCESS",{fileId:Pe.fileId,fileName:Le.name,category:_t}):vn("GRIDFS_UPLOAD_ERROR",{error:Pe.error,fileName:Le.name})}catch(ke){vn("GRIDFS_UPLOAD_EXCEPTION",ke)}if(ta&&Ee.data?._id)try{await fetch(`${Yt}/api/utsf-generator/transporter/${encodeURIComponent(ta)}/link-vendor`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${w}`},credentials:"include",body:JSON.stringify({vendorId:Ee.data._id})})}catch(Le){vn("LINK_VENDOR_DOCS_EXCEPTION",Le)}}if(St==="utsf"||St==="cloud_utsf"){const F=f.state.unit||"cm",te={version:"2.0",meta:{id:void 0,companyName:S.companyName,vendorCode:S.vendorCode,customerID:S.customerID,contactPersonName:S.contactPersonName,vendorPhone:String(S.vendorPhone||""),vendorEmail:S.vendorEmail,gstNo:S.gstNo,address:S.address,city:S.city,state:S.state,pincode:String(S.pincode||""),transportMode:S.transportMode,serviceMode:S.serviceMode,rating:S.rating,subVendor:S.subVendor,transporterType:"regular",isVerified:!1,approvalStatus:"approved",createdAt:new Date().toISOString()},pricing:{priceRate:{...S.prices?.priceRate||{},volumetricUnit:F,divisor:F==="cm"&&f.state.volumetricDivisor||null,cftFactor:F==="in"&&f.state.cftFactor||null},priceChart:S.prices?.priceChart||{},zoneRates:S.prices?.priceChart||{}},serviceability:S.serviceability||{},zoneRates:{},oda:{},stats:{}},w=Ar(),oe=`${Yt}/api/utsf/upload-json`,Q=await fetch(oe,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${w}`},credentials:"include",body:JSON.stringify(te)}),$=await Q.json().catch(()=>({}));if(!Q.ok||!$?.success)throw new Error($?.message||"UTSF save failed");if(G&&!p&&$?.transporter?.id)try{await y0($.transporter.id,$.transporter.companyName,"UTSF")}catch{}}const K=p;if(ie.success(K?"Draft saved!":"Vendor created successfully!",{duration:800}),nt("success"),Dr.current=!0,!K){const F=Hx();F&&sessionStorage.setItem(`fc_promo_dismissed_${F}`,"true"),window.dispatchEvent(new Event("fc:vendor-added"))}if(!K&&hn)try{await ns.deleteVendorDraft(hn),Vr(te=>te.filter(w=>w._id!==hn));const F=localStorage.getItem(hr);if(F){const te=JSON.parse(F).filter(w=>w._id!==hn);localStorage.setItem(hr,JSON.stringify(te))}Er(null)}catch{}Fl(),O(),localStorage.removeItem(dn);try{typeof l.reset=="function"&&l.reset(),typeof s.reset=="function"&&s.reset(),typeof f.reset=="function"&&f.reset(),typeof m.reset=="function"&&m.reset()}catch(F){vn("RESET_HOOKS_ERROR",{err:F})}ee(null),Y([]),E("road"),Ke(""),Ct(""),Fn(!1),nr(!1),yt(null),Ce(null),Qe(null),ce(F=>F+1),Xt(""),fn(!1),wn(null),jt(null),In(null),Gn([]),rt(!1),pe(null),Gt(1),Tn(null),He(Date.now())}catch(S){vn("SUBMIT_EXCEPTION",{error:S instanceof Error?S.message:String(S),stack:S instanceof Error?S.stack:void 0}),ie.error(S instanceof Error?S.message:"Unexpected error. Please try again.",{duration:5200}),Ye(!1)}finally{J(!1)}},gs=Lt>1||gt.trim().length>0||or,on=x.useRef(null),Qt=x.useRef(!1);x.useEffect(()=>{const a=o=>{gs&&!le&&(o.preventDefault(),o.returnValue="")};return window.addEventListener("beforeunload",a),()=>window.removeEventListener("beforeunload",a)},[gs,le]),x.useEffect(()=>{if(!gs||le)return;window.history.pushState(null,"",window.location.href);const a=()=>{Qt.current||(window.history.pushState(null,"",window.location.href),on.current="back",he(!0))};return window.addEventListener("popstate",a),()=>window.removeEventListener("popstate",a)},[gs,le]),x.useEffect(()=>{if(!gs||le)return;const a=window.history.pushState.bind(window.history);return window.history.pushState=function(o,p,v){if(Qt.current)return a(o,p,v);if(v){const T=typeof v=="string"?new URL(v,window.location.origin).pathname:typeof v=="object"?v.pathname:"";if(T&&T!==window.location.pathname){on.current=typeof v=="string"?v:T,he(!0);return}}return a(o,p,v)},()=>{window.history.pushState=a}},[gs,le]);const Sn=x.useCallback(()=>{try{typeof l.reset=="function"&&l.reset(),typeof s.reset=="function"&&s.reset(),typeof f.reset=="function"&&f.reset(),typeof m.reset=="function"&&m.reset()}catch(a){vn("RESET_HOOKS_ERROR",{err:a})}ee(null),E("road"),Ke(""),Ct(""),Fn(!1),nr(!1),Xt(""),fn(!1),wn(null),jt(null),In(null),Gn([]),rt(!1),pe(null),Gt(1),Tn(null),Vn("selection"),M("matrix"),Fl(),O(),Mn(!1)},[l,s,f,m,Fl,O]),Ii=()=>{confirm("Reset the form? Unsaved changes will be lost.")&&(Sn(),ie.success("Form reset",{duration:1200}))},pn=x.useMemo(()=>{const a=l.basics,o=m.charges;return{vendorName:a.companyName||gt||void 0,vendorCode:a.vendorCode||void 0,transportMode:z||void 0,serviceMode:a.serviceMode||void 0,pincodeCount:H?.serviceability?.length??0,hasCompanyInfo:!!(a.companyName&&a.companyName.length>=2),hasContactInfo:!!(a.contactPersonName||a.primaryContactName),hasGST:!!(a.gstin&&a.gstin.length>=15),hasCharges:!!(o&&o.docketCharges!=null&&Number(o.docketCharges)>0&&o.fuelSurchargePct!=null&&Number(o.fuelSurchargePct)>0&&(()=>{const v=(o.handlingCharges?.mode||(o.handlingCharges?.currency==="INR"?"FIXED":"VARIABLE"))==="FIXED"?o.handlingCharges?.fixedAmount:o.handlingCharges?.variableRange;return v!=null&&Number(v)>0})())}},[l.basics,gt,z,H,m.charges]),xs=a=>a?a.mode==="VARIABLE"?parseFloat(a.variableRange)>0:Number(a.fixedAmount)>0:!1,Po=x.useMemo(()=>{const a=l.basics,o=m.charges,p=s.geo||{},v=gt.trim().length>0?5:0,T=Zt!==null?10:0,P=Lt>2?15:0,C=[!!(a.gstin&&a.gstin.length>=15),!!(a.companyName&&a.companyName.trim().length>=2),!!(a.contactPersonName||a.primaryContactName),!!(a.vendorPhoneNumber||a.primaryContactPhone),!!a.whatsappNumber,!!(a.vendorEmailAddress||a.primaryContactEmail),
131!!p.pincode,!!p.state,!!p.city,!!a.subVendor,!!a.address,me!=null],D=[o.docketCharges!=null&&Number(o.docketCharges)>0,o.fuelSurchargePct!=null&&Number(o.fuelSurchargePct)>0,o.minWeightKg!=null&&Number(o.minWeightKg)>0,o.minCharges!=null&&Number(o.minCharges)>0,o.gstPct!=null&&Number(o.gstPct)>0,xs(o.handlingCharges),xs(o.rovCharges),xs(o.odaCharges),xs(o.greenTax),xs(o.hamaliCharges),xs(o.miscCharges)],S=C.filter(Boolean).length/C.length*35,K=D.filter(Boolean).length/D.length*35;return Math.round(v+T+P+S+K)},[gt,Zt,Lt,l.basics,m.charges,s.geo,me]),Do=x.useMemo(()=>{const a=[];return xa.rows===0&&a.push("No zones configured"),pn.hasCompanyInfo||a.push("Company name missing"),pn.hasGST||a.push("GST not provided"),a},[xa.rows,pn.hasCompanyInfo,pn.hasGST]),Fo=x.useMemo(()=>{const a=m.charges,o=fe,p=re,v=Ne,T=[],P=[],C=(K,F)=>{F>0&&T.push({label:K,value:Math.round(F*100)/100})},D=K=>{if(!K)return 0;if((K.mode||(K.currency==="INR"?"FIXED":"VARIABLE"))==="FIXED"){const te=Number(K.fixedAmount||0);return K.unit==="per kg"?te*p:te}else{const te=Number(K.variableRange||0);return o*te/100}},S=(K,F)=>{if(!K)return F;const te=K.mode||(K.currency==="INR"?"FIXED":"VARIABLE");if(te==="FIXED"&&K.unit==="per kg")return`${F} (${p}kg)`;if(te==="VARIABLE"){const w=Number(K.variableRange||0);return w>0?`${F} (${w}%)`:F}return F};if(C("Docket Charges",Number(a.docketCharges||0)),a.fuelSurchargePct!=null){const K=o*Number(a.fuelSurchargePct)/100;C(`Fuel Surcharge (${a.fuelSurchargePct}%)`,K),Number(a.fuelSurchargePct)>15&&P.push({type:"warning",message:"Fuel surcharge is above 15%, which may reduce booking conversion."})}C(S(a.rovCharges,"ROV / FOV"),D(a.rovCharges));{const K=a.odaCharges;if(K){const F=K.mode||(K.currency==="INR"?"FIXED":"VARIABLE"),te=K.billingType??"per_kg";if(te==="matrix"&&Array.isArray(K.matrix)&&K.matrix.length>0){const w=K.matrix.find(Q=>p>=Number(Q.minWeight??0)&&p<Number(Q.maxWeight??1/0)),oe=w?Number(w.rate??0)*p+Number(w.fixedSurcharge??0):0;C(`ODA Charges (${p}kg, matrix)`,oe)}else if(te==="per_kg_excess"&&F==="FIXED"){const w=Number(K.fixedAmount||0),oe=Number(K.thresholdWeight||0),Q=Number(K.variableRange||0),$=w+Math.max(0,p-oe)*Q;C(`ODA Charges (${p}kg, +Extra)`,$)}else if(F==="FIXED"){const w=Number(K.fixedAmount||0),oe=te==="per_shipment"?w:w*p;C(`ODA Charges${te==="per_shipment"?"":` (${p}kg)`}`,oe)}else{const w=Number(K.variableRange||0);C(`ODA Charges (${w}%)`,o*w/100)}}}{const K=a.handlingCharges;if(K)if((K.mode||(K.currency==="INR"?"FIXED":"VARIABLE"))==="FIXED"){const te=Number(K.fixedAmount||0),w=K.unit||"per kg",oe=w==="per kg"?te*p:te;C(`Handling${w==="per kg"?` (${p}kg)`:""}`,oe)}else{const te=Number(K.variableRange||0);C(`Handling (${te}%)`,o*te/100)}}if(C(S(a.greenTax,"Green Tax / NGT"),D(a.greenTax)),C(S(a.hamaliCharges,"Hamali Charges"),D(a.hamaliCharges)),C(S(a.miscCharges,"MISC / AOC Charges"),D(a.miscCharges)),C(S(a.toPayCharges,"To-Pay Charges"),D(a.toPayCharges)),C(S(a.codCharges,"COD / DOD Charges"),D(a.codCharges)),C(S(a.daccCharges,"DACC Charges"),D(a.daccCharges)),C(S(a.appointmentCharges,"Appointment Charges"),D(a.appointmentCharges)),C("Min Charges",Number(a.minCharges||0)),a.docketCharges!=null&&Number(a.docketCharges)>100&&P.push({type:"info",message:"Docket charges are higher than regional average (₹50)."}),v>0){const K=Number(a.insurancePct||0);K>0&&C(`Insurance (${K}% of ₹${v.toLocaleString()})`,v*K/100)}return{baseFreight:o,charges:T,consequences:P}},[m.charges,fe,re,Ne]),bs=async()=>{ia(!1);const a={...Ia},o=[...aa];try{const p={},v=/^[^\s@]+@[^\s@]+\.[^\s@]+$/;for(const T of o){const P=(a[T.id]||"").trim();if(T.required&&!P){p[T.id]=`${T.label} is required`;continue}if(T.id==="vendorPhoneNumber"&&P&&!/^\d{10}$/.test(P)&&(p[T.id]="Must be exactly 10 digits"),T.id==="vendorEmailAddress"&&P)if(P.length>30)p[T.id]="Max 30 characters allowed";else if(/\s/.test(P))p[T.id]="No spaces allowed";else{const C=/\.[a-zA-Z]{2,}$/.test(P);let D=v.test(P)&&C;try{D=tu.validate(P)&&C}catch{}D||(p[T.id]="Invalid email address (e.g. [email protected])")}T.id==="pincode"&&P&&!/^\d{6}$/.test(P)&&(p[T.id]="Must be exactly 6 digits")}if(Ts(p),Object.keys(p).length>0){ie.error("Please fix the highlighted fields");return}ia(!0);for(const T of o){const P=(a[T.id]||"").trim();if(P)switch(T.id){case"pincode":await s.setPincode(P);break;case"serviceMode":l.setField("serviceMode",P);break;case"companyName":l.setField("companyName",P),Xt(P);break;case"contactPersonName":case"vendorPhoneNumber":case"vendorEmailAddress":case"address":case"vendorCode":l.setField(T.id,P);break;default:break}}Ra(!1),Fs({}),Ts({}),ie.success("Details saved — review below and click Add Vendor."),Ge("[OK] Missing fields filled — ready to add vend
131or."),Tn("existing"),Mn(!0),Gt(2),window.scrollTo({top:0,behavior:"smooth"})}catch(p){ie.error(`Save failed: ${p?.message||"Unknown error"}`)}finally{ia(!1)}},j=()=>{ie("Required fields still missing — fill them before submitting",{icon:"⚠️"}),Ra(!1),Fs({}),Ts({}),Ge("[WARN] Required fields skipped — fill them in manually before submitting."),Tn("existing"),Mn(!0),Gt(2),window.scrollTo({top:0,behavior:"smooth"})};return n.jsxs("div",{ref:yn,className:"min-h-screen bg-slate-50",children:[n.jsxs("div",{className:"px-4 md:px-6 pt-3 md:pt-4 pb-6",children:[n.jsxs("div",{className:"flex flex-col lg:flex-row lg:items-start gap-4 min-h-[calc(100vh-140px)]",children:[n.jsxs("div",{className:`flex-1 min-w-0 flex flex-col ${Lt===1?"bg-transparent":"bg-white rounded-2xl shadow-sm border border-slate-200/80"}`,children:[n.jsx("div",{className:"flex-1 min-w-0 p-4 sm:p-6 pt-2 sm:pt-3",children:n.jsxs("form",{id:"add-vendor-form",onSubmit:Ri,autoComplete:"off",children:[n.jsxs("div",{style:{display:Lt===1?"block":"none"},children:[n.jsx("div",{className:"max-w-3xl mx-auto pt-0 mb-4",children:n.jsxs("div",{className:"flex gap-2 bg-slate-100 p-1 rounded-xl w-fit",children:[n.jsxs("button",{type:"button",onClick:()=>Is("transporter"),className:`flex items-center gap-1.5 px-4 py-2 rounded-lg text-sm font-bold transition-colors ${cs==="transporter"?"bg-white text-blue-700 shadow-sm":"text-slate-500 hover:text-slate-700"}`,children:[n.jsx(El,{size:14})," Transporter"]}),n.jsxs("button",{type:"button",onClick:()=>Is("individual_ftl"),className:`flex items-center gap-1.5 px-4 py-2 rounded-lg text-sm font-bold transition-colors ${cs==="individual_ftl"?"bg-white text-blue-700 shadow-sm":"text-slate-500 hover:text-slate-700"}`,children:[n.jsx(v0,{size:14})," Individual FTL Transporter"]})]})}),cs==="individual_ftl"&&n.jsx(S0,{prefillFrom:ds,onPrefillConsumed:()=>za(null)}),n.jsxs(ct.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},style:{display:cs==="individual_ftl"?"none":void 0},className:"max-w-3xl mx-auto pt-0",children:[ht==="idle"&&n.jsxs("div",{className:"relative text-center mb-6 pt-0",children:[n.jsxs("div",{className:"absolute -top-2 right-0 inline-flex items-center gap-1.5 px-2.5 py-1 bg-blue-50 border border-blue-200 rounded-full shadow-sm",children:[n.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-blue-500 animate-pulse flex-shrink-0"}),n.jsx("p",{className:"text-[10px] text-blue-700 font-semibold leading-none",children:"Takes 60s - 90s only"})]}),n.jsx("h2",{className:"text-2xl font-bold text-slate-800 mb-1",children:"Find Your Vendor"}),n.jsx("p",{className:"text-sm text-slate-500",children:"Search for an existing partner or create a new profile."})]}),ht==="idle"&&n.jsxs("div",{ref:Cn,className:"bg-white rounded-2xl shadow-xl border border-slate-100 overflow-hidden relative z-10",children:[n.jsx("div",{className:"p-1",children:n.jsxs("div",{className:"relative group",children:[n.jsx("div",{className:"absolute inset-y-0 left-0 pl-4 flex items-center pointer-events-none",children:Ai?n.jsx(un,{className:"h-6 w-6 text-blue-500 animate-spin"}):n.jsx(gi,{className:"h-6 w-6 text-slate-400 group-focus-within:text-blue-500 transition-colors"})}),n.jsx("input",{type:"text",name:"vendor-search-query-field",maxLength:60,className:"block w-full pl-12 pr-4 py-4 text-lg border-none focus:ring-0 focus:outline-none placeholder:text-slate-300 transition-all bg-transparent",placeholder:"Type vendor name...",autoComplete:"one-time-code",autoCorrect:"off",autoCapitalize:"none",value:gt,onChange:a=>{const o=a.target.value;Xt(o),fn(!1),rt(!1),ht!=="idle"&&(Nn("idle"),ar([]),$r([]),Ta(""),As(null),ra(null),Es(null),Ps(null),Bn(0)),Ba(!0),ua.current&&clearTimeout(ua.current),ua.current=setTimeout(()=>Ba(!1),400),o.length>=2&&us(!0),hs(o)},onFocus:()=>Br.length>0&&Rn(!0),onKeyDown:a=>{if(a.key==="Enter"){a.preventDefault(),Ua&&Br.length>0&&Ls>=0?Fr(Br[Ls]):(hs(a.currentTarget.value),hs.flush());return}!Ua||!Br.length||(a.key==="ArrowDown"?(a.preventDefault(),zs(o=>o<Br.length-1?o+1:0)):a.key==="ArrowUp"?(a.preventDefault(),zs(o=>o>0?o-1:Br.length-1)):a.key==="Escape"&&Rn(!1))}}),gt.length>0&&!or&&n.jsx("button",{type:"button",onClick:()=>{Xt(""),Gn([]),Rn(!1),rt(!1),ht!=="idle"&&(Nn("idle"),ar([]),$r([]),Ta(""),As(null),ra(null),Es(null),Ps(null),Bn(0))},className:"absolute inset-y-0 right-0 pr-4 flex items-center",children:n.jsx(bi,{className:"h-5 w-5 text-slate-300 hover:text-slate-500 transition-colors"})})]})}),n.jsx(Nr,{children:Ua&&gt.trim().length>=2&&n.jsxs(ct.div,{initial:{height:0,opacity:0}
131,animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},className:"border-t border-slate-100 bg-slate-50/50 max-h-60 overflow-y-auto",children:[Br.map((a,o)=>n.jsxs("div",{onClick:()=>Fr(a),onMouseEnter:()=>zs(o),className:`px-4 py-3 cursor-pointer flex items-center gap-3 transition-colors ${a.isSystemVendor?Ls===o?"bg-orange-50":"hover:bg-orange-50/60 border-b border-orange-100":a.isMyVendor?Ls===o?"bg-amber-50":"hover:bg-amber-50/60":Ls===o?"bg-blue-50":"hover:bg-white"}`,children:[!a.isSystemVendor&&n.jsx("input",{type:"checkbox",checked:sn.some(p=>p.type==="search"&&p.result.id===a.id),onClick:p=>p.stopPropagation(),onChange:p=>{p.stopPropagation(),p.target.checked?wo(a):Ei(`search-${a.id}`)},title:"Add to basket — pick a few vendors, fill their details one at a time",className:"appearance-none w-4 h-4 rounded-[4px] border-2 border-slate-300 bg-white checked:bg-blue-600 checked:border-blue-600 cursor-pointer shrink-0 transition-colors focus:outline-none focus:ring-2 focus:ring-blue-300"}),n.jsx("div",{className:`p-2 rounded-lg ${a.isSystemVendor?"bg-orange-100 text-orange-600":a.isMyVendor?"bg-amber-100 text-amber-600":"bg-blue-100 text-blue-600"}`,children:a.isSystemVendor?n.jsx(xi,{className:"w-5 h-5"}):a.isMyVendor?n.jsx(Pl,{className:"w-5 h-5"}):n.jsx(El,{className:"w-5 h-5"})}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[n.jsx("h4",{className:"font-semibold text-slate-800 text-sm",children:a.legalCompanyName||a.companyName}),a.isSystemVendor&&n.jsx("span",{className:"px-1.5 py-0.5 rounded-full text-[10px] font-bold bg-orange-100 text-orange-700 uppercase tracking-wide",children:"Official"}),a.isMyVendor&&n.jsx("span",{className:"px-1.5 py-0.5 rounded-full text-[10px] font-bold bg-amber-100 text-amber-700 border border-amber-200 uppercase tracking-wide",children:"My Vendor"})]}),n.jsx("div",{className:"flex gap-2 text-xs mt-0.5",children:a.isSystemVendor?n.jsx("span",{className:"text-orange-600 font-medium",children:"Click to add instantly — no setup needed"}):a.isMyVendor?n.jsxs("span",{className:"text-amber-600 font-medium flex items-center gap-1",children:[n.jsx(Pl,{className:"w-3 h-3"}),"You will be editing it — Pricing, Details & Charges autofilled"]}):n.jsx(n.Fragment,{children:a.vendorCode&&n.jsx("span",{className:"bg-slate-200 px-1.5 py-0.5 rounded text-slate-600",children:a.vendorCode})})})]}),n.jsx("div",{className:"text-slate-400 shrink-0",children:a.isSystemVendor?n.jsx(ea,{className:"w-5 h-5 text-orange-400"}):a.isMyVendor?n.jsx(Pl,{className:"w-5 h-5 text-amber-400"}):n.jsx(wr,{className:"w-5 h-5 text-slate-300 hover:text-blue-500"})})]},a.id)),gt.trim().length>=2&&n.jsxs("div",{onClick:()=>{Rn(!1),rt(!0),ks("start")},className:"px-4 py-3 cursor-pointer flex items-center gap-3 border-t border-dashed border-slate-200 hover:bg-blue-50 transition-colors",children:[n.jsx("div",{className:"p-2 rounded-lg bg-blue-100 text-blue-600",children:n.jsx(El,{className:"w-5 h-5"})}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsxs("h4",{className:"font-semibold text-slate-800 text-sm break-all",children:['Add "',n.jsx("span",{className:"text-blue-700 break-all",children:gt.trim()}),'" as my own vendor']}),n.jsx("p",{className:"text-xs text-slate-500 mt-0.5",children:"Not in our database? Use our AI generator to onboard instantly"})]}),n.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[n.jsx("button",{type:"button",onClick:a=>{a.stopPropagation(),Co(gt),Xt(""),Rn(!1)},title:"Queue this name for later instead of starting it now",className:"text-[10px] font-bold text-blue-600 bg-blue-50 px-2 py-1 rounded border border-blue-200 hover:bg-blue-100 uppercase tracking-wider whitespace-nowrap",children:"+ Add to basket"}),n.jsxs("div",{className:"flex flex-col items-end gap-1",children:[n.jsx("span",{className:"text-[10px] font-bold text-blue-600 bg-blue-50 px-1.5 py-0.5 rounded border border-blue-100 uppercase tracking-wider",children:"Fast Track"}),n.jsx(Cr,{className:"w-4 h-4 text-emerald-400"})]})]})]})]})})]}),sn.length>0&&n.jsxs("div",{className:"mt-4 bg-blue-50/60 border border-blue-100 rounded-2xl p-4",children:[n.jsxs("div",{className:"flex items-center justify-between mb-2.5",children:[n.jsxs("p",{className:"text-xs font-bold text-blue-800 uppercase tracking-wider",children:["Vendor basket (",sn.length,")"]}),n.jsxs("button",{type:"button",onClick:pa,className:"px-4 py-1.5 bg-blue-600 hover:bg-blue-700 text-white rounded-lg text-xs font-bold shadow-sm transition-colors flex items-center gap-1.5",children:["Continue with ",sn.length," vendor",sn.length!==1?"s":""," ",n.jsx(Cr,{className:"w-3.5 h-3.5"})]})]}),n.jsx("div",{className:"flex flex-wrap gap-2",children:sn.map(a=>n.jsxs("span",{className:"inline-flex items-center gap-1.5 bg-white border border-blue-200 text-blue-800 text-xs font-semibold px-2.5 py-1.5 rounded-full",children:[a.type==="search"?a.result.legalCompanyName||a.result.companyName:a.name,n.jsx("button",{type:"button",onClick:()=>Ei(a.key),title:"Remove from basket",className:"text-blue-300 hover:text-red-500 transition-colors",children:n.jsx(Sr,{className:"w-3 h-3"})})]},a.key))}),n.jsx("p",{className:"text-[11px] text-blue-600/80 mt-2",children:"We'll take you through them one at a time — each is saved as its own draft, so you can finish now or come back later."})]}),n.jsx("input",{ref:Rt,type:"file",accept:".json,.utsf.json",onChange:Pi,className:"hidden"}),n.jsx(Nr,{children:No&&n.jsx(ct.div,{initial:{opacity:0,scale:.95}
131,animate:{opacity:1,scale:1},exit:{opacity:0,scale:.95},className:"mt-6 bg-blue-50 border border-blue-100 rounded-xl p-5 shadow-sm",children:n.jsxs("div",{className:"flex items-center gap-4",children:[n.jsx("div",{className:"bg-blue-100 p-2 rounded-full",children:n.jsx(un,{className:"w-6 h-6 text-blue-600 animate-spin"})}),n.jsxs("div",{children:[n.jsx("h4",{className:"font-bold text-blue-900",children:"Loading Vendor Data…"}),n.jsx("p",{className:"text-sm text-blue-700",children:"Fetching zones and pricing structure, please wait."})]})]})})}),n.jsx(Nr,{children:or&&n.jsx(ct.div,{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},className:"mt-6 bg-blue-50 border border-blue-100 rounded-xl p-5 shadow-sm",children:n.jsxs("div",{className:"flex items-start md:items-center justify-between gap-4 flex-col md:flex-row",children:[n.jsxs("div",{className:"flex items-center gap-4",children:[n.jsx("div",{className:"bg-blue-100 p-2 rounded-full",children:n.jsx(ea,{className:"w-6 h-6 text-blue-600"})}),n.jsxs("div",{children:[n.jsx("h4",{className:"font-bold text-emerald-900",children:"Vendor Loaded"}),n.jsxs("p",{className:"text-sm text-blue-700",children:["Data auto-filled from ",n.jsx("strong",{children:Wa})]}),(()=>{try{const a=sessionStorage.getItem("utsf_uploaded_files");if(!a)return null;const o=JSON.parse(a);return o.length?(sessionStorage.removeItem("utsf_uploaded_files"),n.jsxs("div",{className:"mt-2",children:[n.jsx("p",{className:"text-[11px] font-semibold text-blue-600 uppercase tracking-wider mb-1",children:"Source documents used for generation"}),n.jsx("div",{className:"flex flex-wrap gap-1.5",children:o.map((p,v)=>n.jsxs("span",{className:"inline-flex items-center gap-1 text-[11px] font-medium bg-white border border-blue-200 text-blue-700 rounded-full px-2.5 py-0.5",children:[n.jsx(ci,{className:"w-3 h-3"}),p.name,n.jsxs("span",{className:"text-emerald-400 text-[10px]",children:["(",p.category.replace(/_/g," "),")"]})]},v))})]})):null}catch{return null}})()]})]}),n.jsxs("div",{className:"flex gap-3 w-full md:w-auto flex-wrap",children:[na&&n.jsxs("button",{type:"button",title:"Download the generated UTSF file",onClick:()=>{const a=new Blob([na],{type:"application/json"}),o=URL.createObjectURL(a),p=document.createElement("a");p.href=o,p.download=`${ta||"vendor"}.utsf.json`,p.click(),URL.revokeObjectURL(o),ie.success("UTSF file downloaded")},className:"flex-1 md:flex-none px-4 py-2 bg-white border border-blue-200 text-blue-700 rounded-lg text-sm font-medium hover:bg-blue-50 flex items-center justify-center gap-1.5",children:[n.jsx(Vl,{className:"w-4 h-4"}),"UTSF"]}),n.jsx("button",{type:"button",onClick:ko,className:"flex-1 md:flex-none px-4 py-2 bg-white border border-blue-200 text-blue-700 rounded-lg text-sm font-medium hover:bg-blue-50",children:"Clear"}),n.jsxs("button",{type:"button",onClick:()=>{Tn("existing"),Mn(!0),Kn()},className:"flex-1 md:flex-none px-6 py-2 bg-blue-600 text-white rounded-lg text-sm font-semibold hover:bg-blue-700 shadow-sm flex items-center justify-center gap-2",children:["Continue ",n.jsx(iu,{className:"w-4 h-4 -rotate-90"})]})]})]})})}),!or&&bt&&!Ai&&n.jsxs(ct.div,{id:"create-new-section",initial:{opacity:0}
131,animate:{opacity:1},transition:{delay:.2},className:"mt-4",children:[ht==="idle"&&n.jsx("div",{className:"flex flex-col items-center w-full mb-2",children:n.jsxs("div",{className:"text-slate-600 px-4 py-3 rounded-xl text-sm font-medium inline-flex items-center gap-2 max-w-lg",children:[n.jsx("span",{className:"flex-shrink-0 p-1.5",children:n.jsx(gi,{className:"w-4 h-4 text-slate-400"})}),n.jsxs("span",{className:"break-all",children:["Vendor ",n.jsxs("strong",{children:['"',gt,'"']})," is not available in our records. Please create a new vendor profile."]})]})}),ht==="idle"&&n.jsx(n.Fragment,{children:n.jsxs("div",{className:"flex flex-col sm:flex-row gap-4 max-w-xl mx-auto mt-6",children:[n.jsxs("button",{type:"button",onClick:()=>Nn("files"),className:`flex-1 group relative bg-blue-50 border-2 rounded-2xl pt-7 pb-6 px-6 text-center flex flex-col sm:flex-row items-center justify-center gap-3 overflow-hidden transition-all duration-500
132                                  ${sr==="button1"?"border-blue-500 shadow-[0_0_30px_rgba(59,130,246,0.6)] scale-105 z-10":"border-blue-100 hover:border-blue-500 hover:shadow-lg hover:-translate-y-0.5"}`,children:[n.jsx("div",{className:"absolute top-0 right-0 z-10",children:n.jsx("span",{className:"block text-[8px] font-extrabold tracking-widest text-blue-600 uppercase bg-blue-100 px-4 py-1.5 rounded-bl-2xl border-b border-l border-blue-200 shadow-sm",children:"RECOMMENDED"})}),n.jsx("div",{className:`w-8 h-8 rounded-xl flex items-center justify-center transition-all shrink-0
133                                  ${sr==="button1"?"bg-blue-600 text-white scale-110":"bg-blue-50 text-blue-600 group-hover:scale-105 group-hover:bg-blue-100"}`,children:n.jsx("span",{className:"text-base",children:"⬆️"})}),n.jsxs("div",{className:"flex flex-col items-start text-left",children:[n.jsx("h3",{className:"font-bold text-slate-800 text-lg group-hover:text-blue-700 leading-tight",children:"Upload Your Files"}),n.jsxs("ul",{className:"text-[12px] text-slate-800 font-medium mt-2 list-disc pl-4 space-y-0.5 group-hover:text-blue-700 text-left w-full",children:[n.jsx("li",{children:"Servicability Pincodes (ODA)"}),n.jsx("li",{children:"Zone Price"}),n.jsx("li",{children:"Company Information"})]}),n.jsx("p",{className:"text-[10px] text-slate-500 font-medium mt-2 group-hover:text-blue-600/70",children:"Allowed: Excel, PDF, Word, Images."})]}),n.jsx("div",{className:"absolute inset-0 bg-gradient-to-br from-blue-500/5 to-transparent opacity-0 group-hover:opacity-100 transition-opacity rounded-2xl pointer-events-none"})]}),n.jsxs("button",{type:"button",onClick:()=>{U(a=>({...a||{},priceMatrix:{},zones:[],selectedZones:[]}));try{localStorage.removeItem(dn)}catch{}yt(null),la(!1),Tn("new_without_pincodes"),M("wizard"),Mn(!0),gt.trim()&&l.setField("companyName",gt.trim()),Gt(a=>Math.min(a+1,4)),window.scrollTo({top:0,behavior:"smooth"})},className:`flex-1 group relative bg-blue-50 border-2 rounded-2xl pt-7 pb-6 px-6 text-center flex flex-col sm:flex-row items-center justify-center gap-3 overflow-hidden transition-all duration-500
134                                  ${sr==="button2"?"border-blue-500 shadow-[0_0_30px_rgba(59,130,246,0.6)] scale-105 z-10":"border-blue-100 hover:border-blue-500 hover:shadow-lg hover:-translate-y-0.5"}`,children:[n.jsx("div",{className:`w-8 h-8 rounded-xl flex items-center justify-center transition-all shrink-0
135                                  ${sr==="button2"?"bg-blue-600 text-white scale-110":"bg-slate-50 text-slate-600 group-hover:scale-105 group-hover:bg-slate-100"}`,children:n.jsx("span",{className:"text-base",children:"⬇️"})}),n.jsxs("div",{className:"flex flex-col items-start text-left w-full",children:[n.jsx("h3",{className:"font-bold text-slate-800 text-lg group-hover:text-blue-700 leading-tight",children:"Enter Manually"}),n.jsxs("ul",{className:"text-[12px] text-slate-800 font-medium mt-2 list-disc pl-4 space-y-0.5 group-hover:text-blue-700 text-left w-full",children:[n.jsx("li",{children:"Quick 3-step setup"}),n.jsx("li",{children:"Guided pricing builder"})]}),n.jsx("p",{className:"text-[10px] text-slate-500 font-medium mt
135-2 group-hover:text-blue-600/70"})]}),n.jsx("div",{className:"absolute inset-0 bg-gradient-to-br from-blue-500/5 to-transparent opacity-0 group-hover:opacity-100 transition-opacity rounded-2xl pointer-events-none"})]})]})}),(ht==="files"||ht==="generating"||ht==="error")&&n.jsxs("div",{className:"space-y-5",children:[n.jsxs("div",{className:"flex items-start gap-3",children:[n.jsx("button",{type:"button",disabled:ht!=="files",onClick:()=>{Nn("idle"),ar([])},className:"p-2 rounded-xl hover:bg-slate-100 text-slate-400 hover:text-slate-700 transition-colors shrink-0 disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-transparent",children:n.jsx(Dl,{className:"w-5 h-5"})}),n.jsxs("div",{className:"min-w-0 flex-1",children:[n.jsxs("h4",{className:"font-bold text-slate-800 text-lg break-all",children:['Upload "',gt,'" documents :']}),n.jsx("p",{className:"text-xs text-slate-500 mt-0.5",children:"Please upload your documents below."})]})]}),n.jsxs("div",{className:"bg-blue-50/50 rounded-xl p-4 border border-blue-100/50 text-left mb-4",children:[n.jsx("p",{className:"text-sm text-slate-700 font-semibold mb-2",children:"Document list :"}),n.jsxs("div",{className:"text-xs sm:text-[13px] text-slate-600 font-medium flex flex-wrap items-center gap-x-5 gap-y-2",children:[n.jsxs("span",{children:[n.jsx("span",{className:"text-blue-600 font-bold",children:"1."})," Servicability (ODA)"]}),n.jsxs("span",{children:[n.jsx("span",{className:"text-blue-600 font-bold",children:"2."})," Zone Prices"]}),n.jsxs("span",{children:[n.jsx("span",{className:"text-blue-600 font-bold",children:"3."})," Company Information"]}),n.jsxs("span",{children:[n.jsx("span",{className:"text-blue-600 font-bold",children:"4."})," Other Charges"]})]})]}),n.jsx("input",{ref:Ci,type:"file",multiple:!0,disabled:ht!=="files",accept:".xlsx,.xls,.csv,.pdf,.png,.jpg,.jpeg,.tiff,.bmp,.webp,.docx,.doc,.pptx,.ppt,.json",className:"hidden",onChange:a=>{a.target.files&&Rs(a.target.files),a.target.value=""}}),n.jsx("div",{onDragOver:a=>{ht==="files"&&(a.preventDefault(),sa(!0))},onDragLeave:()=>sa(!1),onDrop:a=>{ht==="files"&&(a.preventDefault(),sa(!1),Rs(a.dataTransfer.files))},onClick:()=>{ht==="files"&&Ci.current?.click()},className:`relative rounded-2xl border-2 border-dashed p-10 text-center transition-all
136                                ${ht!=="files"?"opacity-50 cursor-not-allowed":"cursor-pointer"}
137                                ${wi?"border-blue-500 bg-blue-50":"border-slate-200 hover:border-blue-400 hover:bg-blue-50/40"}`,children:n.jsxs("div",{className:"flex flex-col items-center gap-3",children:[n.jsx("div",{className:"w-14 h-14 bg-white rounded-2xl shadow-sm border border-slate-100 flex items-center justify-center text-blue-500",children:n.jsx(ho,{className:"w-7 h-7"})}),n.jsx("p",{className:"font-semibold text-slate-700",children:wi?"Release to add":"Click or drag files here"}),n.jsx("p",{className:"text-xs text-slate-400",children:"Excel, PDF, image, Word — anything works · Max 13.3 MB per file, 40 MB total"})]})}),rn.length>0&&n.jsx("div",{className:"space-y-2",children:rn.map(a=>n.jsxs("div",{className:"flex items-center gap-3 p-3 bg-slate-50 rounded-xl border border-slate-100",children:[n.jsx(ci,{className:"w-4 h-4 text-slate-400 shrink-0"}),n.jsx("span",{className:"text-sm text-slate-700 flex-1 truncate",children:a.file.name}),n.jsxs("select",{value:a.category,disabled:ht!=="files",onChange:o=>ar(p=>p.map(v=>v.id===a.id?{...v,category:o.target.value}:v)),className:"text-xs border border-slate-200 rounded-lg px-2 py-1 bg-white text-slate-600 focus:outline-none focus:border-blue-400 disabled:opacity-50",children:[n.jsx("option",{value:"charges",children:"Rate Card"}),n.jsx("option",{value:"zone_data",children:"Zone / Serviceability"}),n.jsx("option",{value:"company_details",children:"Company Details"})]}),n.jsx("button",{type:"button",disabled:ht!=="files",onClick:()=>ar(o=>o.filter(p=>p.id!==a.id)),className:"p-1 text-slate-400 hover:text-red-500 transition-colors disabled:opacity-40 disabled:cursor-not-allowed",children:n.jsx(Sr,{className:"w-4 h-4"})})]},a.id))}),ht==="generating"&&n.jsxs("div",{className:"space-y-3",children:[n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx(un,{className:"w-5 h-5 text-blue-500 animate-spin"}),n.jsx("h4",{className:"font-bold text-slate-800",children:"Extracting vendor data…"})]}),n.jsx(Kx,{progress:bo})]}),ht==="error"&&n.jsxs("div",{className:"space-y-3",children:[n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx(bi,{className:"w-5 h-5 text-red-500"}),n.jsx("h4",{className:"font-bold text-slate-800",children:"Generation failed"})]}),n.jsx("div",{className:"rounded-2xl border border-red-100 bg-red-50 p-5 text-sm text-red-600",children:"Something went wrong while reading your files. Please try again — if the problem continues, tr
137y uploading a clearer copy."}),n.jsx("button",{type:"button",onClick:()=>{Nn("files"),$r([])},className:"w-full py-3 rounded-xl border-2 border-slate-200 text-slate-600 font-semibold hover:bg-slate-50 transition-colors",children:"Try Again"})]}),ht==="files"&&n.jsxs("button",{ref:Ds,type:"button",disabled:rn.length===0,onClick:ki,className:"w-full py-3.5 rounded-2xl bg-blue-600 hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed text-white font-bold flex items-center justify-center gap-2 transition-colors",children:[n.jsx(xi,{className:"w-5 h-5"}),"Continue Next"]})]}),ht==="done"&&n.jsxs("div",{className:"space-y-5",children:[n.jsx("div",{className:"bg-gradient-to-br from-blue-50 to-blue-50 border border-blue-100 rounded-2xl p-6",children:n.jsxs("div",{className:"flex items-start gap-5",children:[os!==null&&n.jsxs("div",{className:"flex-shrink-0 flex flex-col items-center",children:[n.jsx("div",{className:`w-20 h-20 rounded-full border-4 flex items-center justify-center font-black text-2xl
138                                      ${os>=75?"border-blue-500 text-blue-700 bg-blue-50":os>=50?"border-amber-400 text-amber-700 bg-amber-50":"border-red-400 text-red-700 bg-red-50"}`,children:os}),n.jsx("p",{className:"text-[10px] font-bold text-slate-400 uppercase tracking-wider mt-1.5",children:"Quality"})]}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[n.jsx(ea,{className:"w-5 h-5 text-blue-600 flex-shrink-0"}),n.jsx("p",{className:"font-bold text-slate-800 text-lg",children:"Vendor profile ready!"})]}),n.jsxs("p",{className:"text-sm text-slate-500 mb-3",children:["All details have been pre-filled. Review each step and click ",n.jsx("strong",{children:"Add Vendor"}),"."]}),Ur&&n.jsxs("div",{className:"flex flex-wrap gap-2",children:[Ur.zones>0&&n.jsxs("span",{className:"inline-flex items-center gap-1 text-xs font-semibold bg-blue-100 text-blue-700 px-2.5 py-1 rounded-full",children:[n.jsx($l,{className:"w-3 h-3"}),Ur.zones," zone",Ur.zones!==1?"s":""]}),Ur.pincodes>0&&n.jsxs("span",{className:"inline-flex items-center gap-1 text-xs font-semibold bg-blue-100 text-blue-700 px-2.5 py-1 rounded-full",children:[n.jsx(ci,{className:"w-3 h-3"}),Ur.pincodes.toLocaleString()," pincodes"]}),Ur.charges.map(a=>n.jsx("span",{className:"inline-flex items-center gap-1 text-xs font-semibold bg-amber-100 text-amber-700 px-2.5 py-1 rounded-full capitalize",children:a},a))]}),os!==null&&os<50&&n.jsxs("p",{className:"text-xs text-amber-600 mt-2 flex items-center gap-1.5",children:[n.jsx(Fa,{className:"w-3.5 h-3.5"}),"Low quality — consider adding more files (rate card, pincode list) and regenerating."]})]})]})}),n.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[n.jsxs("button",{type:"button",onClick:()=>{Mn(!0),Kn()},className:"flex-1 min-w-[160px] py-3.5 rounded-2xl bg-blue-600 hover:bg-blue-700 text-white font-bold flex items-center justify-center gap-2 transition-colors shadow-lg shadow-emerald-500/20",children:[n.jsx(ea,{className:"w-5 h-5"}),"Review & Submit"]}),na&&n.jsxs("button",{type:"button",onClick:()=>{const a=new Blob([na],{type:"application/json"}),o=URL.createObjectURL(a),p=document.createElement("a");p.href=o,p.download=`${ta||"vendor"}.utsf.json`,p.click(),URL.revokeObjectURL(o)},className:"px-5 py-3 rounded-2xl border-2 border-slate-200 hover:border-blue-300 text-slate-600 hover:text-blue-700 font-semibold flex items-center gap-2 transition-colors",children:[n.jsx(Vl,{className:"w-4 h-4"}),"Download UTSF"]}),n.jsx("button",{type:"button",onClick:()=>{Nn("files"),ar([]),$r([]),Es(null),Ps(null)},className:"px-4 py-3 rounded-2xl border-2 border-slate-200 hover:border-slate-300 text-slate-500 text-sm font-medium transition-colors",children:"Add More Files"})]})]})]})]})]}),n.jsxs("div",{style:{display:Lt===3?"block":"none"},children:[n.jsx(J0,{vendorBasics:l,pincodeLookup:s,attemptedSubmit:Te}),n.jsx("div",{className:"border-t border-slate-100"}),n.jsx(Y0,{volumetric:f,transportMode:z,onTransportModeChange:a=>E(a),maxShipmentLengthFt:me,onMaxShipmentLengthFtChange:ve}),n.jsx(zl,{onBack:Os,backLabel:"Back to Pricing",onNext:Kn,nextLabel:"Next: Charges & Save"})]}),n.jsxs("div",{style:{display:Lt===4?"block":"none"},children:[n.jsxs("div",{className:"flex items-center justify-between mb-3 gap-2 flex-wrap",children:[n.jsxs("button",{type:"button",onClick:Os,className:"group flex items-center gap-1.5 text-slate-500 hover:text-slate-800 font-bold text-[11px] uppercase tracking-wider transition-all px-3 py-1.5 rounded-lg hover:bg-slate-100/80 active:scale-95",children:[n.jsx(Dl,{className:"w-3.5 h-3.5 group-hover:-translate-x-1 transition-transform"}),"Back to Company Details"]}
138),n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsxs("label",{className:"flex items-center gap-2 text-xs font-semibold text-slate-600 cursor-pointer",children:[n.jsx("input",{type:"checkbox",checked:G,onChange:a=>ue(a.target.checked),className:"rounded border-slate-300 text-rose-500 focus:ring-rose-400"}),"Mark as my preferred vendor"]}),n.jsx("button",{type:"button",onClick:Ri,disabled:le,className:"relative overflow-hidden flex items-center gap-2 px-5 py-2 rounded-lg font-bold text-xs shadow-md transition-all active:scale-95 bg-gradient-to-r from-blue-600 to-indigo-600 text-white hover:from-blue-700 hover:to-indigo-700 disabled:bg-slate-100 disabled:text-slate-300 disabled:cursor-not-allowed disabled:shadow-none",children:le?n.jsxs(n.Fragment,{children:[n.jsx(un,{className:"w-4 h-4 animate-spin"}),n.jsx("span",{children:"Processing..."})]}):n.jsxs(n.Fragment,{children:[n.jsx("span",{children:"Save Vendor"}),n.jsx(Cr,{className:"w-3.5 h-3.5"})]})})]})]}),n.jsx(ix,{charges:m,baseFreight:fe,onBaseFreightChange:a=>Ae(a),sampleWeight:re,onSampleWeightChange:a=>I(a),sampleInvoice:Ne,onSampleInvoiceChange:a=>ge(a),pricingPreview:Fo}),is&&n.jsx("div",{className:"bg-slate-50/60 border-t border-slate-200 px-6 py-4",children:n.jsxs("div",{className:"w-full",children:[n.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[n.jsx(ci,{className:"w-5 h-5 text-blue-600"}),n.jsx("h3",{className:"text-lg font-semibold text-slate-900",children:"Invoice Value Configuration"})]}),n.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[n.jsxs("div",{children:[n.jsx("label",{className:"block text-sm font-medium text-slate-700 mb-1",children:"Invoice Value Percentage (%)"}),n.jsxs("div",{className:"relative",children:[n.jsx("input",{type:"text",inputMode:"numeric",value:mt,onChange:a=>{const o=a.target.value.replace(/[^0-9.]/g,"");(o.match(/\./g)||[]).length<=1&&(Ke(o),nr(!0))},placeholder:"0.00",className:"w-full rounded-lg border-slate-300 focus:border-blue-500 focus:ring-blue-500 pl-3 pr-8"}),n.jsx("div",{className:"absolute inset-y-0 right-0 pr-3 flex items-center pointer-events-none",children:n.jsx("span",{className:"text-slate-400 text-sm",children:"%"})})]}),n.jsx("p",{className:"text-xs text-slate-500 mt-1",children:"Numeric values only."})]}),n.jsxs("div",{children:[n.jsx("label",{className:"block text-sm font-medium text-slate-700 mb-1",children:"Minimum Amount (₹)"}),n.jsxs("div",{className:"relative",children:[n.jsx("input",{type:"text",inputMode:"numeric",value:Mt,onChange:a=>{const o=pi(a.target.value);Ct(o),nr(!0)},placeholder:"0",className:"w-full rounded-lg border-slate-300 focus:border-blue-500 focus:ring-blue-500 pl-3 pr-8"}),n.jsx("div",{className:"absolute inset-y-0 right-0 pr-3 flex items-center pointer-events-none",children:n.jsx("span",{className:"text-slate-400 text-sm",children:"₹"})})]}),n.jsx("p",{className:"text-xs text-slate-500 mt-1",children:"Numeric values only."})]})]}),n.jsxs("div",{className:"mt-6 flex flex-col md:flex-row md:items-center justify-between gap-4 p-4 bg-white rounded-xl border border-slate-200 shadow-sm",children:[n.jsxs("div",{className:"flex-1",children:[n.jsx("span",{className:"text-sm font-semibold text-slate-900",children:"Calculation Method"}),n.jsx("p",{className:"text-xs text-slate-500 mt-1",children:"Use the maximum of the percentage value and the minimum amount?"})]}),n.jsxs("div",{className:"flex items-center gap-1 bg-slate-100 p-1.5 rounded-lg border border-slate-200",children:[n.jsx("button",{type:"button",onClick:()=>Fn(!0),className:`px-4 py-1.5 text-sm font-medium rounded-md transition-all shadow-sm ${Bt?"bg-white text-blue-600 ring-1 ring-black/5":"bg-transparent text-slate-500 hover:text-slate-700 shadow-none"}`,children:"Yes, Use Max"}),n.jsx("button",{type:"button",onClick:()=>Fn(!1),className:`px-4 py-1.5 text-sm font-medium rounded-md transition-all shadow-sm ${Bt?"bg-transparent text-slate-500 hover:text-slate-700 shadow-none":"bg-white text-slate-900 ring-1 ring-black/5"}`,children:"No"})]})]})]})})]}),n.jsx("div",{style:{display:Lt===2?"block":"none"},children:n.jsxs(ct.div,{initial:{opacity:0,y:10}
138,animate:{opacity:1,y:0},className:"w-full mx-auto",children:[Zt!=="existing"&&n.jsx("div",{className:"flex flex-col items-center mb-2",children:n.jsx("div",{className:"bg-slate-100 p-1 rounded-xl flex items-center shadow-inner",children:[{id:"pincode",label:"Pincode Upload",icon:po},{id:"wizard",label:"Manual Setup",icon:$l}].map(a=>{const o=B===a.id,p=a.icon;return n.jsxs("button",{type:"button",onClick:()=>M(a.id),className:`relative px-5 py-2.5 text-sm font-semibold rounded-lg transition-all flex items-center gap-2 ${o?"bg-white text-green-700 shadow-sm ring-1 ring-black/5":"text-slate-500 hover:text-slate-700"}`,children:[o&&n.jsx(ct.div,{layoutId:"activeTab",className:"absolute inset-0 bg-white rounded-lg shadow-sm ring-1 ring-black/5",initial:!1,transition:{type:"spring",stiffness:500,damping:30}}),n.jsxs("span",{className:"relative z-10 flex items-center gap-2",children:[n.jsx(p,{className:"w-4 h-4"}),a.label]})]},a.id)})})}),n.jsxs("div",{className:"min-h-[400px]",children:[n.jsxs(Nr,{mode:"wait",children:[Zt==="existing"&&Wr==="upload"&&n.jsxs(ct.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},exit:{opacity:0,y:-10},className:"space-y-6 max-w-5xl mx-auto py-6",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{children:[n.jsxs("h3",{className:"text-xl font-bold text-slate-900 flex items-center gap-2",children:[n.jsx(po,{className:"w-6 h-6 text-blue-600"}),"Upload Rate Card"]}),n.jsx("p",{className:"text-sm text-slate-500 mt-0.5",children:"Upload your pricing matrix or list. We'll automatically map zones and fill the grid."})]}),n.jsxs("button",{type:"button",onClick:()=>Vn("selection"),className:"inline-flex items-center gap-2 px-4 py-2 text-sm font-semibold text-slate-600 hover:text-slate-900 bg-slate-100 hover:bg-slate-200 rounded-xl transition-all",children:[n.jsx(Dl,{className:"w-4 h-4"})," Back to Choice"]})]}),n.jsxs("div",{onDragOver:a=>{a.preventDefault(),_s(!0)},onDragLeave:a=>{a.preventDefault(),_s(!1)},onDrop:async a=>{a.preventDefault(),_s(!1);const o=Array.from(a.dataTransfer.files).filter(Boolean);if(!o.length)return;const p=o.reduce((v,T)=>v+T.size,0);if(p>10*1024*1024){ie.error(`Total size ${(p/1024/1024).toFixed(1)} MB exceeds the 10 MB limit`);return}for(let v=0;v<o.length;v++)await oa(o[v],v>0)},onClick:()=>document.getElementById("pricing-upload-input")?.click(),className:`
139                                relative rounded-2xl border-2 border-dashed p-12 text-center transition-all cursor-pointer
140                                ${Wn?"border-blue-500 bg-blue-50":"border-slate-300 bg-slate-50 hover:border-blue-400 hover:bg-blue-50/50"}
141                              `,children:[n.jsx("input",{id:"pricing-upload-input",type:"file",accept:".xlsx,.xls,.csv,.pdf,.png,.jpg,.jpeg,.docx,.doc",multiple:!0,className:"hidden",onChange:async a=>{const o=Array.from(a.target.files||[]);if(!o.length)return;const p=o.reduce((v,T)=>v+T.size,0);if(p>10*1024*1024){ie.error(`Total size ${(p/1024/1024).toFixed(1)} MB exceeds the 10 MB limit`),a.target.value="";return}for(let v=0;v<o.length;v++)await oa(o[v],v>0);a.target.value=""}}),n.jsxs("div",{className:"flex flex-col items-center gap-3",children:[n.jsx("div",{className:"w-16 h-16 bg-white rounded-2xl shadow-sm border border-slate-200 flex items-center justify-center text-blue-600 group-hover:scale-110 transition-transform",children:kr?n.jsx(un,{className:"w-8 h-8 animate-spin"}):n.jsx(ho,{className:"w-8 h-8"})}),n.jsxs("div",{children:[n.jsx("p",{className:"font-bold text-slate-700",children:kr?"Extracting zone rates…":Wn?"Drop file here":"Click or drag your rate card here"}),n.jsx("p",{className:"text-sm text-slate-500 mt-1",children:"Excel, CSV, PDF, images — AI extracts zone rates automatically"})]})]})]}),n.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[n.jsxs("div",{className:"flex items-start gap-4 p-5 rounded-2xl bg-blue-50 border border-blue-100 shadow-sm",children:[n.jsx("div",{className:"p-2 bg-white rounded-lg shadow-sm",children:n.jsx(du,{className:"w-5 h-5 text-blue-600"})}),n.jsxs("div",{className:"text-sm text-blue-900",children:[n.jsx("p",{className:"font-bold mb-2 underline decoration-blue-200 underline-offset-4",children:"How it works:"}),n.jsxs("ul",{className:"space-y-2 text-blue-800/80 font-medium",children:[n.jsxs("li",{className:"flex gap-2",children:[n.jsx("span",{className:"text-blue-400",children:"•"}),n.jsxs("span",{children:[n.jsx("strong",{children:"Excel/CSV:"})," Upload a grid with zone codes as rows/columns — parsed instantly."]})]}),n.jsxs("li",{className:"flex gap-2",children:[n.jsx("span",{className:"text-blue-400",children:"•"}),n.jsxs("span",{children:[n.jsx("strong",{children:"PDF / Image / Word:"})," Scanned rate cards, screenshots — AI reads and maps rates automatically."]})]}),n.jsxs("li",{className:"flex gap-2",children:[n.jsx("span",{className:"text-blue-400",children:"•"}),n.jsxs("span",{children:[n.jsx("strong",{children:"Smart Mapping:"})," City names (e.g. Mumbai) are auto-mapped to standard zones."]})]})]})]})]}),n.jsxs("div",{className:"p-5 rounded-2xl bg-gradient-to-br from-slate-50 to-blue-50 border border-blue-100 shadow-sm",children:[n.jsxs("p",{className:"text-xs font-bold text-emerald-800 mb
141-3 flex items-center gap-1.5 uppercase tracking-wider",children:[n.jsx(O0,{className:"w-4 h-4"}),"Sample Matrix Format"]}),n.jsx("div",{className:"bg-white rounded-xl border border-blue-100 overflow-hidden shadow-md",children:n.jsxs("table",{className:"w-full text-[10px]",children:[n.jsx("thead",{className:"bg-slate-100 border-b border-slate-200",children:n.jsxs("tr",{children:[n.jsx("th",{className:"px-3 py-2 text-left font-bold text-slate-500 border-r border-slate-200",children:"To →"}),n.jsx("th",{className:"px-3 py-2 text-center font-bold text-blue-600",children:"N1"}),n.jsx("th",{className:"px-3 py-2 text-center font-bold text-blue-600",children:"W1"}),n.jsx("th",{className:"px-3 py-2 text-center font-bold text-blue-600",children:"S1"})]})}),n.jsxs("tbody",{className:"divide-y divide-slate-100",children:[n.jsxs("tr",{className:"hover:bg-slate-50",children:[n.jsx("td",{className:"px-3 py-2 font-bold text-blue-600 bg-slate-50 border-r border-slate-200",children:"N1"}),n.jsx("td",{className:"px-3 py-2 text-center text-slate-400",children:"4.5"}),n.jsx("td",{className:"px-3 py-2 text-center text-slate-400",children:"6.2"}),n.jsx("td",{className:"px-3 py-2 text-center text-slate-400",children:"8.1"})]}),n.jsxs("tr",{className:"hover:bg-slate-50",children:[n.jsx("td",{className:"px-3 py-2 font-bold text-blue-600 bg-slate-50 border-r border-slate-200",children:"W1"}),n.jsx("td",{className:"px-3 py-2 text-center text-slate-400",children:"6.5"}),n.jsx("td",{className:"px-3 py-2 text-center text-slate-400",children:"4.5"}),n.jsx("td",{className:"px-3 py-2 text-center text-slate-400",children:"7.8"})]})]})]})}),n.jsxs("div",{className:"mt-3 flex justify-between items-center",children:[n.jsx("p",{className:"text-[10px] text-slate-400 font-medium italic",children:"* Grid values will be imported as base rates"}),n.jsx("button",{type:"button",onClick:()=>ie.info("Opening matrix to download template..."),className:"text-[10px] text-blue-600 font-bold hover:underline",children:"Download Full Template →"})]})]})]})]},"existing-upload"),Zt==="existing"&&Wr==="selection"&&n.jsxs(ct.div,{initial:{opacity:0,scale:.98},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.98},className:"max-w-4xl mx-auto",children:[n.jsx("input",{id:"selection-price-upload",type:"file",accept:".xlsx,.xls,.csv,.pdf,.png,.jpg,.jpeg,.docx,.doc",multiple:!0,className:"hidden",onChange:async a=>{const o=Array.from(a.target.files||[]);if(!o.length)return;const p=o.reduce((v,T)=>v+T.size,0);if(p>10*1024*1024){ie.error(`Total size ${(p/1024/1024).toFixed(1)} MB exceeds the 10 MB limit`),a.target.value="";return}for(let v=0;v<o.length;v++)await oa(o[v],v>0);a.target.value=""}}),n.jsxs("div",{className:"text-center mb-6",children:[n.jsx("h4",{className:"text-2xl font-bold text-slate-800 mb-3",children:"How would you like to enter prices?"}),n.jsxs("p",{className:"text-slate-500",children:["Configure rates for ",n.jsx("span",{className:"font-semibold text-slate-700",children:Wa}),"."]})]}),n.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-5",children:[n.jsxs("button",{type:"button",disabled:kr,onClick:()=>document.getElementById("selection-price-upload")?.click(),className:"group relative bg-white border-2 border-slate-100 hover:border-blue-500 disabled:opacity-60 disabled:cursor-wait rounded-2xl p-5 text-left transition-all hover:shadow-xl hover:-translate-y-1 flex flex-col h-full overflow-hidden",children:[n.jsx("div",{className:"absolute top-4 right-4 text-slate-200 group-hover:text-blue-500 transition-colors",children:kr?n.jsx(un,{className:"w-6 h-6 animate-spin text-blue-500"}):n.jsx(ea,{className:"w-6 h-6"})}),n.jsx("div",{className:"w-12 h-12 bg-blue-50 text-blue-600 rounded-xl flex items-center justify-center mb-4 group-hover:scale-110 group-hover:bg-blue-100 transition-all duration-300",children:kr?n.jsx(un,{className:"w-6 h-6 animate-spin"}):n.jsx(ho,{className:"w-6 h-6"})}),n.jsx("h3",{className:"font-bold text-slate-800 text-base mb-2 group-hover:text-blue-700",children:kr?"Extracting rates…":"Upload Price Sheet"}),n.jsx("p",{className:"text-xs text-slate-500 leading-relaxed mb-4 flex-1",children:kr?"Reading your file and mapping zone rates. This takes a few seconds.":"Excel, CSV, PDF, image, Word — drop any rate card here. We'll auto-extract all zone rates and fill the matrix."}),n.jsxs("div",{className:"mt-auto inline-flex items-center gap-2 text-blue-600 font-bold text-sm uppercase tracking-wider group-hover:translate-x-2 transition-transform",children:[kr?"Processing…":"Choose File"," ",n.jsx(Cr,{className:"w-4 h-4"})]}),n.jsx("div",{className:"absolute inset-0 bg-gradient-to-br from-blue-500/5 to-transparent opacity-0 group-hover:opacity-100 transition-opacity rounded-3xl"})]}),n.jsxs("button",{type:"button",onClick:()=>Vn("manual"),className:"group relative bg-white border-2 border-slate-100 hover:border-blue-500 rounded-2xl p-5 text-left transition-all hover:shadow-xl hover:-translate-y-1 flex flex-col h-full",children:[n.jsx("div",{className:"absolute top-4 right-4 text-slate-200 group-hover:text-blue-500 transition-colors",children:n.jsx(Cr,{className:"w-6 h-6"})}),n.jsx("div",{className:"w-12 h-12 bg-blue-50 text-blue-600 rounded-xl flex items-center justify-center mb-4 group-hover:scale-110 group-hover:bg-blue-100 transition-all duration-300",children:n.jsx(ci,{className:"w-6 h-6"})}),n.jsx("h3",{className:"font-bold text-slate-800 text-base mb-2 group-hover:text-blue-700",children:"Manual Price Entry"}),n.jsx("p",{className:"text-xs text-slate-500 leading-relaxed mb-4 flex-1",children:"Prefer to type them in? Open the interactive grid and enter rates for each zone combination manually."}),n.jsxs("div",{className:"mt-auto inline-flex items-center gap-2 text-blue-600 font-bold text-sm uppercase tracking-wider group-hover:translate-x-2 transition-transform",children:["Open Matrix ",n.jsx(Cr,{className:"w-4 h-4"})]}),n.jsx("div",{className:"absolute inset-0 bg-gradient-to-br from-blue-500/5 to-transparent opacity-0 group-hover:opacity-100 transition-opacity rounded-3xl"})]})]}),n.jsxs("div",{className:"mt-4 p-4 bg-slate-50 border border-slate-200 rounded-xl flex items-start gap-3",children:[n.jsx("div",{className:"p-2.5 bg-white rounded-xl shadow-sm shrink-0 mt-0.5",children:n.jsx(xi,{className:"w-5 h-5 text-amber-500"})}),n.jsxs("div",{children:[n.jsx("p",{className:"text-sm font-semibold text-slate-800",children:"Any format works"}),n.jsx("p",{className:"text-xs text-slate-500 mt-1 leading-relaxed",children:"Excel/CSV is parsed instantly on your device. PDFs, images, and Word docs are sent to our AI extraction engine. Either way, zone rates auto-fill the matrix — you just review and confirm."})]})]})]},"existing-choice"),B==="pincode"&&n.jsxs(ct.div,{initial:{opacity:0,x:-10}
141,animate:{opacity:1,x:0},exit:{opacity:0,x:10},className:"space-y-6",children:[R?n.jsx("div",{className:"rounded-xl border-2 border-green-200 bg-green-50 p-5",children:n.jsxs("div",{className:"flex items-start gap-3",children:[n.jsx(ea,{className:"w-5 h-5 text-green-600 mt-0.5 flex-shrink-0"}),n.jsxs("div",{className:"flex-1",children:[n.jsxs("p",{className:"text-sm font-semibold text-green-800",children:["Serviceability loaded from UTSF — ",R.totalPincodes.toLocaleString()," pincodes across ",R.zonesServed," zones"]}),n.jsxs("p",{className:"text-xs text-green-700 mt-1",children:["Source: ",n.jsx("strong",{children:R.utsfName})," — no re-upload needed. You can still upload a new file below to override."]}),n.jsx("button",{type:"button",onClick:()=>N(null),className:"mt-2 text-xs text-green-600 underline hover:text-green-800",children:"Upload different file"})]})]})}):n.jsx(px,{onServiceabilityReady:ga,onError:a=>console.error(a),onDocumentFile:ps,onFileCaptured:a=>Y(o=>[...o,{file:a,category:"zone_data"}])}),H&&H.serviceability.length>0&&n.jsxs(ct.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:"p-4 border-2 border-green-100 bg-green-50/50 rounded-xl flex items-center justify-between",children:[n.jsxs("div",{children:[n.jsxs("p",{className:"font-bold text-green-800 flex items-center gap-2",children:[n.jsx(wr,{className:"w-5 h-5"}),H.serviceability.length," Pincodes Processed"]}),n.jsxs("p",{className:"text-sm text-green-600 pl-7",children:["Mapped to ",H.zoneSummary.length," zones"]})]}),n.jsx("button",{type:"button",onClick:Kn,className:"px-4 py-2 bg-green-600 text-white rounded-lg font-semibold hover:bg-green-700 shadow-sm",children:"Save & Continue"})]}),n.jsx("button",{type:"button",onClick:()=>Pt("/zone-price-matrix"),className:"ml-1 underline hover:no-underline",children:"Open wizard to fill prices →"})]},"pincode"),B==="wizard"&&n.jsx(ct.div,{initial:{opacity:0,x:10},animate:{opacity:1,x:0},exit:{opacity:0,x:-10},className:"space-y-6",children:n.jsx(ox,{onComplete:Eo,initialSelectedPincodes:(g?.serviceability||[]).map(a=>String(a.pincode))})},"wizard"),B==="matrix"&&(Zt!=="existing"||Wr==="manual")&&n.jsxs(ct.div,{initial:{opacity:0,x:10},animate:{opacity:1,x:0},exit:{opacity:0,x:-10},className:"space-y-6 flex flex-col h-full",children:[n.jsx("div",{className:"mb-2 pb-2 border-b border-slate-100",children:n.jsx(zl,{onBack:Zt==="existing"?()=>Vn("selection"):Os,backLabel:Zt==="existing"?"Back":"Back to Search",onNext:Kn,nextLabel:"Next: Company Details",isNextDisabled:!Ie?.hasPriceMatrix&&!H&&(Zt!=="existing"||Wr==="selection")})}),n.jsx(j0,{wizardData:g,importedSparse:yo,onFileCaptured:a=>Y(o=>[...o,{file:a,category:"zone_data"}]),onUpdatePriceMatrix:a=>{typeof U=="function"&&U(o=>({...o||{},priceMatrix:typeof a=="function"?a(o?.priceMatrix||{}):a}))},onUpdateZones:a=>{typeof U=="function"&&U(o=>{if((o?.zones||[]).length>0)return o;const v=a.map(P=>({zoneCode:P,zoneName:P})),T={zones:a,priceMatrix:o?.priceMatrix||{},timestamp:new Date().toISOString()};return localStorage.setItem(dn,JSON.stringify(T)),yt(T),{...o||{},zones:v,selectedZones:v}})},onBack:Zt==="new_without_pincodes"?()=>{fn(!1),M("wizard")}:Zt==="existing"?()=>Vn("selection"):void 0,onSave:()=>{Kn(),ie.success("Price matrix saved! Proceeding to Company Details.")}})]},"matrix")]}),!(B==="matrix"&&(Zt!=="existing"||Wr==="manual"))&&n.jsx("div",{className:"mt-4 pt-4 border-t border-slate-100",children:n.jsx(zl,{onBack:Os,backLabel:"Back to Search",onNext:Kn,nextLabel:"Next: Company Details",isNextDisabled:!Ie?.hasPriceMatrix&&!H&&(Zt!=="existing"||Wr==="selection")})})]})]})})," "]})})," "]})," ",n.jsx("div",{className:"w-full lg:w-[280px] lg:shrink-0 z-20 relative",children:n.jsx(_0,{currentStep:Lt,vendorName:pn.vendorName,vendorCode:pn.vendorCode,transportMode:pn.transportMode,serviceMode:pn.serviceMode,zonesCount:xa.rows,pincodeCount:pn.pincodeCount,matrixSize:xa,hasCompanyInfo:pn.hasCompanyInfo,hasContactInfo:pn.hasContactInfo,hasGST:pn.hasGST,hasCharges:pn.hasCharges,hasPricing:!!(Ie?.hasPriceMatrix||(H?.serviceability?.length??0)>0),fieldProgressPct:Po,isAutoFilled:or,autoFilledFrom:Wa,vendorMode:Zt,warnings:Do,isActive:_o,onReset:Ii,onSaveDraft:()=>fs(),isSavingDraft:vt,currentDraftId:hn,loadingDrafts:Ka,showDrafts:mn,setShowDrafts:Kr,availableDrafts:qt,loadDraftIntoForm:Za,fetchAvailableDrafts:fa,onDeleteDraft:ha,onStepClick:Gt})})]})," "]})," ",Un&&n.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-slate-900/70 backdrop-blur-sm",children:n.jsxs("div",{className:"bg-white rounded-2xl px-10 py-8 shadow-2xl flex flex-col items-center gap-4 max-w-sm w-[90%] relative",children:[n.jsx("button",{type:"button",onClick:()=>Ye(!1),className:"absolute top-4 right-4 text-slate-400 hover:text-slate-600 transition-colors",children:n.jsx(Sr,{size:20})}),qe==="loading"?n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"w-16 h-16 rounded-full border-4 border-slate-200 border-t-blue-600 animate-spin"}),n.jsx("p",{className:"text-sm text-slate-700 font-medium",children:"Creating vendor, please wait…"})]}):St==="draft"?sn.length>0?n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"w-16 h-16 rounded-full bg-amber-100 flex items-center justify-center",children:n.jsx(wr,{className:"w-10 h-10 text-amber-600"})}),n.jsxs("p",{className:"text-sm text-slate-800 font-semibold",children:["Saved. ",sn.length," more vendor",sn.length!==1?"s":""," in your basket."]}),n.jsx("p",{className:"text-xs text-slate-500 text-center",children:"Add details now, or come back anytime — they're kept as drafts."}),n.jsxs("div",{className:"flex gap-2 mt-2",children:[n.jsx("button",{type:"button",onClick:()=>{Ye(!1),Gt(1),He(Date.now()),Dr.current=!1,pa()},className:"mt-1 px-4 py-2 rounded-lg bg-amber-500 text-white text-sm font-medium hover:bg-amber-600",children:"Add next vendor"}),n.jsx("button",{type:"button",onClick:()=>{Ye(!1),Pt("/my-vendors")},className:"mt-1 px-4 py-2 rounded-lg bg-white border border-slate-200 text-sm font-medium hover:bg-slate-50",children:"Finish later"})]})]}):n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"w-16 h-16 rounded-full bg-amber-100 flex items-center justify-center",children:n.jsx(wr,{className:"w-10 h-10 text-amber-600"})}),n.jsx("p",{className:"text-sm text-slate-800 font-semibold",children:"Draft saved successfully!"}),n.jsx("p",{className:"text-xs text-slate-500",children:"Your draft has been saved. You can restore it later."}),n.jsx("button",{type:"button",onClick:()=>{Ye(!1),Gt(1),He(Date.now())},className:"mt-2 px-5 py-2 rounded-lg bg-amber-500 text-white text-sm font-medium hover:bg-amber-600",children:"Continue Editing"})]}):sn.length>0?n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"w-16 h-16 rounded-full bg-green-100 flex items-center justify-center",children:n.jsx(wr,{className:"w-10 h-10 text-green-600"})}),n.jsxs("p",{className:"text-sm text-slate-800 font-semibold",children:["Vendor added! ",sn.length," more in y
141our basket."]}),n.jsx("p",{className:"text-xs text-slate-500 text-center",children:"Add details now, or come back anytime — they're kept as drafts."}),n.jsxs("div",{className:"flex gap-2 mt-2",children:[n.jsx("button",{type:"button",onClick:()=>{Ye(!1),Gt(1),He(Date.now()),Dr.current=!1,pa()},className:"mt-1 px-4 py-2 rounded-lg bg-blue-600 text-white text-sm font-medium hover:bg-blue-700",children:"Add next vendor"}),n.jsx("button",{type:"button",onClick:()=>{Ye(!1),Pt("/my-vendors")},className:"mt-1 px-4 py-2 rounded-lg bg-white border border-slate-200 text-sm font-medium hover:bg-slate-50",children:"Finish later"})]})]}):n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"w-16 h-16 rounded-full bg-green-100 flex items-center justify-center",children:n.jsx(wr,{className:"w-10 h-10 text-green-600"})}),n.jsx("p",{className:"text-sm text-slate-800 font-semibold",children:"Vendor added successfully!"}),n.jsx("p",{className:"text-xs text-slate-500",children:"Add another vendor?"}),n.jsxs("div",{className:"flex gap-2 mt-2",children:[n.jsx("button",{type:"button",onClick:()=>{Ye(!1),Gt(1),He(Date.now()),Dr.current=!1},className:"mt-1 px-4 py-2 rounded-lg bg-blue-600 text-white text-sm font-medium hover:bg-blue-700",children:"Add another vendor"}),_r.get("onboarding")==="1"?n.jsx("button",{type:"button",onClick:()=>{Ye(!1),Pt("/compare")},className:"mt-1 px-4 py-2 rounded-lg bg-blue-600 text-white text-sm font-medium hover:bg-blue-700",children:"See Your Rates →"}):n.jsx("button",{type:"button",onClick:()=>{Ye(!1),Pt("/my-vendors")},className:"mt-1 px-4 py-2 rounded-lg bg-white border border-slate-200 text-sm font-medium hover:bg-slate-50",children:"Go to Vendor list"})]})]})]})}),n.jsx(lx,{logs:It}),n.jsx(gx,{targetRef:yn,when:ut,offset:80}),n.jsx(Nr,{children:mn&&n.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-slate-900/60 backdrop-blur-sm p-4",onClick:()=>Kr(!1),children:n.jsx(ct.div,{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.95},onClick:a=>a.stopPropagation(),className:"max-w-md w-full",children:n.jsx(xx,{drafts:qt,loading:Ka,onClose:()=>Kr(!1),onContinue:Za,onDelete:ha})})})}),n.jsx(Nr,{children:Nt&&n.jsx(Zx,{isOpen:Nt,onClose:()=>nn(!1),onGoToStep:Ms,errors:Et})}),n.jsx(Nr,{children:vo&&n.jsx(ct.div,{initial:{opacity:0}
141,animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 z-50 flex items-center justify-center bg-slate-900/60 backdrop-blur-sm p-4",children:n.jsxs(ct.div,{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.95},className:"bg-white rounded-2xl shadow-2xl max-w-lg w-full overflow-hidden flex flex-col max-h-[85vh]",children:[n.jsxs("div",{className:"bg-blue-50 p-6 border-b border-blue-100 flex items-center gap-4",children:[n.jsx("div",{className:"p-3 bg-blue-100 rounded-full text-blue-600",children:n.jsx(Fa,{className:"w-6 h-6"})}),n.jsxs("div",{children:[n.jsxs("h3",{className:"text-xl font-bold text-blue-900",children:[aa.filter(a=>a.required).length," required field",aa.filter(a=>a.required).length===1?"":"s"," couldn't be auto-filled."]}),n.jsx("p",{className:"text-blue-700 text-sm mt-1",children:"Please fill in the missing required information below."})]})]}),n.jsx("div",{className:"p-6 overflow-y-auto flex-1 space-y-4",children:aa.map(a=>{const o=Ia[a.id]||"",p=ji[a.id],v=!!p,T=v?"border-red-400 focus:ring-red-400":"border-slate-200 focus:ring-blue-500",P=C=>{Fs(D=>({...D,[a.id]:C})),ji[a.id]&&Ts(D=>{const S={...D};return delete S[a.id],S})};return a.type==="select"?n.jsxs("div",{className:"space-y-1",children:[n.jsxs("label",{className:"text-xs font-semibold text-slate-700 uppercase tracking-wide",children:[a.label,a.required&&n.jsx("span",{className:"text-red-500 ml-1",children:"*"})]}),n.jsxs("select",{value:o,onChange:C=>P(C.target.value),className:`w-full px-3 py-2 rounded-lg border bg-white text-sm text-slate-800 focus:outline-none focus:ring-2 ${T}`,children:[n.jsx("option",{value:"",children:"Select…"}),(a.options||[]).map(C=>n.jsx("option",{value:C,children:C},C))]}),v&&n.jsx("p",{className:"text-xs text-red-600 font-medium",children:p}),!v&&a.helper&&n.jsx("p",{className:"text-xs text-slate-500",children:a.helper})]},a.id):a.type==="pincode"?n.jsxs("div",{className:"space-y-1",children:[n.jsxs("label",{className:"text-xs font-semibold text-slate-700 uppercase tracking-wide",children:[a.label,a.required&&n.jsx("span",{className:"text-red-500 ml-1",children:"*"})]}),n.jsx("input",{type:"text",inputMode:"numeric",maxLength:6,value:o,placeholder:a.placeholder||"6-digit pincode",onChange:C=>{const D=C.target.value.replace(/\D/g,"").slice(0,6);P(D),D.length===6&&s.setPincode(D)},className:`w-full px-3 py-2 rounded-lg border bg-white text-sm text-slate-800 focus:outline-none focus:ring-2 ${T}`}),v&&n.jsx("p",{className:"text-xs text-red-600 font-medium",children:p}),!v&&o.length===6&&s.geo.pincode===o&&(s.loading?n.jsxs("p",{className:"text-xs text-slate-500 flex items-center gap-1",children:[n.jsx(un,{className:"w-3 h-3 animate-spin"})," Resolving…"]}):s.geo.state&&s.geo.city?n.jsxs("p",{className:"text-xs text-blue-700",children:[n.jsx(wr,{className:"w-3 h-3 inline mr-1"}),s.geo.city,", ",s.geo.state]}):s.error?n.jsx("p",{className:"text-xs text-red-600",children:s.error}):null),!v&&a.helper&&o.length<6&&n.jsx("p",{className:"text-xs text-slate-500",children:a.helper})]},a.id):n.jsxs("div",{className:"space-y-1",children:[n.jsxs("label",{className:"text-xs font-semibold text-slate-700 uppercase tracking-wide",children:[a.label,a.required&&n.jsx("span",{className:"text-red-500 ml-1",children:"*"})]}),n.jsx("input",{type:a.type,value:o,placeholder:a.placeholder,onChange:C=>{let D=C.target.value;a.type==="tel"&&(D=D.replace(/\D/g,"").slice(0,10)),P(D)},className:`w-full px-3 py-2 rounded-lg border bg-white text-sm text-slate-800 focus:outline-none focus:ring-2 ${T}`}),v&&n.jsx("p",{className:"text-xs text-red-600 font-medium",children:p}),!v&&a.helper&&n.jsx("p",{className:"text-xs text-slate-500",children:a.helper})]},a.id)})}),n.jsxs("div",{className:"p-4 bg-slate-50 border-t border-slate-100 flex justify-end gap-2",children:[n.jsx("button",{type:"button",onClick:j,disabled:Ma,className:"px-4 py-2 bg-transparent text-slate-500 hover:text-slate-700 hover:underline font-medium rounded-lg transition-colors disabled:opacity-50",children:"Fill Later"}),n.jsxs("button",{type:"button",onClick:bs,disabled:Ma,className:"px-5 py-2 bg-blue-600 hover:bg-blue-700 text-white font-semibold rounded-lg transition-colors disabled:opacity-50 flex items-center gap-2",children:[Ma&&n.jsx(un,{className:"w-4 h-4 animate-spin"}),"Save & Continue"]})]})]})})}),n.jsx(Nr,{children:jo&&n.jsx(ct.div,{initial:{opacity:0}
141,animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 z-50 flex items-center justify-center bg-slate-900/60 backdrop-blur-sm p-4",onClick:a=>{a.target===a.currentTarget&&(mr(!1),on.current=null,Qt.current=!1)},children:n.jsxs(ct.div,{initial:{opacity:0,scale:.95,y:10},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95},className:"bg-white rounded-2xl shadow-2xl max-w-sm w-full overflow-hidden",children:[n.jsxs("div",{className:"bg-amber-50 p-5 border-b border-amber-100 flex items-center gap-3",children:[n.jsx("div",{className:"p-2 bg-amber-100 rounded-full",children:n.jsx(Kl,{className:"w-5 h-5 text-amber-600"})}),n.jsxs("div",{children:[n.jsx("h3",{className:"text-base font-bold text-amber-900",children:"Save Draft"}),n.jsx("p",{className:"text-sm text-amber-700 mt-0.5",children:"Enter a company name to save this draft."})]})]}),n.jsxs("div",{className:"p-5 space-y-4",children:[n.jsxs("div",{children:[n.jsxs("label",{className:"block text-sm font-medium text-slate-700 mb-1.5",children:["Company Name ",n.jsx("span",{className:"text-red-500",children:"*"})]}),n.jsx("input",{type:"text",autoFocus:!0,value:Us,onChange:a=>Ga(a.target.value),onKeyDown:a=>{a.key==="Enter"&&Us.trim()&&(mr(!1),fs(Us.trim()).then(o=>{if(o){const p=on.current;p&&(on.current=null,Qt.current=!0,Pt(p==="back"?-1:p))}})),a.key==="Escape"&&(mr(!1),on.current=null,Qt.current=!1)},placeholder:"e.g. ShipMove North",className:"w-full rounded-lg border border-slate-300 px-3 py-2.5 text-sm focus:border-amber-400 focus:ring-amber-400 focus:outline-none focus:ring-2"})]}),n.jsxs("div",{className:"flex gap-2 justify-end pt-1",children:[n.jsx("button",{type:"button",onClick:()=>{mr(!1),on.current=null,Qt.current=!1},className:"px-4 py-2 text-sm font-medium text-slate-600 hover:text-slate-800 rounded-lg hover:bg-slate-100 transition-colors",children:"Cancel"}),n.jsx("button",{type:"button",disabled:!Us.trim(),onClick:async()=>{if(mr(!1),await fs(Us.trim())){const o=on.current;o&&(on.current=null,Qt.current=!0,Pt(o==="back"?-1:o))}},className:"px-4 py-2 text-sm font-bold text-white bg-amber-500 hover:bg-amber-600 rounded-lg transition-colors disabled:opacity-40 disabled:cursor-not-allowed",children:"Save Draft"})]})]})]})})}),n.jsx(bx,{open:V,isSavingDraft:vt,onSaveDraft:async()=>{if(!(l.basics.companyName||gt||"").trim()){he(!1),Ga(""),mr(!0);return}if(he(!1),await fs()){const p=on.current;on.current=null,Qt.current=!0,Pt(p==="back"?-1:p||"/addvendor")}},onDiscard:()=>{he(!1);const a=on.current;on.current=null,Qt.current=!0,Sn(),Pt(a==="back"?-1:a||"/addvendor")},onCancel:()=>{on.current=null,Qt.current=!1,he(!1)}})]})};export{jb as AddVendor,jb as default};

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