@getcredify/credify-insurance-widget 1.5.2 → 1.5.4
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/credify-insurance-widget.css +1 -1
- package/dist/iframe/assets/{iframe-BEDGs5Rs.css → iframe-B0dgbWwb.css} +1 -1
- package/dist/iframe/assets/{iframe-nHL8IPfa.js → iframe-B5bZiVO8.js} +2 -2
- package/dist/iframe/assets/{iframe-nHL8IPfa.js.map → iframe-B5bZiVO8.js.map} +1 -1
- package/dist/iframe/iframe.html +2 -2
- package/dist/index.es.js +252 -248
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/package.json +2 -2
package/dist/index.umd.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(){if(typeof K>"u")var K={env:{}}})();(function(K,_){typeof exports=="object"&&typeof module<"u"?_(exports,require("react"),require("react-dom/client"),require("react/jsx-runtime")):typeof define=="function"&&define.amd?define(["exports","react","react-dom/client","react/jsx-runtime"],_):(K=typeof globalThis<"u"?globalThis:K||self,_(K.CredifyInsuranceWidget={},K.React,K.ReactDOM,K.React))})(this,(function(K,_,Ge,i){"use strict";function z({id:e,label:t,hint:r,error:s,required:n,className:a,children:l}){return i.jsxs("div",{className:a,children:[i.jsxs("label",{htmlFor:e,className:"form-label",children:[t," ",n&&i.jsx("span",{className:"text-red-600",children:"*"})]}),l,r&&!s&&i.jsx("p",{id:`${e}-hint`,className:"mt-1 text-sm text-slate-500",children:r}),s&&i.jsx("p",{id:`${e}-error`,className:"mt-1 text-sm text-red-600",children:s})]})}function He({id:e,label:t,hint:r,error:s,required:n,className:a,...l}){return i.jsx(z,{id:e,label:t,hint:r,error:s,required:n,className:a,children:i.jsx("input",{id:e,className:`form-input ${s?"input-error":""}`,"aria-invalid":!!s,"aria-describedby":[r?`${e}-hint`:null,s?`${e}-error`:null].filter(Boolean).join(" ")||void 0,required:n,...l,type:"text"})})}function Je({id:e,label:t,hint:r,error:s,required:n,className:a,...l}){return i.jsx(z,{id:e,label:t,hint:r,error:s,required:n,className:a,children:i.jsx("input",{id:e,type:"number",className:`form-input ${s?"input-error":""}`,"aria-invalid":!!s,"aria-describedby":[r?`${e}-hint`:null,s?`${e}-error`:null].filter(Boolean).join(" ")||void 0,required:n,...l})})}function Xe({id:e,label:t,hint:r,error:s,required:n,className:a,...l}){return i.jsx(z,{id:e,label:t,hint:r,error:s,required:n,className:a,children:i.jsx("input",{id:e,type:"email",className:`form-input ${s?"input-error":""}`,inputMode:"email",autoComplete:"email",required:n,"aria-invalid":!!s,"aria-describedby":[r?`${e}-hint`:null,s?`${e}-error`:null].filter(Boolean).join(" ")||void 0,...l})})}function me(e){const t=e.replace(/\D/g,"");if(t.length===10)return`(${t.slice(0,3)}) ${t.slice(3,6)} - ${t.slice(6)}`;if(t.length>10){const r=t.slice(0,10);return`(${r.slice(0,3)}) ${r.slice(3,6)} - ${r.slice(6)}`}return t.length>=6?`(${t.slice(0,3)}) ${t.slice(3,6)} - ${t.slice(6)}`:t.length>=3?`(${t.slice(0,3)}) ${t.slice(3)}`:t.length>0?`(${t}`:t}function ge(e){return e.replace(/\D/g,"")}function Ze({id:e,label:t,hint:r,error:s,required:n,className:a,value:l="",onChange:o,...u}){const[v,k]=_.useState(""),m=_.useRef(null),E=_.useRef(0);_.useEffect(()=>{if(!l){k("");return}let M=ge(l);M.length===11&&M.startsWith("1")&&(M=M.slice(1));const j=M.slice(0,10);k(me(j))},[l]);const I=M=>{const j=M.target,A=j.value;E.current=j.selectionStart||0;const d=ge(A).slice(0,10),g=me(d);k(g);const c=d.length===10?`+1${d}`:d,b={...M,currentTarget:{...M.currentTarget,value:c},target:{...M.target,value:c}};o?.(b),setTimeout(()=>{if(m.current){const w=A.slice(0,E.current),$=ge(w),S=me($),f=Math.min(S.length,g.length);m.current.setSelectionRange(f,f)}},0)};return i.jsx(z,{id:e,label:t,hint:r,error:s,required:n,className:a,children:i.jsxs("div",{className:`tel-input-wrapper flex items-center border rounded-lg transition-colors w-full relative ${s?"border-red-500 error":"border-[var(--accent-color)] focus-within:border-[var(--primary-color)]"}`,children:[i.jsx("label",{htmlFor:e,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"}),i.jsx("input",{ref:m,id:e,type:"tel",className:`flex-1 px-4 py-3 border-0 rounded-r-lg outline-none bg-transparent text-[var(--text-primary)] text-base ${s?"input-error":""}`,inputMode:"tel",autoComplete:"tel",required:n,"aria-invalid":!!s,"aria-describedby":[r?`${e}-hint`:null,s?`${e}-error`:null].filter(Boolean).join(" ")||void 0,value:v,onChange:I,...u})]})})}function Re({id:e,label:t,hint:r,error:s,required:n,className:a,...l}){return i.jsx(z,{id:e,label:t,hint:r,error:s,required:n,className:a,children:i.jsx("input",{id:e,type:"url",className:`form-input ${s?"input-error":""}`,inputMode:"url",autoComplete:"url",required:n,"aria-invalid":!!s,"aria-describedby":[r?`${e}-hint`:null,s?`${e}-error`:null].filter(Boolean).join(" ")||void 0,...l})})}function qe({id:e,label:t,hint:r,error:s,required:n,className:a,...l}){return i.jsx(z,{id:e,label:t,hint:r,error:s,required:n,className:a,children:i.jsx("input",{id:e,type:"password",className:`form-input ${s?"input-error":""}`,autoComplete:"current-password",required:n,"aria-invalid":!!s,"aria-describedby":[r?`${e}-hint`:null,s?`${e}-error`:null].filter(Boolean).join(" ")||void 0,...l})})}function et({id:e,label:t,hint:r,error:s,required:n,className:a,rows:l=4,...o}){return i.jsx(z,{id:e,label:t,hint:r,error:s,required:n,className:a,children:i.jsx("textarea",{id:e,rows:l,className:`form-input ${s?"input-error":""}`,"aria-invalid":!!s,"aria-describedby":[r?`${e}-hint`:null,s?`${e}-error`:null].filter(Boolean).join(" ")||void 0,required:n,...o})})}function tt({id:e,label:t,hint:r,error:s,required:n,className:a,...l}){return i.jsx(z,{id:e,label:t,hint:r,error:s,required:n,className:a,children:i.jsx("input",{id:e,type:"date",className:`form-input ${s?"input-error":""}`,"aria-invalid":!!s,"aria-describedby":[r?`${e}-hint`:null,s?`${e}-error`:null].filter(Boolean).join(" ")||void 0,required:n,...l})})}function Ae({id:e,label:t,className:r,...s}){return i.jsxs("label",{className:`checkbox-card ${r||""}`,htmlFor:e,children:[i.jsx("input",{id:e,type:"checkbox",className:"checkbox-input",...s}),i.jsx("span",{className:"checkbox-label",children:t})]})}function nt({name:e,value:t,checked:r,onChange:s,children:n}){return i.jsxs("label",{className:"radio-card",children:[i.jsx("input",{className:"radio-input",type:"radio",name:e,value:t,checked:r,onChange:s}),i.jsx("span",{className:"radio-label",children:n})]})}function rt({legend:e,children:t,className:r,legendClassName:s}){return i.jsxs("fieldset",{className:r,children:[i.jsx("legend",{className:`mb-4 text-base font-medium ${s||""}`,style:{color:"var(--text-primary)"},children:e}),i.jsx("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2",children:t})]})}function st({id:e,label:t,hint:r,error:s,required:n,className:a,placeholder:l,options:o,children:u,...v}){const k=[r?`${e}-hint`:null,s?`${e}-error`:null].filter(Boolean).join(" ")||void 0,m=!!u;return i.jsx(z,{id:e,label:t,hint:r,error:s,required:n,className:a,children:i.jsxs("select",{id:e,className:`form-input select-caret ${s?"input-error":""}`,"aria-invalid":!!s,"aria-describedby":k,required:n,...v,children:[l&&i.jsx("option",{value:"",disabled:!0,selected:!("value"in v),children:l}),m?u:o?.map(E=>i.jsx("option",{value:E.value,disabled:E.disabled,children:E.label},E.value))]})})}const it="AIzaSyDjLdKLxoa-maLNGAyq_I_2r_Fe_TzFikw";function at(){return new Promise((e,t)=>{if(window.google?.maps?.places){e();return}const r=document.querySelector('script[src*="maps.googleapis.com"]');if(r){r.addEventListener("load",()=>e()),r.addEventListener("error",()=>t(new Error("Failed to load Google Maps script")));return}const s=document.createElement("script");s.src=`https://maps.googleapis.com/maps/api/js?key=${it}&libraries=places`,s.async=!0,s.defer=!0,s.onload=()=>e(),s.onerror=()=>t(new Error("Failed to load Google Maps script")),document.head.appendChild(s)})}function ot(e){const t={fullAddress:e.formatted_address};return e.address_components&&e.address_components.forEach(r=>{const s=r.types;s.includes("street_number")&&(t.streetNumber=r.long_name),s.includes("route")&&(t.streetName=r.long_name),s.includes("locality")&&(t.city=r.long_name),s.includes("administrative_area_level_1")&&(t.state=r.short_name),s.includes("postal_code")&&(t.zipCode=r.long_name),s.includes("country")&&(t.country=r.short_name)}),t}function lt({id:e,label:t,hint:r,error:s,required:n,className:a,onChange:l,onPlaceSelect:o,value:u,...v}){const k=_.useRef(null),m=_.useRef(null),E=_.useRef(null),I=_.useRef(null),[M,j]=_.useState(!0),[A,T]=_.useState(u||""),[d,g]=_.useState([]),[c,b]=_.useState(!1),[w,$]=_.useState(-1),S=_.useRef([]),f=_.useRef(!1),p=_.useRef(-1);_.useEffect(()=>{S.current=d},[d]),_.useEffect(()=>{f.current=c},[c]),_.useEffect(()=>{p.current=w},[w]),_.useEffect(()=>{u!==void 0&&T(String(u))},[u]);const h=_.useRef(null);_.useEffect(()=>{if(!k.current)return;let N=!0;return at().then(()=>{!N||!k.current||(m.current=new google.maps.places.AutocompleteService,E.current=new google.maps.places.PlacesService(document.createElement("div")),j(!1))}).catch(x=>{console.error("Error loading Google Maps:",x),j(!1)}),()=>{N=!1,h.current&&clearTimeout(h.current)}},[]);const y=N=>{const x=N.target.value;if(T(x),l?.(x),h.current&&clearTimeout(h.current),x.length<3){g([]),b(!1);return}h.current=setTimeout(()=>{m.current&&m.current.getPlacePredictions({input:x,types:["address"]},(B,D)=>{D===google.maps.places.PlacesServiceStatus.OK&&B?(g(B),b(!0),$(-1)):(g([]),b(!1))})},300)},F=N=>{if(!f.current||S.current.length===0){N.key==="Escape"&&(b(!1),f.current=!1);return}switch(N.key){case"ArrowDown":N.preventDefault(),$(x=>{const B=x<S.current.length-1?x+1:x;return p.current=B,B});break;case"ArrowUp":N.preventDefault(),$(x=>{const B=x>0?x-1:-1;return p.current=B,B});break;case"Enter":N.preventDefault(),p.current>=0&&p.current<S.current.length&&C(S.current[p.current]);break;case"Escape":N.preventDefault(),b(!1),f.current=!1;break}};_.useEffect(()=>{const N=x=>{I.current&&!I.current.contains(x.target)&&k.current&&!k.current.contains(x.target)&&(b(!1),f.current=!1)};if(c)return document.addEventListener("mousedown",N),()=>{document.removeEventListener("mousedown",N)}},[c]);const C=N=>{E.current&&E.current.getDetails({placeId:N.place_id,fields:["address_components","formatted_address","geometry"]},(x,B)=>{if(B===google.maps.places.PlacesServiceStatus.OK&&x){const D=x.formatted_address||"";T(D),b(!1),g([]),f.current=!1;const Z=ot(x);l?.(D,Z),o?.(x)}})};return i.jsx(z,{id:e,label:t,hint:r,error:s,required:n,className:a,children:i.jsxs("div",{className:"relative",children:[i.jsx("input",{ref:k,id:e,type:"text",className:`form-input ${s?"input-error":""}`,value:A,onChange:y,onKeyDown:F,"aria-invalid":!!s,"aria-describedby":[r?`${e}-hint`:null,s?`${e}-error`:null].filter(Boolean).join(" ")||void 0,required:n,autoComplete:"street-address",placeholder:v.placeholder||"Enter an address",disabled:M||v.disabled,...v}),M&&i.jsx("p",{className:"mt-1 text-sm text-slate-500",children:"Loading address suggestions..."}),c&&d.length>0&&i.jsx("div",{ref:I,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:d.map((N,x)=>i.jsxs("div",{className:`px-4 py-3 cursor-pointer transition-colors ${x===w?"bg-blue-50 text-slate-900":"bg-white text-slate-900 hover:bg-slate-50"} ${x<d.length-1?"border-b border-slate-100":""}`,role:"option","aria-selected":x===w,onClick:()=>C(N),onMouseEnter:()=>$(x),children:[i.jsx("div",{className:"font-medium text-slate-900",children:N.structured_formatting.main_text}),N.structured_formatting.secondary_text&&i.jsx("div",{className:"text-sm text-slate-500 mt-0.5",children:N.structured_formatting.secondary_text})]},N.place_id))})]})})}function he(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/(^-|-$)/g,"")}function Ce(e,t){return e.key??`${he(e.question)}-${t}`}function oe(e,t){const r={},s=n=>n==null||typeof n=="string"&&n.trim()==="";return e.forEach((n,a)=>{const l=Ce(n,a),o=t[l];if(n.required)switch(n.inputType){case"checkbox":o!==!0&&(r[l]="Required");break;case"radio":case"select":s(o)&&(r[l]="Required");break;case"number":(o==null||typeof o=="string"&&o.trim()==="")&&(r[l]="Required");break;case"date":case"email":case"tel":case"url":case"password":case"text":case"textarea":case"address":default:s(o)&&(r[l]="Required");break}}),r}function ct(e){if(e===""||e===null||e===void 0)return;const t=Number(e);return Number.isNaN(t)?void 0:t}function Te(e){return typeof e=="number"&&Number.isFinite(e)?e:typeof e=="string"&&e.trim()!==""&&!Number.isNaN(Number(e))?Number(e):null}function Ie(e){if(e instanceof Date&&!Number.isNaN(e.getTime()))return e.getTime();if(typeof e=="string"){const t=Date.parse(e);return Number.isNaN(t)?null:t}return null}function Me(e,t){const r=Te(e),s=Te(t);if(r!=null&&s!=null)return r-s;const n=Ie(e),a=Ie(t);return n!=null&&a!=null?n-a:e==null||t==null?null:String(e).localeCompare(String(t))}function dt(e,t){return Array.isArray(e)?e.some(r=>r===t):typeof e=="string"?t!=null&&e.includes(String(t)):!1}function se(e,t,r){switch(t){case"equals":return e===r;case"lessThan":{const s=Me(e,r);return s!=null&&s<0}case"greaterThan":{const s=Me(e,r);return s!=null&&s>0}case"contains":return dt(e,r);case"startsWith":return e!=null&&r!=null&&String(e).startsWith(String(r));case"endsWith":return e!=null&&r!=null&&String(e).endsWith(String(r));default:return!1}}function ye(e,t){return t.reduce((r,s)=>r?.[s],e)}function H(e,t,r){if(t.length===0)return e;const[s,...n]=t;if(n.length===0){if(typeof s=="number"){const v=(Array.isArray(e)?e:[]).slice();return v[s]=r,v}return{...e,[s]:r}}const a=e?.[s],l=typeof n[0]=="number"?Array.isArray(a)?a:[]:a&&typeof a=="object"?a:{},o=H(l,n,r);if(typeof s=="number"){const v=(Array.isArray(e)?e:[]).slice();return v[s]=o,v}return{...e,[s]:o}}function ie(e,t,r){return ye(e,[...t??[],r])}function ut(e,t,r,s){return H(e,[...t??[],r],s)}const _t="__items",le=e=>`${e}${_t}`;function ft(e){const t=(r,s)=>r.map((n,a)=>{const l=s.length?s.join("__"):"root",o=n.key??`${l}__q${a}_${String(n.question).slice(0,24).replace(/\W+/g,"-")||"field"}`,v=(n.conditionals??[]).map((k,m)=>{const E=k.conditionalQuestions?t(k.conditionalQuestions,[...s,`${o}__c${m}`]):void 0;return{...k,conditionalQuestions:E}});return{...n,key:o,conditionals:v}});return t(e,[])}function J(e){return e==null?"":typeof e=="string"?e:String(e)}function pt(e){return e==null?"":typeof e=="number"&&Number.isFinite(e)||typeof e=="string"?e:""}function mt(e){return e==null?"":typeof e=="string"||typeof e=="number"?e:String(e)}function gt({questions:e,initialValues:t,controlledValues:r,onChangeValues:s,onSubmit:n}){const a=_.useMemo(()=>ft(e),[e]),l=_.useMemo(()=>{const d={};return t&&Object.assign(d,t),d},[t]),[o,u]=_.useState(l);_.useEffect(()=>{u(l)},[l]);const[v,k]=_.useState({}),m=_.useMemo(()=>({...v,...r??o}),[v,r,o]);_.useEffect(()=>{r&&k(d=>({...d,...r}))},[r]);const[E,I]=_.useState({});function M(d,g){const c=d.key,b=d.question,w=ie(m,g,c),$=E[c],S=f=>{let p=ut(m,g,c,f);if(d.inputType==="radio"&&d.conditionals){const h=d.conditionals??[];for(const y of h){const F=ie(m,g,c),C=se(F,y.conditionalType,y.conditionalValue),N=se(f,y.conditionalType,y.conditionalValue);if(C&&!N&&y.conditionalQuestionsAllowMultiple){const x=y.conditionalQuestions??[];if(x.length>0){const B=le(c);p=H(p,[...g??[],B],[]);const D=(Z,R)=>{Z.forEach(L=>{(L.conditionals??[]).forEach(W=>{if(W.conditionalQuestionsAllowMultiple){const q=le(L.key);p=H(p,[...R,q],[])}const O=W.conditionalQuestions??[];O.length>0&&D(O,R)})})};D(x,[...g??[],B])}}}}r&&s?s(p):u(p),k(p)};switch(d.inputType){case"text":return i.jsx(He,{id:c,label:b,value:J(w),onChange:f=>S(f.currentTarget.value),"aria-required":d.required||void 0,error:$},c);case"email":return i.jsx(Xe,{id:c,label:b,value:J(w),onChange:f=>S(f.currentTarget.value),"aria-required":d.required||void 0,error:$},c);case"password":return i.jsx(qe,{id:c,label:b,value:J(w),onChange:f=>S(f.currentTarget.value),"aria-required":d.required||void 0,error:$},c);case"tel":return i.jsxs(i.Fragment,{children:[i.jsx(Ze,{id:c,label:b,value:J(w),onChange:f=>S(f.currentTarget.value),"aria-required":d.required||void 0,error:$},c),c==="phone"&&i.jsxs("div",{className:"mt-3 text-xs text-slate-600 space-y-1",children:[i.jsx("p",{children:"By entering your phone number, you agree to receive a one-time SMS from Credify Insurance with a verification code."}),i.jsx("p",{children:"Message & data rates may apply. One message per request."}),i.jsxs("p",{children:["See our"," ",i.jsx("a",{href:"https://getcredify.com",target:"_blank",rel:"noopener noreferrer",className:"underline hover:text-slate-800",children:"Privacy Policy"})," ","and"," ",i.jsx("a",{href:"https://getcredify.com",target:"_blank",rel:"noopener noreferrer",className:"underline hover:text-slate-800",children:"Terms of Service"}),"."]})]})]});case"url":return i.jsx(Re,{id:c,label:b,value:J(w),onChange:f=>S(f.currentTarget.value),"aria-required":d.required||void 0,error:$},c);case"number":return i.jsx(Je,{id:c,label:b,value:pt(w),onChange:f=>S(ct(f.currentTarget.value)),"aria-required":d.required||void 0,error:$},c);case"textarea":return i.jsx(et,{id:c,label:b,value:J(w),onChange:f=>S(f.currentTarget.value),"aria-required":d.required||void 0,error:$,rows:4},c);case"date":return i.jsx(tt,{id:c,label:b,value:J(w),onChange:f=>S(f.currentTarget.value),"aria-required":d.required||void 0,error:$},c);case"checkbox":{if(d.options){const f=Array.isArray(w)?w:[];return i.jsxs("div",{className:"space-y-2",children:[i.jsxs("div",{className:"form-label",children:[b,d.required&&i.jsx("span",{className:"text-red-600 ml-1",children:"*"})]}),i.jsx("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:d.options.map(p=>{const h=`${c}-${he(p)}`,y=f.includes(p);return i.jsx(Ae,{id:h,label:p,checked:y,onChange:F=>{const C=new Set(f);F.currentTarget.checked?C.add(p):C.delete(p),S(Array.from(C))},"aria-required":d.required||void 0},h)})}),$&&i.jsx("p",{className:"mt-1 text-sm text-red-600",children:$})]},c)}return i.jsx(Ae,{id:c,label:d.required?`${b} *`:b,checked:!!w,onChange:f=>S(f.currentTarget.checked),"aria-required":d.required||void 0},c)}case"radio":{const f=d.options??[],p=g&&g.length>0?`${c}__${g.join("__")}`:c;return i.jsx(rt,{legend:b,legendClassName:d.required?"legend-required":void 0,children:f.map(h=>i.jsx(nt,{name:p,value:h,checked:w===h,onChange:()=>S(h),children:h},`${c}-${he(h)}`))},c)}case"select":{let f=d.options??[];return c==="quote_vehicle_id"&&(f=r?.vehicles__items?.map(p=>p.vin)??[]),i.jsx(st,{id:c,label:b,"aria-required":d.required||void 0,error:$,value:mt(w),onChange:p=>S(p.currentTarget.value),placeholder:"Select an option",options:f.map(p=>({value:p,label:p}))},c)}case"address":return i.jsx(lt,{id:c,label:b,value:J(w),onChange:f=>S(f),"aria-required":d.required||void 0,error:$},c);default:return null}}function j(d,g){return d.map((c,b)=>{const w=String(c.key),$=M(c,g),S=c.conditionals??[];if(!S.length)return i.jsx("div",{children:$},`wrap-${w}-${b}`);const f=ie(m,g,w),p=S.filter(y=>se(f,y.conditionalType,y.conditionalValue)),h=p.length>1&&!p.some(y=>y.conditionalQuestionsAllowMultiple)?p.slice(0,1):p;return i.jsxs("div",{children:[$,h.map((y,F)=>{const C=y.conditionalQuestions??[];if(!C.length)return null;if(!y.conditionalQuestionsAllowMultiple)return i.jsx("div",{className:"mt-3",children:j(C,g)},`branch-${w}-${F}`);const N=le(w),x=ye(m,[...g??[],N])??[],B=Math.max(1,x.length||1),D=()=>{const L=H(m,[...g??[],N,x.length],{});r&&s?s(L):u(L),k(L)},Z=()=>{const L=x.slice(0,Math.max(0,x.length-1)),G=H(m,[...g??[],N],L);r&&s?s(G):u(G),k(G)},R=`${w}__c${F}`;return i.jsxs("div",{className:"mt-3",children:[i.jsxs("div",{className:"flex items-center justify-between mb-2",children:[i.jsx("div",{className:"text-sm font-medium opacity-75",children:"Add one or more entries"}),i.jsxs("div",{className:"space-x-2",children:[i.jsx("button",{type:"button",className:"btn-outline px-3 py-1",onClick:D,children:"Add another"}),B>1&&i.jsx("button",{type:"button",className:"btn-outline px-3 py-1",onClick:Z,children:"Remove last"})]})]}),Array.from({length:B}).map((L,G)=>{const W=[...g??[],N,G],O=`${R}__i${G}`;return i.jsxs("div",{className:"rounded-lg border p-3 mb-3",children:[i.jsxs("div",{className:"text-sm font-semibold mb-2",children:["Entry #",G+1]}),C.map(q=>i.jsxs("div",{className:"mt-3",children:[M(q,W),(()=>{const Ve=q.conditionals??[];if(!Ve.length)return null;const Wt=ie(m,W,q.key),_e=Ve.filter(ee=>se(Wt,ee.conditionalType,ee.conditionalValue));return(_e.length>1&&!_e.some(ee=>ee.conditionalQuestionsAllowMultiple)?_e.slice(0,1):_e).map((ee,$e)=>{const Ee=ee.conditionalQuestions??[];if(!Ee.length)return null;if(!ee.conditionalQuestionsAllowMultiple)return i.jsx("div",{className:"mt-3",children:j(Ee,W)},`nested-${O}-${$e}`);const fe=le(q.key),pe=ye(m,[...W,fe])??[],Ye=Math.max(1,pe.length||1),Lt=()=>{const re=H(m,[...W,fe,pe.length],{});r&&s?s(re):u(re),k(re)},Ot=()=>{const re=pe.slice(0,Math.max(0,pe.length-1)),te=H(m,[...W,fe],re);r&&s?s(te):u(te),k(te)};return i.jsxs("div",{className:"mt-3",children:[i.jsxs("div",{className:"flex items-center justify-between mb-2",children:[i.jsx("div",{className:"text-sm font-medium opacity-75",children:"Add one or more entries"}),i.jsxs("div",{className:"space-x-2",children:[i.jsx("button",{type:"button",className:"btn-outline px-3 py-1",onClick:Lt,children:"Add another"}),Ye>1&&i.jsx("button",{type:"button",className:"btn-outline px-3 py-1",onClick:Ot,children:"Remove last"})]})]}),Array.from({length:Ye}).map((re,te)=>{const zt=[...W,fe,te];return i.jsxs("div",{className:"rounded-lg border p-3 mb-3",children:[i.jsxs("div",{className:"text-sm font-semibold mb-2",children:["Entry #",te+1]}),j(Ee,zt)]},`nested-item-${O}-${$e}-${te}`)})]},`nested-repeat-${O}-${$e}`)})})()]},`${O}-${String(q.key)}`))]},`group-${O}`)})]},`branch-${w}-${F}`)})]},`wrap-${w}-${b}`)})}const A=_.useMemo(()=>{const d=[],g=(c,b)=>{c.forEach(w=>{d.push(w);const $=String(w.key),S=w.conditionals??[];if(!S.length)return;const f=ie(m,b,$),p=S.filter(y=>se(f,y.conditionalType,y.conditionalValue));(p.length>1&&!p.some(y=>y.conditionalQuestionsAllowMultiple)?p.slice(0,1):p).forEach(y=>{const F=y.conditionalQuestions??[];F.length&&(y.conditionalQuestionsAllowMultiple||g(F,b))})})};return g(a),d},[a,m]);function T(d){d.preventDefault();const g=oe(A,m);if(I(g),Object.keys(g).length>0){const c=A.findIndex(b=>g[b.key]);c>=0&&document.getElementById(A[c].key)?.focus();return}n(m)}return i.jsx("form",{className:"space-y-6 px-1",onSubmit:T,noValidate:!0,children:j(a)})}function Qe(e){return typeof e=="number"&&Number.isFinite(e)?e:typeof e=="string"&&e.trim()!==""&&!Number.isNaN(Number(e))?Number(e):null}function je(e){if(e instanceof Date&&!Number.isNaN(e.getTime()))return e.getTime();if(typeof e=="string"){const t=Date.parse(e);return Number.isNaN(t)?null:t}return null}function Fe(e,t){const r=Qe(e),s=Qe(t);if(r!=null&&s!=null)return r-s;const n=je(e),a=je(t);return n!=null&&a!=null?n-a:e==null||t==null?null:String(e).localeCompare(String(t))}function ht(e,t){return Array.isArray(e)?e.some(r=>r===t):typeof e=="string"?t!=null&&e.includes(String(t)):!1}function Be(e,t,r){switch(t){case"equals":return e===r;case"lessThan":{const s=Fe(e,r);return s!=null&&s<0}case"greaterThan":{const s=Fe(e,r);return s!=null&&s>0}case"contains":return ht(e,r);case"startsWith":return e!=null&&r!=null&&String(e).startsWith(String(r));case"endsWith":return e!=null&&r!=null&&String(e).endsWith(String(r));default:return!1}}function De(e,t){const r=[];return(n=>{n.forEach(a=>{r.push(a);const l=String(a.key),o=t[l],u=a.conditionals??[];if(!u.length)return;const v=u.filter(m=>Be(o,m.conditionalType,m.conditionalValue));(v.length>1&&!v.some(m=>m.conditionalQuestionsAllowMultiple)?v.slice(0,1):v).forEach(m=>{const E=m.conditionalQuestions??[];E.length&&(m.conditionalQuestionsAllowMultiple||E.forEach(I=>r.push(I)))})})})(e),r}const Ke="__items",We=e=>`${e}${Ke}`;function be(e,t){for(const r of e){const s=String(r.key),n=t[s],a=r.conditionals??[];if(!a.length)continue;const l=a.filter(u=>Be(n,u.conditionalType,u.conditionalValue)),o=l.length>1&&!l.some(u=>u.conditionalQuestionsAllowMultiple)?l.slice(0,1):l;for(const u of o){const v=u.conditionalQuestions??[];if(!v.length)continue;if(!u.conditionalQuestionsAllowMultiple){if(be(v,t))return!0;continue}const k=t[We(s)]??[];if(k.length===0)return!0;for(const m of k){const E=oe(v,m);if(Object.values(E).some(Boolean)||be(v,m))return!0}}}return!1}function Le(e,t){return be(e,t)}function yt({stages:e,onStageComplete:t,onComplete:r,initialValues:s,initialActive:n}){const[a,l]=_.useState(n??0),[o,u]=_.useState(s??{}),[v,k]=_.useState({}),[m,E]=_.useState(!1),[I,M]=_.useState(!1),[j,A]=_.useState(null),T=_.useRef([]),d=Array.isArray(e)&&e.length>0,g=d?e[Math.min(a,e.length-1)]:null,c=g?.key??null;_.useEffect(()=>{n!==void 0&&l(n)},[n]),_.useEffect(()=>{const h=T.current[a];h&&h.scrollIntoView({behavior:"smooth",block:"nearest",inline:"center"})},[a]),_.useEffect(()=>{s!==void 0&&u(s)},[s]),_.useEffect(()=>{if(!g||!c){E(!1),A(null);return}if(v[c]){E(!1),A(null);return}let h=!1;return E(!0),A(null),Promise.resolve(g.loadQuestions()).then(y=>{if(!h){if(!Array.isArray(y))throw new Error(`loadQuestions("${c}") did not return an array`);k(F=>({...F,[c]:y}))}}).catch(y=>{h||A(`Failed to load stage "${g?.title??""}": ${y?.message??"Unknown error"}`)}).finally(()=>{h||E(!1)}),()=>{h=!0}},[g,c,v]);const b=c?v[c]:void 0,w=_.useMemo(()=>{if(!b)return{};const h={};(C=>{const N=[],x=B=>{B.forEach((D,Z)=>{const R=Ce(D,Z);N.push(R);const L=We(R);N.push(L),(D.conditionals??[]).forEach(W=>{const O=W.conditionalQuestions??[];O.length>0&&x(O)})})};return x(C),N})(b).forEach(C=>{C in o&&(h[C]=o[C])});for(const[C,N]of Object.entries(o))C.endsWith(Ke)&&!(C in h)&&(h[C]=N);return h},[b,o]),$=h=>{u(y=>({...y,...h}))},S=()=>{l(h=>h>0?h-1:0),document.querySelector(".panel-body")?.scrollTo({top:0,behavior:"instant"})},f=async()=>{if(!b||!g||m||j||I)return;const h=De(b,o),y=oe(h,o),F=Object.values(y).some(Boolean),C=Le(b,o);if(!(F||C)){M(!0);try{const N=Math.min(a+1,e.length-1),x=a>=e.length-1,{success:B,error:D}=x?await r(o,c??""):await t(w,c??"");if(!B){A(D??"An error occurred");return}x||l(N)}finally{M(!1)}}},p=_.useMemo(()=>{if(!b||m||j||I)return!0;const h=De(b,o),y=oe(h,o),F=Object.values(y).some(Boolean),C=Le(b,o);return F||C},[b,o,m,j,I]);return d?i.jsxs("div",{className:"space-y-6",children:[i.jsxs("div",{className:"flex items-center justify-between gap-4",children:[i.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:e.flatMap((h,y)=>[i.jsx("li",{ref:F=>{T.current[y]=F},className:`px-2.5 py-1 rounded-full border whitespace-nowrap flex-shrink-0 ${y<a?"bg-blue-600 text-white border-blue-600":y===a?"border-blue-600 text-blue-600 bg-white":"border-slate-200 text-slate-600"}`,children:h.title},h.key??`stage-${y}`),...y<e.length-1?[i.jsx("li",{className:"text-slate-400 flex-shrink-0",children:"→"},`arrow-${h.key??y}`)]:[]])}),i.jsxs("div",{className:"text-sm text-slate-500 flex-shrink-0",children:[Math.min(a+1,e.length)," / ",e.length]})]}),i.jsxs("div",{children:[m&&i.jsx("div",{className:"text-slate-500",children:"Loading…"}),g&&i.jsx(gt,{questions:b??[],controlledValues:w,onChangeValues:$,onSubmit:()=>f()},g.key)]}),!m&&j&&i.jsxs("div",{className:"text-red-600 text-sm -mt-4",children:[i.jsx("div",{children:j}),g&&i.jsx("button",{type:"button",className:"underline mt-1 font-bold",onClick:()=>{k(h=>{if(!c)return h;const y={...h};return delete y[c],y})},children:"Retry"})]}),i.jsxs("div",{className:a>0?"grid grid-cols-2 gap-3":"",children:[a>0&&i.jsx("button",{type:"button",onClick:S,disabled:m,className:"h-12 rounded-full border border-gray-300 text-text-primary hover:bg-gray-50 transition",children:"Back"}),i.jsxs("button",{type:"button",onClick:f,disabled:p,className:[a>0?"":"w-full","h-12 rounded-full text-white transition","disabled:opacity-50 disabled:cursor-not-allowed","flex items-center justify-center gap-2",p?"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:[I&&i.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:[i.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),i.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"})]}),a===e.length-1?"Finish":"Next"]})]})]}):i.jsx("div",{className:"text-slate-600",children:"Loading..."})}const ve="credify_quote_id",we="credify_auth_token";function bt(e){try{localStorage.setItem(ve,e)}catch(t){console.error("Failed to save quoteId to localStorage:",t)}}function vt(){try{return localStorage.getItem(ve)}catch(e){return console.error("Failed to load quoteId from localStorage:",e),null}}function Oe(){try{localStorage.removeItem(ve)}catch(e){console.error("Failed to clear quoteId from localStorage:",e)}}function wt(e){try{localStorage.setItem(we,e)}catch(t){console.error("Failed to save authToken to localStorage:",t)}}function xt(){try{return localStorage.getItem(we)}catch(e){return console.error("Failed to load authToken from localStorage:",e),null}}function ze(){try{localStorage.removeItem(we)}catch(e){console.error("Failed to clear authToken from localStorage:",e)}}function Nt(){Oe(),ze()}const U="https://api.getcredify.com";let ne=null;function kt(e){ne=e,wt(e)}function ce(){return ne}function xe(){const e=xt();e&&(ne=e)}function Pe(){ne=null,ze()}async function V(e,t){const r={"Content-Type":"application/json"};ne&&(r.Authorization=`Bearer ${ne}`);const s=await fetch(e,{method:"POST",headers:r,body:JSON.stringify(t)});if(!s.ok){let n=`Request failed with status ${s.status}`;try{n=(await s.json()).error||n}catch{n=s.statusText||n}const a=new Error(n);throw a.statusCode=s.status,a}return s}async function St(e){return await(await V(`${U}/get-questions-by-stage`,{stage:e})).json()}async function Ne(){return await(await V(`${U}/get-stages-for-quote`,{})).json()}async function $t(e){const r=await(await V(`${U}/create-quote`,{phone:e})).json();if(!r||typeof r!="object"||!r.quoteId)throw new Error(`Invalid createQuote response: ${JSON.stringify(r)}`);return r}async function ae(e,t,r){const s={payload:e,getRates:t};return r&&typeof r=="string"&&r.trim()!==""&&(s.quoteId=r),await(await V(`${U}/update-quote`,s)).json()}async function Et(e,t){return await(await V(`${U}/verify-quote`,{quoteId:e,smsCode:t})).json()}async function At(e){return await(await V(`${U}/is-supported-state`,{state:e})).json()}async function Ct(){return await(await V(`${U}/get-rates`,{})).json()}async function Tt(e){const t=e?{quoteId:e}:{};return await(await V(`${U}/get-quote`,t)).json()}async function It(e){const r=await(await V(`${U}/request-bind`,{quoteRateId:e})).json();return r&&typeof r=="object"&&"success"in r?r:{success:!0}}const Mt=new Intl.NumberFormat("en-US",{style:"currency",currency:"USD"});function Ue({onBack:e}){return i.jsx("button",{type:"button",onClick:e,className:"mt-4 h-12 rounded-full border border-gray-300 text-text-primary hover:bg-gray-50 transition w-full",children:"Back"})}function Qt({rates:e,onBack:t}){const r=Array.isArray(e)&&e.length>0,[s,n]=_.useState({});return _.useEffect(()=>{xe()},[]),r?i.jsxs("section",{className:"mt-8",children:[i.jsx("h3",{className:"text-lg font-semibold text-slate-900",children:"Rates"}),i.jsx("div",{className:"mt-4 grid gap-4 sm:grid-cols-2 lg:grid-cols-3",children:e.map(a=>{const l=a.premium_cents/100,o=Mt.format(l),u=a.quote_rate_id,v=s[u]??"idle",k=v==="loading",m=v==="success",E=async()=>{n(I=>({...I,[u]:"loading"}));try{if(xe(),!ce())throw new Error("Authentication required. Please verify your phone number first.");if(!((await It(a.quote_rate_id))?.success!==!1))throw new Error("Request failed");Nt(),Pe(),n(A=>({...A,[u]:"success"}))}catch{n(I=>({...I,[u]:"error"}))}};return i.jsxs("div",{className:"flex flex-col rounded-xl border border-slate-200 bg-white p-6 shadow-sm transition hover:shadow-md",children:[i.jsxs("div",{className:"mb-4 flex items-center gap-3",children:[a.carrier_logo_base64?i.jsx("img",{src:`data:image/png;base64,${a.carrier_logo_base64}`,alt:a.carrier_name,className:"h-12 w-auto object-contain"}):i.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:a.carrier_name.charAt(0).toUpperCase()}),i.jsx("div",{className:"flex-1",children:i.jsx("h4",{className:"font-semibold text-slate-900",children:a.carrier_name})})]}),i.jsxs("div",{className:"mb-2",children:[i.jsx("p",{className:"text-sm text-slate-500",children:"Premium"}),i.jsx("p",{className:"text-2xl font-bold text-slate-900",children:o})]}),i.jsxs("div",{className:"mb-4",children:[i.jsx("p",{className:"text-sm text-slate-500",children:"Term"}),i.jsxs("p",{className:"font-medium text-slate-700",children:[a.term_months," months"]})]}),a.carrier_quote_id&&i.jsx("div",{className:"mb-4",children:i.jsxs("p",{className:"text-xs text-slate-400",children:["Quote ID: ",a.carrier_quote_id]})}),i.jsxs("div",{className:"mt-auto pt-4",children:[i.jsx("button",{type:"button",onClick:E,disabled:k||m,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 ${m?"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:k?"Requesting…":m?"Requested":"Request Bind"}),v==="error"&&i.jsx("p",{className:"mt-2 text-xs text-red-600",children:"Something went wrong. Please try again."}),v==="success"&&i.jsx("p",{className:"mt-2 text-xs text-emerald-600",children:"We received your bind request."})]})]},u)})}),t&&i.jsx(Ue,{onBack:t})]}):i.jsxs("section",{className:"mt-8",children:[i.jsx("h3",{className:"text-lg font-semibold text-slate-900",children:"Rates"}),i.jsx("p",{className:"mt-2 text-sm text-slate-500",children:"No rates are available at this time."}),t&&i.jsx(Ue,{onBack:t})]})}function Q(e){if(e===!0)return"Yes";if(e===!1)return"No"}function P(e){if(e)try{const t=typeof e=="string"?new Date(e):e;return isNaN(t.getTime())?void 0:t.toISOString().split("T")[0]}catch{return}}function jt(e){const t={};e.phone&&(t.phone=e.phone),e.first_name&&(t.first_name=e.first_name),e.last_name&&(t.last_name=e.last_name),e.email&&(t.email=e.email),e.date_of_birth&&(t.date_of_birth=P(e.date_of_birth)),e.product&&(t.product=e.product),e.state&&(t.state=e.state);const r=[];e.line_1&&r.push(e.line_1),e.line_2&&r.push(e.line_2),e.city&&r.push(e.city),e.state&&r.push(e.state),e.postal_code&&r.push(e.postal_code),r.length>0&&(t.address=r.join(", ")),e.years_at_address!==null&&e.years_at_address!==void 0&&(t.years_at_address=e.years_at_address),e.months_at_address!==null&&e.months_at_address!==void 0&&(t.months_at_address=e.months_at_address),e.move_in_date&&(t.move_in_date=P(e.move_in_date));const s=[];return e.prior_line_1&&s.push(e.prior_line_1),e.prior_line_2&&s.push(e.prior_line_2),e.prior_city&&s.push(e.prior_city),e.prior_state&&s.push(e.prior_state),e.prior_postal_code&&s.push(e.prior_postal_code),s.length>0&&(t.prior_address=s.join(", ")),e.years_at_prior_address!==null&&e.years_at_prior_address!==void 0&&(t.years_at_prior_address=e.years_at_prior_address),e.auto_has_prior_insurance!==null&&e.auto_has_prior_insurance!==void 0&&(t.auto_has_prior_insurance=Q(e.auto_has_prior_insurance)),e.auto_prior_expiration_date&&(t.auto_prior_expiration_date=P(e.auto_prior_expiration_date)),e.auto_prior_carrier_name&&(t.auto_prior_carrier_name=e.auto_prior_carrier_name),e.auto_prior_liability_limit&&(t.auto_prior_liability_limit=e.auto_prior_liability_limit),e.auto_reason_for_no_insurance&&(t.auto_reason_for_no_insurance=e.auto_reason_for_no_insurance),e.auto_prior_years!==null&&e.auto_prior_years!==void 0&&(t.auto_prior_years=e.auto_prior_years),e.auto_prior_months!==null&&e.auto_prior_months!==void 0&&(t.auto_prior_months=e.auto_prior_months),e.auto_continuous_coverage_years!==null&&e.auto_continuous_coverage_years!==void 0&&(t.auto_continuous_coverage_years=e.auto_continuous_coverage_years),e.auto_cancelled_declined_refused_to_renew!==null&&e.auto_cancelled_declined_refused_to_renew!==void 0&&(t.auto_cancelled_declined_refused_to_renew=Q(e.auto_cancelled_declined_refused_to_renew)),e.home_has_prior_insurance!==null&&e.home_has_prior_insurance!==void 0&&(t.home_has_prior_insurance=Q(e.home_has_prior_insurance)),e.home_prior_expiration_date&&(t.home_prior_expiration_date=P(e.home_prior_expiration_date)),e.home_prior_carrier_name&&(t.home_prior_carrier_name=e.home_prior_carrier_name),e.year_built!==null&&e.year_built!==void 0&&(t.year_built=e.year_built),e.number_of_units!==null&&e.number_of_units!==void 0&&(t.number_of_units=e.number_of_units),e.number_of_stories!==null&&e.number_of_stories!==void 0&&(t.number_of_stories=e.number_of_stories),e.number_of_beds!==null&&e.number_of_beds!==void 0&&(t.number_of_beds=e.number_of_beds),e.number_of_full_baths!==null&&e.number_of_full_baths!==void 0&&(t.number_of_full_baths=e.number_of_full_baths),e.number_of_partial_baths!==null&&e.number_of_partial_baths!==void 0&&(t.number_of_partial_baths=e.number_of_partial_baths),e.under_construction!==null&&e.under_construction!==void 0&&(t.under_construction=Q(e.under_construction)),e.distance_from_fire_hydrant_ft&&(t.distance_from_fire_hydrant_ft=e.distance_from_fire_hydrant_ft),e.distance_from_fire_station_miles&&(t.distance_from_fire_station_miles=e.distance_from_fire_station_miles),e.architectural_style&&(t.architectural_style=e.architectural_style),e.dwelling_type&&(t.dwelling_type=e.dwelling_type),e.construction_quality&&(t.construction_quality=e.construction_quality),e.located_over_water!==null&&e.located_over_water!==void 0&&(t.located_over_water=e.located_over_water),e.construction_type&&(t.construction_type=e.construction_type),e.exterior_wall_type&&(t.exterior_wall_type=e.exterior_wall_type),e.foundation_type&&(t.foundation_type=e.foundation_type),e.roof_material_type&&(t.roof_material_type=e.roof_material_type),e.year_roof_updated!==null&&e.year_roof_updated!==void 0&&(t.year_roof_updated=e.year_roof_updated),e.heating_type&&(t.heating_type=e.heating_type),e.heating_fuel_type&&(t.heating_fuel_type=e.heating_fuel_type),e.number_of_fireplaces!==null&&e.number_of_fireplaces!==void 0&&(t.number_of_fireplaces=e.number_of_fireplaces),e.basement_type&&(t.basement_type=e.basement_type),e.parking_type&&(t.parking_type=e.parking_type),e.number_of_parking_spaces!==null&&e.number_of_parking_spaces!==void 0&&(t.number_of_parking_spaces=e.number_of_parking_spaces),e.plumbing_type&&(t.plumbing_type=e.plumbing_type),e.pool_type&&(t.pool_type=e.pool_type),e.total_area_sq_ft!==null&&e.total_area_sq_ft!==void 0&&(t.total_area_sq_ft=e.total_area_sq_ft),e.parcel_area_sq_ft!==null&&e.parcel_area_sq_ft!==void 0&&(t.parcel_area_sq_ft=e.parcel_area_sq_ft),e.residence_type&&(t.residence_type=e.residence_type),e.usage_type&&(t.usage_type=e.usage_type),e.household_size!==null&&e.household_size!==void 0&&(t.household_size=e.household_size),e.number_of_mortgagees!==null&&e.number_of_mortgagees!==void 0&&(t.number_of_mortgagees=e.number_of_mortgagees),e.has_dog!==null&&e.has_dog!==void 0&&(t.has_dog=Q(e.has_dog)),e.dog_breed_type&&(t.dog_breed_type=e.dog_breed_type),e.number_of_dogs!==null&&e.number_of_dogs!==void 0&&(t.number_of_dogs=e.number_of_dogs),e.has_business_on_premises!==null&&e.has_business_on_premises!==void 0&&(t.has_business_on_premises=Q(e.has_business_on_premises)),e.business_class&&(t.business_class=e.business_class),e.retiree_discount!==null&&e.retiree_discount!==void 0&&(t.retiree_discount=Q(e.retiree_discount)),e.gated_community_discount!==null&&e.gated_community_discount!==void 0&&(t.gated_community_discount=Q(e.gated_community_discount)),e.multi_policy_discount!==null&&e.multi_policy_discount!==void 0&&(t.multi_policy_discount=Q(e.multi_policy_discount)),e.non_smoker_discount!==null&&e.non_smoker_discount!==void 0&&(t.non_smoker_discount=Q(e.non_smoker_discount)),e.first_time_buyer_discount!==null&&e.first_time_buyer_discount!==void 0&&(t.first_time_buyer_discount=Q(e.first_time_buyer_discount)),e.fire_detection_system!==null&&e.fire_detection_system!==void 0&&(t.fire_detection_system=Q(e.fire_detection_system)),e.burglar_alarm_system!==null&&e.burglar_alarm_system!==void 0&&(t.burglar_alarm_system=Q(e.burglar_alarm_system)),e.burglar_alarm_system_type&&(t.burglar_alarm_system_type=e.burglar_alarm_system_type),e.smoke_detectors!==null&&e.smoke_detectors!==void 0&&(t.smoke_detectors=Q(e.smoke_detectors)),e.sprinkler_system!==null&&e.sprinkler_system!==void 0&&(t.sprinkler_system=Q(e.sprinkler_system)),e.sprinkler_system_type&&(t.sprinkler_system_type=e.sprinkler_system_type),e.gas_leakage_detector!==null&&e.gas_leakage_detector!==void 0&&(t.gas_leakage_detector=Q(e.gas_leakage_detector)),e.deadbolt_locks!==null&&e.deadbolt_locks!==void 0&&(t.deadbolt_locks=Q(e.deadbolt_locks)),e.fire_extinguisher!==null&&e.fire_extinguisher!==void 0&&(t.fire_extinguisher=Q(e.fire_extinguisher)),e.order_credit_authorized!==null&&e.order_credit_authorized!==void 0&&(t.order_credit_authorized=Q(e.order_credit_authorized)),e.has_health_insurance_auto_accident!==null&&e.has_health_insurance_auto_accident!==void 0&&(t.has_health_insurance_auto_accident=Q(e.has_health_insurance_auto_accident)),e.named_insured_foreclosure_repo_bankruptcy!==null&&e.named_insured_foreclosure_repo_bankruptcy!==void 0&&(t.named_insured_foreclosure_repo_bankruptcy=Q(e.named_insured_foreclosure_repo_bankruptcy)),e.named_insured_convicted_insurance_fraud!==null&&e.named_insured_convicted_insurance_fraud!==void 0&&(t.named_insured_convicted_insurance_fraud=Q(e.named_insured_convicted_insurance_fraud)),e.drivers&&e.drivers.length>0?(t.drivers="Yes",t.drivers__items=e.drivers.map(n=>{const a={};return n.first_name&&(a.first_name=n.first_name),n.last_name&&(a.last_name=n.last_name),n.date_of_birth&&(a.date_of_birth=P(n.date_of_birth)),n.gender&&(a.gender=n.gender),n.marital_status&&(a.marital_status=n.marital_status),n.relationship_to_insured&&(a.relationship_to_insured=n.relationship_to_insured),n.license_state&&(a.license_state=n.license_state),n.license_status&&(a.license_status=n.license_status),n.license_number&&(a.license_number=n.license_number),n.date_first_licensed&&(a.date_first_licensed=P(n.date_first_licensed)),n.education_level&&(a.education_level=n.education_level),n.occupation&&(a.occupation=n.occupation),n.industry&&(a.industry=n.industry),n.driver_violations&&n.driver_violations.length>0&&(a.driver_violations__items=n.driver_violations.map(l=>{const o={};return l.code&&(o.code=l.code),l.occurred_at&&(o.occurred_at=P(l.occurred_at)),o})),n.driver_accidents&&n.driver_accidents.length>0&&(a.driver_accidents__items=n.driver_accidents.map(l=>{const o={};return l.occurred_at&&(o.occurred_at=P(l.occurred_at)),l.description&&(o.description=l.description),l.quote_vehicle_id&&(o.quote_vehicle_id=l.quote_vehicle_id),l.property_damage_amount_paid_cents!==null&&l.property_damage_amount_paid_cents!==void 0&&(o.property_damage_amount_paid_cents=l.property_damage_amount_paid_cents),l.personal_injury_amount_paid_cents!==null&&l.personal_injury_amount_paid_cents!==void 0&&(o.personal_injury_amount_paid_cents=l.personal_injury_amount_paid_cents),o})),n.losses&&n.losses.length>0&&(a.losses=n.losses.map(l=>{const o={};return l.description&&(o.description=l.description),l.date_of_incident&&(o.date_of_incident=P(l.date_of_incident)),l.amount_paid_cents!==null&&l.amount_paid_cents!==void 0&&(o.amount_paid_cents=l.amount_paid_cents),l.quote_vehicle_id&&(o.quote_vehicle_id=l.quote_vehicle_id),o})),a})):t.drivers="No",e.vehicles&&e.vehicles.length>0?(t.vehicles="Yes",t.vehicles__items=e.vehicles.map(n=>{const a={};n.vin&&(a.vin=n.vin),n.year!==null&&n.year!==void 0&&(a.year=n.year),n.make&&(a.make=n.make),n.model&&(a.model=n.model),n.ownership_type&&(a.ownership_type=n.ownership_type),n.usage&&(a.usage=n.usage),n.annual_mileage!==null&&n.annual_mileage!==void 0&&(a.annual_mileage=n.annual_mileage),n.miles_to_work!==null&&n.miles_to_work!==void 0&&(a.miles_to_work=n.miles_to_work),n.percent_to_work!==null&&n.percent_to_work!==void 0&&(a.percent_to_work=n.percent_to_work);const l=[];return n.garaging_address_line_1&&l.push(n.garaging_address_line_1),n.garaging_address_line_2&&l.push(n.garaging_address_line_2),n.garaging_address_city&&l.push(n.garaging_address_city),n.garaging_address_state&&l.push(n.garaging_address_state),n.garaging_address_postal_code&&l.push(n.garaging_address_postal_code),l.length>0&&(a.garaging_address=l.join(", ")),n.anti_theft_type&&(a.anti_theft_type=n.anti_theft_type),n.passive_restraint_type&&(a.passive_restraint_type=n.passive_restraint_type),n.coverages&&n.coverages.length>0&&(a.coverages__items=n.coverages.map(o=>{const u={};return o.type&&(u.type=o.type),o.per_person_limit_cents!==null&&o.per_person_limit_cents!==void 0&&(u.per_person_limit_cents=o.per_person_limit_cents),o.per_incident_limit_cents!==null&&o.per_incident_limit_cents!==void 0&&(u.per_incident_limit_cents=o.per_incident_limit_cents),o.per_incident_limit_percent!==null&&o.per_incident_limit_percent!==void 0&&(u.per_incident_limit_percent=o.per_incident_limit_percent),o.per_day_limit_cents!==null&&o.per_day_limit_cents!==void 0&&(u.per_day_limit_cents=o.per_day_limit_cents),o.deductible_cents!==null&&o.deductible_cents!==void 0&&(u.deductible_cents=o.deductible_cents),o.is_declined!==null&&o.is_declined!==void 0&&(u.is_declined=Q(o.is_declined)),u})),n.vehicle_lienholders&&n.vehicle_lienholders.length>0&&(a.vehicle_lienholders__items=n.vehicle_lienholders.map(o=>{const u={};return o.name&&(u.name=o.name),o.type&&(u.type=o.type),o.line_1&&(u.line_1=o.line_1),o.line_2&&(u.line_2=o.line_2),o.city&&(u.city=o.city),o.state&&(u.state=o.state),o.postal_code&&(u.postal_code=o.postal_code),o.phone&&(u.phone=o.phone),o.fax&&(u.fax=o.fax),u})),a})):t.vehicles="No",e.losses&&e.losses.length>0&&(t.home_losses__items=e.losses.map(n=>{const a={};return n.description&&(a.description=n.description),n.date_of_incident&&(a.date_of_incident=P(n.date_of_incident)),n.amount_paid_cents!==null&&n.amount_paid_cents!==void 0&&(a.amount_paid_cents=n.amount_paid_cents),a})),t}function ke(e){const t={},r=a=>{if(typeof a=="string"){if(a==="Yes")return!0;if(a==="No")return!1}return a},s=Object.keys(e).filter(a=>!a.includes("__items")),n=new Set;for(const[a,l]of Object.entries(e))a.endsWith("__items")&&Array.isArray(l)&&l.forEach(o=>{typeof o=="object"&&o!==null&&Object.keys(o).forEach(u=>{n.add(u)})});for(const[a,l]of Object.entries(e))if(a.endsWith("__items")){const o=a.replace("__items","");if(s.includes(o)){const v=Array.isArray(l)?l.map(k=>ke(k)):l;t[o]=v}}else a.includes("__items")||n.has(a)||(t[a]=r(l));return t}function Ft({isOpen:e,onClose:t}){const[r,s]=_.useState([]),[n,a]=_.useState(null),[l,o]=_.useState(null),[u,v]=_.useState(null),[k,m]=_.useState(void 0),[E,I]=_.useState(!1);function M(A){const T={SMSVerification:"Verify",AutoCurrentCarrier:"Current Auto Policy",HomeCurrentCarrier:"Current Home Policy"};return A.map(d=>({key:d,title:T[d]||d,loadQuestions:async()=>(await St(d)).questions}))}_.useEffect(()=>{e&&(async()=>{try{const T=vt();if(xe(),T){I(!0),a(T);try{const d=ce(),g=await Tt(d?void 0:T);if(!g||!g.quote)throw new Error("Invalid response from getQuote: missing quote data");const{quote:c}=g,{stages:b}=await Ne(),w=M(b);s(w);try{const $=jt(c);v($)}catch($){throw new Error(`Failed to transform quote data: ${$ instanceof Error?$.message:"Unknown error"}`)}if(c.current_stage){const $=w.findIndex(S=>S.key===c.current_stage);$>=0?m($):m(w.length-1)}else m(w.length-1)}catch(d){d.statusCode===404?(Oe(),a(null)):Pe()}finally{I(!1)}}else{const{stages:d}=await Ne();s(M(d))}}catch{I(!1)}})()},[e]),_.useEffect(()=>{if(!e)return;const{overflow:A}=document.body.style;return document.body.style.overflow="hidden",()=>{document.body.style.overflow=A}},[e]);const j=_.useCallback(A=>{A.key==="Escape"&&t()},[t]);return _.useEffect(()=>{if(e)return window.addEventListener("keydown",j),()=>window.removeEventListener("keydown",j)},[e,j]),_.useEffect(()=>{e||(v(null),m(void 0),I(!1))},[e]),e?i.jsxs("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center",role:"dialog","aria-modal":"true","aria-labelledby":"insurance-modal-title",children:[i.jsx("div",{className:"backdrop",style:{background:"rgba(0, 0, 0, 0.5)"},onClick:t,"aria-hidden":"true"}),i.jsxs("div",{className:"modal-panel bg-white relative w-full max-w-2xl flex flex-col max-h-[90vh] overflow-hidden",style:{background:"#ffffff"},role:"document",children:[i.jsx("button",{onClick:t,className:"absolute top-4 right-4 text-slate-400 hover:text-slate-600 text-xl","aria-label":"Close",type:"button",children:"×"}),i.jsxs("div",{className:"text-center mb-6",children:[i.jsx("h2",{id:"insurance-modal-title",className:"h1-title",children:"Let's get you the best insurance rates."}),i.jsx("p",{className:"p-subtitle",children:"This should only take a few minutes."})]}),i.jsxs("div",{className:"panel-body flex-1 min-h-0 overflow-y-auto",children:[!l&&i.jsx(i.Fragment,{children:E||r.length===0?i.jsx("div",{className:"flex items-center justify-center py-12",children:i.jsx("div",{className:"text-slate-600",children:"Loading..."})}):i.jsx(yt,{stages:r,initialValues:u??void 0,initialActive:k,onStageComplete:async(A,T)=>{try{const d=ke(A),{stages:g}=await Ne(),c=M(g);s(c);const w=c.findIndex(f=>f.key===T)+1,S=(w<c.length?c[w]:null)?.key||T;if(n)if(T==="SMSVerification"){const{isVerified:f,token:p}=await Et(n,d.sms_code);if(!f)throw new Error("Invalid SMS code");p&&kt(p),await ae({current_stage:S},!1)}else if(T==="State"){const{isSupported:f}=await At(d.state);if(!f)throw new Error("State is not supported");const p=ce();await ae({...d,current_stage:S},!1,p?void 0:n)}else{const f=ce();await ae({...d,current_stage:S},!1,f?void 0:n||void 0)}else{const p=(await $t(d.phone))?.quoteId;if(!p||typeof p!="string"||p.trim()==="")throw new Error(`Failed to create quote - invalid quoteId returned: ${p}`);a(p),bt(p),await ae({current_stage:S},!1,p)}return{success:!0}}catch(d){return{success:!1,error:d instanceof Error?d.message:"An error occurred"}}},onComplete:async A=>{try{const T=ke(A);if(!n)throw new Error("Quote ID is required");await ae(T,!0),v(A);const{rates:d}=await Ct();return o(d),{success:!0}}catch(T){return{success:!1,error:T instanceof Error?T.message:"An error occurred"}}}})})," ",l&&n&&i.jsx(Qt,{rates:l,onBack:()=>o(null)})]}),i.jsx("div",{className:"mt-4 pt-4 border-t border-slate-200",children:i.jsx("p",{className:"text-center text-sm text-slate-500",children:"Insurance products offered through Credify Corporation, a licensed insurance agency."})})]})]}):null}function Bt({isOpen:e}){return i.jsx(Ft,{isOpen:e,onClose:()=>{ue.close()}})}let Y=null,X=null,de=!1;function Dt(){Y||(Y=document.createElement("div"),Y.id="insurance-widget-root",document.body.appendChild(Y)),!X&&Y&&(X=Ge.createRoot(Y))}function Se(){Dt(),X&&X.render(_.createElement(Bt,{isOpen:de}))}function Kt(){X&&Y&&(X.unmount(),Y.remove()),X=null,Y=null}const ue={init:e=>{de=!!e?.autoOpen,Se()},open:()=>{de=!0,Se()},close:()=>{de=!1,Se()},destroy:Kt};typeof window<"u"&&(window.CredifyInsuranceWidget=ue),K.CredifyInsuranceWidget=ue,K.default=ue,Object.defineProperties(K,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
|
|
1
|
+
(function(){if(typeof W>"u")var W={env:{}}})();(function(W,_){typeof exports=="object"&&typeof module<"u"?_(exports,require("react"),require("react-dom/client"),require("react/jsx-runtime")):typeof define=="function"&&define.amd?define(["exports","react","react-dom/client","react/jsx-runtime"],_):(W=typeof globalThis<"u"?globalThis:W||self,_(W.CredifyInsuranceWidget={},W.React,W.ReactDOM,W.React))})(this,(function(W,_,He,i){"use strict";function z({id:e,label:t,hint:r,error:s,required:n,className:a,children:l}){return i.jsxs("div",{className:a,children:[i.jsxs("label",{htmlFor:e,className:"form-label",children:[t," ",n&&i.jsx("span",{className:"text-red-600",children:"*"})]}),l,r&&!s&&i.jsx("p",{id:`${e}-hint`,className:"mt-1 text-sm text-slate-500",children:r}),s&&i.jsx("p",{id:`${e}-error`,className:"mt-1 text-sm text-red-600",children:s})]})}function Je({id:e,label:t,hint:r,error:s,required:n,className:a,...l}){return i.jsx(z,{id:e,label:t,hint:r,error:s,required:n,className:a,children:i.jsx("input",{id:e,className:`form-input ${s?"input-error":""}`,"aria-invalid":!!s,"aria-describedby":[r?`${e}-hint`:null,s?`${e}-error`:null].filter(Boolean).join(" ")||void 0,required:n,...l,type:"text"})})}function Xe({id:e,label:t,hint:r,error:s,required:n,className:a,...l}){return i.jsx(z,{id:e,label:t,hint:r,error:s,required:n,className:a,children:i.jsx("input",{id:e,type:"number",className:`form-input ${s?"input-error":""}`,"aria-invalid":!!s,"aria-describedby":[r?`${e}-hint`:null,s?`${e}-error`:null].filter(Boolean).join(" ")||void 0,required:n,...l})})}function Ze({id:e,label:t,hint:r,error:s,required:n,className:a,...l}){return i.jsx(z,{id:e,label:t,hint:r,error:s,required:n,className:a,children:i.jsx("input",{id:e,type:"email",className:`form-input ${s?"input-error":""}`,inputMode:"email",autoComplete:"email",required:n,"aria-invalid":!!s,"aria-describedby":[r?`${e}-hint`:null,s?`${e}-error`:null].filter(Boolean).join(" ")||void 0,...l})})}function me(e){const t=e.replace(/\D/g,"");if(t.length===10)return`(${t.slice(0,3)}) ${t.slice(3,6)} - ${t.slice(6)}`;if(t.length>10){const r=t.slice(0,10);return`(${r.slice(0,3)}) ${r.slice(3,6)} - ${r.slice(6)}`}return t.length>=6?`(${t.slice(0,3)}) ${t.slice(3,6)} - ${t.slice(6)}`:t.length>=3?`(${t.slice(0,3)}) ${t.slice(3)}`:t.length>0?`(${t}`:t}function ge(e){return e.replace(/\D/g,"")}function Re({id:e,label:t,hint:r,error:s,required:n,className:a,value:l="",onChange:o,...u}){const[v,k]=_.useState(""),m=_.useRef(null),E=_.useRef(0);_.useEffect(()=>{if(!l){k("");return}let M=ge(l);M.length===11&&M.startsWith("1")&&(M=M.slice(1));const Q=M.slice(0,10);k(me(Q))},[l]);const I=M=>{const Q=M.target,A=Q.value;E.current=Q.selectionStart||0;const d=ge(A).slice(0,10),g=me(d);k(g);const c=d.length===10?`+1${d}`:d,b={...M,currentTarget:{...M.currentTarget,value:c},target:{...M.target,value:c}};o?.(b),setTimeout(()=>{if(m.current){const w=A.slice(0,E.current),$=ge(w),S=me($),f=Math.min(S.length,g.length);m.current.setSelectionRange(f,f)}},0)};return i.jsx(z,{id:e,label:t,hint:r,error:s,required:n,className:a,children:i.jsxs("div",{className:`tel-input-wrapper flex items-center border rounded-lg transition-colors w-full relative ${s?"border-red-500 error":"border-[var(--accent-color)] focus-within:border-[var(--primary-color)]"}`,children:[i.jsx("label",{htmlFor:e,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"}),i.jsx("input",{ref:m,id:e,type:"tel",className:`flex-1 px-4 py-3 border-0 rounded-r-lg outline-none bg-transparent text-[var(--text-primary)] text-base ${s?"input-error":""}`,inputMode:"tel",autoComplete:"tel",required:n,"aria-invalid":!!s,"aria-describedby":[r?`${e}-hint`:null,s?`${e}-error`:null].filter(Boolean).join(" ")||void 0,value:v,onChange:I,...u})]})})}function qe({id:e,label:t,hint:r,error:s,required:n,className:a,...l}){return i.jsx(z,{id:e,label:t,hint:r,error:s,required:n,className:a,children:i.jsx("input",{id:e,type:"url",className:`form-input ${s?"input-error":""}`,inputMode:"url",autoComplete:"url",required:n,"aria-invalid":!!s,"aria-describedby":[r?`${e}-hint`:null,s?`${e}-error`:null].filter(Boolean).join(" ")||void 0,...l})})}function et({id:e,label:t,hint:r,error:s,required:n,className:a,...l}){return i.jsx(z,{id:e,label:t,hint:r,error:s,required:n,className:a,children:i.jsx("input",{id:e,type:"password",className:`form-input ${s?"input-error":""}`,autoComplete:"current-password",required:n,"aria-invalid":!!s,"aria-describedby":[r?`${e}-hint`:null,s?`${e}-error`:null].filter(Boolean).join(" ")||void 0,...l})})}function tt({id:e,label:t,hint:r,error:s,required:n,className:a,rows:l=4,...o}){return i.jsx(z,{id:e,label:t,hint:r,error:s,required:n,className:a,children:i.jsx("textarea",{id:e,rows:l,className:`form-input ${s?"input-error":""}`,"aria-invalid":!!s,"aria-describedby":[r?`${e}-hint`:null,s?`${e}-error`:null].filter(Boolean).join(" ")||void 0,required:n,...o})})}function nt({id:e,label:t,hint:r,error:s,required:n,className:a,...l}){return i.jsx(z,{id:e,label:t,hint:r,error:s,required:n,className:a,children:i.jsx("input",{id:e,type:"date",className:`form-input ${s?"input-error":""}`,"aria-invalid":!!s,"aria-describedby":[r?`${e}-hint`:null,s?`${e}-error`:null].filter(Boolean).join(" ")||void 0,required:n,...l})})}function Ae({id:e,label:t,className:r,...s}){return i.jsxs("label",{className:`checkbox-card ${r||""}`,htmlFor:e,children:[i.jsx("input",{id:e,type:"checkbox",className:"checkbox-input",...s}),i.jsx("span",{className:"checkbox-label",children:t})]})}function rt({name:e,value:t,checked:r,onChange:s,children:n}){return i.jsxs("label",{className:"radio-card",children:[i.jsx("input",{className:"radio-input",type:"radio",name:e,value:t,checked:r,onChange:s}),i.jsx("span",{className:"radio-label",children:n})]})}function st({legend:e,children:t,className:r,legendClassName:s}){return i.jsxs("fieldset",{className:r,children:[i.jsx("legend",{className:`mb-4 text-base font-medium ${s||""}`,style:{color:"var(--text-primary)"},children:e}),i.jsx("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2",children:t})]})}function it({id:e,label:t,hint:r,error:s,required:n,className:a,placeholder:l,options:o,children:u,...v}){const k=[r?`${e}-hint`:null,s?`${e}-error`:null].filter(Boolean).join(" ")||void 0,m=!!u;return i.jsx(z,{id:e,label:t,hint:r,error:s,required:n,className:a,children:i.jsxs("select",{id:e,className:`form-input select-caret ${s?"input-error":""}`,"aria-invalid":!!s,"aria-describedby":k,required:n,...v,children:[l&&i.jsx("option",{value:"",disabled:!0,selected:!("value"in v),children:l}),m?u:o?.map(E=>i.jsx("option",{value:E.value,disabled:E.disabled,children:E.label},E.value))]})})}const at="AIzaSyDjLdKLxoa-maLNGAyq_I_2r_Fe_TzFikw";function ot(){return new Promise((e,t)=>{if(window.google?.maps?.places){e();return}const r=document.querySelector('script[src*="maps.googleapis.com"]');if(r){r.addEventListener("load",()=>e()),r.addEventListener("error",()=>t(new Error("Failed to load Google Maps script")));return}const s=document.createElement("script");s.src=`https://maps.googleapis.com/maps/api/js?key=${at}&libraries=places`,s.async=!0,s.defer=!0,s.onload=()=>e(),s.onerror=()=>t(new Error("Failed to load Google Maps script")),document.head.appendChild(s)})}function lt(e){const t={fullAddress:e.formatted_address};return e.address_components&&e.address_components.forEach(r=>{const s=r.types;s.includes("street_number")&&(t.streetNumber=r.long_name),s.includes("route")&&(t.streetName=r.long_name),s.includes("locality")&&(t.city=r.long_name),s.includes("administrative_area_level_1")&&(t.state=r.short_name),s.includes("postal_code")&&(t.zipCode=r.long_name),s.includes("country")&&(t.country=r.short_name)}),t}function ct({id:e,label:t,hint:r,error:s,required:n,className:a,onChange:l,onPlaceSelect:o,value:u,...v}){const k=_.useRef(null),m=_.useRef(null),E=_.useRef(null),I=_.useRef(null),[M,Q]=_.useState(!0),[A,T]=_.useState(u||""),[d,g]=_.useState([]),[c,b]=_.useState(!1),[w,$]=_.useState(-1),S=_.useRef([]),f=_.useRef(!1),p=_.useRef(-1);_.useEffect(()=>{S.current=d},[d]),_.useEffect(()=>{f.current=c},[c]),_.useEffect(()=>{p.current=w},[w]),_.useEffect(()=>{u!==void 0&&T(String(u))},[u]);const h=_.useRef(null);_.useEffect(()=>{if(!k.current)return;let N=!0;return ot().then(()=>{!N||!k.current||(m.current=new google.maps.places.AutocompleteService,E.current=new google.maps.places.PlacesService(document.createElement("div")),Q(!1))}).catch(x=>{console.error("Error loading Google Maps:",x),Q(!1)}),()=>{N=!1,h.current&&clearTimeout(h.current)}},[]);const y=N=>{const x=N.target.value;if(T(x),l?.(x),h.current&&clearTimeout(h.current),x.length<3){g([]),b(!1);return}h.current=setTimeout(()=>{m.current&&m.current.getPlacePredictions({input:x,types:["address"]},(F,D)=>{D===google.maps.places.PlacesServiceStatus.OK&&F?(g(F),b(!0),$(-1)):(g([]),b(!1))})},300)},B=N=>{if(!f.current||S.current.length===0){N.key==="Escape"&&(b(!1),f.current=!1);return}switch(N.key){case"ArrowDown":N.preventDefault(),$(x=>{const F=x<S.current.length-1?x+1:x;return p.current=F,F});break;case"ArrowUp":N.preventDefault(),$(x=>{const F=x>0?x-1:-1;return p.current=F,F});break;case"Enter":N.preventDefault(),p.current>=0&&p.current<S.current.length&&C(S.current[p.current]);break;case"Escape":N.preventDefault(),b(!1),f.current=!1;break}};_.useEffect(()=>{const N=x=>{I.current&&!I.current.contains(x.target)&&k.current&&!k.current.contains(x.target)&&(b(!1),f.current=!1)};if(c)return document.addEventListener("mousedown",N),()=>{document.removeEventListener("mousedown",N)}},[c]);const C=N=>{E.current&&E.current.getDetails({placeId:N.place_id,fields:["address_components","formatted_address","geometry"]},(x,F)=>{if(F===google.maps.places.PlacesServiceStatus.OK&&x){const D=x.formatted_address||"";T(D),b(!1),g([]),f.current=!1;const Z=lt(x);l?.(D,Z),o?.(x)}})};return i.jsx(z,{id:e,label:t,hint:r,error:s,required:n,className:a,children:i.jsxs("div",{className:"relative",children:[i.jsx("input",{ref:k,id:e,type:"text",className:`form-input ${s?"input-error":""}`,value:A,onChange:y,onKeyDown:B,"aria-invalid":!!s,"aria-describedby":[r?`${e}-hint`:null,s?`${e}-error`:null].filter(Boolean).join(" ")||void 0,required:n,autoComplete:"street-address",placeholder:v.placeholder||"Enter an address",disabled:M||v.disabled,...v}),M&&i.jsx("p",{className:"mt-1 text-sm text-slate-500",children:"Loading address suggestions..."}),c&&d.length>0&&i.jsx("div",{ref:I,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:d.map((N,x)=>i.jsxs("div",{className:`px-4 py-3 cursor-pointer transition-colors ${x===w?"bg-blue-50 text-slate-900":"bg-white text-slate-900 hover:bg-slate-50"} ${x<d.length-1?"border-b border-slate-100":""}`,role:"option","aria-selected":x===w,onClick:()=>C(N),onMouseEnter:()=>$(x),children:[i.jsx("div",{className:"font-medium text-slate-900",children:N.structured_formatting.main_text}),N.structured_formatting.secondary_text&&i.jsx("div",{className:"text-sm text-slate-500 mt-0.5",children:N.structured_formatting.secondary_text})]},N.place_id))})]})})}function he(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/(^-|-$)/g,"")}function Ce(e,t){return e.key??`${he(e.question)}-${t}`}function oe(e,t){const r={},s=n=>n==null||typeof n=="string"&&n.trim()==="";return e.forEach((n,a)=>{const l=Ce(n,a),o=t[l];if(n.required)switch(n.inputType){case"checkbox":o!==!0&&(r[l]="Required");break;case"radio":case"select":s(o)&&(r[l]="Required");break;case"number":(o==null||typeof o=="string"&&o.trim()==="")&&(r[l]="Required");break;case"date":case"email":case"tel":case"url":case"password":case"text":case"textarea":case"address":default:s(o)&&(r[l]="Required");break}}),r}function dt(e){if(e===""||e===null||e===void 0)return;const t=Number(e);return Number.isNaN(t)?void 0:t}function Te(e){return typeof e=="number"&&Number.isFinite(e)?e:typeof e=="string"&&e.trim()!==""&&!Number.isNaN(Number(e))?Number(e):null}function Ie(e){if(e instanceof Date&&!Number.isNaN(e.getTime()))return e.getTime();if(typeof e=="string"){const t=Date.parse(e);return Number.isNaN(t)?null:t}return null}function Me(e,t){const r=Te(e),s=Te(t);if(r!=null&&s!=null)return r-s;const n=Ie(e),a=Ie(t);return n!=null&&a!=null?n-a:e==null||t==null?null:String(e).localeCompare(String(t))}function ut(e,t){return Array.isArray(e)?e.some(r=>r===t):typeof e=="string"?t!=null&&e.includes(String(t)):!1}function se(e,t,r){switch(t){case"equals":return e===r;case"lessThan":{const s=Me(e,r);return s!=null&&s<0}case"greaterThan":{const s=Me(e,r);return s!=null&&s>0}case"contains":return ut(e,r);case"startsWith":return e!=null&&r!=null&&String(e).startsWith(String(r));case"endsWith":return e!=null&&r!=null&&String(e).endsWith(String(r));default:return!1}}function ye(e,t){return t.reduce((r,s)=>r?.[s],e)}function H(e,t,r){if(t.length===0)return e;const[s,...n]=t;if(n.length===0){if(typeof s=="number"){const v=(Array.isArray(e)?e:[]).slice();return v[s]=r,v}return{...e,[s]:r}}const a=e?.[s],l=typeof n[0]=="number"?Array.isArray(a)?a:[]:a&&typeof a=="object"?a:{},o=H(l,n,r);if(typeof s=="number"){const v=(Array.isArray(e)?e:[]).slice();return v[s]=o,v}return{...e,[s]:o}}function ie(e,t,r){return ye(e,[...t??[],r])}function _t(e,t,r,s){return H(e,[...t??[],r],s)}const ft="__items",le=e=>`${e}${ft}`;function pt(e){const t=(r,s)=>r.map((n,a)=>{const l=s.length?s.join("__"):"root",o=n.key??`${l}__q${a}_${String(n.question).slice(0,24).replace(/\W+/g,"-")||"field"}`,v=(n.conditionals??[]).map((k,m)=>{const E=k.conditionalQuestions?t(k.conditionalQuestions,[...s,`${o}__c${m}`]):void 0;return{...k,conditionalQuestions:E}});return{...n,key:o,conditionals:v}});return t(e,[])}function J(e){return e==null?"":typeof e=="string"?e:String(e)}function mt(e){return e==null?"":typeof e=="number"&&Number.isFinite(e)||typeof e=="string"?e:""}function gt(e){return e==null?"":typeof e=="string"||typeof e=="number"?e:String(e)}function ht({questions:e,initialValues:t,controlledValues:r,onChangeValues:s,onSubmit:n}){const a=_.useMemo(()=>pt(e),[e]),l=_.useMemo(()=>{const d={};return t&&Object.assign(d,t),d},[t]),[o,u]=_.useState(l);_.useEffect(()=>{u(l)},[l]);const[v,k]=_.useState({}),m=_.useMemo(()=>({...v,...r??o}),[v,r,o]);_.useEffect(()=>{r&&k(d=>({...d,...r}))},[r]);const[E,I]=_.useState({});function M(d,g){const c=d.key,b=d.question,w=ie(m,g,c),$=E[c],S=f=>{let p=_t(m,g,c,f);if(d.inputType==="radio"&&d.conditionals){const h=d.conditionals??[];for(const y of h){const B=ie(m,g,c),C=se(B,y.conditionalType,y.conditionalValue),N=se(f,y.conditionalType,y.conditionalValue);if(C&&!N&&y.conditionalQuestionsAllowMultiple){const x=y.conditionalQuestions??[];if(x.length>0){const F=le(c);p=H(p,[...g??[],F],[]);const D=(Z,R)=>{Z.forEach(L=>{(L.conditionals??[]).forEach(K=>{if(K.conditionalQuestionsAllowMultiple){const q=le(L.key);p=H(p,[...R,q],[])}const O=K.conditionalQuestions??[];O.length>0&&D(O,R)})})};D(x,[...g??[],F])}}}}r&&s?s(p):u(p),k(p)};switch(d.inputType){case"text":return i.jsx(Je,{id:c,label:b,value:J(w),onChange:f=>S(f.currentTarget.value),"aria-required":d.required||void 0,error:$},c);case"email":return i.jsx(Ze,{id:c,label:b,value:J(w),onChange:f=>S(f.currentTarget.value),"aria-required":d.required||void 0,error:$},c);case"password":return i.jsx(et,{id:c,label:b,value:J(w),onChange:f=>S(f.currentTarget.value),"aria-required":d.required||void 0,error:$},c);case"tel":return i.jsxs(i.Fragment,{children:[i.jsx(Re,{id:c,label:b,value:J(w),onChange:f=>S(f.currentTarget.value),"aria-required":d.required||void 0,error:$},c),c==="phone"&&i.jsxs("div",{className:"mt-3 text-xs text-slate-600 space-y-1",children:[i.jsx("p",{children:"By entering your phone number, you agree to receive a one-time SMS from Credify Insurance with a verification code."}),i.jsx("p",{children:"Message & data rates may apply. One message per request."}),i.jsxs("p",{children:["See our"," ",i.jsx("a",{href:"https://getcredify.com",target:"_blank",rel:"noopener noreferrer",className:"underline hover:text-slate-800",children:"Privacy Policy"})," ","and"," ",i.jsx("a",{href:"https://getcredify.com",target:"_blank",rel:"noopener noreferrer",className:"underline hover:text-slate-800",children:"Terms of Service"}),"."]})]})]});case"url":return i.jsx(qe,{id:c,label:b,value:J(w),onChange:f=>S(f.currentTarget.value),"aria-required":d.required||void 0,error:$},c);case"number":return i.jsx(Xe,{id:c,label:b,value:mt(w),onChange:f=>S(dt(f.currentTarget.value)),"aria-required":d.required||void 0,error:$},c);case"textarea":return i.jsx(tt,{id:c,label:b,value:J(w),onChange:f=>S(f.currentTarget.value),"aria-required":d.required||void 0,error:$,rows:4},c);case"date":return i.jsx(nt,{id:c,label:b,value:J(w),onChange:f=>S(f.currentTarget.value),"aria-required":d.required||void 0,error:$},c);case"checkbox":{if(d.options){const f=Array.isArray(w)?w:[];return i.jsxs("div",{className:"space-y-2",children:[i.jsxs("div",{className:"form-label",children:[b,d.required&&i.jsx("span",{className:"text-red-600 ml-1",children:"*"})]}),i.jsx("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2",children:d.options.map(p=>{const h=`${c}-${he(p)}`,y=f.includes(p);return i.jsx(Ae,{id:h,label:p,checked:y,onChange:B=>{const C=new Set(f);B.currentTarget.checked?C.add(p):C.delete(p),S(Array.from(C))},"aria-required":d.required||void 0},h)})}),$&&i.jsx("p",{className:"mt-1 text-sm text-red-600",children:$})]},c)}return i.jsx(Ae,{id:c,label:d.required?`${b} *`:b,checked:!!w,onChange:f=>S(f.currentTarget.checked),"aria-required":d.required||void 0},c)}case"radio":{const f=d.options??[],p=g&&g.length>0?`${c}__${g.join("__")}`:c;return i.jsx(st,{legend:b,legendClassName:d.required?"legend-required":void 0,children:f.map(h=>i.jsx(rt,{name:p,value:h,checked:w===h,onChange:()=>S(h),children:h},`${c}-${he(h)}`))},c)}case"select":{let f=d.options??[];return c==="quote_vehicle_id"&&(f=r?.vehicles__items?.map(p=>p.vin)??[]),i.jsx(it,{id:c,label:b,"aria-required":d.required||void 0,error:$,value:gt(w),onChange:p=>S(p.currentTarget.value),placeholder:"Select an option",options:f.map(p=>({value:p,label:p}))},c)}case"address":return i.jsx(ct,{id:c,label:b,value:J(w),onChange:f=>S(f),"aria-required":d.required||void 0,error:$},c);default:return null}}function Q(d,g){return d.map((c,b)=>{const w=String(c.key),$=M(c,g),S=c.conditionals??[];if(!S.length)return i.jsx("div",{children:$},`wrap-${w}-${b}`);const f=ie(m,g,w),p=S.filter(y=>se(f,y.conditionalType,y.conditionalValue)),h=p.length>1&&!p.some(y=>y.conditionalQuestionsAllowMultiple)?p.slice(0,1):p;return i.jsxs("div",{children:[$,h.map((y,B)=>{const C=y.conditionalQuestions??[];if(!C.length)return null;if(!y.conditionalQuestionsAllowMultiple)return i.jsx("div",{className:"mt-3",children:Q(C,g)},`branch-${w}-${B}`);const N=le(w),x=ye(m,[...g??[],N])??[],F=Math.max(1,x.length||1),D=()=>{const L=H(m,[...g??[],N,x.length],{});r&&s?s(L):u(L),k(L)},Z=()=>{const L=x.slice(0,Math.max(0,x.length-1)),G=H(m,[...g??[],N],L);r&&s?s(G):u(G),k(G)},R=`${w}__c${B}`;return i.jsxs("div",{className:"mt-3",children:[i.jsxs("div",{className:"flex items-center justify-between mb-2",children:[i.jsx("div",{className:"text-sm font-medium opacity-75",children:"Add one or more entries"}),i.jsxs("div",{className:"space-x-2",children:[i.jsx("button",{type:"button",className:"btn-outline px-3 py-1",onClick:D,children:"Add another"}),F>1&&i.jsx("button",{type:"button",className:"btn-outline px-3 py-1",onClick:Z,children:"Remove last"})]})]}),Array.from({length:F}).map((L,G)=>{const K=[...g??[],N,G],O=`${R}__i${G}`;return i.jsxs("div",{className:"rounded-lg border p-3 mb-3",children:[i.jsxs("div",{className:"text-sm font-semibold mb-2",children:["Entry #",G+1]}),C.map(q=>i.jsxs("div",{className:"mt-3",children:[M(q,K),(()=>{const Ye=q.conditionals??[];if(!Ye.length)return null;const Ot=ie(m,K,q.key),_e=Ye.filter(ee=>se(Ot,ee.conditionalType,ee.conditionalValue));return(_e.length>1&&!_e.some(ee=>ee.conditionalQuestionsAllowMultiple)?_e.slice(0,1):_e).map((ee,$e)=>{const Ee=ee.conditionalQuestions??[];if(!Ee.length)return null;if(!ee.conditionalQuestionsAllowMultiple)return i.jsx("div",{className:"mt-3",children:Q(Ee,K)},`nested-${O}-${$e}`);const fe=le(q.key),pe=ye(m,[...K,fe])??[],Ge=Math.max(1,pe.length||1),zt=()=>{const re=H(m,[...K,fe,pe.length],{});r&&s?s(re):u(re),k(re)},Pt=()=>{const re=pe.slice(0,Math.max(0,pe.length-1)),te=H(m,[...K,fe],re);r&&s?s(te):u(te),k(te)};return i.jsxs("div",{className:"mt-3",children:[i.jsxs("div",{className:"flex items-center justify-between mb-2",children:[i.jsx("div",{className:"text-sm font-medium opacity-75",children:"Add one or more entries"}),i.jsxs("div",{className:"space-x-2",children:[i.jsx("button",{type:"button",className:"btn-outline px-3 py-1",onClick:zt,children:"Add another"}),Ge>1&&i.jsx("button",{type:"button",className:"btn-outline px-3 py-1",onClick:Pt,children:"Remove last"})]})]}),Array.from({length:Ge}).map((re,te)=>{const Ut=[...K,fe,te];return i.jsxs("div",{className:"rounded-lg border p-3 mb-3",children:[i.jsxs("div",{className:"text-sm font-semibold mb-2",children:["Entry #",te+1]}),Q(Ee,Ut)]},`nested-item-${O}-${$e}-${te}`)})]},`nested-repeat-${O}-${$e}`)})})()]},`${O}-${String(q.key)}`))]},`group-${O}`)})]},`branch-${w}-${B}`)})]},`wrap-${w}-${b}`)})}const A=_.useMemo(()=>{const d=[],g=(c,b)=>{c.forEach(w=>{d.push(w);const $=String(w.key),S=w.conditionals??[];if(!S.length)return;const f=ie(m,b,$),p=S.filter(y=>se(f,y.conditionalType,y.conditionalValue));(p.length>1&&!p.some(y=>y.conditionalQuestionsAllowMultiple)?p.slice(0,1):p).forEach(y=>{const B=y.conditionalQuestions??[];B.length&&(y.conditionalQuestionsAllowMultiple||g(B,b))})})};return g(a),d},[a,m]);function T(d){d.preventDefault();const g=oe(A,m);if(I(g),Object.keys(g).length>0){const c=A.findIndex(b=>g[b.key]);c>=0&&document.getElementById(A[c].key)?.focus();return}n(m)}return i.jsx("form",{className:"space-y-6 px-1",onSubmit:T,noValidate:!0,children:Q(a)})}function je(e){return typeof e=="number"&&Number.isFinite(e)?e:typeof e=="string"&&e.trim()!==""&&!Number.isNaN(Number(e))?Number(e):null}function Qe(e){if(e instanceof Date&&!Number.isNaN(e.getTime()))return e.getTime();if(typeof e=="string"){const t=Date.parse(e);return Number.isNaN(t)?null:t}return null}function Be(e,t){const r=je(e),s=je(t);if(r!=null&&s!=null)return r-s;const n=Qe(e),a=Qe(t);return n!=null&&a!=null?n-a:e==null||t==null?null:String(e).localeCompare(String(t))}function yt(e,t){return Array.isArray(e)?e.some(r=>r===t):typeof e=="string"?t!=null&&e.includes(String(t)):!1}function Fe(e,t,r){switch(t){case"equals":return e===r;case"lessThan":{const s=Be(e,r);return s!=null&&s<0}case"greaterThan":{const s=Be(e,r);return s!=null&&s>0}case"contains":return yt(e,r);case"startsWith":return e!=null&&r!=null&&String(e).startsWith(String(r));case"endsWith":return e!=null&&r!=null&&String(e).endsWith(String(r));default:return!1}}function De(e,t){const r=[];return(n=>{n.forEach(a=>{r.push(a);const l=String(a.key),o=t[l],u=a.conditionals??[];if(!u.length)return;const v=u.filter(m=>Fe(o,m.conditionalType,m.conditionalValue));(v.length>1&&!v.some(m=>m.conditionalQuestionsAllowMultiple)?v.slice(0,1):v).forEach(m=>{const E=m.conditionalQuestions??[];E.length&&(m.conditionalQuestionsAllowMultiple||E.forEach(I=>r.push(I)))})})})(e),r}const We="__items",Ke=e=>`${e}${We}`;function be(e,t){for(const r of e){const s=String(r.key),n=t[s],a=r.conditionals??[];if(!a.length)continue;const l=a.filter(u=>Fe(n,u.conditionalType,u.conditionalValue)),o=l.length>1&&!l.some(u=>u.conditionalQuestionsAllowMultiple)?l.slice(0,1):l;for(const u of o){const v=u.conditionalQuestions??[];if(!v.length)continue;if(!u.conditionalQuestionsAllowMultiple){if(be(v,t))return!0;continue}const k=t[Ke(s)]??[];if(k.length===0)return!0;for(const m of k){const E=oe(v,m);if(Object.values(E).some(Boolean)||be(v,m))return!0}}}return!1}function Le(e,t){return be(e,t)}function bt({stages:e,onStageComplete:t,onComplete:r,initialValues:s,initialActive:n}){const[a,l]=_.useState(n??0),[o,u]=_.useState(s??{}),[v,k]=_.useState({}),[m,E]=_.useState(!1),[I,M]=_.useState(!1),[Q,A]=_.useState(null),T=_.useRef([]),d=Array.isArray(e)&&e.length>0,g=d?e[Math.min(a,e.length-1)]:null,c=g?.key??null;_.useEffect(()=>{n!==void 0&&l(n)},[n]),_.useEffect(()=>{const h=T.current[a];h&&h.scrollIntoView({behavior:"smooth",block:"nearest",inline:"center"})},[a]),_.useEffect(()=>{s!==void 0&&u(s)},[s]),_.useEffect(()=>{if(!g||!c){E(!1),A(null);return}if(v[c]){E(!1),A(null);return}let h=!1;return E(!0),A(null),Promise.resolve(g.loadQuestions()).then(y=>{if(!h){if(!Array.isArray(y))throw new Error(`loadQuestions("${c}") did not return an array`);k(B=>({...B,[c]:y}))}}).catch(y=>{h||A(`Failed to load stage "${g?.title??""}": ${y?.message??"Unknown error"}`)}).finally(()=>{h||E(!1)}),()=>{h=!0}},[g,c,v]);const b=c?v[c]:void 0,w=_.useMemo(()=>{if(!b)return{};const h={};(C=>{const N=[],x=F=>{F.forEach((D,Z)=>{const R=Ce(D,Z);N.push(R);const L=Ke(R);N.push(L),(D.conditionals??[]).forEach(K=>{const O=K.conditionalQuestions??[];O.length>0&&x(O)})})};return x(C),N})(b).forEach(C=>{C in o&&(h[C]=o[C])});for(const[C,N]of Object.entries(o))C.endsWith(We)&&!(C in h)&&(h[C]=N);return h},[b,o]),$=h=>{u(y=>({...y,...h}))},S=()=>{l(h=>h>0?h-1:0),document.querySelector(".panel-body")?.scrollTo({top:0,behavior:"instant"})},f=async()=>{if(!b||!g||m||Q||I)return;const h=De(b,o),y=oe(h,o),B=Object.values(y).some(Boolean),C=Le(b,o);if(!(B||C)){M(!0);try{const N=Math.min(a+1,e.length-1),x=a>=e.length-1,{success:F,error:D}=x?await r(o,c??""):await t(w,c??"");if(!F){A(D??"An error occurred");return}x||l(N)}finally{M(!1)}}},p=_.useMemo(()=>{if(!b||m||Q||I)return!0;const h=De(b,o),y=oe(h,o),B=Object.values(y).some(Boolean),C=Le(b,o);return B||C},[b,o,m,Q,I]);return d?i.jsxs("div",{className:"space-y-6",children:[i.jsxs("div",{className:"flex items-center justify-between gap-4",children:[i.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:e.flatMap((h,y)=>[i.jsx("li",{ref:B=>{T.current[y]=B},className:`px-2.5 py-1 rounded-full border whitespace-nowrap flex-shrink-0 ${y<a?"bg-blue-600 text-white border-blue-600":y===a?"border-blue-600 text-blue-600 bg-white":"border-slate-200 text-slate-600"}`,children:h.title},h.key??`stage-${y}`),...y<e.length-1?[i.jsx("li",{className:"text-slate-400 flex-shrink-0",children:"→"},`arrow-${h.key??y}`)]:[]])}),i.jsxs("div",{className:"text-sm text-slate-500 flex-shrink-0",children:[Math.min(a+1,e.length)," / ",e.length]})]}),i.jsxs("div",{children:[m&&i.jsx("div",{className:"text-slate-500",children:"Loading…"}),g&&i.jsx(ht,{questions:b??[],controlledValues:w,onChangeValues:$,onSubmit:()=>f()},g.key)]}),!m&&Q&&i.jsxs("div",{className:"text-red-600 text-sm -mt-4",children:[i.jsx("div",{children:Q}),g&&i.jsx("button",{type:"button",className:"underline mt-1 font-bold",onClick:()=>{k(h=>{if(!c)return h;const y={...h};return delete y[c],y})},children:"Retry"})]}),i.jsxs("div",{className:a>0?"grid grid-cols-2 gap-3":"",children:[a>0&&i.jsx("button",{type:"button",onClick:S,disabled:m,className:"h-12 rounded-full border border-gray-300 text-text-primary hover:bg-gray-50 transition",children:"Back"}),i.jsxs("button",{type:"button",onClick:f,disabled:p,className:[a>0?"":"w-full","h-12 rounded-full text-white transition","disabled:opacity-50 disabled:cursor-not-allowed","flex items-center justify-center gap-2",p?"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:[I&&i.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:[i.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),i.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"})]}),a===e.length-1?"Finish":"Next"]})]})]}):i.jsx("div",{className:"text-slate-600",children:"Loading..."})}const ve="credify_quote_id",we="credify_auth_token";function vt(e){try{localStorage.setItem(ve,e)}catch(t){console.error("Failed to save quoteId to localStorage:",t)}}function wt(){try{return localStorage.getItem(ve)}catch(e){return console.error("Failed to load quoteId from localStorage:",e),null}}function Oe(){try{localStorage.removeItem(ve)}catch(e){console.error("Failed to clear quoteId from localStorage:",e)}}function xt(e){try{localStorage.setItem(we,e)}catch(t){console.error("Failed to save authToken to localStorage:",t)}}function Nt(){try{return localStorage.getItem(we)}catch(e){return console.error("Failed to load authToken from localStorage:",e),null}}function ze(){try{localStorage.removeItem(we)}catch(e){console.error("Failed to clear authToken from localStorage:",e)}}function kt(){Oe(),ze()}const U="https://api.getcredify.com";let ne=null;function St(e){ne=e,xt(e)}function ce(){return ne}function xe(){const e=Nt();e&&(ne=e)}function Pe(){ne=null,ze()}async function V(e,t){const r={"Content-Type":"application/json"};ne&&(r.Authorization=`Bearer ${ne}`);const s=await fetch(e,{method:"POST",headers:r,body:JSON.stringify(t)});if(!s.ok){let n=`Request failed with status ${s.status}`;try{n=(await s.json()).error||n}catch{n=s.statusText||n}const a=new Error(n);throw a.statusCode=s.status,a}return s}async function $t(e){return await(await V(`${U}/get-questions-by-stage`,{stage:e})).json()}async function Ne(){return await(await V(`${U}/get-stages-for-quote`,{})).json()}async function Et(e){const r=await(await V(`${U}/create-quote`,{phone:e})).json();if(!r||typeof r!="object"||!r.quoteId)throw new Error(`Invalid createQuote response: ${JSON.stringify(r)}`);return r}async function ae(e,t,r){const s={payload:e,getRates:t};return r&&typeof r=="string"&&r.trim()!==""&&(s.quoteId=r),await(await V(`${U}/update-quote`,s)).json()}async function At(e,t){return await(await V(`${U}/verify-quote`,{quoteId:e,smsCode:t})).json()}async function Ct(e){return await(await V(`${U}/is-supported-state`,{state:e})).json()}async function Tt(){return await(await V(`${U}/get-rates`,{})).json()}async function It(e){const t=e?{quoteId:e}:{};return await(await V(`${U}/get-quote`,t)).json()}async function Mt(e){const r=await(await V(`${U}/request-bind`,{quoteRateId:e})).json();return r&&typeof r=="object"&&"success"in r?r:{success:!0}}const jt=new Intl.NumberFormat("en-US",{style:"currency",currency:"USD"});function Ue({onBack:e}){return i.jsx("button",{type:"button",onClick:e,className:"mt-4 h-12 rounded-full border border-gray-300 text-text-primary hover:bg-gray-50 transition w-full",children:"Back"})}function Qt({rates:e,onBack:t}){const r=Array.isArray(e)&&e.length>0,[s,n]=_.useState({});return _.useEffect(()=>{xe()},[]),r?i.jsxs("section",{className:"mt-8",children:[i.jsx("h3",{className:"text-lg font-semibold text-slate-900",children:"Rates"}),i.jsx("div",{className:"mt-4 grid gap-4 sm:grid-cols-2 lg:grid-cols-3",children:e.map(a=>{const l=a.premium_cents/100,o=jt.format(l),u=a.quote_rate_id,v=s[u]??"idle",k=v==="loading",m=v==="success",E=async()=>{n(I=>({...I,[u]:"loading"}));try{if(xe(),!ce())throw new Error("Authentication required. Please verify your phone number first.");if(!((await Mt(a.quote_rate_id))?.success!==!1))throw new Error("Request failed");kt(),Pe(),n(A=>({...A,[u]:"success"}))}catch{n(I=>({...I,[u]:"error"}))}};return i.jsxs("div",{className:"flex flex-col rounded-xl border border-slate-200 bg-white p-6 shadow-sm transition hover:shadow-md",children:[i.jsxs("div",{className:"mb-4 flex items-center gap-3",children:[a.carrier_logo_base64?i.jsx("img",{src:`data:image/png;base64,${a.carrier_logo_base64}`,alt:a.carrier_name,className:"h-12 w-auto object-contain"}):i.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:a.carrier_name.charAt(0).toUpperCase()}),i.jsx("div",{className:"flex-1",children:i.jsx("h4",{className:"font-semibold text-slate-900",children:a.carrier_name})})]}),i.jsxs("div",{className:"mb-2",children:[i.jsx("p",{className:"text-sm text-slate-500",children:"Premium"}),i.jsx("p",{className:"text-2xl font-bold text-slate-900",children:o})]}),i.jsxs("div",{className:"mb-4",children:[i.jsx("p",{className:"text-sm text-slate-500",children:"Term"}),i.jsxs("p",{className:"font-medium text-slate-700",children:[a.term_months," months"]})]}),a.carrier_quote_id&&i.jsx("div",{className:"mb-4",children:i.jsxs("p",{className:"text-xs text-slate-400",children:["Quote ID: ",a.carrier_quote_id]})}),i.jsxs("div",{className:"mt-auto pt-4",children:[i.jsx("button",{type:"button",onClick:E,disabled:k||m,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 ${m?"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:k?"Requesting…":m?"Requested":"Request Bind"}),v==="error"&&i.jsx("p",{className:"mt-2 text-xs text-red-600",children:"Something went wrong. Please try again."}),v==="success"&&i.jsx("p",{className:"mt-2 text-xs text-emerald-600",children:"We received your bind request."})]})]},u)})}),t&&i.jsx(Ue,{onBack:t})]}):i.jsxs("section",{className:"mt-8",children:[i.jsx("h3",{className:"text-lg font-semibold text-slate-900",children:"Rates"}),i.jsx("p",{className:"mt-2 text-sm text-slate-500",children:"No rates are available at this time."}),t&&i.jsx(Ue,{onBack:t})]})}function j(e){if(e===!0)return"Yes";if(e===!1)return"No"}function P(e){if(e)try{const t=typeof e=="string"?new Date(e):e;return isNaN(t.getTime())?void 0:t.toISOString().split("T")[0]}catch{return}}function Bt(e){const t={};e.phone&&(t.phone=e.phone),e.first_name&&(t.first_name=e.first_name),e.last_name&&(t.last_name=e.last_name),e.email&&(t.email=e.email),e.date_of_birth&&(t.date_of_birth=P(e.date_of_birth)),e.product&&(t.product=e.product),e.state&&(t.state=e.state);const r=[];e.line_1&&r.push(e.line_1),e.line_2&&r.push(e.line_2),e.city&&r.push(e.city),e.state&&r.push(e.state),e.postal_code&&r.push(e.postal_code),r.length>0&&(t.address=r.join(", ")),e.years_at_address!==null&&e.years_at_address!==void 0&&(t.years_at_address=e.years_at_address),e.months_at_address!==null&&e.months_at_address!==void 0&&(t.months_at_address=e.months_at_address),e.move_in_date&&(t.move_in_date=P(e.move_in_date));const s=[];return e.prior_line_1&&s.push(e.prior_line_1),e.prior_line_2&&s.push(e.prior_line_2),e.prior_city&&s.push(e.prior_city),e.prior_state&&s.push(e.prior_state),e.prior_postal_code&&s.push(e.prior_postal_code),s.length>0&&(t.prior_address=s.join(", ")),e.years_at_prior_address!==null&&e.years_at_prior_address!==void 0&&(t.years_at_prior_address=e.years_at_prior_address),e.auto_has_prior_insurance!==null&&e.auto_has_prior_insurance!==void 0&&(t.auto_has_prior_insurance=j(e.auto_has_prior_insurance)),e.auto_prior_expiration_date&&(t.auto_prior_expiration_date=P(e.auto_prior_expiration_date)),e.auto_prior_carrier_name&&(t.auto_prior_carrier_name=e.auto_prior_carrier_name),e.auto_prior_liability_limit&&(t.auto_prior_liability_limit=e.auto_prior_liability_limit),e.auto_reason_for_no_insurance&&(t.auto_reason_for_no_insurance=e.auto_reason_for_no_insurance),e.auto_prior_years!==null&&e.auto_prior_years!==void 0&&(t.auto_prior_years=e.auto_prior_years),e.auto_prior_months!==null&&e.auto_prior_months!==void 0&&(t.auto_prior_months=e.auto_prior_months),e.auto_continuous_coverage_years!==null&&e.auto_continuous_coverage_years!==void 0&&(t.auto_continuous_coverage_years=e.auto_continuous_coverage_years),e.auto_cancelled_declined_refused_to_renew!==null&&e.auto_cancelled_declined_refused_to_renew!==void 0&&(t.auto_cancelled_declined_refused_to_renew=j(e.auto_cancelled_declined_refused_to_renew)),e.home_has_prior_insurance!==null&&e.home_has_prior_insurance!==void 0&&(t.home_has_prior_insurance=j(e.home_has_prior_insurance)),e.home_prior_expiration_date&&(t.home_prior_expiration_date=P(e.home_prior_expiration_date)),e.home_prior_carrier_name&&(t.home_prior_carrier_name=e.home_prior_carrier_name),e.year_built!==null&&e.year_built!==void 0&&(t.year_built=e.year_built),e.number_of_units!==null&&e.number_of_units!==void 0&&(t.number_of_units=e.number_of_units),e.number_of_stories!==null&&e.number_of_stories!==void 0&&(t.number_of_stories=e.number_of_stories),e.number_of_beds!==null&&e.number_of_beds!==void 0&&(t.number_of_beds=e.number_of_beds),e.number_of_full_baths!==null&&e.number_of_full_baths!==void 0&&(t.number_of_full_baths=e.number_of_full_baths),e.number_of_partial_baths!==null&&e.number_of_partial_baths!==void 0&&(t.number_of_partial_baths=e.number_of_partial_baths),e.under_construction!==null&&e.under_construction!==void 0&&(t.under_construction=j(e.under_construction)),e.distance_from_fire_hydrant_ft&&(t.distance_from_fire_hydrant_ft=e.distance_from_fire_hydrant_ft),e.distance_from_fire_station_miles&&(t.distance_from_fire_station_miles=e.distance_from_fire_station_miles),e.architectural_style&&(t.architectural_style=e.architectural_style),e.dwelling_type&&(t.dwelling_type=e.dwelling_type),e.construction_quality&&(t.construction_quality=e.construction_quality),e.located_over_water!==null&&e.located_over_water!==void 0&&(t.located_over_water=e.located_over_water),e.construction_type&&(t.construction_type=e.construction_type),e.exterior_wall_type&&(t.exterior_wall_type=e.exterior_wall_type),e.foundation_type&&(t.foundation_type=e.foundation_type),e.roof_material_type&&(t.roof_material_type=e.roof_material_type),e.year_roof_updated!==null&&e.year_roof_updated!==void 0&&(t.year_roof_updated=e.year_roof_updated),e.heating_type&&(t.heating_type=e.heating_type),e.heating_fuel_type&&(t.heating_fuel_type=e.heating_fuel_type),e.number_of_fireplaces!==null&&e.number_of_fireplaces!==void 0&&(t.number_of_fireplaces=e.number_of_fireplaces),e.basement_type&&(t.basement_type=e.basement_type),e.parking_type&&(t.parking_type=e.parking_type),e.number_of_parking_spaces!==null&&e.number_of_parking_spaces!==void 0&&(t.number_of_parking_spaces=e.number_of_parking_spaces),e.plumbing_type&&(t.plumbing_type=e.plumbing_type),e.pool_type&&(t.pool_type=e.pool_type),e.total_area_sq_ft!==null&&e.total_area_sq_ft!==void 0&&(t.total_area_sq_ft=e.total_area_sq_ft),e.parcel_area_sq_ft!==null&&e.parcel_area_sq_ft!==void 0&&(t.parcel_area_sq_ft=e.parcel_area_sq_ft),e.residence_type&&(t.residence_type=e.residence_type),e.usage_type&&(t.usage_type=e.usage_type),e.household_size!==null&&e.household_size!==void 0&&(t.household_size=e.household_size),e.number_of_mortgagees!==null&&e.number_of_mortgagees!==void 0&&(t.number_of_mortgagees=e.number_of_mortgagees),e.has_dog!==null&&e.has_dog!==void 0&&(t.has_dog=j(e.has_dog)),e.dog_breed_type&&(t.dog_breed_type=e.dog_breed_type),e.number_of_dogs!==null&&e.number_of_dogs!==void 0&&(t.number_of_dogs=e.number_of_dogs),e.has_business_on_premises!==null&&e.has_business_on_premises!==void 0&&(t.has_business_on_premises=j(e.has_business_on_premises)),e.business_class&&(t.business_class=e.business_class),e.retiree_discount!==null&&e.retiree_discount!==void 0&&(t.retiree_discount=j(e.retiree_discount)),e.gated_community_discount!==null&&e.gated_community_discount!==void 0&&(t.gated_community_discount=j(e.gated_community_discount)),e.multi_policy_discount!==null&&e.multi_policy_discount!==void 0&&(t.multi_policy_discount=j(e.multi_policy_discount)),e.non_smoker_discount!==null&&e.non_smoker_discount!==void 0&&(t.non_smoker_discount=j(e.non_smoker_discount)),e.first_time_buyer_discount!==null&&e.first_time_buyer_discount!==void 0&&(t.first_time_buyer_discount=j(e.first_time_buyer_discount)),e.fire_detection_system!==null&&e.fire_detection_system!==void 0&&(t.fire_detection_system=j(e.fire_detection_system)),e.burglar_alarm_system!==null&&e.burglar_alarm_system!==void 0&&(t.burglar_alarm_system=j(e.burglar_alarm_system)),e.burglar_alarm_system_type&&(t.burglar_alarm_system_type=e.burglar_alarm_system_type),e.smoke_detectors!==null&&e.smoke_detectors!==void 0&&(t.smoke_detectors=j(e.smoke_detectors)),e.sprinkler_system!==null&&e.sprinkler_system!==void 0&&(t.sprinkler_system=j(e.sprinkler_system)),e.sprinkler_system_type&&(t.sprinkler_system_type=e.sprinkler_system_type),e.gas_leakage_detector!==null&&e.gas_leakage_detector!==void 0&&(t.gas_leakage_detector=j(e.gas_leakage_detector)),e.deadbolt_locks!==null&&e.deadbolt_locks!==void 0&&(t.deadbolt_locks=j(e.deadbolt_locks)),e.fire_extinguisher!==null&&e.fire_extinguisher!==void 0&&(t.fire_extinguisher=j(e.fire_extinguisher)),e.order_credit_authorized!==null&&e.order_credit_authorized!==void 0&&(t.order_credit_authorized=j(e.order_credit_authorized)),e.has_health_insurance_auto_accident!==null&&e.has_health_insurance_auto_accident!==void 0&&(t.has_health_insurance_auto_accident=j(e.has_health_insurance_auto_accident)),e.named_insured_foreclosure_repo_bankruptcy!==null&&e.named_insured_foreclosure_repo_bankruptcy!==void 0&&(t.named_insured_foreclosure_repo_bankruptcy=j(e.named_insured_foreclosure_repo_bankruptcy)),e.named_insured_convicted_insurance_fraud!==null&&e.named_insured_convicted_insurance_fraud!==void 0&&(t.named_insured_convicted_insurance_fraud=j(e.named_insured_convicted_insurance_fraud)),e.drivers&&e.drivers.length>0?(t.drivers="Yes",t.drivers__items=e.drivers.map(n=>{const a={};return n.first_name&&(a.first_name=n.first_name),n.last_name&&(a.last_name=n.last_name),n.date_of_birth&&(a.date_of_birth=P(n.date_of_birth)),n.gender&&(a.gender=n.gender),n.marital_status&&(a.marital_status=n.marital_status),n.relationship_to_insured&&(a.relationship_to_insured=n.relationship_to_insured),n.license_state&&(a.license_state=n.license_state),n.license_status&&(a.license_status=n.license_status),n.license_number&&(a.license_number=n.license_number),n.date_first_licensed&&(a.date_first_licensed=P(n.date_first_licensed)),n.education_level&&(a.education_level=n.education_level),n.occupation&&(a.occupation=n.occupation),n.industry&&(a.industry=n.industry),n.driver_violations&&n.driver_violations.length>0&&(a.driver_violations__items=n.driver_violations.map(l=>{const o={};return l.code&&(o.code=l.code),l.occurred_at&&(o.occurred_at=P(l.occurred_at)),o})),n.driver_accidents&&n.driver_accidents.length>0&&(a.driver_accidents__items=n.driver_accidents.map(l=>{const o={};return l.occurred_at&&(o.occurred_at=P(l.occurred_at)),l.description&&(o.description=l.description),l.quote_vehicle_id&&(o.quote_vehicle_id=l.quote_vehicle_id),l.property_damage_amount_paid_cents!==null&&l.property_damage_amount_paid_cents!==void 0&&(o.property_damage_amount_paid_cents=l.property_damage_amount_paid_cents),l.personal_injury_amount_paid_cents!==null&&l.personal_injury_amount_paid_cents!==void 0&&(o.personal_injury_amount_paid_cents=l.personal_injury_amount_paid_cents),o})),n.losses&&n.losses.length>0&&(a.losses=n.losses.map(l=>{const o={};return l.description&&(o.description=l.description),l.date_of_incident&&(o.date_of_incident=P(l.date_of_incident)),l.amount_paid_cents!==null&&l.amount_paid_cents!==void 0&&(o.amount_paid_cents=l.amount_paid_cents),l.quote_vehicle_id&&(o.quote_vehicle_id=l.quote_vehicle_id),o})),a})):t.drivers="No",e.vehicles&&e.vehicles.length>0?(t.vehicles="Yes",t.vehicles__items=e.vehicles.map(n=>{const a={};n.vin&&(a.vin=n.vin),n.year!==null&&n.year!==void 0&&(a.year=n.year),n.make&&(a.make=n.make),n.model&&(a.model=n.model),n.ownership_type&&(a.ownership_type=n.ownership_type),n.usage&&(a.usage=n.usage),n.annual_mileage!==null&&n.annual_mileage!==void 0&&(a.annual_mileage=n.annual_mileage),n.miles_to_work!==null&&n.miles_to_work!==void 0&&(a.miles_to_work=n.miles_to_work),n.percent_to_work!==null&&n.percent_to_work!==void 0&&(a.percent_to_work=n.percent_to_work);const l=[];return n.garaging_address_line_1&&l.push(n.garaging_address_line_1),n.garaging_address_line_2&&l.push(n.garaging_address_line_2),n.garaging_address_city&&l.push(n.garaging_address_city),n.garaging_address_state&&l.push(n.garaging_address_state),n.garaging_address_postal_code&&l.push(n.garaging_address_postal_code),l.length>0&&(a.garaging_address=l.join(", ")),n.anti_theft_type&&(a.anti_theft_type=n.anti_theft_type),n.passive_restraint_type&&(a.passive_restraint_type=n.passive_restraint_type),n.coverages&&n.coverages.length>0&&(a.coverages__items=n.coverages.map(o=>{const u={};return o.type&&(u.type=o.type),o.per_person_limit_cents!==null&&o.per_person_limit_cents!==void 0&&(u.per_person_limit_cents=o.per_person_limit_cents),o.per_incident_limit_cents!==null&&o.per_incident_limit_cents!==void 0&&(u.per_incident_limit_cents=o.per_incident_limit_cents),o.per_incident_limit_percent!==null&&o.per_incident_limit_percent!==void 0&&(u.per_incident_limit_percent=o.per_incident_limit_percent),o.per_day_limit_cents!==null&&o.per_day_limit_cents!==void 0&&(u.per_day_limit_cents=o.per_day_limit_cents),o.deductible_cents!==null&&o.deductible_cents!==void 0&&(u.deductible_cents=o.deductible_cents),o.is_declined!==null&&o.is_declined!==void 0&&(u.is_declined=j(o.is_declined)),u})),n.vehicle_lienholders&&n.vehicle_lienholders.length>0&&(a.vehicle_lienholders__items=n.vehicle_lienholders.map(o=>{const u={};return o.name&&(u.name=o.name),o.type&&(u.type=o.type),o.line_1&&(u.line_1=o.line_1),o.line_2&&(u.line_2=o.line_2),o.city&&(u.city=o.city),o.state&&(u.state=o.state),o.postal_code&&(u.postal_code=o.postal_code),o.phone&&(u.phone=o.phone),o.fax&&(u.fax=o.fax),u})),a})):t.vehicles="No",e.losses&&e.losses.length>0&&(t.home_losses__items=e.losses.map(n=>{const a={};return n.description&&(a.description=n.description),n.date_of_incident&&(a.date_of_incident=P(n.date_of_incident)),n.amount_paid_cents!==null&&n.amount_paid_cents!==void 0&&(a.amount_paid_cents=n.amount_paid_cents),a})),t}function ke(e){const t={},r=a=>{if(typeof a=="string"){if(a==="Yes")return!0;if(a==="No")return!1}return a},s=Object.keys(e).filter(a=>!a.includes("__items")),n=new Set;for(const[a,l]of Object.entries(e))a.endsWith("__items")&&Array.isArray(l)&&l.forEach(o=>{typeof o=="object"&&o!==null&&Object.keys(o).forEach(u=>{n.add(u)})});for(const[a,l]of Object.entries(e))if(a.endsWith("__items")){const o=a.replace("__items","");if(s.includes(o)){const v=Array.isArray(l)?l.map(k=>ke(k)):l;t[o]=v}}else a.includes("__items")||n.has(a)||(t[a]=r(l));return t}function Ft({isOpen:e,onClose:t}){const[r,s]=_.useState([]),[n,a]=_.useState(null),[l,o]=_.useState(null),[u,v]=_.useState(null),[k,m]=_.useState(void 0),[E,I]=_.useState(!1);function M(A){const T={SMSVerification:"Verify",AutoCurrentCarrier:"Current Auto Policy",HomeCurrentCarrier:"Current Home Policy"};return A.map(d=>({key:d,title:T[d]||d,loadQuestions:async()=>(await $t(d)).questions}))}_.useEffect(()=>{e&&(async()=>{try{const T=wt();if(xe(),T){I(!0),a(T);try{const d=ce(),g=await It(d?void 0:T);if(!g||!g.quote)throw new Error("Invalid response from getQuote: missing quote data");const{quote:c}=g,{stages:b}=await Ne(),w=M(b);s(w);try{const $=Bt(c);v($)}catch($){throw new Error(`Failed to transform quote data: ${$ instanceof Error?$.message:"Unknown error"}`)}if(c.current_stage){const $=w.findIndex(S=>S.key===c.current_stage);$>=0?m($):m(w.length-1)}else m(w.length-1)}catch(d){d.statusCode===404?(Oe(),a(null)):Pe()}finally{I(!1)}}else{const{stages:d}=await Ne();s(M(d))}}catch{I(!1)}})()},[e]),_.useEffect(()=>{if(!e)return;const{overflow:A}=document.body.style;return document.body.style.overflow="hidden",()=>{document.body.style.overflow=A}},[e]);const Q=_.useCallback(A=>{A.key==="Escape"&&t()},[t]);return _.useEffect(()=>{if(e)return window.addEventListener("keydown",Q),()=>window.removeEventListener("keydown",Q)},[e,Q]),_.useEffect(()=>{e||(v(null),m(void 0),I(!1))},[e]),e?i.jsxs("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center",role:"dialog","aria-modal":"true","aria-labelledby":"insurance-modal-title",children:[i.jsx("div",{className:"backdrop",onClick:t,"aria-hidden":"true"}),i.jsxs("div",{className:"modal-panel bg-white relative w-full max-w-2xl flex flex-col max-h-[90vh] overflow-hidden",role:"document",children:[i.jsx("button",{onClick:t,className:"absolute top-4 right-4 text-slate-400 hover:text-slate-600 text-xl","aria-label":"Close",type:"button",children:"×"}),i.jsxs("div",{className:"text-center mb-6",children:[i.jsx("h2",{id:"insurance-modal-title",className:"h1-title",children:"Let's get you the best insurance rates."}),i.jsx("p",{className:"p-subtitle",children:"This should only take a few minutes."})]}),i.jsxs("div",{className:"panel-body flex-1 min-h-0 overflow-y-auto",children:[!l&&i.jsx(i.Fragment,{children:E||r.length===0?i.jsx("div",{className:"flex items-center justify-center py-12",children:i.jsx("div",{className:"text-slate-600",children:"Loading..."})}):i.jsx(bt,{stages:r,initialValues:u??void 0,initialActive:k,onStageComplete:async(A,T)=>{try{const d=ke(A),{stages:g}=await Ne(),c=M(g);s(c);const w=c.findIndex(f=>f.key===T)+1,S=(w<c.length?c[w]:null)?.key||T;if(n)if(T==="SMSVerification"){const{isVerified:f,token:p}=await At(n,d.sms_code);if(!f)throw new Error("Invalid SMS code");p&&St(p),await ae({current_stage:S},!1)}else if(T==="State"){const{isSupported:f}=await Ct(d.state);if(!f)throw new Error("State is not supported");const p=ce();await ae({...d,current_stage:S},!1,p?void 0:n)}else{const f=ce();await ae({...d,current_stage:S},!1,f?void 0:n||void 0)}else{const p=(await Et(d.phone))?.quoteId;if(!p||typeof p!="string"||p.trim()==="")throw new Error(`Failed to create quote - invalid quoteId returned: ${p}`);a(p),vt(p),await ae({current_stage:S},!1,p)}return{success:!0}}catch(d){return{success:!1,error:d instanceof Error?d.message:"An error occurred"}}},onComplete:async A=>{try{const T=ke(A);if(!n)throw new Error("Quote ID is required");await ae(T,!0),v(A);const{rates:d}=await Tt();return o(d),{success:!0}}catch(T){return{success:!1,error:T instanceof Error?T.message:"An error occurred"}}}})})," ",l&&n&&i.jsx(Qt,{rates:l,onBack:()=>o(null)})]}),i.jsx("div",{className:"mt-4 pt-4 border-t border-slate-200",children:i.jsx("p",{className:"text-center text-sm text-slate-500",children:"Insurance products offered through Credify Corporation, a licensed insurance agency."})})]})]}):null}function Dt({isOpen:e}){return i.jsx(Ft,{isOpen:e,onClose:()=>{ue.close()}})}const Ve="credify-insurance-widget-styles";function Wt(){if(typeof document>"u"||document.getElementById(Ve))return;const e=document.currentScript,t=e?.getAttribute?.("src")||e?.src;if(!(!t||!/credify-insurance-widget|index\.umd\.js/.test(t)))try{const n=`${t.replace(/\/[^/?#]+(\?.*)?$/,"")}/credify-insurance-widget.css`,a=document.createElement("link");a.id=Ve,a.rel="stylesheet",a.href=n,document.head.appendChild(a)}catch{}}Wt();let Y=null,X=null,de=!1;function Kt(){Y||(Y=document.createElement("div"),Y.id="insurance-widget-root",document.documentElement.appendChild(Y)),!X&&Y&&(X=He.createRoot(Y))}function Se(){Kt(),X&&X.render(_.createElement(Dt,{isOpen:de}))}function Lt(){X&&Y&&(X.unmount(),Y.remove()),X=null,Y=null}const ue={init:e=>{de=!!e?.autoOpen,Se()},open:()=>{de=!0,Se()},close:()=>{de=!1,Se()},destroy:Lt};typeof window<"u"&&(window.CredifyInsuranceWidget=ue),W.CredifyInsuranceWidget=ue,W.default=ue,Object.defineProperties(W,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
|
|
2
2
|
//# sourceMappingURL=index.umd.js.map
|