1import{n as t,t as e}from"@theme/normalizeUsPhone";/* empty css */function findValue(t,e){const a=Object.keys(t).find(t=>e.test(t));return a?t[a]?.trim():void 0}function showToast({message:t,secondaryMessage:e,type:a="info",position:o="bottom-center",duration:s=4e3}){const n=document.createElement("div");n.className=`toast toast--${o} toast--${a}`;const i=document.createElement("div");i.className="toast__content";const r=document.createElement("div");if(r.className="toast__message",r.textContent=t,i.appendChild(r),e){const t=document.createElement("div");t.className="toast__secondary-message",t.textContent=e,i.appendChild(t)}const c=document.createElement("button");c.type="button",c.className="toast__close-btn",c.setAttribute("aria-label","Close toast"),c.textContent="Ã",n.appendChild(i),n.appendChild(c),document.body.appendChild(n),requestAnimationFrame(()=>{n.classList.add("toast--visible")});let l=!1;const remove=()=>{l||(l=!0,n.classList.remove("toast--visible"),setTimeout(()=>n.remove(),300))};c.addEventListener("click",remove),s>0&&setTimeout(remove,s)}var a=/phone|mobile|tel/i;async function handleFormCarrySubmission({form:o}){if(!function validatePhoneFields(o){const s=o.querySelectorAll('input[type="text"], input[type="tel"]');for(const n of Array.from(s)){if(!a.test(n.name))continue;const{e164:o,valid:s}=t(n.value);if(!s)return n.setCustomValidity(e),n.addEventListener("input",()=>n.setCustomValidity(""),{once:!0}),n.reportValidity(),!1;o&&(n.value=o)}return!0}(o))return null;const s=o.dataset.formcarry,n=o.querySelector("[type='submit']");n?.classList.add("loading");const i=new FormData(o),r=o.id.substring(o.id.indexOf("-")+1),c=document.getElementById(`success-${r}`),l=o.dataset.errorMessage||"Something went wrong. Please try again.",d=new FormData,u=new Set;i.forEach((t,e)=>{if(e.endsWith("[]")){const t=e.slice(0,-2);if(u.has(t))return;u.add(t);const a=i.getAll(e).map(t=>"string"==typeof t?t:"");d.append(t,a.join(", "))}else d.append(e,t)});const m={};d.forEach((t,e)=>{m[e]=t});try{const e=await fetch(`https://formcarry.com/s/${s}`,{method:"POST",headers:{Accept:"application/json"},body:d});if(!e.ok){let t="";try{const a=await e.json();t=a?.message||a?.title||""}catch{}return showToast({message:l,secondaryMessage:t||`Status ${e.status}`,type:"error"}),null}if(function shouldSubscribeToKlaviyo(t,e){return!(!t.dataset.klaviyoListId||!t.dataset.klaviyoCompanyId)&&("true"===t.dataset.klaviyoSignupAll||Boolean(e.newsletter_consent))}(o,m)&&async function subscribeToKlaviyo({companyId:e,listId:a,formObject:o,source:s="Formcarry Form"}){const n=findValue(o,/e-?mail/i);if(!n)return console.warn("subscribeToKlaviyo: no email found in form, skipping."),!1;const i=findValue(o,/phone|mobile|tel/i),r=i?t(i).e164:null,c={email:n,first_name:findValue(o,/first.?name/i)??"",last_name:findValue(o,/last.?name/i)??"",phone_number:r,properties:o,subscriptions:{email:{marketing:{consent:"SUBSCRIBED"}}}},l=findValue(o,/state|province|region/i);l&&(c.location={region:l});const d={data:{type:"subscription",attributes:{custom_source:s,profile:{data:{type:"profile",attributes:c}}},relationships:{list:{data:{type:"list",id:a}}}}};try{const t=await fetch(`https://a.klaviyo.com/client/subscriptions?company_id=${e}`,{method:"POST",headers:{"content-type":"application/vnd.api+json",REVISION:"2025-04-15"},body:JSON.stringify(d)});return 202===t.status||(console.warn("subscribeToKlaviyo: unexpected response",t.status),!1)}catch(u){return console.error("subscribeToKlaviyo: request failed",u),!1}}({companyId:o.dataset.klaviyoCompanyId,listId:o.dataset.klaviyoListId,formObject:m,source:o.dataset.klaviyoSource||"Formcarry Form"}),o.dataset.redirect)return window.location.href=o.dataset.redirect,null;const a=await e.json();return function updateGoogleDataLayer(t){t?(window.dataLayer=window.dataLayer||[],window.dataLayer.push(t)):console.error("No data provided to updateGoogleDataLayer")}({event:o.dataset.event?o.dataset.event:"form_submit",eventAction:o.dataset.action?o.dataset.action:"Submit",eventCategory:o.dataset.category?o.dataset.category:"Form",eventLabel:o.dataset.label?o.dataset.label:""}),c&&(o.classList.add("hidden"),c.classList.remove("hidden")),a}catch(p){return console.error("FormCarry submission failed:",p),showToast({message:l,secondaryMessage:"Please check your connection and try again.",type:"error"}),null}finally{n?.classList.remove("loading")}}export{handleFormCarrySubmission as t};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.