import{Gt as e,It as t,Pt as n,Wt as i,Xt as a,en as o,ft as s,yt as r}from"./630ba094.L_X-5TXi.js";import{Ay as l,Gg as c,Il as u,JD as p,Jp as m,Pp as d,Xy as h,Yf as v,_f as g,al as _,xO as f}from"./6ec9a0fa.rdcQt2v8.js";import{i as k,n as y,r as b,t as S}from"./2c7267bc.DG2jhNnF.js";import{t as P}from"./19286c78.BbePfvbV.js";import{n as I,t as M}from"./f1754c88.Brd5q1On.js";import{t as C}from"./5d731017.BIuS-T4U.js";import{n as x,t as O}from"./f00fed33.B3oCNX4A.js";function A(){const{shop:e,source:t,checkout:i}=f(),a=h(),o=_();return n(()=>C({shop:e,source:t,checkout:i},{isPickupSelected:a.value,vaultedSections:o.value}))}var D=/[^>]*)>(?.*?)<\/a>/gi,j=/data-policy-handle=(["'])(?privacy-policy|terms-of-service)\1/i,E=/<\/?[a-z][\s\S]*>/i;function H(e){return r(g,{dangerouslySetInnerHTML:{__html:e}})}function F(e,t){return r("span",{dangerouslySetInnerHTML:{__html:e}},t)}function N(e){const t=[];let n=0,i=!1;for(const o of e.matchAll(D)){const a=o.index,s=w(o);if(null==a||!s)continue;const l=e.slice(n,a);if(E.test(l))return H(e);l&&t.push(F(l,`text-before-${a}`)),t.push(r(x,{handle:s,tone:"monochrome"},`${s}-${a}`)),n=a+o[0].length,i=!0}const a=e.slice(n);return!i||E.test(a)?H(e):(a&&t.push(F(a,"trailing-text")),r(g,{children:t}))}function w(e){const t=(e.groups?.attributes??"").match(j)?.groups?.handle;return"privacy-policy"===t?"privacy-policy":"terms-of-service"===t?"terms-of-service":null}function B(e){return e?.label&&e.disclaimerHtml.trim()?e:void 0}function J(){const{i18n:a,shop:s,checkout:l,embed:p}=f(),{marketingPhoneInputError:_,previousPhoneMarketingDisclosureKeySignal:C,smsMarketingOptInShownSignal:O}=l.negotiator.context,{phone:D,acceptSmsMarketing:j,smsMarketingPhone:E,shippingAddress:H}=l.negotiator.parts,F=b(),w=function(){const{shop:e,checkout:t}=f(),{shippingAddress:i,billingAddress:a}=t.negotiator.parts,o=h();return n(()=>{const n=M({isShippingRequired:t.isShippingRequired.value,isPickupSelected:o.value,shippingCountryCode:i.fields.countryCode.value,billingCountryCode:a.fields.countryCode.value});return I(e,n)})}(),J=w.value,L=B(J),R=!J&&"OFF"!==s.smsMarketing,T=L?.label??(R?a.translate("marketing.accept_sms_checkbox_label"):void 0),$=Boolean(T);e(()=>{$&&(O.value=!0)},[$,O]);const{handleSmsMarketingConsent:q}=k(),G=n(()=>l.negotiator.current.fields.buyerIdentity.value?.customerProfile),K=n(()=>!D.value&&!l.proposal.negotiated.fields.availableDeliveryAddresses.value?.length),V=n(()=>Boolean(!D.value)),W=n(()=>!p?.isFlagshipPartner&&!G.value&&!V.value);i(()=>{if(!E.value){const e=K.value?H.fields.phone.value:D.value;E.value=e??""}},[]),t(()=>{const e=H.fields.phone.value;K.value&&!B(w.value)&&"OFF"===s.smsMarketing&&(E.value=e||"")}),y(),t(()=>{const e=(t=w.value)?JSON.stringify([t.label,t.disclaimerHtml]):null;var t;const n=C.peek();C.value=e,null!=n&&null!=e&&n!==e&&j.value&&(j.value=!1)}),t(()=>{D.value&&!G.value&&(E.value=D.value)});const X=a.translate("field_errors.sms_marketing_phone_invalid"),z=A(),Q=n(()=>{const e=z.value;return e.isContact?"contactInfo":e.isDelivery?"shippingAddress":e.isBilling?"billingAddress":void 0}),Y=S(X,Q.value),U=o(()=>({state:{phone:E},errors:{phone:_}}),[_,E]);if(!T)return null;const Z=r(v,L?{type:"small",color:"subdued",children:N(L.disclaimerHtml)}:{type:"small",color:"subdued",children:r(g,{children:a.translate("marketing.sms.disclaimer.description_html",{privacy_policy_link:r(x,{handle:"privacy-policy",tone:"monochrome"}),terms_of_service_link:r(x,{handle:"terms-of-service",tone:"monochrome"})})})});return r(u,{...U,children:r(d,{id:"smsMarketingOptInDisclosure",open:j.value,summary:r(m,{id:"sms_marketing_opt_in",name:"sms_marketing_opt_in",label:T,checked:j.value,onChange:function(e){_.value=void 0,q(e)},"aria-controls":"smsMarketingOptInDisclosure"}),content:r(c,{gap:"base",paddingBlockStart:"base",children:[r(P,{countryCode:F.value??"",label:a.translate("marketing.sms.mobile_phone_number"),disabled:W.value,caretPosition:0,prefillCountryCode:!0,icon:"mobile",...j.value?Y:{}}),Z]})})})}function L({origin:t="contact_info_page"}){const{i18n:n,userEvents:i,checkout:{negotiator:a,configuration:o,identity:s},source:{checkoutSessionIdentifier:l,sourceId:u},shop:{id:d,myshopifyDomain:h}}=f(),{emailMarketingOptInShownSignal:_}=a.context,{acceptEmailMarketing:k}=a.parts,y=o.layout.isOnePage.value;e(()=>{_.value=!0},[_]);const b=O("marketing.disclaimer.description_html",n)?r(v,{type:"small",color:"subdued",children:r(g,{children:n.translate("marketing.disclaimer.description_html",{privacy_policy_link:r(x,{handle:"privacy-policy",tone:"monochrome"}),terms_of_service_link:r(x,{handle:"terms-of-service",tone:"monochrome"})})})}):null;return r(c,{gap:"small-200",children:[r(m,{id:"marketing_opt_in",name:"marketing_opt_in",checked:k.value,onChange:function(e){k.value=e,a.negotiate({withResultHandling:!0,loading:["acceptEmailMarketing"],silenceViolations:["payment-session"]}),i.monorailEvent({schemaId:"checkout_email_marketing_optin_ui_interaction/1.0",payload:{checkoutToken:l||u,shopId:Number(p(d)),shopifyDomain:h,action:e?"click_email_opt_in":"unclick_email_opt_in",origin:t,checkoutVersion:y?"checkout_one_redesign":"checkout_one"}})},label:R({identity:s,i18n:n})}),b]})}function R({identity:e,i18n:t}){switch(e.current.value){case"shopPay":case"buyWithPrime":return t.translate("marketing.accept_shop_pay_marketing_checkbox_label");default:return t.translate("marketing.accept_marketing_checkbox_label")}}function T(){const e=l(),{checkout:{negotiator:t}}=f(),{editorSetShopPaySignal:i}=t.context,o=a(e=>i.value?.setShopPay(e),[i]),r=s(e),c=s(o);return{setEditorShopPay:n(()=>r.value&&i.value?c.value:void 0)}}J.displayName="PhoneMarketingOptIn",L.displayName="MarketingOptIn";export{A as i,L as n,J as r,T as t};