new-site/site/public/_astro/hoisted.iRmzRB-L.js
justin f8cd37ac8c Initial commit — Performance West telecom compliance platform
Includes: API (Express/TypeScript), Astro site, Python workers,
document generators, FCC compliance tools, Canada CRTC formation,
Ansible infrastructure, and deployment scripts.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-27 06:54:22 -05:00

43 lines
54 KiB
JavaScript

import"./hoisted.yFz1BYXO.js";const ne=389900,ie=8500,re=7500,oe=5e4,se=350,ae=390,de=380,ce=10*1024*1024;let E=null,O=null,L="pending",M=null,U=null,P=null,$=!1,D=null,V=null,W=[],k="";function X(i){return"$"+(i/100).toLocaleString("en-US",{minimumFractionDigits:0,maximumFractionDigits:0})}function e(i){return document.getElementById(i)}function s(i){return document.getElementById(i)}function S(i){return document.getElementById(i)}function j(i){return document.getElementById(i)}function z(){if(e("own_ca_address")?.checked)return 0;const i=W.find(t=>t.slug===k);return i?i.yearly_price_usd:0}function Z(){const i=e("own_ca_address")?.checked;e("own-address-fields")?.classList.toggle("hidden",!i),e("amb-location-section")?.classList.toggle("hidden",i),T()}let x=1;const K=5,le=new URLSearchParams(window.location.search).get("test_mode")==="1";function Y(i){for(let l=1;l<=K;l++){const _=e(`step-${l}`);_&&_.classList.toggle("hidden",l!==i)}e("step-success")?.classList.add("hidden"),document.querySelectorAll("#progress li").forEach(l=>{const _=parseInt(l.dataset.step||"0"),g=l.querySelector(".step-dot"),A=l.querySelector("p"),a=l.querySelector(".step-line");_<i?(g.className="step-dot flex items-center justify-center w-8 h-8 rounded-full border-2 border-pw-600 bg-pw-600 text-white text-xs font-bold shrink-0",g.innerHTML='<svg class="w-4 h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="3"><path stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"/></svg>',A&&(A.className="mt-1.5 text-xs font-medium text-pw-700 hidden sm:block"),a&&(a.className="step-line hidden sm:block flex-1 h-0.5 bg-pw-600 mx-2")):_===i?(g.className="step-dot flex items-center justify-center w-8 h-8 rounded-full border-2 border-pw-600 bg-pw-600 text-white text-xs font-bold shrink-0",g.textContent=String(_),A&&(A.className="mt-1.5 text-xs font-medium text-pw-700 hidden sm:block"),a&&(a.className="step-line hidden sm:block flex-1 h-0.5 bg-gray-200 mx-2")):(g.className="step-dot flex items-center justify-center w-8 h-8 rounded-full border-2 border-gray-300 bg-white text-gray-400 text-xs font-bold shrink-0",g.textContent=String(_),A&&(A.className="mt-1.5 text-xs font-medium text-gray-400 hidden sm:block"),a&&(a.className="step-line hidden sm:block flex-1 h-0.5 bg-gray-200 mx-2"))});const t=e("btn-back"),r=e("btn-next"),n=e("btn-start-over");t.classList.toggle("hidden",i===1),n&&n.classList.toggle("hidden",i!==1),i===K?r.innerHTML='Submit Order <svg class="w-4 h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"/></svg>':r.innerHTML='Next <svg class="w-4 h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M13.5 4.5L21 12m0 0l-7.5 7.5M21 12H3"/></svg>',x=i;const m=document.getElementById("form-top");if(m?m.scrollIntoView({behavior:"smooth",block:"start"}):window.scrollTo({top:0,behavior:"smooth"}),i===4){const l=e("identity-director-name-echo");l&&(l.textContent=s("director_name").value.trim()||"(not entered)"),R()}}function ue(i){for(let m=1;m<=K;m++)e(`step-${m}`)?.classList.add("hidden");e("step-success")?.classList.remove("hidden"),e("form-nav")?.classList.add("hidden"),e("progress")?.classList.add("hidden");const t=e("success-order-number");t&&(t.textContent=i);const r=e("btn-proceed-payment"),n=e("payment-redirect-status");r&&r.addEventListener("click",async()=>{const m=document.querySelector('input[name="payment_method_choice"]:checked')?.value||"card";r.disabled=!0,n&&(n.classList.remove("hidden"),n.textContent="Preparing secure checkout...");try{const l=await fetch((window.__PW_API||"https://api.performancewest.net")+"/api/v1/checkout/create-session",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({order_id:i,order_type:"canada_crtc",payment_method:m})}),_=await l.json();if(l.ok&&_.checkout_url)n&&(n.textContent="Redirecting to secure payment..."),window.location.href=_.checkout_url;else throw new Error(_.error||"Could not create checkout session")}catch(l){n&&(n.textContent=l.message||"Payment setup failed. Please contact us.",n.className="mt-3 text-sm text-red-600"),r.disabled=!1}})}function b(){return document.querySelector('input[name="company_type"]:checked')?.value||"numbered"}function me(){const i=b();e("named-fields")?.classList.toggle("hidden",i!=="named"),e("trade-name-fields")?.classList.toggle("hidden",i!=="numbered_tradename"),pe(),document.querySelectorAll(".company-type-radio").forEach(t=>{const r=t.querySelector("input"),n=t.querySelector("span:first-of-type");if(r.checked){t.classList.add("border-pw-500","bg-pw-50"),t.classList.remove("border-gray-200"),n.classList.add("border-pw-600","bg-pw-600"),n.classList.remove("border-gray-300");const m=n.querySelector("span");m&&m.classList.remove("hidden")}else{t.classList.remove("border-pw-500","bg-pw-50"),t.classList.add("border-gray-200"),n.classList.remove("border-pw-600","bg-pw-600"),n.classList.add("border-gray-300");const m=n.querySelector("span");m&&m.classList.add("hidden")}})}function q(){return e("expedited")?.checked||!1}function B(){const i=b();let t=ne;return i==="named"&&(t+=ie),i==="numbered_tradename"&&(t+=re),q()&&(t+=oe),t}function G(){const i=b();return i==="named"?de:i==="numbered_tradename"?ae:se}function pe(){const i=b(),t=B(),r=e("estimate-total");r&&(r.textContent="$"+(t/100).toLocaleString("en-US"));const n=e("estimate-gov-fee");n&&(n.textContent=`~C$${G()}`);const m=e("estimate-addon");m&&(i==="named"?(m.textContent="+ $85 named company service",m.classList.remove("hidden")):i==="numbered_tradename"?(m.textContent="+ $75 trade name service",m.classList.remove("hidden")):m.classList.add("hidden"))}function w(i,t){const r=e("submit-status");if(r&&(r.className="mt-3 rounded-lg p-3 text-sm bg-red-50 text-red-800 border border-red-200",r.textContent=i,r.classList.remove("hidden")),t){const n=document.getElementById(t);n&&(n.focus(),n.scrollIntoView({behavior:"smooth",block:"center"}))}return!1}function ee(){const i=e("submit-status");i&&i.classList.add("hidden")}function _e(i){if(ee(),i===1){const t=b();return t==="named"&&!s("name_choice_1").value.trim()?w("Please enter at least your first name choice.","name_choice_1"):t==="numbered_tradename"&&!s("trade_name").value.trim()?w("Please enter your desired trade name.","trade_name"):!0}if(i===2){const t=s("director_first_name").value.trim(),r=s("director_middle_name").value.trim(),n=s("director_last_name").value.trim();return s("director_name").value=[t,r,n].filter(Boolean).join(" "),t?n?S("director_country").value?s("director_street").value.trim()?s("director_city").value.trim()?e("director_province").value.trim()?s("director_postal").value.trim()?!0:w("Please enter the director's postal/ZIP code.","director_postal"):w("Please enter the director's state/province/region.",e("director_province_select").classList.contains("hidden")?"director_province_text":"director_province_select"):w("Please enter the director's city.","director_city"):w("Please enter the director's street address.","director_street"):w("Please select the director's country.","director_country"):w("Please enter the director's last name.","director_last_name"):w("Please enter the director's first name.","director_first_name")}if(i===3){if(!j("service_description").value.trim())return w("Please describe the telecom services you plan to offer.","service_description");if(e("own_ca_address")?.checked){if(!s("own_ca_company")?.value.trim())return w("Please enter the company or organisation name at your BC address (needed to address your corporate binder).","own_ca_company");if(!s("own_ca_street")?.value.trim())return w("Please enter your BC street address.","own_ca_street");if(!s("own_ca_postal")?.value.trim())return w("Please enter your BC postal code.","own_ca_postal");if(!e("own_address_confirm")?.checked)return w("Please confirm that your address can store your corporate binder as required by the BC Business Corporations Act.","own_address_confirm")}const t=s("existing_ca_did")?.value.trim();if(t){const r=["236","250","604","672","778","226","249","289","343","365","382","416","437","519","548","613","647","683","705","742","753","807","905","368","403","587","780","825","263","354","367","418","438","450","468","514","579","581","819","873","204","431","306","639","782","902","428","506","709","867"],n=t.replace(/\D/g,""),m=n.startsWith("1")?n.slice(1,4):n.slice(0,3);if(!r.includes(m))return w(`"${m}" is not a valid Canadian area code. Please enter a Canadian phone number (e.g. +1 604-555-0199).`,"existing_ca_did")}return!0}if(i===4)return le?!0:L==="pending"||!O?w("Please complete identity verification before continuing."):L==="failed"?w("Identity verification failed. Please try again with a valid government-issued ID."):!0;if(i===5){if(!s("customer_name").value.trim())return w("Please enter your name.","customer_name");const t=s("customer_email").value.trim();if(!t||!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t))return w("Please enter a valid email address.","customer_email");if(!s("customer_phone").value.trim())return w("Please enter your phone number.","customer_phone");if(!s("disclaimer").checked){const r=e("disclaimer");return r&&r.scrollIntoView({behavior:"smooth",block:"center"}),w("Please acknowledge that Performance West provides formation services only and is not a substitute for legal advice.")}if(!s("consent").checked){const r=e("consent");return r&&r.scrollIntoView({behavior:"smooth",block:"center"}),w("Please read and agree to the Terms of Service and Privacy Policy before submitting.")}return!0}return!0}function te(){const i=b()==="named",t=e("review-company-type");t&&(t.textContent=i?"Named Company":"Numbered Company");const r=e("review-names-row");if(r&&r.classList.toggle("hidden",!i),i){const v=[],N=s("name_choice_1").value.trim(),I=s("name_choice_2").value.trim(),C=s("name_choice_3").value.trim();N&&v.push("1. "+N),I&&v.push("2. "+I),C&&v.push("3. "+C);const J=e("review-names");J&&(J.innerHTML=v.join("<br />"))}const n=e("review-legal-ending");n&&(n.textContent=S("legal_ending").value);const m=b()==="numbered_tradename",l=e("review-trade-name-row");if(l&&l.classList.toggle("hidden",!m),m){const v=e("review-trade-name");v&&(v.textContent=s("trade_name").value.trim())}const _=e("review-director-name");_&&(_.textContent=s("director_name").value.trim());const g=e("review-director-address");g&&(g.textContent=[s("director_street").value.trim(),s("director_city").value.trim()+", "+s("director_province").value.trim()+" "+s("director_postal").value.trim(),s("director_country").value.trim()].join(", "));const A=S("director_citizenship").value,a=e("review-citizenship-row");a&&a.classList.toggle("hidden",!A);const h=e("review-director-citizenship");h&&(h.textContent=A||"Not specified");const f=e("review-services");f&&(f.textContent=j("service_description").value.trim());const y=e("review-coverage");y&&(y.textContent=s("geographic_coverage").value.trim()||"Canada-wide");const o=e("review-bits");o&&(o.textContent=s("include_bits").checked?"Yes":"No");const d=e("review-id-status");d&&(D&&V?d.innerHTML='<svg class="w-5 h-5 text-green-600" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5" /></svg><span class="text-green-700 font-medium">ID uploaded (direct)</span>':$?d.innerHTML='<svg class="w-5 h-5 text-green-600" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5" /></svg><span class="text-green-700 font-medium">ID uploaded (phone)</span>':U?d.innerHTML='<svg class="w-5 h-5 text-yellow-500" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M12 9v3.75m9-.75a9 9 0 11-18 0 9 9 0 0118 0zm-9 3.75h.008v.008H12v-.008z" /></svg><span class="text-yellow-700 font-medium">Phone upload link generated — waiting for upload</span>':d.innerHTML='<svg class="w-5 h-5 text-gray-400" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M12 9v3.75m9-.75a9 9 0 11-18 0 9 9 0 0118 0zm-9 3.75h.008v.008H12v-.008z" /></svg><span class="text-gray-500">Not uploaded — you can submit and upload later via email</span>');const c=b(),u=G(),p=e("summary-gov-fee");p&&(p.textContent=`~C$${u}`),e("summary-named-addon-row")?.classList.toggle("hidden",c!=="named"),e("summary-tradename-addon-row")?.classList.toggle("hidden",c!=="numbered_tradename"),e("summary-trade-name-row")?.classList.toggle("hidden",c!=="numbered_tradename"),e("summary-expedited-row")?.classList.toggle("hidden",!q()),T()}function T(){const i=typeof z=="function"?z():0;let t=B()+i;E&&(t-=E.cents),t<0&&(t=0);const r=e("summary-total");r&&(r.textContent=X(t));const n=e("summary-mailbox-row"),m=e("summary-mailbox-fee");n&&n.classList.toggle("hidden",i===0),m&&(m.textContent=X(i))}function fe(i){if(i.size>ce)return"File is too large. Maximum size is 10 MB.";const t=i.name.split(".").pop()?.toLowerCase()||"";return["jpg","jpeg","png","pdf"].includes(t)?null:"Unsupported file type. Please use JPG, PNG, or PDF."}function Q(i,t){const r=i.files?.[0];if(!r)return;const n=fe(r);if(n){alert(n),i.value="";return}t==="front"?D=r:V=r;const m=e(`drop-${t}-placeholder`),l=e(`drop-${t}-preview`),_=e(`drop-${t}-name`),g=e(`drop-${t}`);m&&m.classList.add("hidden"),l&&l.classList.remove("hidden"),_&&(_.textContent=r.name),g&&(g.classList.add("border-green-400"),g.classList.remove("border-gray-300"))}function ve(i){i==="front"?(D=null,e("id-front").value=""):(V=null,e("id-back").value="");const t=e(`drop-${i}-placeholder`),r=e(`drop-${i}-preview`),n=e(`drop-${i}`);t&&t.classList.remove("hidden"),r&&r.classList.add("hidden"),n&&(n.classList.remove("border-green-400"),n.classList.add("border-gray-300"))}async function he(){const i=e("btn-phone-upload");i.disabled=!0,i.textContent="Generating...";try{const t=await fetch((window.__PW_API||"https://api.performancewest.net")+"/api/v1/id-upload/create-token",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({service:"canada-crtc"})}),r=await t.json();if(t.ok&&r.token){U=r.token;const n=window.location.origin+"/upload/id?token="+encodeURIComponent(r.token),m=e("phone-upload-url");m&&(m.value=n),e("phone-upload-area")?.classList.remove("hidden"),i.textContent="Link generated",ge(r.token)}else throw new Error(r.error||"Failed to generate upload link.")}catch(t){alert(t.message||"Could not generate upload link. Please try the direct upload instead."),i.disabled=!1,i.innerHTML='<svg class="w-5 h-5" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="1.5"><path stroke-linecap="round" stroke-linejoin="round" d="M10.5 1.5H8.25A2.25 2.25 0 006 3.75v16.5a2.25 2.25 0 002.25 2.25h7.5A2.25 2.25 0 0018 20.25V3.75a2.25 2.25 0 00-2.25-2.25H13.5m-3 0V3h3V1.5m-3 0h3m-3 18.75h3" /></svg> Generate phone upload link'}}function ge(i){P&&clearInterval(P),P=window.setInterval(async()=>{try{if((await(await fetch((window.__PW_API||"https://api.performancewest.net")+"/api/v1/id-upload/"+encodeURIComponent(i)+"/status")).json()).uploaded){$=!0,P&&(clearInterval(P),P=null);const n=e("phone-upload-status");n&&(n.innerHTML=`
<svg class="w-5 h-5 text-green-600" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5" /></svg>
<span class="text-green-700 font-medium">ID uploaded successfully!</span>
`)}}catch{}},3e3)}function R(){["identity-start","identity-loading","identity-waiting","identity-verified","identity-review","identity-failed"].forEach(t=>e(`${t}`)?.classList.add("hidden")),!O||L==="pending"?e("identity-start")?.classList.remove("hidden"):L==="verified"?e("identity-verified")?.classList.remove("hidden"):L==="needs_review"?e("identity-review")?.classList.remove("hidden"):L==="failed"&&e("identity-failed")?.classList.remove("hidden")}async function ye(){const i=s("director_name").value.trim(),t=s("director_dob")?.value||null,r=s("customer_email").value.trim();if(!i){alert("Please enter the director's full legal name in Step 2 before verifying identity.");return}e("identity-start")?.classList.add("hidden"),e("identity-loading")?.classList.remove("hidden");try{const n=window.__PW_API||"https://api.performancewest.net",m=await fetch(n+"/api/v1/identity/create-session",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({director_name:i,director_dob:t,customer_email:r,order_type:"canada_crtc"})}),l=await m.json();if(!m.ok||!l.url)throw new Error(l.error||"Could not start verification");O=l.session_id;const _={},g=["director_first_name","director_middle_name","director_last_name","director_name","director_dob","director_country","director_street","director_street2","director_city","director_province","director_postal","director_citizenship","company_type","company_name","entity_suffix","reg_contact_name","reg_contact_email","reg_contact_phone","customer_name","customer_email","customer_phone","customer_company","existing_ca_did","did_routing_type","did_forward_number","service_description","geographic_coverage","own_ca_company","own_ca_attn","own_ca_street","own_ca_city","own_ca_province","own_ca_postal"];for(const A of g){const a=document.getElementById(A);a&&a.value&&(_[A]=a.value)}k&&(_._amb_location_slug=k),e("own_ca_address")?.checked&&(_._own_ca_address="1"),sessionStorage.setItem("pw_form_snapshot",JSON.stringify(_)),sessionStorage.setItem("pw_identity_session",l.session_id),sessionStorage.setItem("pw_order_return_url",window.location.pathname+window.location.search),window.location.href=l.url}catch(n){e("identity-loading")?.classList.add("hidden"),e("identity-start")?.classList.remove("hidden"),alert("Could not start identity verification: "+(n.message||"Unknown error"))}}async function H(i){try{const r=await(await fetch((window.__PW_API||"https://api.performancewest.net")+`/api/v1/identity/session/${encodeURIComponent(i)}`)).json();if(r.overall_result==="verified"||r.overall_result==="needs_review"||r.overall_result==="failed"){if(M&&(clearInterval(M),M=null),L=r.overall_result,r.overall_result==="verified"||r.overall_result==="needs_review"){const n=e("btn-next");n&&(n.disabled=!1,n.title=""),e("identity-pending-notice")?.classList.add("hidden"),sessionStorage.removeItem("pw_identity_session"),sessionStorage.removeItem("pw_order_return_url")}else r.overall_result==="failed"&&(e("identity-pending-notice")?.classList.add("hidden"),sessionStorage.removeItem("pw_identity_session"),sessionStorage.removeItem("pw_order_return_url"));if(r.overall_result==="verified"){const n=e("identity-verified-detail");if(n){const m=r.name_match_score?` (${r.name_match_score}% name match)`:"",l=r.dob_match==="exact"?", date of birth confirmed":"";n.textContent=`${r.doc_type?.replace("_"," ")||"ID"} from ${r.issuing_country||"unknown country"} verified${m}${l}.`}R(),setTimeout(()=>{te(),Y(x+1)},1500)}if(r.overall_result==="failed"){const n=e("identity-failed-detail");n&&r.name_match_score!==void 0&&(n.textContent=`Name match score: ${r.name_match_score}%. The name on your ID doesn't closely enough match "${s("director_name").value.trim()}". Please check your name in Step 2 or try a different ID document.`)}R()}}catch{}}(function(){const t=new URLSearchParams(window.location.search);if(!(t.get("identity_return")==="1"))return;const n=sessionStorage.getItem("pw_identity_session");if(!n)return;O=n;try{const f=JSON.parse(sessionStorage.getItem("pw_form_snapshot")||"{}");console.log("[restore] Snapshot keys:",Object.keys(f).join(", "));let y=0;for(const[p,v]of Object.entries(f)){const N=document.getElementById(p);N&&v?(N.value=v,N.dispatchEvent(new Event("change",{bubbles:!0})),N.dispatchEvent(new Event("input",{bubbles:!0})),y++):N||console.warn("[restore] Element not found:",p)}const o=document.getElementById("director_first_name")?.value||"",d=document.getElementById("director_middle_name")?.value||"",c=document.getElementById("director_last_name")?.value||"",u=document.getElementById("director_name");if(u&&(o||c)&&(u.value=[o,d,c].filter(Boolean).join(" ")),f._amb_location_slug){k=f._amb_location_slug;const p=document.querySelector(`input[name="amb_location"][value="${f._amb_location_slug}"]`);p&&(p.checked=!0)}if(f._own_ca_address==="1"){const p=e("own_ca_address");p&&(p.checked=!0,p.dispatchEvent(new Event("change",{bubbles:!0})))}console.log("[restore] Restored",y,"fields. service_description value:",document.getElementById("service_description")?.value?.slice(0,30))}catch(f){console.error("[restore] Error:",f)}["identity-start","identity-loading","identity-failed","identity-verified","identity-review"].forEach(f=>e(`${f}`)?.classList.add("hidden")),e("identity-waiting")?.classList.remove("hidden"),Y(4);const l=e("btn-next");l&&(l.disabled=!0,l.title="Waiting for identity verification result..."),e("identity-pending-notice")?.classList.remove("hidden");const _=window.location.pathname+(t.get("test_mode")?"?test_mode=1":"");window.history.replaceState({},"",_);function g(){sessionStorage.removeItem("pw_identity_session"),sessionStorage.removeItem("pw_order_return_url"),l&&(L==="verified"||L==="needs_review")?(l.disabled=!1,l.title="",e("identity-pending-notice")?.classList.add("hidden")):L==="failed"&&e("identity-pending-notice")?.classList.add("hidden")}let A=0;const a=15,h=window.setInterval(async()=>{await H(n),A++,(L!=="pending"||A>=a)&&(clearInterval(h),L==="pending"?M=window.setInterval(()=>H(n),5e3):g())},2e3);H(n).then(()=>{L!=="pending"&&(clearInterval(h),g())})})();e("btn-start-identity")?.addEventListener("click",ye);e("btn-retry-identity")?.addEventListener("click",()=>{O=null,L="pending",sessionStorage.removeItem("pw_identity_session"),R(),Y(1)});async function Ae(){const i=e("btn-next"),t=e("submit-status");i.disabled=!0,i.innerHTML="Submitting...",t&&(t.classList.remove("hidden"),t.className="mt-5 rounded-lg p-4 text-sm bg-gray-50 text-gray-600 border border-gray-200",t.textContent="Placing your order...");const r=b()==="named",n=E?E.cents:0;G();let m=B()-n;m<0&&(m=0);const l={incorporation_province:document.querySelector('input[name="incorporation_province"]:checked')?.value||"BC",company_type:b(),legal_ending:S("legal_ending").value,company_name_choice1:r?s("name_choice_1").value.trim():null,company_name_choice2:r&&s("name_choice_2").value.trim()||null,company_name_choice3:r&&s("name_choice_3").value.trim()||null,add_trade_name:b()==="numbered_tradename",trade_name:b()==="numbered_tradename"?s("trade_name").value.trim():null,director_first_name:s("director_first_name").value.trim(),director_middle_name:s("director_middle_name").value.trim()||null,director_last_name:s("director_last_name").value.trim(),director_name:s("director_name").value.trim(),director_street:s("director_street").value.trim(),director_street2:s("director_street2").value.trim()||null,director_city:s("director_city").value.trim(),director_province:s("director_province").value.trim(),director_postal:s("director_postal").value.trim(),director_country:s("director_country").value.trim(),director_citizenship:S("director_citizenship").value||null,director_mailing_different:e("director_mailing_different")?.checked||!1,director_mailing_street:e("director_mailing_different")?.checked&&s("director_mailing_street").value.trim()||null,director_mailing_street2:e("director_mailing_different")?.checked&&e("director_mailing_street2")?.value.trim()||null,director_mailing_city:e("director_mailing_different")?.checked&&s("director_mailing_city").value.trim()||null,director_mailing_province:e("director_mailing_different")?.checked&&s("director_mailing_province").value.trim()||null,director_mailing_postal:e("director_mailing_different")?.checked&&s("director_mailing_postal").value.trim()||null,director_mailing_country:e("director_mailing_different")?.checked&&e("director_mailing_country")?.value||null,additional_directors:(()=>{const _=[];return document.querySelectorAll("[id^='additional-director-']").forEach(g=>{const A=g.id.split("-").pop(),a=y=>g.querySelector(`[name='addl_director_${A}_${y}']`)?.value?.trim()||"",h=a("first_name"),f=a("last_name");h&&f&&_.push({first_name:h,middle_name:a("middle_name")||null,last_name:f,street:a("street"),city:a("city"),province:a("province"),postal:a("postal"),country:a("country")||"US"})}),_.length>0?_:null})(),expedited:q(),amb_location_slug:e("own_ca_address")?.checked?null:k||null,has_own_ca_address:s("own_ca_address")?.checked||!1,own_ca_company:s("own_ca_company")?.value.trim()||null,own_ca_attn:s("own_ca_attn")?.value.trim()||null,own_ca_street:s("own_ca_street")?.value.trim()||null,own_ca_city:s("own_ca_city")?.value.trim()||null,own_ca_province:s("own_ca_province")?.value.trim()||null,own_ca_postal:s("own_ca_postal")?.value.trim()||null,existing_ca_did:s("existing_ca_did")?.value.trim()||null,did_routing_type:document.querySelector('input[name="did_routing_type"]:checked')?.value||"later",did_forward_number:s("did_forward_number")?.value.trim()||null,did_sip_uri:s("did_sip_uri")?.value.trim()||null,did_sip_ip:s("did_sip_ip")?.value.trim()||null,services_description:j("service_description").value.trim()||JSON.parse(sessionStorage.getItem("pw_form_snapshot")||"{}").service_description||"",geographic_coverage:s("geographic_coverage").value.trim()||JSON.parse(sessionStorage.getItem("pw_form_snapshot")||"{}").geographic_coverage||`${document.querySelector('input[name="incorporation_province"]:checked')?.value||"BC"} and Worldwide`,include_bits:s("include_bits").checked,domain_privacy:s("domain_privacy").checked,regulatory_contact_name:s("reg_contact_name").value.trim()||null,regulatory_contact_email:s("reg_contact_email").value.trim()||null,regulatory_contact_phone:s("reg_contact_phone").value.trim()||null,identity_session_id:O,id_upload_token:U,id_uploaded_direct:!!(D&&V),id_uploaded_phone:$,customer_name:s("customer_name").value.trim(),customer_email:s("customer_email").value.trim(),customer_phone:s("customer_phone").value.trim()||null,customer_company:s("customer_company").value.trim()||null,disclaimer_agreed:s("disclaimer")?.checked||!1,service_fee_cents:B(),discount_code:E?E.code:null,discount_cents:n,total_cents:m};try{if(D&&V&&!$){const d=new FormData;d.append("front",D),d.append("back",V),d.append("service","canada-crtc");const c=await fetch((window.__PW_API||"https://api.performancewest.net")+"/api/v1/id-upload/direct",{method:"POST",body:d}),u=await c.json();c.ok&&u.token&&(l.id_upload_token=u.token,l.id_uploaded_direct=!0)}const _=window.__PW_API||"https://api.performancewest.net";t&&(t.className="mt-5 rounded-lg p-4 text-sm bg-blue-50 text-blue-800 border border-blue-200",t.textContent="Creating your order...",t.classList.remove("hidden"));const g=["customer_name","customer_email","services_description","director_name"].filter(d=>!l[d]);g.length&&console.warn("[submit] Empty required fields:",g.join(", "),"| service_description textarea value:",JSON.stringify(document.getElementById("service_description")?.value));const A=await fetch(_+"/api/v1/canada-crtc/orders",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(l)}),a=await A.json();if(!A.ok||!a.success)throw new Error(a.error||"Order creation failed");const h=a.order_number;t&&(t.textContent="Redirecting to payment...");const f=await fetch(_+"/api/v1/checkout/create-session",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({order_type:"canada_crtc",order_id:h,payment_method:document.querySelector('input[name="payment_method_choice"]:checked')?.value||"card"})}),y=await f.json(),o=y.url||y.checkout_url||y.redirect_url;f.ok&&o?(sessionStorage.setItem("pw_order_number",h),sessionStorage.removeItem("pw_form_snapshot"),sessionStorage.removeItem("pw_identity_session"),window.location.href=o):ue(h)}catch(_){t&&(t.className="mt-5 rounded-lg p-4 text-sm bg-red-50 text-red-800 border border-red-200",t.classList.remove("hidden"),t.textContent=_.message||"Something went wrong. Please try again or contact us."),i.disabled=!1,i.innerHTML='Submit Order <svg class="w-4 h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"/></svg>'}}async function F(i){if(!i||i.trim().length<2)return;i=i.toUpperCase().trim();const t=e("discount-status"),r=s("discount_code"),n=e("btn-apply-discount");n&&(n.disabled=!0,n.textContent="Checking..."),t&&(t.classList.remove("hidden"),t.className="mt-2 text-xs text-gray-500",t.textContent="Validating code...");try{const m=await fetch(`${window.__PW_API||"https://api.performancewest.net"}/api/v1/discount/${encodeURIComponent(i)}?service=canada-crtc&amount=${B()}`),l=await m.json();if(m.ok&&l.valid){E={code:l.code,type:l.discount_type,value:l.discount_value,cents:l.discount_cents,description:l.description},r&&(r.value=l.code,r.disabled=!0,r.classList.add("bg-green-50","border-green-300")),n&&(n.textContent="Applied",n.classList.add("bg-green-100","text-green-700","border-green-300")),t&&(t.className="mt-2 text-xs text-green-700",t.textContent=`${l.description} applied.${l.referral_partner?` Referred by: ${l.referral_partner}`:""}`),e("summary-discount-row")?.classList.remove("hidden");const _=e("summary-discount-code");_&&(_.textContent=l.code);const g=e("summary-discount-amount");g&&(g.textContent=`-${X(l.discount_cents)}`),T()}else E=null,t&&(t.className="mt-2 text-xs text-red-600",t.textContent=l.error||"Invalid discount code."),n&&(n.disabled=!1,n.textContent="Apply"),e("summary-discount-row")?.classList.add("hidden"),T()}catch{t&&(t.className="mt-2 text-xs text-gray-500",t.textContent="Could not verify code. You can proceed without it."),n&&(n.disabled=!1,n.textContent="Apply")}}document.addEventListener("DOMContentLoaded",()=>{document.querySelectorAll('input[name="company_type"]').forEach(o=>{o.addEventListener("change",me)});const i=[["AL","Alabama"],["AK","Alaska"],["AZ","Arizona"],["AR","Arkansas"],["CA","California"],["CO","Colorado"],["CT","Connecticut"],["DE","Delaware"],["FL","Florida"],["GA","Georgia"],["HI","Hawaii"],["ID","Idaho"],["IL","Illinois"],["IN","Indiana"],["IA","Iowa"],["KS","Kansas"],["KY","Kentucky"],["LA","Louisiana"],["ME","Maine"],["MD","Maryland"],["MA","Massachusetts"],["MI","Michigan"],["MN","Minnesota"],["MS","Mississippi"],["MO","Missouri"],["MT","Montana"],["NE","Nebraska"],["NV","Nevada"],["NH","New Hampshire"],["NJ","New Jersey"],["NM","New Mexico"],["NY","New York"],["NC","North Carolina"],["ND","North Dakota"],["OH","Ohio"],["OK","Oklahoma"],["OR","Oregon"],["PA","Pennsylvania"],["RI","Rhode Island"],["SC","South Carolina"],["SD","South Dakota"],["TN","Tennessee"],["TX","Texas"],["UT","Utah"],["VT","Vermont"],["VA","Virginia"],["WA","Washington"],["WV","West Virginia"],["WI","Wisconsin"],["WY","Wyoming"],["DC","District of Columbia"]],t=[["AB","Alberta"],["BC","British Columbia"],["MB","Manitoba"],["NB","New Brunswick"],["NL","Newfoundland and Labrador"],["NS","Nova Scotia"],["NT","Northwest Territories"],["NU","Nunavut"],["ON","Ontario"],["PE","Prince Edward Island"],["QC","Quebec"],["SK","Saskatchewan"],["YT","Yukon"]],r=[["ACT","Australian Capital Territory"],["NSW","New South Wales"],["NT","Northern Territory"],["QLD","Queensland"],["SA","South Australia"],["TAS","Tasmania"],["VIC","Victoria"],["WA","Western Australia"]],n=[["ENG","England"],["SCT","Scotland"],["WLS","Wales"],["NIR","Northern Ireland"]];function m(){const o=S("director_country").value,d=e("director_province_select"),c=e("director_province_text"),u=e("director_province");let p=null,v="State / Region / Province";o==="US"?(p=i,v="State"):o==="CA"?(p=t,v="Province"):o==="AU"?(p=r,v="State / Territory"):o==="GB"&&(p=n,v="Country / Region"),p?(d.innerHTML=`<option value="">Select ${v}</option>`+p.map(([N,I])=>`<option value="${N}">${I}</option>`).join(""),d.classList.remove("hidden"),c.classList.add("hidden"),c.value="",d.onchange=()=>{u.value=d.value},u.value=d.value):(d.classList.add("hidden"),d.innerHTML="",c.placeholder=v,c.classList.remove("hidden"),c.oninput=()=>{u.value=c.value},u.value=c.value)}e("director_country")?.addEventListener("change",()=>{e("director_street").value="",e("director_street2").value="",e("director_city").value="",e("director_postal").value="",e("director_province").value="";const o=e("director_province_select");o&&(o.value="");const d=e("director_province_text");d&&(d.value=""),m();const c=e("director_address_fields"),u=S("director_country").value;c?.classList.toggle("hidden",!u)});const l={"005":"NY","006":"PR","007":"PR","008":"VI","009":"PR","010":"MA","011":"MA","012":"MA","013":"MA","014":"MA","015":"MA","016":"MA","017":"MA","018":"MA","019":"MA","020":"MA","021":"MA","022":"MA","023":"MA","024":"MA","025":"MA","026":"MA","027":"MA","028":"RI","029":"RI","030":"NH","031":"NH","032":"NH","033":"NH","034":"NH","035":"NH","036":"NH","037":"NH","038":"NH","039":"ME","040":"ME","041":"ME","042":"ME","043":"ME","044":"ME","045":"ME","046":"ME","047":"ME","048":"ME","049":"ME","050":"VT","051":"VT","052":"VT","053":"VT","054":"VT","055":"MA","056":"VT","057":"VT","058":"VT","059":"VT","060":"CT","061":"CT","062":"CT","063":"CT","064":"CT","065":"CT","066":"CT","067":"CT","068":"CT","069":"CT","070":"NJ","071":"NJ","072":"NJ","073":"NJ","074":"NJ","075":"NJ","076":"NJ","077":"NJ","078":"NJ","079":"NJ","080":"NJ","081":"NJ","082":"NJ","083":"NJ","084":"NJ","085":"NJ","086":"NJ","087":"NJ","088":"NJ","089":"NJ",100:"NY",101:"NY",102:"NY",103:"NY",104:"NY",105:"NY",106:"NY",107:"NY",108:"NY",109:"NY",110:"NY",111:"NY",112:"NY",113:"NY",114:"NY",115:"NY",116:"NY",117:"NY",118:"NY",119:"NY",120:"NY",121:"NY",122:"NY",123:"NY",124:"NY",125:"NY",126:"NY",127:"NY",128:"NY",129:"NY",130:"NY",131:"NY",132:"NY",133:"NY",134:"NY",135:"NY",136:"NY",137:"NY",138:"NY",139:"NY",140:"NY",141:"NY",142:"NY",143:"NY",144:"NY",145:"NY",146:"NY",147:"NY",148:"NY",149:"NY",150:"PA",151:"PA",152:"PA",153:"PA",154:"PA",155:"PA",156:"PA",157:"PA",158:"PA",159:"PA",160:"PA",161:"PA",162:"PA",163:"PA",164:"PA",165:"PA",166:"PA",167:"PA",168:"PA",169:"PA",170:"PA",171:"PA",172:"PA",173:"PA",174:"PA",175:"PA",176:"PA",177:"PA",178:"PA",179:"PA",180:"PA",181:"PA",182:"PA",183:"PA",184:"PA",185:"PA",186:"PA",187:"PA",188:"PA",189:"PA",190:"PA",191:"PA",192:"PA",193:"PA",194:"PA",195:"PA",196:"PA",197:"DE",198:"DE",199:"DE",200:"DC",201:"VA",202:"DC",203:"DC",204:"DC",205:"DC",206:"MD",207:"MD",208:"MD",209:"MD",210:"MD",211:"MD",212:"MD",214:"MD",215:"MD",216:"MD",217:"WV",218:"WV",219:"WV",220:"VA",221:"VA",222:"VA",223:"VA",224:"VA",225:"VA",226:"VA",227:"VA",228:"VA",229:"VA",230:"VA",231:"VA",232:"VA",233:"VA",234:"VA",235:"VA",236:"VA",237:"VA",238:"VA",239:"VA",240:"VA",241:"VA",242:"VA",243:"VA",244:"VA",245:"VA",246:"WV",247:"WV",248:"WV",249:"WV",250:"WV",251:"WV",252:"WV",253:"WV",254:"WV",255:"WV",256:"WV",257:"WV",258:"WV",259:"WV",260:"WV",261:"WV",262:"WV",263:"WV",264:"WV",265:"WV",266:"WV",267:"WV",268:"WV",270:"NC",271:"NC",272:"NC",273:"NC",274:"NC",275:"NC",276:"NC",277:"NC",278:"NC",279:"NC",280:"NC",281:"NC",282:"NC",283:"NC",284:"NC",285:"NC",286:"NC",287:"NC",288:"NC",289:"NC",290:"SC",291:"SC",292:"SC",293:"SC",294:"SC",295:"SC",296:"SC",297:"SC",298:"SC",299:"SC",300:"GA",301:"GA",302:"GA",303:"GA",304:"GA",305:"FL",306:"FL",307:"WY",308:"WY",309:"GA",310:"GA",311:"GA",312:"GA",313:"GA",314:"GA",315:"GA",316:"GA",317:"GA",318:"GA",319:"GA",320:"FL",321:"FL",322:"FL",323:"FL",324:"FL",325:"FL",326:"FL",327:"FL",328:"FL",329:"FL",330:"FL",331:"FL",332:"FL",333:"FL",334:"FL",335:"FL",336:"FL",337:"FL",338:"FL",339:"FL",340:"AA",341:"FL",342:"FL",344:"FL",346:"FL",347:"FL",349:"FL",350:"AL",351:"AL",352:"AL",353:"AL",354:"AL",355:"AL",356:"AL",357:"AL",358:"AL",359:"AL",360:"AL",361:"AL",362:"AL",363:"AL",364:"AL",365:"AL",366:"AL",367:"AL",368:"AL",369:"AL",370:"TN",371:"TN",372:"TN",373:"TN",374:"TN",375:"TN",376:"TN",377:"TN",378:"TN",379:"TN",380:"TN",381:"TN",382:"TN",383:"TN",384:"TN",385:"TN",386:"MS",387:"MS",388:"MS",389:"MS",390:"MS",391:"MS",392:"MS",393:"MS",394:"MS",395:"MS",396:"MS",397:"MS",398:"GA",399:"GA",400:"KY",401:"KY",402:"KY",403:"KY",404:"KY",405:"OK",406:"MT",407:"KY",408:"KY",409:"KY",410:"KY",411:"KY",412:"KY",413:"KY",414:"KY",415:"KY",416:"KY",417:"KY",418:"KY",419:"KY",420:"KY",421:"KY",422:"KY",423:"KY",424:"KY",425:"KY",426:"KY",427:"KY",430:"OH",431:"OH",432:"OH",433:"OH",434:"OH",435:"OH",436:"OH",437:"OH",438:"OH",439:"OH",440:"OH",441:"OH",442:"OH",443:"OH",444:"OH",445:"OH",446:"OH",447:"OH",448:"OH",449:"OH",450:"OH",451:"OH",452:"OH",453:"OH",454:"OH",455:"OH",456:"OH",457:"OH",458:"OH",459:"OH",460:"IN",461:"IN",462:"IN",463:"IN",464:"IN",465:"IN",466:"IN",467:"IN",468:"IN",469:"IN",470:"IN",471:"IN",472:"IN",473:"IN",474:"IN",475:"IN",476:"IN",477:"IN",478:"IN",479:"IN",480:"MI",481:"MI",482:"MI",483:"MI",484:"MI",485:"MI",486:"MI",487:"MI",488:"MI",489:"MI",490:"MI",491:"MI",492:"MI",493:"MI",494:"MI",495:"MI",496:"MI",497:"MI",498:"MI",499:"MI",500:"IA",501:"IA",502:"IA",503:"IA",504:"IA",505:"NM",506:"IA",507:"IA",508:"IA",509:"IA",510:"IA",511:"IA",512:"IA",513:"IA",514:"IA",515:"IA",516:"IA",520:"AZ",521:"AZ",522:"IA",523:"IA",524:"IA",525:"IA",526:"IA",527:"IA",528:"IA",530:"WI",531:"WI",532:"WI",534:"WI",535:"WI",537:"WI",538:"WI",539:"WI",540:"WI",541:"WI",542:"WI",543:"WI",544:"WI",545:"WI",546:"WI",547:"WI",548:"WI",549:"WI",550:"MN",551:"MN",553:"MN",554:"MN",555:"MN",556:"MN",557:"MN",558:"MN",559:"MN",560:"MN",561:"MN",562:"MN",563:"MN",564:"MN",565:"MN",566:"MN",567:"MN",570:"SD",571:"SD",572:"SD",573:"SD",574:"SD",575:"SD",576:"SD",577:"SD",580:"ND",581:"ND",582:"ND",583:"ND",584:"ND",585:"ND",586:"ND",587:"ND",588:"ND",590:"MT",591:"MT",592:"MT",593:"MT",594:"MT",595:"MT",596:"MT",597:"MT",598:"MT",599:"MT",600:"IL",601:"IL",602:"IL",603:"IL",604:"IL",605:"IL",606:"IL",607:"IL",608:"IL",609:"IL",610:"IL",611:"IL",612:"IL",613:"IL",614:"IL",615:"IL",616:"IL",617:"IL",618:"IL",619:"IL",620:"IL",621:"IL",622:"IL",623:"IL",624:"IL",625:"IL",626:"IL",627:"IL",628:"IL",629:"IL",630:"MO",631:"MO",633:"MO",634:"MO",635:"MO",636:"MO",637:"MO",638:"MO",639:"MO",640:"MO",641:"MO",644:"MO",645:"MO",646:"MO",647:"MO",648:"MO",649:"MO",650:"MO",651:"MO",652:"MO",653:"MO",654:"MO",655:"MO",656:"MO",657:"MO",658:"MO",659:"MO",660:"KS",661:"KS",662:"KS",664:"KS",665:"KS",666:"KS",667:"KS",668:"KS",669:"KS",670:"KS",671:"KS",672:"KS",673:"KS",674:"KS",675:"KS",676:"KS",677:"KS",678:"KS",679:"KS",680:"NE",681:"NE",683:"NE",684:"NE",685:"NE",686:"NE",687:"NE",688:"NE",689:"NE",690:"NE",691:"NE",692:"NE",693:"NE",700:"LA",701:"LA",703:"LA",704:"LA",705:"LA",706:"LA",707:"LA",708:"LA",710:"LA",711:"LA",712:"LA",713:"LA",714:"LA",716:"AR",717:"AR",718:"AR",719:"CO",720:"CO",721:"AR",722:"AR",723:"AR",724:"AR",725:"AR",726:"AR",727:"AR",728:"AR",729:"AR",730:"OK",731:"OK",733:"TX",734:"OK",735:"OK",736:"OK",737:"TX",738:"OK",739:"OK",740:"OK",741:"OK",743:"OK",744:"OK",745:"OK",746:"OK",747:"OK",748:"OK",749:"OK",750:"TX",751:"TX",752:"TX",753:"TX",754:"TX",755:"TX",756:"TX",757:"TX",758:"TX",759:"TX",760:"TX",761:"TX",762:"TX",763:"TX",764:"TX",765:"TX",766:"TX",767:"TX",768:"TX",769:"TX",770:"TX",771:"TX",772:"TX",773:"TX",774:"TX",775:"TX",776:"TX",777:"TX",778:"TX",779:"TX",780:"TX",781:"TX",782:"TX",783:"TX",784:"TX",785:"TX",786:"TX",787:"TX",788:"TX",789:"TX",790:"TX",791:"TX",792:"TX",793:"TX",794:"TX",795:"TX",796:"TX",797:"TX",798:"TX",799:"TX",800:"CO",801:"CO",802:"CO",803:"CO",804:"CO",805:"CO",806:"CO",807:"CO",808:"CO",809:"CO",810:"CO",811:"CO",812:"CO",813:"CO",814:"CO",815:"CO",816:"CO",820:"WY",821:"WY",822:"WY",823:"WY",824:"WY",825:"WY",826:"WY",827:"WY",828:"WY",829:"WY",830:"WY",831:"WY",832:"ID",833:"ID",834:"ID",835:"ID",836:"ID",837:"ID",838:"ID",840:"UT",841:"UT",842:"UT",843:"UT",844:"UT",845:"UT",846:"UT",847:"UT",850:"AZ",852:"AZ",853:"AZ",855:"AZ",856:"AZ",857:"AZ",859:"AZ",860:"AZ",863:"AZ",864:"AZ",865:"AZ",870:"NM",871:"NM",873:"NM",874:"NM",875:"NM",877:"NM",878:"NM",879:"NM",880:"TX",881:"TX",882:"NM",883:"NM",884:"NM",889:"NV",890:"NV",891:"NV",893:"NV",894:"NV",895:"NV",897:"NV",898:"NV",900:"CA",901:"CA",902:"CA",903:"CA",904:"CA",905:"CA",906:"CA",907:"CA",908:"CA",910:"CA",911:"CA",912:"CA",913:"CA",914:"CA",915:"CA",916:"CA",917:"CA",918:"CA",919:"CA",920:"CA",921:"CA",922:"CA",923:"CA",924:"CA",925:"CA",926:"CA",927:"CA",928:"CA",930:"CA",931:"CA",932:"CA",933:"CA",934:"CA",935:"CA",936:"CA",937:"CA",938:"CA",939:"CA",940:"CA",941:"CA",942:"CA",943:"CA",944:"CA",945:"CA",946:"CA",947:"CA",948:"CA",949:"CA",950:"CA",951:"CA",952:"CA",953:"CA",954:"CA",955:"CA",956:"CA",957:"CA",958:"CA",959:"CA",960:"CA",961:"CA",967:"HI",968:"HI",970:"OR",971:"OR",972:"OR",973:"OR",974:"OR",975:"OR",976:"OR",977:"OR",978:"OR",979:"OR",980:"WA",981:"WA",982:"WA",983:"WA",984:"WA",985:"WA",986:"WA",988:"WA",989:"WA",990:"WA",991:"WA",992:"WA",993:"WA",994:"WA",995:"AK",996:"AK",997:"AK",998:"AK",999:"AK"},_={A:"NL",B:"NS",C:"PE",E:"NB",G:"QC",H:"QC",J:"QC",K:"ON",L:"ON",M:"ON",N:"ON",P:"ON",R:"MB",S:"SK",T:"AB",V:"BC",X:"NT",Y:"YT"};function g(){const o=S("director_country").value,d=s("director_postal").value.trim().toUpperCase();if(!d||!o)return;let c="";if(o==="US"&&/^\d{5}/.test(d)?c=l[d.slice(0,3)]||"":o==="CA"&&/^[A-Z]\d/.test(d)&&(c=_[d[0]]||""),!c)return;const u=e("director_province_select"),p=e("director_province_text"),v=e("director_province");u&&!u.classList.contains("hidden")?Array.from(u.options).map(I=>I.value).includes(c)&&(u.value=c,u.dispatchEvent(new Event("change",{bubbles:!0}))):p&&!p.classList.contains("hidden")&&(p.value=c,p.dispatchEvent(new Event("input",{bubbles:!0}))),v&&(v.value=c)}e("director_postal")?.addEventListener("blur",g),e("director_postal")?.addEventListener("change",g);async function A(o){const d=window.__PW_API||"https://api.performancewest.net",c=o||"BC";try{W=(await(await fetch(`${d}/api/v1/amb/locations?province=${c}`)).json()).locations||[];const v=e("amb-location-list");if(!v)return;if(!W.length){v.innerHTML='<p class="text-xs text-gray-400">No locations available for this province yet.</p>';return}v.innerHTML="",W.forEach((N,I)=>{const C=document.createElement("label");C.className="flex items-center gap-3 p-3 rounded-lg border border-gray-200 cursor-pointer hover:border-pw-400 has-[:checked]:border-pw-500 has-[:checked]:bg-pw-50 transition-colors",C.innerHTML=`
<input type="radio" name="amb_location" value="${N.slug}" ${I===0?"checked":""} class="text-pw-600" />
<div class="flex-1">
<span class="text-sm font-medium text-gray-800">${N.name}, ${N.city}, ${N.province||c}</span>
</div>
<span class="text-sm font-semibold text-gray-700 tabular-nums">$${(N.yearly_price_usd/100).toFixed(2)}/yr</span>
`,C.querySelector("input")?.addEventListener("change",()=>{k=N.slug,T()}),v.appendChild(C)}),W.length>0&&(k=W[0].slug)}catch{const p=e("amb-location-error");p&&(p.textContent="Could not load mailbox locations.",p.classList.remove("hidden"))}}A("BC"),document.querySelectorAll("input[name='incorporation_province']").forEach(o=>{o.addEventListener("change",d=>{const c=d.target.value,u=e("selected_province");u&&(u.value=c),A(c);const p=e("geographic_coverage");p&&(["BC and Worldwide","ON and Worldwide"].includes(p.value)||!p.value)&&(p.value=`${c} and Worldwide`),document.querySelectorAll(".province-radio").forEach(v=>{const N=v.querySelector("input"),I=v.querySelector("span > span"),C=v.querySelector("span:first-child");N?.checked?(v.classList.remove("border-gray-200"),v.classList.add("border-pw-500","bg-pw-50"),C&&(C.classList.remove("border-gray-300"),C.classList.add("border-pw-600","bg-pw-600")),I&&I.classList.remove("opacity-0")):(v.classList.remove("border-pw-500","bg-pw-50"),v.classList.add("border-gray-200"),C&&(C.classList.remove("border-pw-600","bg-pw-600"),C.classList.add("border-gray-300")),I&&I.classList.add("opacity-0"))}),T()})}),e("own_ca_address")?.addEventListener("change",Z),Z(),e("expedited")?.addEventListener("change",()=>{const o=e("expedited")?.checked,d=document.querySelectorAll("#payment-methods-list > label[data-expedited]");let c=null;if(d.forEach(u=>{const p=u.getAttribute("data-expedited")==="yes";if(o&&!p){u.classList.add("hidden");const v=u.querySelector("input[type='radio']");v&&(v.checked=!1)}else u.classList.remove("hidden"),c||(c=u.querySelector("input[type='radio']"))}),o&&c)c.checked=!0;else if(!o){const u=document.querySelector('input[name="payment_method_choice"][value="ach"]');u&&(u.checked=!0)}e("expedited-payment-note")?.classList.toggle("hidden",!o),e("summary-expedited-row")?.classList.toggle("hidden",!o),T()}),document.querySelectorAll('input[name="did_routing_type"]').forEach(o=>{o.addEventListener("change",()=>{const d=document.querySelector('input[name="did_routing_type"]:checked')?.value;e("did-forward-fields")?.classList.toggle("hidden",d!=="forward"),e("did-sip-fields")?.classList.toggle("hidden",d!=="sip")})});function a(){const o=!!s("existing_ca_did")?.value.trim();e("did-routing-section")?.classList.toggle("hidden",o),e("existing-did-note")?.classList.toggle("hidden",!o)}e("existing_ca_did")?.addEventListener("input",a),e("existing_ca_did")?.addEventListener("change",a),e("director_mailing_different")?.addEventListener("change",()=>{const o=e("director_mailing_different")?.checked;e("director_mailing_fields")?.classList.toggle("hidden",!o)});let h=0;e("btn-add-director")?.addEventListener("click",()=>{h++;const o=h,d=e("additional-directors-container");if(!d)return;const c=document.createElement("div");c.className="mb-6 p-4 rounded-lg border border-blue-200 bg-blue-50 relative",c.id=`additional-director-${o}`,c.innerHTML=`
<div class="flex items-center justify-between mb-3">
<h3 class="text-sm font-semibold text-blue-800">Additional Director ${o}</h3>
<button type="button" class="text-xs text-red-500 hover:text-red-700" onclick="this.closest('[id^=additional-director]').remove()">Remove</button>
</div>
<div class="grid sm:grid-cols-3 gap-3 mb-3">
<input type="text" name="addl_director_${o}_first_name" placeholder="First name" required
class="rounded-lg border border-gray-300 px-3 py-2 text-sm placeholder:text-gray-400 focus:outline-none focus:ring-2 focus:ring-pw-500" />
<input type="text" name="addl_director_${o}_middle_name" placeholder="Middle (optional)"
class="rounded-lg border border-gray-300 px-3 py-2 text-sm placeholder:text-gray-400 focus:outline-none focus:ring-2 focus:ring-pw-500" />
<input type="text" name="addl_director_${o}_last_name" placeholder="Last name" required
class="rounded-lg border border-gray-300 px-3 py-2 text-sm placeholder:text-gray-400 focus:outline-none focus:ring-2 focus:ring-pw-500" />
</div>
<div class="space-y-3">
<select name="addl_director_${o}_country"
class="w-full rounded-lg border border-gray-300 px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-pw-500 bg-white">
<option value="">Country</option>
<option value="US" selected>United States</option>
<option value="CA">Canada</option>
<option value="GB">United Kingdom</option>
<option value="AU">Australia</option>
</select>
<input type="text" name="addl_director_${o}_street" placeholder="Street address"
class="w-full rounded-lg border border-gray-300 px-3 py-2 text-sm placeholder:text-gray-400 focus:outline-none focus:ring-2 focus:ring-pw-500" />
<div class="grid sm:grid-cols-3 gap-3">
<input type="text" name="addl_director_${o}_city" placeholder="City"
class="rounded-lg border border-gray-300 px-3 py-2 text-sm placeholder:text-gray-400 focus:outline-none focus:ring-2 focus:ring-pw-500" />
<input type="text" name="addl_director_${o}_province" placeholder="State / Province"
class="rounded-lg border border-gray-300 px-3 py-2 text-sm placeholder:text-gray-400 focus:outline-none focus:ring-2 focus:ring-pw-500" />
<input type="text" name="addl_director_${o}_postal" placeholder="Postal / ZIP"
class="rounded-lg border border-gray-300 px-3 py-2 text-sm placeholder:text-gray-400 focus:outline-none focus:ring-2 focus:ring-pw-500" maxlength="12" />
</div>
</div>
`,d.appendChild(c)}),e("id-front")?.addEventListener("change",()=>Q(s("id-front"),"front")),e("id-back")?.addEventListener("change",()=>Q(s("id-back"),"back")),document.querySelectorAll(".id-remove-btn").forEach(o=>{o.addEventListener("click",d=>{d.stopPropagation();const c=o.dataset.side;ve(c)})}),e("btn-phone-upload")?.addEventListener("click",he),e("btn-copy-link")?.addEventListener("click",()=>{const o=e("phone-upload-url");o&&navigator.clipboard.writeText(o.value).then(()=>{const d=e("btn-copy-link");d.textContent="Copied!",setTimeout(()=>{d.textContent="Copy"},2e3)}).catch(()=>{o.select()})}),e("btn-apply-discount")?.addEventListener("click",()=>{const o=s("discount_code").value.trim();o&&F(o)}),e("discount_code")?.addEventListener("keydown",o=>{if(o.key==="Enter"){o.preventDefault();const d=s("discount_code").value.trim();d&&F(d)}});const y=new URLSearchParams(window.location.search).get("code");if(y){const o=s("discount_code");o&&(o.value=y.toUpperCase()),F(y)}e("btn-next")?.addEventListener("click",()=>{if(_e(x)){if(ee(),x===4&&te(),x===K){Ae();return}Y(x+1)}}),e("btn-back")?.addEventListener("click",()=>{x>1&&Y(x-1)}),e("btn-start-over")?.addEventListener("click",()=>{sessionStorage.removeItem("pw_identity_session"),sessionStorage.removeItem("pw_order_return_url"),sessionStorage.removeItem("pw_form_snapshot"),O=null,L="pending",M&&(clearInterval(M),M=null);const o=document.querySelector("form");o&&o.reset();const d=e("btn-next");d&&(d.disabled=!1,d.title=""),e("identity-pending-notice")?.classList.add("hidden"),Y(1)})});(function(){const t=window.__PW_API;function r(a){const h=a.customer;document.getElementById("auth-logged-out")?.classList.add("hidden"),document.getElementById("auth-logged-in")?.classList.remove("hidden");const f=document.getElementById("auth-welcome");f&&(f.textContent=h.name?`Welcome back, ${h.name.split(" ")[0]}`:"Welcome back");const y=document.getElementById("auth-email-display");if(y&&(y.textContent=h.email),a.orders.length>0){const o=document.getElementById("auth-prior-orders"),d=document.getElementById("auth-order-select");o&&d&&(a.orders.forEach(c=>{const u=document.createElement("option");u.value=c.order_number;const p=new Date(c.created_at).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"});u.textContent=`${c.order_number}${c.company_type}${p}`,d.appendChild(u)}),o.classList.remove("hidden"),d.addEventListener("change",()=>{const c=a.orders.find(u=>u.order_number===d.value);c&&g(c,a)}))}if(a.directors.length>0){const o=document.getElementById("saved-director-picker"),d=document.getElementById("saved-director-select");if(o&&d){a.directors.forEach(u=>{const p=document.createElement("option");p.value=String(u.id),p.textContent=u.name+(u.citizenship?` (${u.citizenship})`:""),d.appendChild(p)}),o.classList.remove("hidden"),d.addEventListener("change",()=>{const u=a.directors.find(p=>String(p.id)===d.value);u&&l(u)});const c=a.directors.find(u=>u.is_default)||a.directors[0];c&&(d.value=String(c.id),l(c))}}if(a.addresses.length>0){const o=document.getElementById("saved-address-picker"),d=document.getElementById("saved-address-select");o&&d&&(a.addresses.forEach(c=>{const u=document.createElement("option");u.value=String(c.id),u.textContent=(c.label||`${c.city}, ${c.country}`)+(c.is_default?" (default)":""),d.appendChild(u)}),o.classList.remove("hidden"),d.addEventListener("change",()=>{const c=a.addresses.find(u=>String(u.id)===d.value);c&&_(c)}))}m(h)}function n(a,h){const f=document.getElementById(a);f&&h&&(f.value=h)}function m(a){n("customer_name",a.name),n("customer_email",a.email),n("customer_phone",a.phone),n("customer_company",a.company)}function l(a){n("director_name",a.name),n("director_citizenship",a.citizenship),a.address&&_(a.address)}function _(a){const h=document.getElementById("director_country");h&&(h.value=a.country,h.dispatchEvent(new Event("change"))),setTimeout(()=>{n("director_street",a.street),n("director_street2",a.street2),n("director_city",a.city),n("director_postal",a.postal);const f=document.getElementById("director_province_select"),y=document.getElementById("director_province_text"),o=document.getElementById("director_province");f&&!f.classList.contains("hidden")?(f.value=a.province||"",o&&(o.value=a.province||"")):y&&!y.classList.contains("hidden")&&(y.value=a.province||"",o&&(o.value=a.province||"")),document.getElementById("director_address_fields")?.classList.remove("hidden")},50)}function g(a,h){m({...h.customer,name:a.customer_name,phone:a.customer_phone,company:a.customer_company}),n("director_name",a.director_name);const f=h.directors.find(y=>y.name===a.director_name);if(f){const y=document.getElementById("saved-director-select");y&&(y.value=String(f.id)),l(f)}}async function A(){try{if(!(await(await fetch(`${t}/api/v1/auth/me`,{credentials:"include"})).json()).authenticated)return;const f=await fetch(`${t}/api/v1/portal/me`,{credentials:"include"});if(!f.ok)return;const y=await f.json();r(y)}catch{}}document.getElementById("auth-open-modal-btn")?.addEventListener("click",()=>{window.pwOpenAuth?.("login")}),window.addEventListener("pw:auth",async()=>{try{const a=await fetch(`${t}/api/v1/portal/me`,{credentials:"include"});if(a.ok){const h=await a.json();r(h)}}catch{}}),window.addEventListener("pw:portal-logout",()=>{document.getElementById("auth-logged-in")?.classList.add("hidden"),document.getElementById("auth-logged-out")?.classList.remove("hidden"),document.getElementById("saved-director-picker")?.classList.add("hidden"),document.getElementById("saved-address-picker")?.classList.add("hidden"),document.getElementById("auth-prior-orders")?.classList.add("hidden")}),document.getElementById("auth-logout-btn")?.addEventListener("click",async()=>{try{await fetch(`${t}/api/v1/auth/logout`,{method:"POST",credentials:"include"})}catch{}document.getElementById("auth-logged-in")?.classList.add("hidden"),document.getElementById("auth-logged-out")?.classList.remove("hidden"),document.getElementById("saved-director-picker")?.classList.add("hidden"),document.getElementById("saved-address-picker")?.classList.add("hidden"),document.getElementById("auth-prior-orders")?.classList.add("hidden"),window.dispatchEvent(new CustomEvent("pw:portal-logout"))}),A()})();