@getcredify/credify-insurance-widget 1.1.0 → 1.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.umd.js CHANGED
@@ -30,5 +30,5 @@ Error generating stack: `+e.message+`
30
30
  *
31
31
  * This source code is licensed under the MIT license found in the
32
32
  * LICENSE file in the root directory of this source tree.
33
- */var Yf;function lm(){if(Yf)return Ba;Yf=1;var i=Symbol.for("react.transitional.element"),r=Symbol.for("react.fragment");function h(y,s,p){var E=null;if(p!==void 0&&(E=""+p),s.key!==void 0&&(E=""+s.key),"key"in s){p={};for(var A in s)A!=="key"&&(p[A]=s[A])}else p=s;return s=p.ref,{$$typeof:i,type:y,key:E,ref:s!==void 0?s:null,props:p}}return Ba.Fragment=r,Ba.jsx=h,Ba.jsxs=h,Ba}var Gf;function tm(){return Gf||(Gf=1,ci.exports=lm()),ci.exports}var g=tm();function At({id:i,label:r,hint:h,error:y,required:s,className:p,children:E}){return g.jsxs("div",{className:p,children:[g.jsxs("label",{htmlFor:i,className:"form-label",children:[r," ",s&&g.jsx("span",{className:"text-red-600",children:"*"})]}),E,h&&!y&&g.jsx("p",{id:`${i}-hint`,className:"mt-1 text-sm text-slate-500",children:h}),y&&g.jsx("p",{id:`${i}-error`,className:"mt-1 text-sm text-red-600",children:y})]})}function em({id:i,label:r,hint:h,error:y,required:s,className:p,...E}){return g.jsx(At,{id:i,label:r,hint:h,error:y,required:s,className:p,children:g.jsx("input",{id:i,className:`form-input ${y?"input-error":""}`,"aria-invalid":!!y,"aria-describedby":[h?`${i}-hint`:null,y?`${i}-error`:null].filter(Boolean).join(" ")||void 0,required:s,...E,type:"text"})})}function am({id:i,label:r,hint:h,error:y,required:s,className:p,...E}){return g.jsx(At,{id:i,label:r,hint:h,error:y,required:s,className:p,children:g.jsx("input",{id:i,type:"number",className:`form-input ${y?"input-error":""}`,"aria-invalid":!!y,"aria-describedby":[h?`${i}-hint`:null,y?`${i}-error`:null].filter(Boolean).join(" ")||void 0,required:s,...E})})}function nm({id:i,label:r,hint:h,error:y,required:s,className:p,...E}){return g.jsx(At,{id:i,label:r,hint:h,error:y,required:s,className:p,children:g.jsx("input",{id:i,type:"email",className:`form-input ${y?"input-error":""}`,inputMode:"email",autoComplete:"email",required:s,"aria-invalid":!!y,"aria-describedby":[h?`${i}-hint`:null,y?`${i}-error`:null].filter(Boolean).join(" ")||void 0,...E})})}function fi(i){const r=i.replace(/\D/g,"");if(r.length===10)return`(${r.slice(0,3)}) ${r.slice(3,6)} - ${r.slice(6)}`;if(r.length>10){const h=r.slice(0,10);return`(${h.slice(0,3)}) ${h.slice(3,6)} - ${h.slice(6)}`}return r.length>=6?`(${r.slice(0,3)}) ${r.slice(3,6)} - ${r.slice(6)}`:r.length>=3?`(${r.slice(0,3)}) ${r.slice(3)}`:r.length>0?`(${r}`:r}function si(i){return i.replace(/\D/g,"")}function um({id:i,label:r,hint:h,error:y,required:s,className:p,value:E="",onChange:A,...R}){const[C,P]=H.useState(""),D=H.useRef(null),q=H.useRef(0);H.useEffect(()=>{if(!E){P("");return}let ul=si(E);ul.length===11&&ul.startsWith("1")&&(ul=ul.slice(1));const il=ul.slice(0,10);P(fi(il))},[E]);const rl=ul=>{const il=ul.target,cl=il.value;q.current=il.selectionStart||0;const U=si(cl).slice(0,10),Z=fi(U);P(Z);const O=U.length===10?`+1${U}`:U,V={...ul,currentTarget:{...ul.currentTarget,value:O},target:{...ul.target,value:O}};A?.(V),setTimeout(()=>{if(D.current){const K=cl.slice(0,q.current),W=si(K),I=fi(W),B=Math.min(I.length,Z.length);D.current.setSelectionRange(B,B)}},0)};return g.jsx(At,{id:i,label:r,hint:h,error:y,required:s,className:p,children:g.jsxs("div",{className:`tel-input-wrapper flex items-center border rounded-lg transition-colors w-full relative ${y?"border-red-500 error":"border-[var(--accent-color)] focus-within:border-[var(--primary-color)]"}`,children:[g.jsx("label",{htmlFor:i,className:"px-3 py-3 text-slate-700 font-medium border-r border-[var(--accent-color)] bg-slate-50 flex-shrink-0 relative z-0 rounded-l-lg",children:"+1"}),g.jsx("input",{ref:D,id:i,type:"tel",className:`flex-1 px-4 py-3 border-0 rounded-r-lg outline-none bg-transparent text-[var(--text-primary)] text-base ${y?"input-error":""}`,inputMode:"tel",autoComplete:"tel",required:s,"aria-invalid":!!y,"aria-describedby":[h?`${i}-hint`:null,y?`${i}-error`:null].filter(Boolean).join(" ")||void 0,value:C,onChange:rl,...R})]})})}function im({id:i,label:r,hint:h,error:y,required:s,className:p,...E}){return g.jsx(At,{id:i,label:r,hint:h,error:y,required:s,className:p,children:g.jsx("input",{id:i,type:"url",className:`form-input ${y?"input-error":""}`,inputMode:"url",autoComplete:"url",required:s,"aria-invalid":!!y,"aria-describedby":[h?`${i}-hint`:null,y?`${i}-error`:null].filter(Boolean).join(" ")||void 0,...E})})}function cm({id:i,label:r,hint:h,error:y,required:s,className:p,...E}){return g.jsx(At,{id:i,label:r,hint:h,error:y,required:s,className:p,children:g.jsx("input",{id:i,type:"password",className:`form-input ${y?"input-error":""}`,autoComplete:"current-password",required:s,"aria-invalid":!!y,"aria-describedby":[h?`${i}-hint`:null,y?`${i}-error`:null].filter(Boolean).join(" ")||void 0,...E})})}function fm({id:i,label:r,hint:h,error:y,required:s,className:p,rows:E=4,...A}){return g.jsx(At,{id:i,label:r,hint:h,error:y,required:s,className:p,children:g.jsx("textarea",{id:i,rows:E,className:`form-input ${y?"input-error":""}`,"aria-invalid":!!y,"aria-describedby":[h?`${i}-hint`:null,y?`${i}-error`:null].filter(Boolean).join(" ")||void 0,required:s,...A})})}function sm({id:i,label:r,hint:h,error:y,required:s,className:p,...E}){return g.jsx(At,{id:i,label:r,hint:h,error:y,required:s,className:p,children:g.jsx("input",{id:i,type:"date",className:`form-input ${y?"input-error":""}`,"aria-invalid":!!y,"aria-describedby":[h?`${i}-hint`:null,y?`${i}-error`:null].filter(Boolean).join(" ")||void 0,required:s,...E})})}function Xf({id:i,label:r,className:h,...y}){return g.jsxs("label",{className:`checkbox-card ${h||""}`,htmlFor:i,children:[g.jsx("input",{id:i,type:"checkbox",className:"checkbox-input",...y}),g.jsx("span",{className:"checkbox-label",children:r})]})}function rm({name:i,value:r,checked:h,onChange:y,children:s}){return g.jsxs("label",{className:"radio-card",children:[g.jsx("input",{className:"radio-input",type:"radio",name:i,value:r,checked:h,onChange:y}),g.jsx("span",{className:"radio-label",children:s})]})}function om({legend:i,children:r,className:h,legendClassName:y}){return g.jsxs("fieldset",{className:h,children:[g.jsx("legend",{className:`mb-4 text-base font-medium ${y||""}`,style:{color:"var(--text-primary)"},children:i}),g.jsx("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2",children:r})]})}function dm({id:i,label:r,hint:h,error:y,required:s,className:p,placeholder:E,options:A,children:R,...C}){const P=[h?`${i}-hint`:null,y?`${i}-error`:null].filter(Boolean).join(" ")||void 0,D=!!R;return g.jsx(At,{id:i,label:r,hint:h,error:y,required:s,className:p,children:g.jsxs("select",{id:i,className:`form-input select-caret ${y?"input-error":""}`,"aria-invalid":!!y,"aria-describedby":P,required:s,...C,children:[E&&g.jsx("option",{value:"",disabled:!0,selected:!("value"in C),children:E}),D?R:A?.map(q=>g.jsx("option",{value:q.value,disabled:q.disabled,children:q.label},q.value))]})})}const mm="AIzaSyDjLdKLxoa-maLNGAyq_I_2r_Fe_TzFikw";function hm(){return new Promise((i,r)=>{if(window.google?.maps?.places){i();return}const h=document.querySelector('script[src*="maps.googleapis.com"]');if(h){h.addEventListener("load",()=>i()),h.addEventListener("error",()=>r(new Error("Failed to load Google Maps script")));return}const y=document.createElement("script");y.src=`https://maps.googleapis.com/maps/api/js?key=${mm}&libraries=places`,y.async=!0,y.defer=!0,y.onload=()=>i(),y.onerror=()=>r(new Error("Failed to load Google Maps script")),document.head.appendChild(y)})}function ym(i){const r={fullAddress:i.formatted_address};return i.address_components&&i.address_components.forEach(h=>{const y=h.types;y.includes("street_number")&&(r.streetNumber=h.long_name),y.includes("route")&&(r.streetName=h.long_name),y.includes("locality")&&(r.city=h.long_name),y.includes("administrative_area_level_1")&&(r.state=h.short_name),y.includes("postal_code")&&(r.zipCode=h.long_name),y.includes("country")&&(r.country=h.short_name)}),r}function _m({id:i,label:r,hint:h,error:y,required:s,className:p,onChange:E,onPlaceSelect:A,value:R,...C}){const P=H.useRef(null),D=H.useRef(null),q=H.useRef(null),rl=H.useRef(null),[ul,il]=H.useState(!0),[cl,ol]=H.useState(R||""),[U,Z]=H.useState([]),[O,V]=H.useState(!1),[K,W]=H.useState(-1),I=H.useRef([]),B=H.useRef(!1),Y=H.useRef(-1);H.useEffect(()=>{I.current=U},[U]),H.useEffect(()=>{B.current=O},[O]),H.useEffect(()=>{Y.current=K},[K]),H.useEffect(()=>{R!==void 0&&ol(String(R))},[R]);const w=H.useRef(null);H.useEffect(()=>{if(!P.current)return;let $=!0;return hm().then(()=>{!$||!P.current||(D.current=new google.maps.places.AutocompleteService,q.current=new google.maps.places.PlacesService(document.createElement("div")),il(!1))}).catch(z=>{console.error("Error loading Google Maps:",z),il(!1)}),()=>{$=!1,w.current&&clearTimeout(w.current)}},[]);const G=$=>{const z=$.target.value;if(ol(z),E?.(z),w.current&&clearTimeout(w.current),z.length<3){Z([]),V(!1);return}w.current=setTimeout(()=>{D.current&&D.current.getPlacePredictions({input:z,types:["address"]},(M,j)=>{j===google.maps.places.PlacesServiceStatus.OK&&M?(Z(M),V(!0),W(-1)):(Z([]),V(!1))})},300)},hl=$=>{if(!B.current||I.current.length===0){$.key==="Escape"&&(V(!1),B.current=!1);return}switch($.key){case"ArrowDown":$.preventDefault(),W(z=>{const M=z<I.current.length-1?z+1:z;return Y.current=M,M});break;case"ArrowUp":$.preventDefault(),W(z=>{const M=z>0?z-1:-1;return Y.current=M,M});break;case"Enter":$.preventDefault(),Y.current>=0&&Y.current<I.current.length&&yl(I.current[Y.current]);break;case"Escape":$.preventDefault(),V(!1),B.current=!1;break}};H.useEffect(()=>{const $=z=>{rl.current&&!rl.current.contains(z.target)&&P.current&&!P.current.contains(z.target)&&(V(!1),B.current=!1)};if(O)return document.addEventListener("mousedown",$),()=>{document.removeEventListener("mousedown",$)}},[O]);const yl=$=>{q.current&&q.current.getDetails({placeId:$.place_id,fields:["address_components","formatted_address","geometry"]},(z,M)=>{if(M===google.maps.places.PlacesServiceStatus.OK&&z){const j=z.formatted_address||"";ol(j),V(!1),Z([]),B.current=!1;const el=ym(z);E?.(j,el),A?.(z)}})};return g.jsx(At,{id:i,label:r,hint:h,error:y,required:s,className:p,children:g.jsxs("div",{className:"relative",children:[g.jsx("input",{ref:P,id:i,type:"text",className:`form-input ${y?"input-error":""}`,value:cl,onChange:G,onKeyDown:hl,"aria-invalid":!!y,"aria-describedby":[h?`${i}-hint`:null,y?`${i}-error`:null].filter(Boolean).join(" ")||void 0,required:s,autoComplete:"street-address",placeholder:C.placeholder||"Enter an address",disabled:ul||C.disabled,...C}),ul&&g.jsx("p",{className:"mt-1 text-sm text-slate-500",children:"Loading address suggestions..."}),O&&U.length>0&&g.jsx("div",{ref:rl,className:"absolute z-50 w-full mt-1 bg-white border border-slate-200 rounded-lg shadow-lg max-h-60 overflow-y-auto",role:"listbox",children:U.map(($,z)=>g.jsxs("div",{className:`px-4 py-3 cursor-pointer transition-colors ${z===K?"bg-blue-50 text-slate-900":"bg-white text-slate-900 hover:bg-slate-50"} ${z<U.length-1?"border-b border-slate-100":""}`,role:"option","aria-selected":z===K,onClick:()=>yl($),onMouseEnter:()=>W(z),children:[g.jsx("div",{className:"font-medium text-slate-900",children:$.structured_formatting.main_text}),$.structured_formatting.secondary_text&&g.jsx("div",{className:"text-sm text-slate-500 mt-0.5",children:$.structured_formatting.secondary_text})]},$.place_id))})]})})}function ri(i){return i.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/(^-|-$)/g,"")}function Cf(i,r){return i.key??`${ri(i.question)}-${r}`}function Gn(i,r){const h={},y=s=>s==null||typeof s=="string"&&s.trim()==="";return i.forEach((s,p)=>{const E=Cf(s,p),A=r[E];if(s.required)switch(s.inputType){case"checkbox":A!==!0&&(h[E]="Required");break;case"radio":case"select":y(A)&&(h[E]="Required");break;case"number":(A==null||typeof A=="string"&&A.trim()==="")&&(h[E]="Required");break;case"date":case"email":case"tel":case"url":case"password":case"text":case"textarea":case"address":default:y(A)&&(h[E]="Required");break}}),h}function vm(i){if(i===""||i===null||i===void 0)return;const r=Number(i);return Number.isNaN(r)?void 0:r}function Zf(i){return typeof i=="number"&&Number.isFinite(i)?i:typeof i=="string"&&i.trim()!==""&&!Number.isNaN(Number(i))?Number(i):null}function Vf(i){if(i instanceof Date&&!Number.isNaN(i.getTime()))return i.getTime();if(typeof i=="string"){const r=Date.parse(i);return Number.isNaN(r)?null:r}return null}function Kf(i,r){const h=Zf(i),y=Zf(r);if(h!=null&&y!=null)return h-y;const s=Vf(i),p=Vf(r);return s!=null&&p!=null?s-p:i==null||r==null?null:String(i).localeCompare(String(r))}function gm(i,r){return Array.isArray(i)?i.some(h=>h===r):typeof i=="string"?r!=null&&i.includes(String(r)):!1}function Ha(i,r,h){switch(r){case"equals":return i===h;case"lessThan":{const y=Kf(i,h);return y!=null&&y<0}case"greaterThan":{const y=Kf(i,h);return y!=null&&y>0}case"contains":return gm(i,h);case"startsWith":return i!=null&&h!=null&&String(i).startsWith(String(h));case"endsWith":return i!=null&&h!=null&&String(i).endsWith(String(h));default:return!1}}function oi(i,r){return r.reduce((h,y)=>h?.[y],i)}function $t(i,r,h){if(r.length===0)return i;const[y,...s]=r;if(s.length===0){if(typeof y=="number"){const C=(Array.isArray(i)?i:[]).slice();return C[y]=h,C}return{...i,[y]:h}}const p=i?.[y],E=typeof s[0]=="number"?Array.isArray(p)?p:[]:p&&typeof p=="object"?p:{},A=$t(E,s,h);if(typeof y=="number"){const C=(Array.isArray(i)?i:[]).slice();return C[y]=A,C}return{...i,[y]:A}}function Qa(i,r,h){return oi(i,[...r??[],h])}function bm(i,r,h,y){return $t(i,[...r??[],h],y)}const pm="__items",Xn=i=>`${i}${pm}`;function Sm(i){const r=(h,y)=>h.map((s,p)=>{const E=y.length?y.join("__"):"root",A=s.key??`${E}__q${p}_${String(s.question).slice(0,24).replace(/\W+/g,"-")||"field"}`,C=(s.conditionals??[]).map((P,D)=>{const q=P.conditionalQuestions?r(P.conditionalQuestions,[...y,`${A}__c${D}`]):void 0;return{...P,conditionalQuestions:q}});return{...s,key:A,conditionals:C}});return r(i,[])}function Ft(i){return i==null?"":typeof i=="string"?i:String(i)}function xm(i){return i==null?"":typeof i=="number"&&Number.isFinite(i)||typeof i=="string"?i:""}function Am(i){return i==null?"":typeof i=="string"||typeof i=="number"?i:String(i)}function Tm({questions:i,initialValues:r,controlledValues:h,onChangeValues:y,onSubmit:s}){const p=H.useMemo(()=>Sm(i),[i]),E=H.useMemo(()=>{const U={};return r&&Object.assign(U,r),U},[r]),[A,R]=H.useState(E);H.useEffect(()=>{R(E)},[E]);const[C,P]=H.useState({}),D=H.useMemo(()=>({...C,...h??A}),[C,h,A]);H.useEffect(()=>{h&&P(U=>({...U,...h}))},[h]);const[q,rl]=H.useState({});function ul(U,Z){const O=U.key,V=U.question,K=Qa(D,Z,O),W=q[O],I=B=>{let Y=bm(D,Z,O,B);if(U.inputType==="radio"&&U.conditionals){const w=U.conditionals??[];for(const G of w){const hl=Qa(D,Z,O),yl=Ha(hl,G.conditionalType,G.conditionalValue),$=Ha(B,G.conditionalType,G.conditionalValue);if(yl&&!$&&G.conditionalQuestionsAllowMultiple){const z=G.conditionalQuestions??[];if(z.length>0){const M=Xn(O);Y=$t(Y,[...Z??[],M],[]);const j=(el,_l)=>{el.forEach(Nl=>{(Nl.conditionals??[]).forEach(fl=>{if(fl.conditionalQuestionsAllowMultiple){const Ml=Xn(Nl.key);Y=$t(Y,[..._l,Ml],[])}const F=fl.conditionalQuestions??[];F.length>0&&j(F,_l)})})};j(z,[...Z??[],M])}}}}h&&y?y(Y):R(Y),P(Y)};switch(U.inputType){case"text":return g.jsx(em,{id:O,label:V,value:Ft(K),onChange:B=>I(B.currentTarget.value),"aria-required":U.required||void 0,error:W},O);case"email":return g.jsx(nm,{id:O,label:V,value:Ft(K),onChange:B=>I(B.currentTarget.value),"aria-required":U.required||void 0,error:W},O);case"password":return g.jsx(cm,{id:O,label:V,value:Ft(K),onChange:B=>I(B.currentTarget.value),"aria-required":U.required||void 0,error:W},O);case"tel":return g.jsxs(g.Fragment,{children:[g.jsx(um,{id:O,label:V,value:Ft(K),onChange:B=>I(B.currentTarget.value),"aria-required":U.required||void 0,error:W},O),O==="phone"&&g.jsxs("div",{className:"mt-3 text-xs text-slate-600 space-y-1",children:[g.jsx("p",{children:"By entering your phone number, you agree to receive a one-time SMS from Credify Insurance with a verification code."}),g.jsx("p",{children:"Message & data rates may apply. One message per request."}),g.jsxs("p",{children:["See our"," ",g.jsx("a",{href:"https://getcredify.com",target:"_blank",rel:"noopener noreferrer",className:"underline hover:text-slate-800",children:"Privacy Policy"})," ","and"," ",g.jsx("a",{href:"https://getcredify.com",target:"_blank",rel:"noopener noreferrer",className:"underline hover:text-slate-800",children:"Terms of Service"}),"."]})]})]});case"url":return g.jsx(im,{id:O,label:V,value:Ft(K),onChange:B=>I(B.currentTarget.value),"aria-required":U.required||void 0,error:W},O);case"number":return g.jsx(am,{id:O,label:V,value:xm(K),onChange:B=>I(vm(B.currentTarget.value)),"aria-required":U.required||void 0,error:W},O);case"textarea":return g.jsx(fm,{id:O,label:V,value:Ft(K),onChange:B=>I(B.currentTarget.value),"aria-required":U.required||void 0,error:W,rows:4},O);case"date":return g.jsx(sm,{id:O,label:V,value:Ft(K),onChange:B=>I(B.currentTarget.value),"aria-required":U.required||void 0,error:W},O);case"checkbox":{if(U.options){const B=Array.isArray(K)?K:[];return g.jsxs("div",{className:"space-y-2",children:[g.jsxs("div",{className:"form-label",children:[V,U.required&&g.jsx("span",{className:"text-red-600 ml-1",children:"*"})]}),g.jsx("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:U.options.map(Y=>{const w=`${O}-${ri(Y)}`,G=B.includes(Y);return g.jsx(Xf,{id:w,label:Y,checked:G,onChange:hl=>{const yl=new Set(B);hl.currentTarget.checked?yl.add(Y):yl.delete(Y),I(Array.from(yl))},"aria-required":U.required||void 0},w)})}),W&&g.jsx("p",{className:"mt-1 text-sm text-red-600",children:W})]},O)}return g.jsx(Xf,{id:O,label:U.required?`${V} *`:V,checked:!!K,onChange:B=>I(B.currentTarget.checked),"aria-required":U.required||void 0},O)}case"radio":{const B=U.options??[],Y=Z&&Z.length>0?`${O}__${Z.join("__")}`:O;return g.jsx(om,{legend:V,legendClassName:U.required?"legend-required":void 0,children:B.map(w=>g.jsx(rm,{name:Y,value:w,checked:K===w,onChange:()=>I(w),children:w},`${O}-${ri(w)}`))},O)}case"select":{let B=U.options??[];return O==="quote_vehicle_id"&&(B=h?.vehicles__items?.map(Y=>Y.vin)??[]),g.jsx(dm,{id:O,label:V,"aria-required":U.required||void 0,error:W,value:Am(K),onChange:Y=>I(Y.currentTarget.value),placeholder:"Select an option",options:B.map(Y=>({value:Y,label:Y}))},O)}case"address":return g.jsx(_m,{id:O,label:V,value:Ft(K),onChange:B=>I(B),"aria-required":U.required||void 0,error:W},O);default:return null}}function il(U,Z){return U.map((O,V)=>{const K=String(O.key),W=ul(O,Z),I=O.conditionals??[];if(!I.length)return g.jsx("div",{children:W},`wrap-${K}-${V}`);const B=Qa(D,Z,K),Y=I.filter(G=>Ha(B,G.conditionalType,G.conditionalValue)),w=Y.length>1&&!Y.some(G=>G.conditionalQuestionsAllowMultiple)?Y.slice(0,1):Y;return g.jsxs("div",{children:[W,w.map((G,hl)=>{const yl=G.conditionalQuestions??[];if(!yl.length)return null;if(!G.conditionalQuestionsAllowMultiple)return g.jsx("div",{className:"mt-3",children:il(yl,Z)},`branch-${K}-${hl}`);const $=Xn(K),z=oi(D,[...Z??[],$])??[],M=Math.max(1,z.length||1),j=()=>{const Nl=$t(D,[...Z??[],$,z.length],{});h&&y?y(Nl):R(Nl),P(Nl)},el=()=>{const Nl=z.slice(0,Math.max(0,z.length-1)),Tl=$t(D,[...Z??[],$],Nl);h&&y?y(Tl):R(Tl),P(Tl)},_l=`${K}__c${hl}`;return g.jsxs("div",{className:"mt-3",children:[g.jsxs("div",{className:"flex items-center justify-between mb-2",children:[g.jsx("div",{className:"text-sm font-medium opacity-75",children:"Add one or more entries"}),g.jsxs("div",{className:"space-x-2",children:[g.jsx("button",{type:"button",className:"btn-outline px-3 py-1",onClick:j,children:"Add another"}),M>1&&g.jsx("button",{type:"button",className:"btn-outline px-3 py-1",onClick:el,children:"Remove last"})]})]}),Array.from({length:M}).map((Nl,Tl)=>{const fl=[...Z??[],$,Tl],F=`${_l}__i${Tl}`;return g.jsxs("div",{className:"rounded-lg border p-3 mb-3",children:[g.jsxs("div",{className:"text-sm font-semibold mb-2",children:["Entry #",Tl+1]}),yl.map(Ml=>g.jsxs("div",{className:"mt-3",children:[ul(Ml,fl),(()=>{const Pt=Ml.conditionals??[];if(!Pt.length)return null;const Et=Qa(D,fl,Ml.key),Rt=Pt.filter(Wl=>Ha(Et,Wl.conditionalType,Wl.conditionalValue));return(Rt.length>1&&!Rt.some(Wl=>Wl.conditionalQuestionsAllowMultiple)?Rt.slice(0,1):Rt).map((Wl,Ne)=>{const le=Wl.conditionalQuestions??[];if(!le.length)return null;if(!Wl.conditionalQuestionsAllowMultiple)return g.jsx("div",{className:"mt-3",children:il(le,fl)},`nested-${F}-${Ne}`);const te=Xn(Ml.key),ee=oi(D,[...fl,te])??[],qe=Math.max(1,ee.length||1),bi=()=>{const Vl=$t(D,[...fl,te,ee.length],{});h&&y?y(Vl):R(Vl),P(Vl)},pi=()=>{const Vl=ee.slice(0,Math.max(0,ee.length-1)),Bt=$t(D,[...fl,te],Vl);h&&y?y(Bt):R(Bt),P(Bt)};return g.jsxs("div",{className:"mt-3",children:[g.jsxs("div",{className:"flex items-center justify-between mb-2",children:[g.jsx("div",{className:"text-sm font-medium opacity-75",children:"Add one or more entries"}),g.jsxs("div",{className:"space-x-2",children:[g.jsx("button",{type:"button",className:"btn-outline px-3 py-1",onClick:bi,children:"Add another"}),qe>1&&g.jsx("button",{type:"button",className:"btn-outline px-3 py-1",onClick:pi,children:"Remove last"})]})]}),Array.from({length:qe}).map((Vl,Bt)=>{const Kn=[...fl,te,Bt];return g.jsxs("div",{className:"rounded-lg border p-3 mb-3",children:[g.jsxs("div",{className:"text-sm font-semibold mb-2",children:["Entry #",Bt+1]}),il(le,Kn)]},`nested-item-${F}-${Ne}-${Bt}`)})]},`nested-repeat-${F}-${Ne}`)})})()]},`${F}-${String(Ml.key)}`))]},`group-${F}`)})]},`branch-${K}-${hl}`)})]},`wrap-${K}-${V}`)})}const cl=H.useMemo(()=>{const U=[],Z=(O,V)=>{O.forEach(K=>{U.push(K);const W=String(K.key),I=K.conditionals??[];if(!I.length)return;const B=Qa(D,V,W),Y=I.filter(G=>Ha(B,G.conditionalType,G.conditionalValue));(Y.length>1&&!Y.some(G=>G.conditionalQuestionsAllowMultiple)?Y.slice(0,1):Y).forEach(G=>{const hl=G.conditionalQuestions??[];hl.length&&(G.conditionalQuestionsAllowMultiple||Z(hl,V))})})};return Z(p),U},[p,D]);function ol(U){U.preventDefault();const Z=Gn(cl,D);if(rl(Z),Object.keys(Z).length>0){const O=cl.findIndex(V=>Z[V.key]);O>=0&&document.getElementById(cl[O].key)?.focus();return}s(D)}return g.jsx("form",{className:"space-y-6 px-1",onSubmit:ol,noValidate:!0,children:il(p)})}function wf(i){return typeof i=="number"&&Number.isFinite(i)?i:typeof i=="string"&&i.trim()!==""&&!Number.isNaN(Number(i))?Number(i):null}function Lf(i){if(i instanceof Date&&!Number.isNaN(i.getTime()))return i.getTime();if(typeof i=="string"){const r=Date.parse(i);return Number.isNaN(r)?null:r}return null}function Jf(i,r){const h=wf(i),y=wf(r);if(h!=null&&y!=null)return h-y;const s=Lf(i),p=Lf(r);return s!=null&&p!=null?s-p:i==null||r==null?null:String(i).localeCompare(String(r))}function Em(i,r){return Array.isArray(i)?i.some(h=>h===r):typeof i=="string"?r!=null&&i.includes(String(r)):!1}function qf(i,r,h){switch(r){case"equals":return i===h;case"lessThan":{const y=Jf(i,h);return y!=null&&y<0}case"greaterThan":{const y=Jf(i,h);return y!=null&&y>0}case"contains":return Em(i,h);case"startsWith":return i!=null&&h!=null&&String(i).startsWith(String(h));case"endsWith":return i!=null&&h!=null&&String(i).endsWith(String(h));default:return!1}}function kf(i,r){const h=[];return(s=>{s.forEach(p=>{h.push(p);const E=String(p.key),A=r[E],R=p.conditionals??[];if(!R.length)return;const C=R.filter(D=>qf(A,D.conditionalType,D.conditionalValue));(C.length>1&&!C.some(D=>D.conditionalQuestionsAllowMultiple)?C.slice(0,1):C).forEach(D=>{const q=D.conditionalQuestions??[];q.length&&(D.conditionalQuestionsAllowMultiple||q.forEach(rl=>h.push(rl)))})})})(i),h}const Wf="__items",$f=i=>`${i}${Wf}`;function di(i,r){for(const h of i){const y=String(h.key),s=r[y],p=h.conditionals??[];if(!p.length)continue;const E=p.filter(R=>qf(s,R.conditionalType,R.conditionalValue)),A=E.length>1&&!E.some(R=>R.conditionalQuestionsAllowMultiple)?E.slice(0,1):E;for(const R of A){const C=R.conditionalQuestions??[];if(!C.length)continue;if(!R.conditionalQuestionsAllowMultiple){if(di(C,r))return!0;continue}const P=r[$f(y)]??[];if(P.length===0)return!0;for(const D of P){const q=Gn(C,D);if(Object.values(q).some(Boolean)||di(C,D))return!0}}}return!1}function Ff(i,r){return di(i,r)}function zm({stages:i,onStageComplete:r,onComplete:h,initialValues:y,initialActive:s}){const[p,E]=H.useState(s??0),[A,R]=H.useState(y??{}),[C,P]=H.useState({}),[D,q]=H.useState(!1),[rl,ul]=H.useState(!1),[il,cl]=H.useState(null),ol=H.useRef([]),U=Array.isArray(i)&&i.length>0,Z=U?i[Math.min(p,i.length-1)]:null,O=Z?.key??null;H.useEffect(()=>{s!==void 0&&E(s)},[s]),H.useEffect(()=>{const w=ol.current[p];w&&w.scrollIntoView({behavior:"smooth",block:"nearest",inline:"center"})},[p]),H.useEffect(()=>{y!==void 0&&R(y)},[y]),H.useEffect(()=>{if(!Z||!O){q(!1),cl(null);return}if(C[O]){q(!1),cl(null);return}let w=!1;return q(!0),cl(null),Promise.resolve(Z.loadQuestions()).then(G=>{if(!w){if(!Array.isArray(G))throw new Error(`loadQuestions("${O}") did not return an array`);P(hl=>({...hl,[O]:G}))}}).catch(G=>{w||cl(`Failed to load stage "${Z?.title??""}": ${G?.message??"Unknown error"}`)}).finally(()=>{w||q(!1)}),()=>{w=!0}},[Z,O,C]);const V=O?C[O]:void 0,K=H.useMemo(()=>{if(!V)return{};const w={};(yl=>{const $=[],z=M=>{M.forEach((j,el)=>{const _l=Cf(j,el);$.push(_l);const Nl=$f(_l);$.push(Nl),(j.conditionals??[]).forEach(fl=>{const F=fl.conditionalQuestions??[];F.length>0&&z(F)})})};return z(yl),$})(V).forEach(yl=>{yl in A&&(w[yl]=A[yl])});for(const[yl,$]of Object.entries(A))yl.endsWith(Wf)&&!(yl in w)&&(w[yl]=$);return w},[V,A]),W=w=>{R(G=>({...G,...w}))},I=()=>{E(w=>w>0?w-1:0),document.querySelector(".panel-body")?.scrollTo({top:0,behavior:"instant"})},B=async()=>{if(!V||!Z||D||il||rl)return;const w=kf(V,A),G=Gn(w,A),hl=Object.values(G).some(Boolean),yl=Ff(V,A);if(!(hl||yl)){ul(!0);try{const $=Math.min(p+1,i.length-1),z=p>=i.length-1,{success:M,error:j}=z?await h(A,O??""):await r(K,O??"");if(!M){cl(j??"An error occurred");return}z||E($)}finally{ul(!1)}}},Y=H.useMemo(()=>{if(!V||D||il||rl)return!0;const w=kf(V,A),G=Gn(w,A),hl=Object.values(G).some(Boolean),yl=Ff(V,A);return hl||yl},[V,A,D,il,rl]);return U?g.jsxs("div",{className:"space-y-6",children:[g.jsxs("div",{className:"flex items-center justify-between gap-4",children:[g.jsx("ol",{className:"flex gap-2 text-xs overflow-x-auto flex-1 pb-1 scrollbar-hide items-center",style:{scrollbarWidth:"none",msOverflowStyle:"none"},children:i.flatMap((w,G)=>[g.jsx("li",{ref:hl=>{ol.current[G]=hl},className:`px-2.5 py-1 rounded-full border whitespace-nowrap flex-shrink-0 ${G<p?"bg-blue-600 text-white border-blue-600":G===p?"border-blue-600 text-blue-600 bg-white":"border-slate-200 text-slate-600"}`,children:w.title},w.key??`stage-${G}`),...G<i.length-1?[g.jsx("li",{className:"text-slate-400 flex-shrink-0",children:"→"},`arrow-${w.key??G}`)]:[]])}),g.jsxs("div",{className:"text-sm text-slate-500 flex-shrink-0",children:[Math.min(p+1,i.length)," / ",i.length]})]}),g.jsxs("div",{children:[D&&g.jsx("div",{className:"text-slate-500",children:"Loading…"}),Z&&g.jsx(Tm,{questions:V??[],controlledValues:K,onChangeValues:W,onSubmit:()=>B()},Z.key)]}),!D&&il&&g.jsxs("div",{className:"text-red-600 text-sm -mt-4",children:[g.jsx("div",{children:il}),Z&&g.jsx("button",{type:"button",className:"underline mt-1 font-bold",onClick:()=>{P(w=>{if(!O)return w;const G={...w};return delete G[O],G})},children:"Retry"})]}),g.jsxs("div",{className:p>0?"grid grid-cols-2 gap-3":"",children:[p>0&&g.jsx("button",{type:"button",onClick:I,disabled:D,className:"h-12 rounded-full border border-gray-300 text-text-primary hover:bg-gray-50 transition",children:"Back"}),g.jsxs("button",{type:"button",onClick:B,disabled:Y,className:[p>0?"":"w-full","h-12 rounded-full text-white transition","disabled:opacity-50 disabled:cursor-not-allowed","flex items-center justify-center gap-2",Y?"bg-gray-300":"bg-blue-600 hover:bg-blue-600/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-600/40 bg-primary hover:bg-primary/90 focus-visible:ring-primary/40"].join(" "),children:[rl&&g.jsxs("svg",{className:"animate-spin h-5 w-5 text-white",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[g.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),g.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),p===i.length-1?"Finish":"Next"]})]})]}):g.jsx("div",{className:"text-slate-600",children:"Loading..."})}const mi="credify_quote_id",hi="credify_auth_token";function Nm(i){try{localStorage.setItem(mi,i)}catch(r){console.error("Failed to save quoteId to localStorage:",r)}}function Mm(){try{return localStorage.getItem(mi)}catch(i){return console.error("Failed to load quoteId from localStorage:",i),null}}function If(){try{localStorage.removeItem(mi)}catch(i){console.error("Failed to clear quoteId from localStorage:",i)}}function Dm(i){try{localStorage.setItem(hi,i)}catch(r){console.error("Failed to save authToken to localStorage:",r)}}function Om(){try{return localStorage.getItem(hi)}catch(i){return console.error("Failed to load authToken from localStorage:",i),null}}function Pf(){try{localStorage.removeItem(hi)}catch(i){console.error("Failed to clear authToken from localStorage:",i)}}function jm(){If(),Pf()}const jt="https://api.getcredify.com";let Je=null;function Um(i){Je=i,Dm(i)}function Cn(){return Je}function yi(){const i=Om();i&&(Je=i)}function ls(){Je=null,Pf()}async function Ut(i,r){const h={"Content-Type":"application/json"};Je&&(h.Authorization=`Bearer ${Je}`);const y=await fetch(i,{method:"POST",headers:h,body:JSON.stringify(r)});if(!y.ok){let s=`Request failed with status ${y.status}`;try{s=(await y.json()).error||s}catch{s=y.statusText||s}const p=new Error(s);throw p.statusCode=y.status,p}return y}async function Rm(i){return await(await Ut(`${jt}/get-questions-by-stage`,{stage:i})).json()}async function _i(){return await(await Ut(`${jt}/get-stages-for-quote`,{})).json()}async function Bm(i){const h=await(await Ut(`${jt}/create-quote`,{phone:i})).json();if(!h||typeof h!="object"||!h.quoteId)throw new Error(`Invalid createQuote response: ${JSON.stringify(h)}`);return h}async function Ya(i,r,h){const y={payload:i,getRates:r};return h&&typeof h=="string"&&h.trim()!==""&&(y.quoteId=h),await(await Ut(`${jt}/update-quote`,y)).json()}async function Hm(i,r){return await(await Ut(`${jt}/verify-quote`,{quoteId:i,smsCode:r})).json()}async function Qm(i){return await(await Ut(`${jt}/is-supported-state`,{state:i})).json()}async function Ym(){return await(await Ut(`${jt}/get-rates`,{})).json()}async function Gm(i){const r=i?{quoteId:i}:{};return await(await Ut(`${jt}/get-quote`,r)).json()}async function Xm(i){const h=await(await Ut(`${jt}/request-bind`,{quoteRateId:i})).json();return h&&typeof h=="object"&&"success"in h?h:{success:!0}}const Cm=new Intl.NumberFormat("en-US",{style:"currency",currency:"USD"});function ts({onBack:i}){return g.jsx("button",{type:"button",onClick:i,className:"mt-4 h-12 rounded-full border border-gray-300 text-text-primary hover:bg-gray-50 transition w-full",children:"Back"})}function Zm({rates:i,onBack:r}){const h=Array.isArray(i)&&i.length>0,[y,s]=H.useState({});return H.useEffect(()=>{yi()},[]),h?g.jsxs("section",{className:"mt-8",children:[g.jsx("h3",{className:"text-lg font-semibold text-slate-900",children:"Rates"}),g.jsx("div",{className:"mt-4 grid gap-4 sm:grid-cols-2 lg:grid-cols-3",children:i.map(p=>{const E=p.premium_cents/100,A=Cm.format(E),R=p.quote_rate_id,C=y[R]??"idle",P=C==="loading",D=C==="success",q=async()=>{s(rl=>({...rl,[R]:"loading"}));try{if(yi(),!Cn())throw new Error("Authentication required. Please verify your phone number first.");if(!((await Xm(p.quote_rate_id))?.success!==!1))throw new Error("Request failed");jm(),ls(),s(cl=>({...cl,[R]:"success"}))}catch{s(rl=>({...rl,[R]:"error"}))}};return g.jsxs("div",{className:"flex flex-col rounded-xl border border-slate-200 bg-white p-6 shadow-sm transition hover:shadow-md",children:[g.jsxs("div",{className:"mb-4 flex items-center gap-3",children:[p.carrier_logo_base64?g.jsx("img",{src:`data:image/png;base64,${p.carrier_logo_base64}`,alt:p.carrier_name,className:"h-12 w-auto object-contain"}):g.jsx("div",{className:"flex h-12 w-12 items-center justify-center rounded-md bg-slate-100 text-sm font-semibold text-slate-500",children:p.carrier_name.charAt(0).toUpperCase()}),g.jsx("div",{className:"flex-1",children:g.jsx("h4",{className:"font-semibold text-slate-900",children:p.carrier_name})})]}),g.jsxs("div",{className:"mb-2",children:[g.jsx("p",{className:"text-sm text-slate-500",children:"Premium"}),g.jsx("p",{className:"text-2xl font-bold text-slate-900",children:A})]}),g.jsxs("div",{className:"mb-4",children:[g.jsx("p",{className:"text-sm text-slate-500",children:"Term"}),g.jsxs("p",{className:"font-medium text-slate-700",children:[p.term_months," months"]})]}),p.carrier_quote_id&&g.jsx("div",{className:"mb-4",children:g.jsxs("p",{className:"text-xs text-slate-400",children:["Quote ID: ",p.carrier_quote_id]})}),g.jsxs("div",{className:"mt-auto pt-4",children:[g.jsx("button",{type:"button",onClick:q,disabled:P||D,className:`w-full rounded-full px-4 py-2.5 text-sm font-semibold transition focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-600/40 ${D?"bg-emerald-500 text-white":"bg-blue-600 text-white hover:bg-blue-600/90 disabled:bg-slate-300 disabled:text-slate-500 disabled:cursor-not-allowed"}`,children:P?"Requesting…":D?"Requested":"Request Bind"}),C==="error"&&g.jsx("p",{className:"mt-2 text-xs text-red-600",children:"Something went wrong. Please try again."}),C==="success"&&g.jsx("p",{className:"mt-2 text-xs text-emerald-600",children:"We received your bind request."})]})]},R)})}),r&&g.jsx(ts,{onBack:r})]}):g.jsxs("section",{className:"mt-8",children:[g.jsx("h3",{className:"text-lg font-semibold text-slate-900",children:"Rates"}),g.jsx("p",{className:"mt-2 text-sm text-slate-500",children:"No rates are available at this time."}),r&&g.jsx(ts,{onBack:r})]})}function zl(i){if(i===!0)return"Yes";if(i===!1)return"No"}function Tt(i){if(i)try{const r=typeof i=="string"?new Date(i):i;return isNaN(r.getTime())?void 0:r.toISOString().split("T")[0]}catch{return}}function Vm(i){const r={};i.phone&&(r.phone=i.phone),i.first_name&&(r.first_name=i.first_name),i.last_name&&(r.last_name=i.last_name),i.email&&(r.email=i.email),i.date_of_birth&&(r.date_of_birth=Tt(i.date_of_birth)),i.product&&(r.product=i.product),i.state&&(r.state=i.state);const h=[];i.line_1&&h.push(i.line_1),i.line_2&&h.push(i.line_2),i.city&&h.push(i.city),i.state&&h.push(i.state),i.postal_code&&h.push(i.postal_code),h.length>0&&(r.address=h.join(", ")),i.years_at_address!==null&&i.years_at_address!==void 0&&(r.years_at_address=i.years_at_address),i.months_at_address!==null&&i.months_at_address!==void 0&&(r.months_at_address=i.months_at_address),i.move_in_date&&(r.move_in_date=Tt(i.move_in_date));const y=[];return i.prior_line_1&&y.push(i.prior_line_1),i.prior_line_2&&y.push(i.prior_line_2),i.prior_city&&y.push(i.prior_city),i.prior_state&&y.push(i.prior_state),i.prior_postal_code&&y.push(i.prior_postal_code),y.length>0&&(r.prior_address=y.join(", ")),i.years_at_prior_address!==null&&i.years_at_prior_address!==void 0&&(r.years_at_prior_address=i.years_at_prior_address),i.auto_has_prior_insurance!==null&&i.auto_has_prior_insurance!==void 0&&(r.auto_has_prior_insurance=zl(i.auto_has_prior_insurance)),i.auto_prior_expiration_date&&(r.auto_prior_expiration_date=Tt(i.auto_prior_expiration_date)),i.auto_prior_carrier_name&&(r.auto_prior_carrier_name=i.auto_prior_carrier_name),i.auto_prior_liability_limit&&(r.auto_prior_liability_limit=i.auto_prior_liability_limit),i.auto_reason_for_no_insurance&&(r.auto_reason_for_no_insurance=i.auto_reason_for_no_insurance),i.auto_prior_years!==null&&i.auto_prior_years!==void 0&&(r.auto_prior_years=i.auto_prior_years),i.auto_prior_months!==null&&i.auto_prior_months!==void 0&&(r.auto_prior_months=i.auto_prior_months),i.auto_continuous_coverage_years!==null&&i.auto_continuous_coverage_years!==void 0&&(r.auto_continuous_coverage_years=i.auto_continuous_coverage_years),i.auto_cancelled_declined_refused_to_renew!==null&&i.auto_cancelled_declined_refused_to_renew!==void 0&&(r.auto_cancelled_declined_refused_to_renew=zl(i.auto_cancelled_declined_refused_to_renew)),i.home_has_prior_insurance!==null&&i.home_has_prior_insurance!==void 0&&(r.home_has_prior_insurance=zl(i.home_has_prior_insurance)),i.home_prior_expiration_date&&(r.home_prior_expiration_date=Tt(i.home_prior_expiration_date)),i.home_prior_carrier_name&&(r.home_prior_carrier_name=i.home_prior_carrier_name),i.year_built!==null&&i.year_built!==void 0&&(r.year_built=i.year_built),i.number_of_units!==null&&i.number_of_units!==void 0&&(r.number_of_units=i.number_of_units),i.number_of_stories!==null&&i.number_of_stories!==void 0&&(r.number_of_stories=i.number_of_stories),i.number_of_beds!==null&&i.number_of_beds!==void 0&&(r.number_of_beds=i.number_of_beds),i.number_of_full_baths!==null&&i.number_of_full_baths!==void 0&&(r.number_of_full_baths=i.number_of_full_baths),i.number_of_partial_baths!==null&&i.number_of_partial_baths!==void 0&&(r.number_of_partial_baths=i.number_of_partial_baths),i.under_construction!==null&&i.under_construction!==void 0&&(r.under_construction=zl(i.under_construction)),i.distance_from_fire_hydrant_ft&&(r.distance_from_fire_hydrant_ft=i.distance_from_fire_hydrant_ft),i.distance_from_fire_station_miles&&(r.distance_from_fire_station_miles=i.distance_from_fire_station_miles),i.architectural_style&&(r.architectural_style=i.architectural_style),i.dwelling_type&&(r.dwelling_type=i.dwelling_type),i.construction_quality&&(r.construction_quality=i.construction_quality),i.located_over_water!==null&&i.located_over_water!==void 0&&(r.located_over_water=i.located_over_water),i.construction_type&&(r.construction_type=i.construction_type),i.exterior_wall_type&&(r.exterior_wall_type=i.exterior_wall_type),i.foundation_type&&(r.foundation_type=i.foundation_type),i.roof_material_type&&(r.roof_material_type=i.roof_material_type),i.year_roof_updated!==null&&i.year_roof_updated!==void 0&&(r.year_roof_updated=i.year_roof_updated),i.heating_type&&(r.heating_type=i.heating_type),i.heating_fuel_type&&(r.heating_fuel_type=i.heating_fuel_type),i.number_of_fireplaces!==null&&i.number_of_fireplaces!==void 0&&(r.number_of_fireplaces=i.number_of_fireplaces),i.basement_type&&(r.basement_type=i.basement_type),i.parking_type&&(r.parking_type=i.parking_type),i.number_of_parking_spaces!==null&&i.number_of_parking_spaces!==void 0&&(r.number_of_parking_spaces=i.number_of_parking_spaces),i.plumbing_type&&(r.plumbing_type=i.plumbing_type),i.pool_type&&(r.pool_type=i.pool_type),i.total_area_sq_ft!==null&&i.total_area_sq_ft!==void 0&&(r.total_area_sq_ft=i.total_area_sq_ft),i.parcel_area_sq_ft!==null&&i.parcel_area_sq_ft!==void 0&&(r.parcel_area_sq_ft=i.parcel_area_sq_ft),i.residence_type&&(r.residence_type=i.residence_type),i.usage_type&&(r.usage_type=i.usage_type),i.household_size!==null&&i.household_size!==void 0&&(r.household_size=i.household_size),i.number_of_mortgagees!==null&&i.number_of_mortgagees!==void 0&&(r.number_of_mortgagees=i.number_of_mortgagees),i.has_dog!==null&&i.has_dog!==void 0&&(r.has_dog=zl(i.has_dog)),i.dog_breed_type&&(r.dog_breed_type=i.dog_breed_type),i.number_of_dogs!==null&&i.number_of_dogs!==void 0&&(r.number_of_dogs=i.number_of_dogs),i.has_business_on_premises!==null&&i.has_business_on_premises!==void 0&&(r.has_business_on_premises=zl(i.has_business_on_premises)),i.business_class&&(r.business_class=i.business_class),i.retiree_discount!==null&&i.retiree_discount!==void 0&&(r.retiree_discount=zl(i.retiree_discount)),i.gated_community_discount!==null&&i.gated_community_discount!==void 0&&(r.gated_community_discount=zl(i.gated_community_discount)),i.multi_policy_discount!==null&&i.multi_policy_discount!==void 0&&(r.multi_policy_discount=zl(i.multi_policy_discount)),i.non_smoker_discount!==null&&i.non_smoker_discount!==void 0&&(r.non_smoker_discount=zl(i.non_smoker_discount)),i.first_time_buyer_discount!==null&&i.first_time_buyer_discount!==void 0&&(r.first_time_buyer_discount=zl(i.first_time_buyer_discount)),i.fire_detection_system!==null&&i.fire_detection_system!==void 0&&(r.fire_detection_system=zl(i.fire_detection_system)),i.burglar_alarm_system!==null&&i.burglar_alarm_system!==void 0&&(r.burglar_alarm_system=zl(i.burglar_alarm_system)),i.burglar_alarm_system_type&&(r.burglar_alarm_system_type=i.burglar_alarm_system_type),i.smoke_detectors!==null&&i.smoke_detectors!==void 0&&(r.smoke_detectors=zl(i.smoke_detectors)),i.sprinkler_system!==null&&i.sprinkler_system!==void 0&&(r.sprinkler_system=zl(i.sprinkler_system)),i.sprinkler_system_type&&(r.sprinkler_system_type=i.sprinkler_system_type),i.gas_leakage_detector!==null&&i.gas_leakage_detector!==void 0&&(r.gas_leakage_detector=zl(i.gas_leakage_detector)),i.deadbolt_locks!==null&&i.deadbolt_locks!==void 0&&(r.deadbolt_locks=zl(i.deadbolt_locks)),i.fire_extinguisher!==null&&i.fire_extinguisher!==void 0&&(r.fire_extinguisher=zl(i.fire_extinguisher)),i.order_credit_authorized!==null&&i.order_credit_authorized!==void 0&&(r.order_credit_authorized=zl(i.order_credit_authorized)),i.has_health_insurance_auto_accident!==null&&i.has_health_insurance_auto_accident!==void 0&&(r.has_health_insurance_auto_accident=zl(i.has_health_insurance_auto_accident)),i.named_insured_foreclosure_repo_bankruptcy!==null&&i.named_insured_foreclosure_repo_bankruptcy!==void 0&&(r.named_insured_foreclosure_repo_bankruptcy=zl(i.named_insured_foreclosure_repo_bankruptcy)),i.named_insured_convicted_insurance_fraud!==null&&i.named_insured_convicted_insurance_fraud!==void 0&&(r.named_insured_convicted_insurance_fraud=zl(i.named_insured_convicted_insurance_fraud)),i.drivers&&i.drivers.length>0?(r.drivers="Yes",r.drivers__items=i.drivers.map(s=>{const p={};return s.first_name&&(p.first_name=s.first_name),s.last_name&&(p.last_name=s.last_name),s.date_of_birth&&(p.date_of_birth=Tt(s.date_of_birth)),s.gender&&(p.gender=s.gender),s.marital_status&&(p.marital_status=s.marital_status),s.relationship_to_insured&&(p.relationship_to_insured=s.relationship_to_insured),s.license_state&&(p.license_state=s.license_state),s.license_status&&(p.license_status=s.license_status),s.license_number&&(p.license_number=s.license_number),s.date_first_licensed&&(p.date_first_licensed=Tt(s.date_first_licensed)),s.education_level&&(p.education_level=s.education_level),s.occupation&&(p.occupation=s.occupation),s.industry&&(p.industry=s.industry),s.driver_violations&&s.driver_violations.length>0&&(p.driver_violations__items=s.driver_violations.map(E=>{const A={};return E.code&&(A.code=E.code),E.occurred_at&&(A.occurred_at=Tt(E.occurred_at)),A})),s.driver_accidents&&s.driver_accidents.length>0&&(p.driver_accidents__items=s.driver_accidents.map(E=>{const A={};return E.occurred_at&&(A.occurred_at=Tt(E.occurred_at)),E.description&&(A.description=E.description),E.quote_vehicle_id&&(A.quote_vehicle_id=E.quote_vehicle_id),E.property_damage_amount_paid_cents!==null&&E.property_damage_amount_paid_cents!==void 0&&(A.property_damage_amount_paid_cents=E.property_damage_amount_paid_cents),E.personal_injury_amount_paid_cents!==null&&E.personal_injury_amount_paid_cents!==void 0&&(A.personal_injury_amount_paid_cents=E.personal_injury_amount_paid_cents),A})),s.losses&&s.losses.length>0&&(p.losses=s.losses.map(E=>{const A={};return E.description&&(A.description=E.description),E.date_of_incident&&(A.date_of_incident=Tt(E.date_of_incident)),E.amount_paid_cents!==null&&E.amount_paid_cents!==void 0&&(A.amount_paid_cents=E.amount_paid_cents),E.quote_vehicle_id&&(A.quote_vehicle_id=E.quote_vehicle_id),A})),p})):r.drivers="No",i.vehicles&&i.vehicles.length>0?(r.vehicles="Yes",r.vehicles__items=i.vehicles.map(s=>{const p={};s.vin&&(p.vin=s.vin),s.year!==null&&s.year!==void 0&&(p.year=s.year),s.make&&(p.make=s.make),s.model&&(p.model=s.model),s.ownership_type&&(p.ownership_type=s.ownership_type),s.usage&&(p.usage=s.usage),s.annual_mileage!==null&&s.annual_mileage!==void 0&&(p.annual_mileage=s.annual_mileage),s.miles_to_work!==null&&s.miles_to_work!==void 0&&(p.miles_to_work=s.miles_to_work),s.percent_to_work!==null&&s.percent_to_work!==void 0&&(p.percent_to_work=s.percent_to_work);const E=[];return s.garaging_address_line_1&&E.push(s.garaging_address_line_1),s.garaging_address_line_2&&E.push(s.garaging_address_line_2),s.garaging_address_city&&E.push(s.garaging_address_city),s.garaging_address_state&&E.push(s.garaging_address_state),s.garaging_address_postal_code&&E.push(s.garaging_address_postal_code),E.length>0&&(p.garaging_address=E.join(", ")),s.anti_theft_type&&(p.anti_theft_type=s.anti_theft_type),s.passive_restraint_type&&(p.passive_restraint_type=s.passive_restraint_type),s.coverages&&s.coverages.length>0&&(p.coverages__items=s.coverages.map(A=>{const R={};return A.type&&(R.type=A.type),A.per_person_limit_cents!==null&&A.per_person_limit_cents!==void 0&&(R.per_person_limit_cents=A.per_person_limit_cents),A.per_incident_limit_cents!==null&&A.per_incident_limit_cents!==void 0&&(R.per_incident_limit_cents=A.per_incident_limit_cents),A.per_incident_limit_percent!==null&&A.per_incident_limit_percent!==void 0&&(R.per_incident_limit_percent=A.per_incident_limit_percent),A.per_day_limit_cents!==null&&A.per_day_limit_cents!==void 0&&(R.per_day_limit_cents=A.per_day_limit_cents),A.deductible_cents!==null&&A.deductible_cents!==void 0&&(R.deductible_cents=A.deductible_cents),A.is_declined!==null&&A.is_declined!==void 0&&(R.is_declined=zl(A.is_declined)),R})),s.vehicle_lienholders&&s.vehicle_lienholders.length>0&&(p.vehicle_lienholders__items=s.vehicle_lienholders.map(A=>{const R={};return A.name&&(R.name=A.name),A.type&&(R.type=A.type),A.line_1&&(R.line_1=A.line_1),A.line_2&&(R.line_2=A.line_2),A.city&&(R.city=A.city),A.state&&(R.state=A.state),A.postal_code&&(R.postal_code=A.postal_code),A.phone&&(R.phone=A.phone),A.fax&&(R.fax=A.fax),R})),p})):r.vehicles="No",i.losses&&i.losses.length>0&&(r.home_losses__items=i.losses.map(s=>{const p={};return s.description&&(p.description=s.description),s.date_of_incident&&(p.date_of_incident=Tt(s.date_of_incident)),s.amount_paid_cents!==null&&s.amount_paid_cents!==void 0&&(p.amount_paid_cents=s.amount_paid_cents),p})),r}function vi(i){const r={},h=p=>{if(typeof p=="string"){if(p==="Yes")return!0;if(p==="No")return!1}return p},y=Object.keys(i).filter(p=>!p.includes("__items")),s=new Set;for(const[p,E]of Object.entries(i))p.endsWith("__items")&&Array.isArray(E)&&E.forEach(A=>{typeof A=="object"&&A!==null&&Object.keys(A).forEach(R=>{s.add(R)})});for(const[p,E]of Object.entries(i))if(p.endsWith("__items")){const A=p.replace("__items","");if(y.includes(A)){const C=Array.isArray(E)?E.map(P=>vi(P)):E;r[A]=C}}else p.includes("__items")||s.has(p)||(r[p]=h(E));return r}function Km({isOpen:i,onClose:r}){const[h,y]=H.useState([]),[s,p]=H.useState(null),[E,A]=H.useState(null),[R,C]=H.useState(null),[P,D]=H.useState(void 0),[q,rl]=H.useState(!1);function ul(cl){const ol={SMSVerification:"Verify",AutoCurrentCarrier:"Current Auto Policy",HomeCurrentCarrier:"Current Home Policy"};return cl.map(U=>({key:U,title:ol[U]||U,loadQuestions:async()=>(await Rm(U)).questions}))}H.useEffect(()=>{i&&(async()=>{try{const ol=Mm();if(yi(),ol){rl(!0),p(ol);try{const U=Cn(),Z=await Gm(U?void 0:ol);if(!Z||!Z.quote)throw new Error("Invalid response from getQuote: missing quote data");const{quote:O}=Z,{stages:V}=await _i(),K=ul(V);y(K);try{const W=Vm(O);C(W)}catch(W){throw new Error(`Failed to transform quote data: ${W instanceof Error?W.message:"Unknown error"}`)}if(O.current_stage){const W=K.findIndex(I=>I.key===O.current_stage);W>=0?D(W):D(K.length-1)}else D(K.length-1)}catch(U){U.statusCode===404?(If(),p(null)):ls()}finally{rl(!1)}}else{const{stages:U}=await _i();y(ul(U))}}catch{rl(!1)}})()},[i]),H.useEffect(()=>{if(!i)return;const{overflow:cl}=document.body.style;return document.body.style.overflow="hidden",()=>{document.body.style.overflow=cl}},[i]);const il=H.useCallback(cl=>{cl.key==="Escape"&&r()},[r]);return H.useEffect(()=>{if(i)return window.addEventListener("keydown",il),()=>window.removeEventListener("keydown",il)},[i,il]),H.useEffect(()=>{i||(C(null),D(void 0),rl(!1))},[i]),i?g.jsxs("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center",role:"dialog","aria-modal":"true","aria-labelledby":"insurance-modal-title",children:[g.jsx("div",{className:"backdrop",onClick:r}),g.jsxs("div",{className:"modal-panel relative w-full max-w-2xl flex flex-col max-h-[90vh] overflow-hidden",role:"document",children:[g.jsx("button",{onClick:r,className:"absolute top-4 right-4 text-slate-400 hover:text-slate-600 text-xl","aria-label":"Close",type:"button",children:"×"}),g.jsxs("div",{className:"text-center mb-6",children:[g.jsx("h2",{id:"insurance-modal-title",className:"h1-title",children:"Let's get you the best insurance rates."}),g.jsx("p",{className:"p-subtitle",children:"This should only take a few minutes."})]}),g.jsxs("div",{className:"panel-body flex-1 min-h-0 overflow-y-auto",children:[!E&&g.jsx(g.Fragment,{children:q||h.length===0?g.jsx("div",{className:"flex items-center justify-center py-12",children:g.jsx("div",{className:"text-slate-600",children:"Loading..."})}):g.jsx(zm,{stages:h,initialValues:R??void 0,initialActive:P,onStageComplete:async(cl,ol)=>{try{const U=vi(cl),{stages:Z}=await _i(),O=ul(Z);y(O);const K=O.findIndex(B=>B.key===ol)+1,I=(K<O.length?O[K]:null)?.key||ol;if(s)if(ol==="SMSVerification"){const{isVerified:B,token:Y}=await Hm(s,U.sms_code);if(!B)throw new Error("Invalid SMS code");Y&&Um(Y),await Ya({current_stage:I},!1)}else if(ol==="State"){const{isSupported:B}=await Qm(U.state);if(!B)throw new Error("State is not supported");const Y=Cn();await Ya({...U,current_stage:I},!1,Y?void 0:s)}else{const B=Cn();await Ya({...U,current_stage:I},!1,B?void 0:s||void 0)}else{const Y=(await Bm(U.phone))?.quoteId;if(!Y||typeof Y!="string"||Y.trim()==="")throw new Error(`Failed to create quote - invalid quoteId returned: ${Y}`);p(Y),Nm(Y),await Ya({current_stage:I},!1,Y)}return{success:!0}}catch(U){return{success:!1,error:U instanceof Error?U.message:"An error occurred"}}},onComplete:async cl=>{try{const ol=vi(cl);if(!s)throw new Error("Quote ID is required");await Ya(ol,!0),C(cl);const{rates:U}=await Ym();return A(U),{success:!0}}catch(ol){return{success:!1,error:ol instanceof Error?ol.message:"An error occurred"}}}})})," ",E&&s&&g.jsx(Zm,{rates:E,onBack:()=>A(null)})]}),g.jsx("div",{className:"mt-4 pt-4 border-t border-slate-200",children:g.jsx("p",{className:"text-center text-sm text-slate-500",children:"Insurance products offered through Credify Corporation, a licensed insurance agency."})})]})]}):null}function wm({isOpen:i}){return g.jsx(Km,{isOpen:i,onClose:()=>{Vn.close()}})}let It=null,Ga=null,Zn=!1;function Lm(){It||(It=document.createElement("div"),It.id="insurance-widget-root",document.body.appendChild(It),Ga=Pd.createRoot(It))}function gi(){Lm(),Ga.render(H.createElement(wm,{isOpen:Zn}))}function Jm(){Ga&&It&&(Ga.unmount(),It.remove()),Ga=null,It=null}const Vn={init:i=>{Zn=!!i?.autoOpen,gi()},open:()=>{Zn=!0,gi()},close:()=>{Zn=!1,gi()},destroy:Jm};typeof window<"u"&&(window.CredifyInsuranceWidget=Vn),bt.CredifyInsuranceWidget=Vn,bt.default=Vn,Object.defineProperties(bt,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
33
+ */var Yf;function lm(){if(Yf)return Ba;Yf=1;var i=Symbol.for("react.transitional.element"),r=Symbol.for("react.fragment");function h(y,s,p){var E=null;if(p!==void 0&&(E=""+p),s.key!==void 0&&(E=""+s.key),"key"in s){p={};for(var A in s)A!=="key"&&(p[A]=s[A])}else p=s;return s=p.ref,{$$typeof:i,type:y,key:E,ref:s!==void 0?s:null,props:p}}return Ba.Fragment=r,Ba.jsx=h,Ba.jsxs=h,Ba}var Gf;function tm(){return Gf||(Gf=1,ci.exports=lm()),ci.exports}var g=tm();function At({id:i,label:r,hint:h,error:y,required:s,className:p,children:E}){return g.jsxs("div",{className:p,children:[g.jsxs("label",{htmlFor:i,className:"form-label",children:[r," ",s&&g.jsx("span",{className:"text-red-600",children:"*"})]}),E,h&&!y&&g.jsx("p",{id:`${i}-hint`,className:"mt-1 text-sm text-slate-500",children:h}),y&&g.jsx("p",{id:`${i}-error`,className:"mt-1 text-sm text-red-600",children:y})]})}function em({id:i,label:r,hint:h,error:y,required:s,className:p,...E}){return g.jsx(At,{id:i,label:r,hint:h,error:y,required:s,className:p,children:g.jsx("input",{id:i,className:`form-input ${y?"input-error":""}`,"aria-invalid":!!y,"aria-describedby":[h?`${i}-hint`:null,y?`${i}-error`:null].filter(Boolean).join(" ")||void 0,required:s,...E,type:"text"})})}function am({id:i,label:r,hint:h,error:y,required:s,className:p,...E}){return g.jsx(At,{id:i,label:r,hint:h,error:y,required:s,className:p,children:g.jsx("input",{id:i,type:"number",className:`form-input ${y?"input-error":""}`,"aria-invalid":!!y,"aria-describedby":[h?`${i}-hint`:null,y?`${i}-error`:null].filter(Boolean).join(" ")||void 0,required:s,...E})})}function nm({id:i,label:r,hint:h,error:y,required:s,className:p,...E}){return g.jsx(At,{id:i,label:r,hint:h,error:y,required:s,className:p,children:g.jsx("input",{id:i,type:"email",className:`form-input ${y?"input-error":""}`,inputMode:"email",autoComplete:"email",required:s,"aria-invalid":!!y,"aria-describedby":[h?`${i}-hint`:null,y?`${i}-error`:null].filter(Boolean).join(" ")||void 0,...E})})}function fi(i){const r=i.replace(/\D/g,"");if(r.length===10)return`(${r.slice(0,3)}) ${r.slice(3,6)} - ${r.slice(6)}`;if(r.length>10){const h=r.slice(0,10);return`(${h.slice(0,3)}) ${h.slice(3,6)} - ${h.slice(6)}`}return r.length>=6?`(${r.slice(0,3)}) ${r.slice(3,6)} - ${r.slice(6)}`:r.length>=3?`(${r.slice(0,3)}) ${r.slice(3)}`:r.length>0?`(${r}`:r}function si(i){return i.replace(/\D/g,"")}function um({id:i,label:r,hint:h,error:y,required:s,className:p,value:E="",onChange:A,...R}){const[C,P]=H.useState(""),D=H.useRef(null),q=H.useRef(0);H.useEffect(()=>{if(!E){P("");return}let ul=si(E);ul.length===11&&ul.startsWith("1")&&(ul=ul.slice(1));const il=ul.slice(0,10);P(fi(il))},[E]);const rl=ul=>{const il=ul.target,cl=il.value;q.current=il.selectionStart||0;const U=si(cl).slice(0,10),Z=fi(U);P(Z);const O=U.length===10?`+1${U}`:U,V={...ul,currentTarget:{...ul.currentTarget,value:O},target:{...ul.target,value:O}};A?.(V),setTimeout(()=>{if(D.current){const K=cl.slice(0,q.current),W=si(K),I=fi(W),B=Math.min(I.length,Z.length);D.current.setSelectionRange(B,B)}},0)};return g.jsx(At,{id:i,label:r,hint:h,error:y,required:s,className:p,children:g.jsxs("div",{className:`tel-input-wrapper flex items-center border rounded-lg transition-colors w-full relative ${y?"border-red-500 error":"border-[var(--accent-color)] focus-within:border-[var(--primary-color)]"}`,children:[g.jsx("label",{htmlFor:i,className:"px-3 py-3 text-slate-700 font-medium border-r border-[var(--accent-color)] bg-slate-50 flex-shrink-0 relative z-0 rounded-l-lg",children:"+1"}),g.jsx("input",{ref:D,id:i,type:"tel",className:`flex-1 px-4 py-3 border-0 rounded-r-lg outline-none bg-transparent text-[var(--text-primary)] text-base ${y?"input-error":""}`,inputMode:"tel",autoComplete:"tel",required:s,"aria-invalid":!!y,"aria-describedby":[h?`${i}-hint`:null,y?`${i}-error`:null].filter(Boolean).join(" ")||void 0,value:C,onChange:rl,...R})]})})}function im({id:i,label:r,hint:h,error:y,required:s,className:p,...E}){return g.jsx(At,{id:i,label:r,hint:h,error:y,required:s,className:p,children:g.jsx("input",{id:i,type:"url",className:`form-input ${y?"input-error":""}`,inputMode:"url",autoComplete:"url",required:s,"aria-invalid":!!y,"aria-describedby":[h?`${i}-hint`:null,y?`${i}-error`:null].filter(Boolean).join(" ")||void 0,...E})})}function cm({id:i,label:r,hint:h,error:y,required:s,className:p,...E}){return g.jsx(At,{id:i,label:r,hint:h,error:y,required:s,className:p,children:g.jsx("input",{id:i,type:"password",className:`form-input ${y?"input-error":""}`,autoComplete:"current-password",required:s,"aria-invalid":!!y,"aria-describedby":[h?`${i}-hint`:null,y?`${i}-error`:null].filter(Boolean).join(" ")||void 0,...E})})}function fm({id:i,label:r,hint:h,error:y,required:s,className:p,rows:E=4,...A}){return g.jsx(At,{id:i,label:r,hint:h,error:y,required:s,className:p,children:g.jsx("textarea",{id:i,rows:E,className:`form-input ${y?"input-error":""}`,"aria-invalid":!!y,"aria-describedby":[h?`${i}-hint`:null,y?`${i}-error`:null].filter(Boolean).join(" ")||void 0,required:s,...A})})}function sm({id:i,label:r,hint:h,error:y,required:s,className:p,...E}){return g.jsx(At,{id:i,label:r,hint:h,error:y,required:s,className:p,children:g.jsx("input",{id:i,type:"date",className:`form-input ${y?"input-error":""}`,"aria-invalid":!!y,"aria-describedby":[h?`${i}-hint`:null,y?`${i}-error`:null].filter(Boolean).join(" ")||void 0,required:s,...E})})}function Xf({id:i,label:r,className:h,...y}){return g.jsxs("label",{className:`checkbox-card ${h||""}`,htmlFor:i,children:[g.jsx("input",{id:i,type:"checkbox",className:"checkbox-input",...y}),g.jsx("span",{className:"checkbox-label",children:r})]})}function rm({name:i,value:r,checked:h,onChange:y,children:s}){return g.jsxs("label",{className:"radio-card",children:[g.jsx("input",{className:"radio-input",type:"radio",name:i,value:r,checked:h,onChange:y}),g.jsx("span",{className:"radio-label",children:s})]})}function om({legend:i,children:r,className:h,legendClassName:y}){return g.jsxs("fieldset",{className:h,children:[g.jsx("legend",{className:`mb-4 text-base font-medium ${y||""}`,style:{color:"var(--text-primary)"},children:i}),g.jsx("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2",children:r})]})}function dm({id:i,label:r,hint:h,error:y,required:s,className:p,placeholder:E,options:A,children:R,...C}){const P=[h?`${i}-hint`:null,y?`${i}-error`:null].filter(Boolean).join(" ")||void 0,D=!!R;return g.jsx(At,{id:i,label:r,hint:h,error:y,required:s,className:p,children:g.jsxs("select",{id:i,className:`form-input select-caret ${y?"input-error":""}`,"aria-invalid":!!y,"aria-describedby":P,required:s,...C,children:[E&&g.jsx("option",{value:"",disabled:!0,selected:!("value"in C),children:E}),D?R:A?.map(q=>g.jsx("option",{value:q.value,disabled:q.disabled,children:q.label},q.value))]})})}const mm="AIzaSyDjLdKLxoa-maLNGAyq_I_2r_Fe_TzFikw";function hm(){return new Promise((i,r)=>{if(window.google?.maps?.places){i();return}const h=document.querySelector('script[src*="maps.googleapis.com"]');if(h){h.addEventListener("load",()=>i()),h.addEventListener("error",()=>r(new Error("Failed to load Google Maps script")));return}const y=document.createElement("script");y.src=`https://maps.googleapis.com/maps/api/js?key=${mm}&libraries=places`,y.async=!0,y.defer=!0,y.onload=()=>i(),y.onerror=()=>r(new Error("Failed to load Google Maps script")),document.head.appendChild(y)})}function ym(i){const r={fullAddress:i.formatted_address};return i.address_components&&i.address_components.forEach(h=>{const y=h.types;y.includes("street_number")&&(r.streetNumber=h.long_name),y.includes("route")&&(r.streetName=h.long_name),y.includes("locality")&&(r.city=h.long_name),y.includes("administrative_area_level_1")&&(r.state=h.short_name),y.includes("postal_code")&&(r.zipCode=h.long_name),y.includes("country")&&(r.country=h.short_name)}),r}function _m({id:i,label:r,hint:h,error:y,required:s,className:p,onChange:E,onPlaceSelect:A,value:R,...C}){const P=H.useRef(null),D=H.useRef(null),q=H.useRef(null),rl=H.useRef(null),[ul,il]=H.useState(!0),[cl,ol]=H.useState(R||""),[U,Z]=H.useState([]),[O,V]=H.useState(!1),[K,W]=H.useState(-1),I=H.useRef([]),B=H.useRef(!1),Y=H.useRef(-1);H.useEffect(()=>{I.current=U},[U]),H.useEffect(()=>{B.current=O},[O]),H.useEffect(()=>{Y.current=K},[K]),H.useEffect(()=>{R!==void 0&&ol(String(R))},[R]);const w=H.useRef(null);H.useEffect(()=>{if(!P.current)return;let $=!0;return hm().then(()=>{!$||!P.current||(D.current=new google.maps.places.AutocompleteService,q.current=new google.maps.places.PlacesService(document.createElement("div")),il(!1))}).catch(z=>{console.error("Error loading Google Maps:",z),il(!1)}),()=>{$=!1,w.current&&clearTimeout(w.current)}},[]);const G=$=>{const z=$.target.value;if(ol(z),E?.(z),w.current&&clearTimeout(w.current),z.length<3){Z([]),V(!1);return}w.current=setTimeout(()=>{D.current&&D.current.getPlacePredictions({input:z,types:["address"]},(M,j)=>{j===google.maps.places.PlacesServiceStatus.OK&&M?(Z(M),V(!0),W(-1)):(Z([]),V(!1))})},300)},hl=$=>{if(!B.current||I.current.length===0){$.key==="Escape"&&(V(!1),B.current=!1);return}switch($.key){case"ArrowDown":$.preventDefault(),W(z=>{const M=z<I.current.length-1?z+1:z;return Y.current=M,M});break;case"ArrowUp":$.preventDefault(),W(z=>{const M=z>0?z-1:-1;return Y.current=M,M});break;case"Enter":$.preventDefault(),Y.current>=0&&Y.current<I.current.length&&yl(I.current[Y.current]);break;case"Escape":$.preventDefault(),V(!1),B.current=!1;break}};H.useEffect(()=>{const $=z=>{rl.current&&!rl.current.contains(z.target)&&P.current&&!P.current.contains(z.target)&&(V(!1),B.current=!1)};if(O)return document.addEventListener("mousedown",$),()=>{document.removeEventListener("mousedown",$)}},[O]);const yl=$=>{q.current&&q.current.getDetails({placeId:$.place_id,fields:["address_components","formatted_address","geometry"]},(z,M)=>{if(M===google.maps.places.PlacesServiceStatus.OK&&z){const j=z.formatted_address||"";ol(j),V(!1),Z([]),B.current=!1;const el=ym(z);E?.(j,el),A?.(z)}})};return g.jsx(At,{id:i,label:r,hint:h,error:y,required:s,className:p,children:g.jsxs("div",{className:"relative",children:[g.jsx("input",{ref:P,id:i,type:"text",className:`form-input ${y?"input-error":""}`,value:cl,onChange:G,onKeyDown:hl,"aria-invalid":!!y,"aria-describedby":[h?`${i}-hint`:null,y?`${i}-error`:null].filter(Boolean).join(" ")||void 0,required:s,autoComplete:"street-address",placeholder:C.placeholder||"Enter an address",disabled:ul||C.disabled,...C}),ul&&g.jsx("p",{className:"mt-1 text-sm text-slate-500",children:"Loading address suggestions..."}),O&&U.length>0&&g.jsx("div",{ref:rl,className:"absolute z-50 w-full mt-1 bg-white border border-slate-200 rounded-lg shadow-lg max-h-60 overflow-y-auto",role:"listbox",children:U.map(($,z)=>g.jsxs("div",{className:`px-4 py-3 cursor-pointer transition-colors ${z===K?"bg-blue-50 text-slate-900":"bg-white text-slate-900 hover:bg-slate-50"} ${z<U.length-1?"border-b border-slate-100":""}`,role:"option","aria-selected":z===K,onClick:()=>yl($),onMouseEnter:()=>W(z),children:[g.jsx("div",{className:"font-medium text-slate-900",children:$.structured_formatting.main_text}),$.structured_formatting.secondary_text&&g.jsx("div",{className:"text-sm text-slate-500 mt-0.5",children:$.structured_formatting.secondary_text})]},$.place_id))})]})})}function ri(i){return i.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/(^-|-$)/g,"")}function Cf(i,r){return i.key??`${ri(i.question)}-${r}`}function Gn(i,r){const h={},y=s=>s==null||typeof s=="string"&&s.trim()==="";return i.forEach((s,p)=>{const E=Cf(s,p),A=r[E];if(s.required)switch(s.inputType){case"checkbox":A!==!0&&(h[E]="Required");break;case"radio":case"select":y(A)&&(h[E]="Required");break;case"number":(A==null||typeof A=="string"&&A.trim()==="")&&(h[E]="Required");break;case"date":case"email":case"tel":case"url":case"password":case"text":case"textarea":case"address":default:y(A)&&(h[E]="Required");break}}),h}function vm(i){if(i===""||i===null||i===void 0)return;const r=Number(i);return Number.isNaN(r)?void 0:r}function Zf(i){return typeof i=="number"&&Number.isFinite(i)?i:typeof i=="string"&&i.trim()!==""&&!Number.isNaN(Number(i))?Number(i):null}function Vf(i){if(i instanceof Date&&!Number.isNaN(i.getTime()))return i.getTime();if(typeof i=="string"){const r=Date.parse(i);return Number.isNaN(r)?null:r}return null}function Kf(i,r){const h=Zf(i),y=Zf(r);if(h!=null&&y!=null)return h-y;const s=Vf(i),p=Vf(r);return s!=null&&p!=null?s-p:i==null||r==null?null:String(i).localeCompare(String(r))}function gm(i,r){return Array.isArray(i)?i.some(h=>h===r):typeof i=="string"?r!=null&&i.includes(String(r)):!1}function Ha(i,r,h){switch(r){case"equals":return i===h;case"lessThan":{const y=Kf(i,h);return y!=null&&y<0}case"greaterThan":{const y=Kf(i,h);return y!=null&&y>0}case"contains":return gm(i,h);case"startsWith":return i!=null&&h!=null&&String(i).startsWith(String(h));case"endsWith":return i!=null&&h!=null&&String(i).endsWith(String(h));default:return!1}}function oi(i,r){return r.reduce((h,y)=>h?.[y],i)}function $t(i,r,h){if(r.length===0)return i;const[y,...s]=r;if(s.length===0){if(typeof y=="number"){const C=(Array.isArray(i)?i:[]).slice();return C[y]=h,C}return{...i,[y]:h}}const p=i?.[y],E=typeof s[0]=="number"?Array.isArray(p)?p:[]:p&&typeof p=="object"?p:{},A=$t(E,s,h);if(typeof y=="number"){const C=(Array.isArray(i)?i:[]).slice();return C[y]=A,C}return{...i,[y]:A}}function Qa(i,r,h){return oi(i,[...r??[],h])}function bm(i,r,h,y){return $t(i,[...r??[],h],y)}const pm="__items",Xn=i=>`${i}${pm}`;function Sm(i){const r=(h,y)=>h.map((s,p)=>{const E=y.length?y.join("__"):"root",A=s.key??`${E}__q${p}_${String(s.question).slice(0,24).replace(/\W+/g,"-")||"field"}`,C=(s.conditionals??[]).map((P,D)=>{const q=P.conditionalQuestions?r(P.conditionalQuestions,[...y,`${A}__c${D}`]):void 0;return{...P,conditionalQuestions:q}});return{...s,key:A,conditionals:C}});return r(i,[])}function Ft(i){return i==null?"":typeof i=="string"?i:String(i)}function xm(i){return i==null?"":typeof i=="number"&&Number.isFinite(i)||typeof i=="string"?i:""}function Am(i){return i==null?"":typeof i=="string"||typeof i=="number"?i:String(i)}function Tm({questions:i,initialValues:r,controlledValues:h,onChangeValues:y,onSubmit:s}){const p=H.useMemo(()=>Sm(i),[i]),E=H.useMemo(()=>{const U={};return r&&Object.assign(U,r),U},[r]),[A,R]=H.useState(E);H.useEffect(()=>{R(E)},[E]);const[C,P]=H.useState({}),D=H.useMemo(()=>({...C,...h??A}),[C,h,A]);H.useEffect(()=>{h&&P(U=>({...U,...h}))},[h]);const[q,rl]=H.useState({});function ul(U,Z){const O=U.key,V=U.question,K=Qa(D,Z,O),W=q[O],I=B=>{let Y=bm(D,Z,O,B);if(U.inputType==="radio"&&U.conditionals){const w=U.conditionals??[];for(const G of w){const hl=Qa(D,Z,O),yl=Ha(hl,G.conditionalType,G.conditionalValue),$=Ha(B,G.conditionalType,G.conditionalValue);if(yl&&!$&&G.conditionalQuestionsAllowMultiple){const z=G.conditionalQuestions??[];if(z.length>0){const M=Xn(O);Y=$t(Y,[...Z??[],M],[]);const j=(el,_l)=>{el.forEach(Nl=>{(Nl.conditionals??[]).forEach(fl=>{if(fl.conditionalQuestionsAllowMultiple){const Ml=Xn(Nl.key);Y=$t(Y,[..._l,Ml],[])}const F=fl.conditionalQuestions??[];F.length>0&&j(F,_l)})})};j(z,[...Z??[],M])}}}}h&&y?y(Y):R(Y),P(Y)};switch(U.inputType){case"text":return g.jsx(em,{id:O,label:V,value:Ft(K),onChange:B=>I(B.currentTarget.value),"aria-required":U.required||void 0,error:W},O);case"email":return g.jsx(nm,{id:O,label:V,value:Ft(K),onChange:B=>I(B.currentTarget.value),"aria-required":U.required||void 0,error:W},O);case"password":return g.jsx(cm,{id:O,label:V,value:Ft(K),onChange:B=>I(B.currentTarget.value),"aria-required":U.required||void 0,error:W},O);case"tel":return g.jsxs(g.Fragment,{children:[g.jsx(um,{id:O,label:V,value:Ft(K),onChange:B=>I(B.currentTarget.value),"aria-required":U.required||void 0,error:W},O),O==="phone"&&g.jsxs("div",{className:"mt-3 text-xs text-slate-600 space-y-1",children:[g.jsx("p",{children:"By entering your phone number, you agree to receive a one-time SMS from Credify Insurance with a verification code."}),g.jsx("p",{children:"Message & data rates may apply. One message per request."}),g.jsxs("p",{children:["See our"," ",g.jsx("a",{href:"https://getcredify.com",target:"_blank",rel:"noopener noreferrer",className:"underline hover:text-slate-800",children:"Privacy Policy"})," ","and"," ",g.jsx("a",{href:"https://getcredify.com",target:"_blank",rel:"noopener noreferrer",className:"underline hover:text-slate-800",children:"Terms of Service"}),"."]})]})]});case"url":return g.jsx(im,{id:O,label:V,value:Ft(K),onChange:B=>I(B.currentTarget.value),"aria-required":U.required||void 0,error:W},O);case"number":return g.jsx(am,{id:O,label:V,value:xm(K),onChange:B=>I(vm(B.currentTarget.value)),"aria-required":U.required||void 0,error:W},O);case"textarea":return g.jsx(fm,{id:O,label:V,value:Ft(K),onChange:B=>I(B.currentTarget.value),"aria-required":U.required||void 0,error:W,rows:4},O);case"date":return g.jsx(sm,{id:O,label:V,value:Ft(K),onChange:B=>I(B.currentTarget.value),"aria-required":U.required||void 0,error:W},O);case"checkbox":{if(U.options){const B=Array.isArray(K)?K:[];return g.jsxs("div",{className:"space-y-2",children:[g.jsxs("div",{className:"form-label",children:[V,U.required&&g.jsx("span",{className:"text-red-600 ml-1",children:"*"})]}),g.jsx("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:U.options.map(Y=>{const w=`${O}-${ri(Y)}`,G=B.includes(Y);return g.jsx(Xf,{id:w,label:Y,checked:G,onChange:hl=>{const yl=new Set(B);hl.currentTarget.checked?yl.add(Y):yl.delete(Y),I(Array.from(yl))},"aria-required":U.required||void 0},w)})}),W&&g.jsx("p",{className:"mt-1 text-sm text-red-600",children:W})]},O)}return g.jsx(Xf,{id:O,label:U.required?`${V} *`:V,checked:!!K,onChange:B=>I(B.currentTarget.checked),"aria-required":U.required||void 0},O)}case"radio":{const B=U.options??[],Y=Z&&Z.length>0?`${O}__${Z.join("__")}`:O;return g.jsx(om,{legend:V,legendClassName:U.required?"legend-required":void 0,children:B.map(w=>g.jsx(rm,{name:Y,value:w,checked:K===w,onChange:()=>I(w),children:w},`${O}-${ri(w)}`))},O)}case"select":{let B=U.options??[];return O==="quote_vehicle_id"&&(B=h?.vehicles__items?.map(Y=>Y.vin)??[]),g.jsx(dm,{id:O,label:V,"aria-required":U.required||void 0,error:W,value:Am(K),onChange:Y=>I(Y.currentTarget.value),placeholder:"Select an option",options:B.map(Y=>({value:Y,label:Y}))},O)}case"address":return g.jsx(_m,{id:O,label:V,value:Ft(K),onChange:B=>I(B),"aria-required":U.required||void 0,error:W},O);default:return null}}function il(U,Z){return U.map((O,V)=>{const K=String(O.key),W=ul(O,Z),I=O.conditionals??[];if(!I.length)return g.jsx("div",{children:W},`wrap-${K}-${V}`);const B=Qa(D,Z,K),Y=I.filter(G=>Ha(B,G.conditionalType,G.conditionalValue)),w=Y.length>1&&!Y.some(G=>G.conditionalQuestionsAllowMultiple)?Y.slice(0,1):Y;return g.jsxs("div",{children:[W,w.map((G,hl)=>{const yl=G.conditionalQuestions??[];if(!yl.length)return null;if(!G.conditionalQuestionsAllowMultiple)return g.jsx("div",{className:"mt-3",children:il(yl,Z)},`branch-${K}-${hl}`);const $=Xn(K),z=oi(D,[...Z??[],$])??[],M=Math.max(1,z.length||1),j=()=>{const Nl=$t(D,[...Z??[],$,z.length],{});h&&y?y(Nl):R(Nl),P(Nl)},el=()=>{const Nl=z.slice(0,Math.max(0,z.length-1)),Tl=$t(D,[...Z??[],$],Nl);h&&y?y(Tl):R(Tl),P(Tl)},_l=`${K}__c${hl}`;return g.jsxs("div",{className:"mt-3",children:[g.jsxs("div",{className:"flex items-center justify-between mb-2",children:[g.jsx("div",{className:"text-sm font-medium opacity-75",children:"Add one or more entries"}),g.jsxs("div",{className:"space-x-2",children:[g.jsx("button",{type:"button",className:"btn-outline px-3 py-1",onClick:j,children:"Add another"}),M>1&&g.jsx("button",{type:"button",className:"btn-outline px-3 py-1",onClick:el,children:"Remove last"})]})]}),Array.from({length:M}).map((Nl,Tl)=>{const fl=[...Z??[],$,Tl],F=`${_l}__i${Tl}`;return g.jsxs("div",{className:"rounded-lg border p-3 mb-3",children:[g.jsxs("div",{className:"text-sm font-semibold mb-2",children:["Entry #",Tl+1]}),yl.map(Ml=>g.jsxs("div",{className:"mt-3",children:[ul(Ml,fl),(()=>{const Pt=Ml.conditionals??[];if(!Pt.length)return null;const Et=Qa(D,fl,Ml.key),Rt=Pt.filter(Wl=>Ha(Et,Wl.conditionalType,Wl.conditionalValue));return(Rt.length>1&&!Rt.some(Wl=>Wl.conditionalQuestionsAllowMultiple)?Rt.slice(0,1):Rt).map((Wl,Ne)=>{const le=Wl.conditionalQuestions??[];if(!le.length)return null;if(!Wl.conditionalQuestionsAllowMultiple)return g.jsx("div",{className:"mt-3",children:il(le,fl)},`nested-${F}-${Ne}`);const te=Xn(Ml.key),ee=oi(D,[...fl,te])??[],qe=Math.max(1,ee.length||1),bi=()=>{const Vl=$t(D,[...fl,te,ee.length],{});h&&y?y(Vl):R(Vl),P(Vl)},pi=()=>{const Vl=ee.slice(0,Math.max(0,ee.length-1)),Bt=$t(D,[...fl,te],Vl);h&&y?y(Bt):R(Bt),P(Bt)};return g.jsxs("div",{className:"mt-3",children:[g.jsxs("div",{className:"flex items-center justify-between mb-2",children:[g.jsx("div",{className:"text-sm font-medium opacity-75",children:"Add one or more entries"}),g.jsxs("div",{className:"space-x-2",children:[g.jsx("button",{type:"button",className:"btn-outline px-3 py-1",onClick:bi,children:"Add another"}),qe>1&&g.jsx("button",{type:"button",className:"btn-outline px-3 py-1",onClick:pi,children:"Remove last"})]})]}),Array.from({length:qe}).map((Vl,Bt)=>{const Kn=[...fl,te,Bt];return g.jsxs("div",{className:"rounded-lg border p-3 mb-3",children:[g.jsxs("div",{className:"text-sm font-semibold mb-2",children:["Entry #",Bt+1]}),il(le,Kn)]},`nested-item-${F}-${Ne}-${Bt}`)})]},`nested-repeat-${F}-${Ne}`)})})()]},`${F}-${String(Ml.key)}`))]},`group-${F}`)})]},`branch-${K}-${hl}`)})]},`wrap-${K}-${V}`)})}const cl=H.useMemo(()=>{const U=[],Z=(O,V)=>{O.forEach(K=>{U.push(K);const W=String(K.key),I=K.conditionals??[];if(!I.length)return;const B=Qa(D,V,W),Y=I.filter(G=>Ha(B,G.conditionalType,G.conditionalValue));(Y.length>1&&!Y.some(G=>G.conditionalQuestionsAllowMultiple)?Y.slice(0,1):Y).forEach(G=>{const hl=G.conditionalQuestions??[];hl.length&&(G.conditionalQuestionsAllowMultiple||Z(hl,V))})})};return Z(p),U},[p,D]);function ol(U){U.preventDefault();const Z=Gn(cl,D);if(rl(Z),Object.keys(Z).length>0){const O=cl.findIndex(V=>Z[V.key]);O>=0&&document.getElementById(cl[O].key)?.focus();return}s(D)}return g.jsx("form",{className:"space-y-6 px-1",onSubmit:ol,noValidate:!0,children:il(p)})}function wf(i){return typeof i=="number"&&Number.isFinite(i)?i:typeof i=="string"&&i.trim()!==""&&!Number.isNaN(Number(i))?Number(i):null}function Lf(i){if(i instanceof Date&&!Number.isNaN(i.getTime()))return i.getTime();if(typeof i=="string"){const r=Date.parse(i);return Number.isNaN(r)?null:r}return null}function Jf(i,r){const h=wf(i),y=wf(r);if(h!=null&&y!=null)return h-y;const s=Lf(i),p=Lf(r);return s!=null&&p!=null?s-p:i==null||r==null?null:String(i).localeCompare(String(r))}function Em(i,r){return Array.isArray(i)?i.some(h=>h===r):typeof i=="string"?r!=null&&i.includes(String(r)):!1}function qf(i,r,h){switch(r){case"equals":return i===h;case"lessThan":{const y=Jf(i,h);return y!=null&&y<0}case"greaterThan":{const y=Jf(i,h);return y!=null&&y>0}case"contains":return Em(i,h);case"startsWith":return i!=null&&h!=null&&String(i).startsWith(String(h));case"endsWith":return i!=null&&h!=null&&String(i).endsWith(String(h));default:return!1}}function kf(i,r){const h=[];return(s=>{s.forEach(p=>{h.push(p);const E=String(p.key),A=r[E],R=p.conditionals??[];if(!R.length)return;const C=R.filter(D=>qf(A,D.conditionalType,D.conditionalValue));(C.length>1&&!C.some(D=>D.conditionalQuestionsAllowMultiple)?C.slice(0,1):C).forEach(D=>{const q=D.conditionalQuestions??[];q.length&&(D.conditionalQuestionsAllowMultiple||q.forEach(rl=>h.push(rl)))})})})(i),h}const Wf="__items",$f=i=>`${i}${Wf}`;function di(i,r){for(const h of i){const y=String(h.key),s=r[y],p=h.conditionals??[];if(!p.length)continue;const E=p.filter(R=>qf(s,R.conditionalType,R.conditionalValue)),A=E.length>1&&!E.some(R=>R.conditionalQuestionsAllowMultiple)?E.slice(0,1):E;for(const R of A){const C=R.conditionalQuestions??[];if(!C.length)continue;if(!R.conditionalQuestionsAllowMultiple){if(di(C,r))return!0;continue}const P=r[$f(y)]??[];if(P.length===0)return!0;for(const D of P){const q=Gn(C,D);if(Object.values(q).some(Boolean)||di(C,D))return!0}}}return!1}function Ff(i,r){return di(i,r)}function zm({stages:i,onStageComplete:r,onComplete:h,initialValues:y,initialActive:s}){const[p,E]=H.useState(s??0),[A,R]=H.useState(y??{}),[C,P]=H.useState({}),[D,q]=H.useState(!1),[rl,ul]=H.useState(!1),[il,cl]=H.useState(null),ol=H.useRef([]),U=Array.isArray(i)&&i.length>0,Z=U?i[Math.min(p,i.length-1)]:null,O=Z?.key??null;H.useEffect(()=>{s!==void 0&&E(s)},[s]),H.useEffect(()=>{const w=ol.current[p];w&&w.scrollIntoView({behavior:"smooth",block:"nearest",inline:"center"})},[p]),H.useEffect(()=>{y!==void 0&&R(y)},[y]),H.useEffect(()=>{if(!Z||!O){q(!1),cl(null);return}if(C[O]){q(!1),cl(null);return}let w=!1;return q(!0),cl(null),Promise.resolve(Z.loadQuestions()).then(G=>{if(!w){if(!Array.isArray(G))throw new Error(`loadQuestions("${O}") did not return an array`);P(hl=>({...hl,[O]:G}))}}).catch(G=>{w||cl(`Failed to load stage "${Z?.title??""}": ${G?.message??"Unknown error"}`)}).finally(()=>{w||q(!1)}),()=>{w=!0}},[Z,O,C]);const V=O?C[O]:void 0,K=H.useMemo(()=>{if(!V)return{};const w={};(yl=>{const $=[],z=M=>{M.forEach((j,el)=>{const _l=Cf(j,el);$.push(_l);const Nl=$f(_l);$.push(Nl),(j.conditionals??[]).forEach(fl=>{const F=fl.conditionalQuestions??[];F.length>0&&z(F)})})};return z(yl),$})(V).forEach(yl=>{yl in A&&(w[yl]=A[yl])});for(const[yl,$]of Object.entries(A))yl.endsWith(Wf)&&!(yl in w)&&(w[yl]=$);return w},[V,A]),W=w=>{R(G=>({...G,...w}))},I=()=>{E(w=>w>0?w-1:0),document.querySelector(".panel-body")?.scrollTo({top:0,behavior:"instant"})},B=async()=>{if(!V||!Z||D||il||rl)return;const w=kf(V,A),G=Gn(w,A),hl=Object.values(G).some(Boolean),yl=Ff(V,A);if(!(hl||yl)){ul(!0);try{const $=Math.min(p+1,i.length-1),z=p>=i.length-1,{success:M,error:j}=z?await h(A,O??""):await r(K,O??"");if(!M){cl(j??"An error occurred");return}z||E($)}finally{ul(!1)}}},Y=H.useMemo(()=>{if(!V||D||il||rl)return!0;const w=kf(V,A),G=Gn(w,A),hl=Object.values(G).some(Boolean),yl=Ff(V,A);return hl||yl},[V,A,D,il,rl]);return U?g.jsxs("div",{className:"space-y-6",children:[g.jsxs("div",{className:"flex items-center justify-between gap-4",children:[g.jsx("ol",{className:"flex gap-2 text-xs overflow-x-auto flex-1 pb-1 scrollbar-hide items-center",style:{scrollbarWidth:"none",msOverflowStyle:"none"},children:i.flatMap((w,G)=>[g.jsx("li",{ref:hl=>{ol.current[G]=hl},className:`px-2.5 py-1 rounded-full border whitespace-nowrap flex-shrink-0 ${G<p?"bg-blue-600 text-white border-blue-600":G===p?"border-blue-600 text-blue-600 bg-white":"border-slate-200 text-slate-600"}`,children:w.title},w.key??`stage-${G}`),...G<i.length-1?[g.jsx("li",{className:"text-slate-400 flex-shrink-0",children:"→"},`arrow-${w.key??G}`)]:[]])}),g.jsxs("div",{className:"text-sm text-slate-500 flex-shrink-0",children:[Math.min(p+1,i.length)," / ",i.length]})]}),g.jsxs("div",{children:[D&&g.jsx("div",{className:"text-slate-500",children:"Loading…"}),Z&&g.jsx(Tm,{questions:V??[],controlledValues:K,onChangeValues:W,onSubmit:()=>B()},Z.key)]}),!D&&il&&g.jsxs("div",{className:"text-red-600 text-sm -mt-4",children:[g.jsx("div",{children:il}),Z&&g.jsx("button",{type:"button",className:"underline mt-1 font-bold",onClick:()=>{P(w=>{if(!O)return w;const G={...w};return delete G[O],G})},children:"Retry"})]}),g.jsxs("div",{className:p>0?"grid grid-cols-2 gap-3":"",children:[p>0&&g.jsx("button",{type:"button",onClick:I,disabled:D,className:"h-12 rounded-full border border-gray-300 text-text-primary hover:bg-gray-50 transition",children:"Back"}),g.jsxs("button",{type:"button",onClick:B,disabled:Y,className:[p>0?"":"w-full","h-12 rounded-full text-white transition","disabled:opacity-50 disabled:cursor-not-allowed","flex items-center justify-center gap-2",Y?"bg-gray-300":"bg-blue-600 hover:bg-blue-600/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-600/40 bg-primary hover:bg-primary/90 focus-visible:ring-primary/40"].join(" "),children:[rl&&g.jsxs("svg",{className:"animate-spin h-5 w-5 text-white",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[g.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),g.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),p===i.length-1?"Finish":"Next"]})]})]}):g.jsx("div",{className:"text-slate-600",children:"Loading..."})}const mi="credify_quote_id",hi="credify_auth_token";function Nm(i){try{localStorage.setItem(mi,i)}catch(r){console.error("Failed to save quoteId to localStorage:",r)}}function Mm(){try{return localStorage.getItem(mi)}catch(i){return console.error("Failed to load quoteId from localStorage:",i),null}}function If(){try{localStorage.removeItem(mi)}catch(i){console.error("Failed to clear quoteId from localStorage:",i)}}function Dm(i){try{localStorage.setItem(hi,i)}catch(r){console.error("Failed to save authToken to localStorage:",r)}}function Om(){try{return localStorage.getItem(hi)}catch(i){return console.error("Failed to load authToken from localStorage:",i),null}}function Pf(){try{localStorage.removeItem(hi)}catch(i){console.error("Failed to clear authToken from localStorage:",i)}}function jm(){If(),Pf()}const jt="https://api.getcredify.com";let Je=null;function Um(i){Je=i,Dm(i)}function Cn(){return Je}function yi(){const i=Om();i&&(Je=i)}function ls(){Je=null,Pf()}async function Ut(i,r){const h={"Content-Type":"application/json"};Je&&(h.Authorization=`Bearer ${Je}`);const y=await fetch(i,{method:"POST",headers:h,body:JSON.stringify(r)});if(!y.ok){let s=`Request failed with status ${y.status}`;try{s=(await y.json()).error||s}catch{s=y.statusText||s}const p=new Error(s);throw p.statusCode=y.status,p}return y}async function Rm(i){return await(await Ut(`${jt}/get-questions-by-stage`,{stage:i})).json()}async function _i(){return await(await Ut(`${jt}/get-stages-for-quote`,{})).json()}async function Bm(i){const h=await(await Ut(`${jt}/create-quote`,{phone:i})).json();if(!h||typeof h!="object"||!h.quoteId)throw new Error(`Invalid createQuote response: ${JSON.stringify(h)}`);return h}async function Ya(i,r,h){const y={payload:i,getRates:r};return h&&typeof h=="string"&&h.trim()!==""&&(y.quoteId=h),await(await Ut(`${jt}/update-quote`,y)).json()}async function Hm(i,r){return await(await Ut(`${jt}/verify-quote`,{quoteId:i,smsCode:r})).json()}async function Qm(i){return await(await Ut(`${jt}/is-supported-state`,{state:i})).json()}async function Ym(){return await(await Ut(`${jt}/get-rates`,{})).json()}async function Gm(i){const r=i?{quoteId:i}:{};return await(await Ut(`${jt}/get-quote`,r)).json()}async function Xm(i){const h=await(await Ut(`${jt}/request-bind`,{quoteRateId:i})).json();return h&&typeof h=="object"&&"success"in h?h:{success:!0}}const Cm=new Intl.NumberFormat("en-US",{style:"currency",currency:"USD"});function ts({onBack:i}){return g.jsx("button",{type:"button",onClick:i,className:"mt-4 h-12 rounded-full border border-gray-300 text-text-primary hover:bg-gray-50 transition w-full",children:"Back"})}function Zm({rates:i,onBack:r}){const h=Array.isArray(i)&&i.length>0,[y,s]=H.useState({});return H.useEffect(()=>{yi()},[]),h?g.jsxs("section",{className:"mt-8",children:[g.jsx("h3",{className:"text-lg font-semibold text-slate-900",children:"Rates"}),g.jsx("div",{className:"mt-4 grid gap-4 sm:grid-cols-2 lg:grid-cols-3",children:i.map(p=>{const E=p.premium_cents/100,A=Cm.format(E),R=p.quote_rate_id,C=y[R]??"idle",P=C==="loading",D=C==="success",q=async()=>{s(rl=>({...rl,[R]:"loading"}));try{if(yi(),!Cn())throw new Error("Authentication required. Please verify your phone number first.");if(!((await Xm(p.quote_rate_id))?.success!==!1))throw new Error("Request failed");jm(),ls(),s(cl=>({...cl,[R]:"success"}))}catch{s(rl=>({...rl,[R]:"error"}))}};return g.jsxs("div",{className:"flex flex-col rounded-xl border border-slate-200 bg-white p-6 shadow-sm transition hover:shadow-md",children:[g.jsxs("div",{className:"mb-4 flex items-center gap-3",children:[p.carrier_logo_base64?g.jsx("img",{src:`data:image/png;base64,${p.carrier_logo_base64}`,alt:p.carrier_name,className:"h-12 w-auto object-contain"}):g.jsx("div",{className:"flex h-12 w-12 items-center justify-center rounded-md bg-slate-100 text-sm font-semibold text-slate-500",children:p.carrier_name.charAt(0).toUpperCase()}),g.jsx("div",{className:"flex-1",children:g.jsx("h4",{className:"font-semibold text-slate-900",children:p.carrier_name})})]}),g.jsxs("div",{className:"mb-2",children:[g.jsx("p",{className:"text-sm text-slate-500",children:"Premium"}),g.jsx("p",{className:"text-2xl font-bold text-slate-900",children:A})]}),g.jsxs("div",{className:"mb-4",children:[g.jsx("p",{className:"text-sm text-slate-500",children:"Term"}),g.jsxs("p",{className:"font-medium text-slate-700",children:[p.term_months," months"]})]}),p.carrier_quote_id&&g.jsx("div",{className:"mb-4",children:g.jsxs("p",{className:"text-xs text-slate-400",children:["Quote ID: ",p.carrier_quote_id]})}),g.jsxs("div",{className:"mt-auto pt-4",children:[g.jsx("button",{type:"button",onClick:q,disabled:P||D,className:`w-full rounded-full px-4 py-2.5 text-sm font-semibold transition focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-600/40 ${D?"bg-emerald-500 text-white":"bg-blue-600 text-white hover:bg-blue-600/90 disabled:bg-slate-300 disabled:text-slate-500 disabled:cursor-not-allowed"}`,children:P?"Requesting…":D?"Requested":"Request Bind"}),C==="error"&&g.jsx("p",{className:"mt-2 text-xs text-red-600",children:"Something went wrong. Please try again."}),C==="success"&&g.jsx("p",{className:"mt-2 text-xs text-emerald-600",children:"We received your bind request."})]})]},R)})}),r&&g.jsx(ts,{onBack:r})]}):g.jsxs("section",{className:"mt-8",children:[g.jsx("h3",{className:"text-lg font-semibold text-slate-900",children:"Rates"}),g.jsx("p",{className:"mt-2 text-sm text-slate-500",children:"No rates are available at this time."}),r&&g.jsx(ts,{onBack:r})]})}function zl(i){if(i===!0)return"Yes";if(i===!1)return"No"}function Tt(i){if(i)try{const r=typeof i=="string"?new Date(i):i;return isNaN(r.getTime())?void 0:r.toISOString().split("T")[0]}catch{return}}function Vm(i){const r={};i.phone&&(r.phone=i.phone),i.first_name&&(r.first_name=i.first_name),i.last_name&&(r.last_name=i.last_name),i.email&&(r.email=i.email),i.date_of_birth&&(r.date_of_birth=Tt(i.date_of_birth)),i.product&&(r.product=i.product),i.state&&(r.state=i.state);const h=[];i.line_1&&h.push(i.line_1),i.line_2&&h.push(i.line_2),i.city&&h.push(i.city),i.state&&h.push(i.state),i.postal_code&&h.push(i.postal_code),h.length>0&&(r.address=h.join(", ")),i.years_at_address!==null&&i.years_at_address!==void 0&&(r.years_at_address=i.years_at_address),i.months_at_address!==null&&i.months_at_address!==void 0&&(r.months_at_address=i.months_at_address),i.move_in_date&&(r.move_in_date=Tt(i.move_in_date));const y=[];return i.prior_line_1&&y.push(i.prior_line_1),i.prior_line_2&&y.push(i.prior_line_2),i.prior_city&&y.push(i.prior_city),i.prior_state&&y.push(i.prior_state),i.prior_postal_code&&y.push(i.prior_postal_code),y.length>0&&(r.prior_address=y.join(", ")),i.years_at_prior_address!==null&&i.years_at_prior_address!==void 0&&(r.years_at_prior_address=i.years_at_prior_address),i.auto_has_prior_insurance!==null&&i.auto_has_prior_insurance!==void 0&&(r.auto_has_prior_insurance=zl(i.auto_has_prior_insurance)),i.auto_prior_expiration_date&&(r.auto_prior_expiration_date=Tt(i.auto_prior_expiration_date)),i.auto_prior_carrier_name&&(r.auto_prior_carrier_name=i.auto_prior_carrier_name),i.auto_prior_liability_limit&&(r.auto_prior_liability_limit=i.auto_prior_liability_limit),i.auto_reason_for_no_insurance&&(r.auto_reason_for_no_insurance=i.auto_reason_for_no_insurance),i.auto_prior_years!==null&&i.auto_prior_years!==void 0&&(r.auto_prior_years=i.auto_prior_years),i.auto_prior_months!==null&&i.auto_prior_months!==void 0&&(r.auto_prior_months=i.auto_prior_months),i.auto_continuous_coverage_years!==null&&i.auto_continuous_coverage_years!==void 0&&(r.auto_continuous_coverage_years=i.auto_continuous_coverage_years),i.auto_cancelled_declined_refused_to_renew!==null&&i.auto_cancelled_declined_refused_to_renew!==void 0&&(r.auto_cancelled_declined_refused_to_renew=zl(i.auto_cancelled_declined_refused_to_renew)),i.home_has_prior_insurance!==null&&i.home_has_prior_insurance!==void 0&&(r.home_has_prior_insurance=zl(i.home_has_prior_insurance)),i.home_prior_expiration_date&&(r.home_prior_expiration_date=Tt(i.home_prior_expiration_date)),i.home_prior_carrier_name&&(r.home_prior_carrier_name=i.home_prior_carrier_name),i.year_built!==null&&i.year_built!==void 0&&(r.year_built=i.year_built),i.number_of_units!==null&&i.number_of_units!==void 0&&(r.number_of_units=i.number_of_units),i.number_of_stories!==null&&i.number_of_stories!==void 0&&(r.number_of_stories=i.number_of_stories),i.number_of_beds!==null&&i.number_of_beds!==void 0&&(r.number_of_beds=i.number_of_beds),i.number_of_full_baths!==null&&i.number_of_full_baths!==void 0&&(r.number_of_full_baths=i.number_of_full_baths),i.number_of_partial_baths!==null&&i.number_of_partial_baths!==void 0&&(r.number_of_partial_baths=i.number_of_partial_baths),i.under_construction!==null&&i.under_construction!==void 0&&(r.under_construction=zl(i.under_construction)),i.distance_from_fire_hydrant_ft&&(r.distance_from_fire_hydrant_ft=i.distance_from_fire_hydrant_ft),i.distance_from_fire_station_miles&&(r.distance_from_fire_station_miles=i.distance_from_fire_station_miles),i.architectural_style&&(r.architectural_style=i.architectural_style),i.dwelling_type&&(r.dwelling_type=i.dwelling_type),i.construction_quality&&(r.construction_quality=i.construction_quality),i.located_over_water!==null&&i.located_over_water!==void 0&&(r.located_over_water=i.located_over_water),i.construction_type&&(r.construction_type=i.construction_type),i.exterior_wall_type&&(r.exterior_wall_type=i.exterior_wall_type),i.foundation_type&&(r.foundation_type=i.foundation_type),i.roof_material_type&&(r.roof_material_type=i.roof_material_type),i.year_roof_updated!==null&&i.year_roof_updated!==void 0&&(r.year_roof_updated=i.year_roof_updated),i.heating_type&&(r.heating_type=i.heating_type),i.heating_fuel_type&&(r.heating_fuel_type=i.heating_fuel_type),i.number_of_fireplaces!==null&&i.number_of_fireplaces!==void 0&&(r.number_of_fireplaces=i.number_of_fireplaces),i.basement_type&&(r.basement_type=i.basement_type),i.parking_type&&(r.parking_type=i.parking_type),i.number_of_parking_spaces!==null&&i.number_of_parking_spaces!==void 0&&(r.number_of_parking_spaces=i.number_of_parking_spaces),i.plumbing_type&&(r.plumbing_type=i.plumbing_type),i.pool_type&&(r.pool_type=i.pool_type),i.total_area_sq_ft!==null&&i.total_area_sq_ft!==void 0&&(r.total_area_sq_ft=i.total_area_sq_ft),i.parcel_area_sq_ft!==null&&i.parcel_area_sq_ft!==void 0&&(r.parcel_area_sq_ft=i.parcel_area_sq_ft),i.residence_type&&(r.residence_type=i.residence_type),i.usage_type&&(r.usage_type=i.usage_type),i.household_size!==null&&i.household_size!==void 0&&(r.household_size=i.household_size),i.number_of_mortgagees!==null&&i.number_of_mortgagees!==void 0&&(r.number_of_mortgagees=i.number_of_mortgagees),i.has_dog!==null&&i.has_dog!==void 0&&(r.has_dog=zl(i.has_dog)),i.dog_breed_type&&(r.dog_breed_type=i.dog_breed_type),i.number_of_dogs!==null&&i.number_of_dogs!==void 0&&(r.number_of_dogs=i.number_of_dogs),i.has_business_on_premises!==null&&i.has_business_on_premises!==void 0&&(r.has_business_on_premises=zl(i.has_business_on_premises)),i.business_class&&(r.business_class=i.business_class),i.retiree_discount!==null&&i.retiree_discount!==void 0&&(r.retiree_discount=zl(i.retiree_discount)),i.gated_community_discount!==null&&i.gated_community_discount!==void 0&&(r.gated_community_discount=zl(i.gated_community_discount)),i.multi_policy_discount!==null&&i.multi_policy_discount!==void 0&&(r.multi_policy_discount=zl(i.multi_policy_discount)),i.non_smoker_discount!==null&&i.non_smoker_discount!==void 0&&(r.non_smoker_discount=zl(i.non_smoker_discount)),i.first_time_buyer_discount!==null&&i.first_time_buyer_discount!==void 0&&(r.first_time_buyer_discount=zl(i.first_time_buyer_discount)),i.fire_detection_system!==null&&i.fire_detection_system!==void 0&&(r.fire_detection_system=zl(i.fire_detection_system)),i.burglar_alarm_system!==null&&i.burglar_alarm_system!==void 0&&(r.burglar_alarm_system=zl(i.burglar_alarm_system)),i.burglar_alarm_system_type&&(r.burglar_alarm_system_type=i.burglar_alarm_system_type),i.smoke_detectors!==null&&i.smoke_detectors!==void 0&&(r.smoke_detectors=zl(i.smoke_detectors)),i.sprinkler_system!==null&&i.sprinkler_system!==void 0&&(r.sprinkler_system=zl(i.sprinkler_system)),i.sprinkler_system_type&&(r.sprinkler_system_type=i.sprinkler_system_type),i.gas_leakage_detector!==null&&i.gas_leakage_detector!==void 0&&(r.gas_leakage_detector=zl(i.gas_leakage_detector)),i.deadbolt_locks!==null&&i.deadbolt_locks!==void 0&&(r.deadbolt_locks=zl(i.deadbolt_locks)),i.fire_extinguisher!==null&&i.fire_extinguisher!==void 0&&(r.fire_extinguisher=zl(i.fire_extinguisher)),i.order_credit_authorized!==null&&i.order_credit_authorized!==void 0&&(r.order_credit_authorized=zl(i.order_credit_authorized)),i.has_health_insurance_auto_accident!==null&&i.has_health_insurance_auto_accident!==void 0&&(r.has_health_insurance_auto_accident=zl(i.has_health_insurance_auto_accident)),i.named_insured_foreclosure_repo_bankruptcy!==null&&i.named_insured_foreclosure_repo_bankruptcy!==void 0&&(r.named_insured_foreclosure_repo_bankruptcy=zl(i.named_insured_foreclosure_repo_bankruptcy)),i.named_insured_convicted_insurance_fraud!==null&&i.named_insured_convicted_insurance_fraud!==void 0&&(r.named_insured_convicted_insurance_fraud=zl(i.named_insured_convicted_insurance_fraud)),i.drivers&&i.drivers.length>0?(r.drivers="Yes",r.drivers__items=i.drivers.map(s=>{const p={};return s.first_name&&(p.first_name=s.first_name),s.last_name&&(p.last_name=s.last_name),s.date_of_birth&&(p.date_of_birth=Tt(s.date_of_birth)),s.gender&&(p.gender=s.gender),s.marital_status&&(p.marital_status=s.marital_status),s.relationship_to_insured&&(p.relationship_to_insured=s.relationship_to_insured),s.license_state&&(p.license_state=s.license_state),s.license_status&&(p.license_status=s.license_status),s.license_number&&(p.license_number=s.license_number),s.date_first_licensed&&(p.date_first_licensed=Tt(s.date_first_licensed)),s.education_level&&(p.education_level=s.education_level),s.occupation&&(p.occupation=s.occupation),s.industry&&(p.industry=s.industry),s.driver_violations&&s.driver_violations.length>0&&(p.driver_violations__items=s.driver_violations.map(E=>{const A={};return E.code&&(A.code=E.code),E.occurred_at&&(A.occurred_at=Tt(E.occurred_at)),A})),s.driver_accidents&&s.driver_accidents.length>0&&(p.driver_accidents__items=s.driver_accidents.map(E=>{const A={};return E.occurred_at&&(A.occurred_at=Tt(E.occurred_at)),E.description&&(A.description=E.description),E.quote_vehicle_id&&(A.quote_vehicle_id=E.quote_vehicle_id),E.property_damage_amount_paid_cents!==null&&E.property_damage_amount_paid_cents!==void 0&&(A.property_damage_amount_paid_cents=E.property_damage_amount_paid_cents),E.personal_injury_amount_paid_cents!==null&&E.personal_injury_amount_paid_cents!==void 0&&(A.personal_injury_amount_paid_cents=E.personal_injury_amount_paid_cents),A})),s.losses&&s.losses.length>0&&(p.losses=s.losses.map(E=>{const A={};return E.description&&(A.description=E.description),E.date_of_incident&&(A.date_of_incident=Tt(E.date_of_incident)),E.amount_paid_cents!==null&&E.amount_paid_cents!==void 0&&(A.amount_paid_cents=E.amount_paid_cents),E.quote_vehicle_id&&(A.quote_vehicle_id=E.quote_vehicle_id),A})),p})):r.drivers="No",i.vehicles&&i.vehicles.length>0?(r.vehicles="Yes",r.vehicles__items=i.vehicles.map(s=>{const p={};s.vin&&(p.vin=s.vin),s.year!==null&&s.year!==void 0&&(p.year=s.year),s.make&&(p.make=s.make),s.model&&(p.model=s.model),s.ownership_type&&(p.ownership_type=s.ownership_type),s.usage&&(p.usage=s.usage),s.annual_mileage!==null&&s.annual_mileage!==void 0&&(p.annual_mileage=s.annual_mileage),s.miles_to_work!==null&&s.miles_to_work!==void 0&&(p.miles_to_work=s.miles_to_work),s.percent_to_work!==null&&s.percent_to_work!==void 0&&(p.percent_to_work=s.percent_to_work);const E=[];return s.garaging_address_line_1&&E.push(s.garaging_address_line_1),s.garaging_address_line_2&&E.push(s.garaging_address_line_2),s.garaging_address_city&&E.push(s.garaging_address_city),s.garaging_address_state&&E.push(s.garaging_address_state),s.garaging_address_postal_code&&E.push(s.garaging_address_postal_code),E.length>0&&(p.garaging_address=E.join(", ")),s.anti_theft_type&&(p.anti_theft_type=s.anti_theft_type),s.passive_restraint_type&&(p.passive_restraint_type=s.passive_restraint_type),s.coverages&&s.coverages.length>0&&(p.coverages__items=s.coverages.map(A=>{const R={};return A.type&&(R.type=A.type),A.per_person_limit_cents!==null&&A.per_person_limit_cents!==void 0&&(R.per_person_limit_cents=A.per_person_limit_cents),A.per_incident_limit_cents!==null&&A.per_incident_limit_cents!==void 0&&(R.per_incident_limit_cents=A.per_incident_limit_cents),A.per_incident_limit_percent!==null&&A.per_incident_limit_percent!==void 0&&(R.per_incident_limit_percent=A.per_incident_limit_percent),A.per_day_limit_cents!==null&&A.per_day_limit_cents!==void 0&&(R.per_day_limit_cents=A.per_day_limit_cents),A.deductible_cents!==null&&A.deductible_cents!==void 0&&(R.deductible_cents=A.deductible_cents),A.is_declined!==null&&A.is_declined!==void 0&&(R.is_declined=zl(A.is_declined)),R})),s.vehicle_lienholders&&s.vehicle_lienholders.length>0&&(p.vehicle_lienholders__items=s.vehicle_lienholders.map(A=>{const R={};return A.name&&(R.name=A.name),A.type&&(R.type=A.type),A.line_1&&(R.line_1=A.line_1),A.line_2&&(R.line_2=A.line_2),A.city&&(R.city=A.city),A.state&&(R.state=A.state),A.postal_code&&(R.postal_code=A.postal_code),A.phone&&(R.phone=A.phone),A.fax&&(R.fax=A.fax),R})),p})):r.vehicles="No",i.losses&&i.losses.length>0&&(r.home_losses__items=i.losses.map(s=>{const p={};return s.description&&(p.description=s.description),s.date_of_incident&&(p.date_of_incident=Tt(s.date_of_incident)),s.amount_paid_cents!==null&&s.amount_paid_cents!==void 0&&(p.amount_paid_cents=s.amount_paid_cents),p})),r}function vi(i){const r={},h=p=>{if(typeof p=="string"){if(p==="Yes")return!0;if(p==="No")return!1}return p},y=Object.keys(i).filter(p=>!p.includes("__items")),s=new Set;for(const[p,E]of Object.entries(i))p.endsWith("__items")&&Array.isArray(E)&&E.forEach(A=>{typeof A=="object"&&A!==null&&Object.keys(A).forEach(R=>{s.add(R)})});for(const[p,E]of Object.entries(i))if(p.endsWith("__items")){const A=p.replace("__items","");if(y.includes(A)){const C=Array.isArray(E)?E.map(P=>vi(P)):E;r[A]=C}}else p.includes("__items")||s.has(p)||(r[p]=h(E));return r}function Km({isOpen:i,onClose:r}){const[h,y]=H.useState([]),[s,p]=H.useState(null),[E,A]=H.useState(null),[R,C]=H.useState(null),[P,D]=H.useState(void 0),[q,rl]=H.useState(!1);function ul(cl){const ol={SMSVerification:"Verify",AutoCurrentCarrier:"Current Auto Policy",HomeCurrentCarrier:"Current Home Policy"};return cl.map(U=>({key:U,title:ol[U]||U,loadQuestions:async()=>(await Rm(U)).questions}))}H.useEffect(()=>{i&&(async()=>{try{const ol=Mm();if(yi(),ol){rl(!0),p(ol);try{const U=Cn(),Z=await Gm(U?void 0:ol);if(!Z||!Z.quote)throw new Error("Invalid response from getQuote: missing quote data");const{quote:O}=Z,{stages:V}=await _i(),K=ul(V);y(K);try{const W=Vm(O);C(W)}catch(W){throw new Error(`Failed to transform quote data: ${W instanceof Error?W.message:"Unknown error"}`)}if(O.current_stage){const W=K.findIndex(I=>I.key===O.current_stage);W>=0?D(W):D(K.length-1)}else D(K.length-1)}catch(U){U.statusCode===404?(If(),p(null)):ls()}finally{rl(!1)}}else{const{stages:U}=await _i();y(ul(U))}}catch{rl(!1)}})()},[i]),H.useEffect(()=>{if(!i)return;const{overflow:cl}=document.body.style;return document.body.style.overflow="hidden",()=>{document.body.style.overflow=cl}},[i]);const il=H.useCallback(cl=>{cl.key==="Escape"&&r()},[r]);return H.useEffect(()=>{if(i)return window.addEventListener("keydown",il),()=>window.removeEventListener("keydown",il)},[i,il]),H.useEffect(()=>{i||(C(null),D(void 0),rl(!1))},[i]),i?g.jsxs("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center",role:"dialog","aria-modal":"true","aria-labelledby":"insurance-modal-title",children:[g.jsx("div",{className:"backdrop",onClick:r}),g.jsxs("div",{className:"modal-panel bg-white relative w-full max-w-2xl flex flex-col max-h-[90vh] overflow-hidden",role:"document",children:[g.jsx("button",{onClick:r,className:"absolute top-4 right-4 text-slate-400 hover:text-slate-600 text-xl","aria-label":"Close",type:"button",children:"×"}),g.jsxs("div",{className:"text-center mb-6",children:[g.jsx("h2",{id:"insurance-modal-title",className:"h1-title",children:"Let's get you the best insurance rates."}),g.jsx("p",{className:"p-subtitle",children:"This should only take a few minutes."})]}),g.jsxs("div",{className:"panel-body flex-1 min-h-0 overflow-y-auto",children:[!E&&g.jsx(g.Fragment,{children:q||h.length===0?g.jsx("div",{className:"flex items-center justify-center py-12",children:g.jsx("div",{className:"text-slate-600",children:"Loading..."})}):g.jsx(zm,{stages:h,initialValues:R??void 0,initialActive:P,onStageComplete:async(cl,ol)=>{try{const U=vi(cl),{stages:Z}=await _i(),O=ul(Z);y(O);const K=O.findIndex(B=>B.key===ol)+1,I=(K<O.length?O[K]:null)?.key||ol;if(s)if(ol==="SMSVerification"){const{isVerified:B,token:Y}=await Hm(s,U.sms_code);if(!B)throw new Error("Invalid SMS code");Y&&Um(Y),await Ya({current_stage:I},!1)}else if(ol==="State"){const{isSupported:B}=await Qm(U.state);if(!B)throw new Error("State is not supported");const Y=Cn();await Ya({...U,current_stage:I},!1,Y?void 0:s)}else{const B=Cn();await Ya({...U,current_stage:I},!1,B?void 0:s||void 0)}else{const Y=(await Bm(U.phone))?.quoteId;if(!Y||typeof Y!="string"||Y.trim()==="")throw new Error(`Failed to create quote - invalid quoteId returned: ${Y}`);p(Y),Nm(Y),await Ya({current_stage:I},!1,Y)}return{success:!0}}catch(U){return{success:!1,error:U instanceof Error?U.message:"An error occurred"}}},onComplete:async cl=>{try{const ol=vi(cl);if(!s)throw new Error("Quote ID is required");await Ya(ol,!0),C(cl);const{rates:U}=await Ym();return A(U),{success:!0}}catch(ol){return{success:!1,error:ol instanceof Error?ol.message:"An error occurred"}}}})})," ",E&&s&&g.jsx(Zm,{rates:E,onBack:()=>A(null)})]}),g.jsx("div",{className:"mt-4 pt-4 border-t border-slate-200",children:g.jsx("p",{className:"text-center text-sm text-slate-500",children:"Insurance products offered through Credify Corporation, a licensed insurance agency."})})]})]}):null}function wm({isOpen:i}){return g.jsx(Km,{isOpen:i,onClose:()=>{Vn.close()}})}let It=null,Ga=null,Zn=!1;function Lm(){It||(It=document.createElement("div"),It.id="insurance-widget-root",document.body.appendChild(It),Ga=Pd.createRoot(It))}function gi(){Lm(),Ga.render(H.createElement(wm,{isOpen:Zn}))}function Jm(){Ga&&It&&(Ga.unmount(),It.remove()),Ga=null,It=null}const Vn={init:i=>{Zn=!!i?.autoOpen,gi()},open:()=>{Zn=!0,gi()},close:()=>{Zn=!1,gi()},destroy:Jm};typeof window<"u"&&(window.CredifyInsuranceWidget=Vn),bt.CredifyInsuranceWidget=Vn,bt.default=Vn,Object.defineProperties(bt,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
34
34
  //# sourceMappingURL=index.umd.js.map