import{Ft as e,Gt as n,It as a,Jt as t,Pt as c,Vt as i,Wt as s,Xt as l,Zt as r,ft as o,jt as u,nn as d,pt as h,yt as p}from"./630ba094.L_X-5TXi.js";import{AA as _,AO as v,Gg as m,Hd as g,Kg as k,OA as f,UA as b,Xg as y,Yf as C,_p as w,jO as A,kA as x,ld as S,qg as j,vp as z,xO as L}from"./6ec9a0fa.rdcQt2v8.js";import{t as $}from"./1befea5c.DNUfNYYr.js";import{a as M,r as P}from"./e1177f6f.BdwRWO6B.js";import{x as I}from"./4205169c.D52g_3ca.js";import{t as R}from"./bace9a08.CgQzfzYE.js";import{i as U,r as F,t as B}from"./121bd940.CVLb0LrK.js";import{t as E}from"./0b704646.CbhE_p2Q.js";function N({href:e,children:n,onClick:a}){return p(k,{tone:"monochrome",href:e,onClick:a,children:n})}function O(){const{i18n:e}=L();return p(N,{href:"https://www.shopify.com/legal/cookies",children:e.translate("user_consent.policy")})}function T(){const{i18n:e}=L();return p(N,{href:"https://help.shop.app/en/shop/shopping/ads-personalization",children:e.translate("user_consent.detailed_view.learn_about_ads")})}function G({title:e,description:n,checked:a,onChange:t,disabled:c,badgeLabel:i}){return p(m,{gap:"small-200",children:[p(m,{direction:"inline",gap:"small-200",alignItems:"center",children:[p(v,{type:"strong",children:e}),i?p(z,{color:"subdued",children:i}):null]}),p(A,{gridTemplateColumns:"minmax(0, 1fr) minmax(auto, max-content)",gap:"base",alignItems:"start",children:[p(v,{children:n}),p($,{checked:a.value,onChange:t,disabled:c.value,accessibilityLabel:e})]})]})}function H({open:n,onClose:t,onConsentSaved:r}){const{consentManager:u,i18n:d,shopPay:_}=L(),k=_.user.shopAccountUuid,f=k.value,b=c(()=>void 0!==u.trackingConsentSelection?.value),y=o(n),C=e(!1),w=e(!1),A=e(!1),x=e(null),S=e(!1),j=c(()=>S.value||!b.value),z=e(!0);s(()=>{if(!n)return;const e=u.trackingConsentSelection?.peek();i(()=>{C.value=e?.analytics??!1,w.value=e?.marketing??!1,A.value=!1,x.value=null,S.value=!1})},[C,u,f,x,A,S,w,n]),a(()=>{if(!y.value||A.value)return;const e=u.trackingConsentSelection?.value;e&&i(()=>{C.value=e.analytics,w.value=e.marketing})});const $=l(async()=>{if(j.value)return;const e=k.value;S.value=!0,x.value=null;const n=await u.setTrackingConsent({analytics:C.value,marketing:w.value});_.user.shopAccountUuid.value===e&&(n.success?(r(),t()):x.value=d.translate("user_consent.error_saving_consent"),S.value=!1)},[C,u,x,d,j,S,w,r,t,_,k]),P=d.translate("user_consent.detailed_view.description",{cookie_policy_href:p(O,{})}),I=p(J,{isLocked:j,onSave:$});return p(M,{heading:d.translate("user_consent.title"),accessibilityLabel:d.translate("user_consent.manage"),open:n,onHide:t,primaryAction:I,children:p(m,{gap:"base",children:[p(m,{gap:"small-200",children:[p(h,{when:x,children:e=>p(g,{tone:"critical",children:e})}),p(v,{children:P})]}),p(m,{gap:"base",children:[p(G,{title:d.translate("user_consent.detailed_view.necessary"),description:d.translate("user_consent.detailed_view.necessary_description"),checked:z,disabled:z,badgeLabel:d.translate("user_consent.detailed_view.required")}),p(G,{title:d.translate("user_consent.detailed_view.analytics"),description:d.translate("user_consent.detailed_view.analytics_description"),checked:C,onChange:e=>{C.value=e,A.value=!0},disabled:j}),p(G,{title:d.translate("user_consent.detailed_view.advertising"),description:d.translate("user_consent.detailed_view.advertising_description",{learn_about_ads_href:p(T,{})}),checked:w,onChange:e=>{w.value=e,A.value=!0},disabled:j})]})]})})}function J({isLocked:e,onSave:n}){const{i18n:a}=L();return p(y,{inlineSize:"@media (inline-size >= small) auto, 100%",children:p(j,{variant:"primary",onClick:n,inlineSize:"fill",loading:e.value,disabled:e.value,children:p(A,{minInlineSize:"100px",justifyItems:"center",children:p(v,{children:a.translate("user_consent.detailed_view.save")})})})})}function X(){const{consentManager:a,i18n:i,mobileCheckoutSdk:o,shopPay:u}=L(),v=u.user.shopAccountUuid,[k,C]=r(!1),[A,S]=r(null),[j,z]=r(v.value),$=e(!1);s(()=>{j!==v.value&&(z(v.value),$.value=!1,S(null))},[$,j,v.value]);const M=l(()=>{S(null),C(!0)},[]),P=l(()=>{C(!1)},[]),I=l(()=>{$.value=!0},[$]),R=l(async()=>{const e=v.value;S(null);const n=await a.acceptAll();u.user.shopAccountUuid.value===e&&(n.success?I():S(i.translate("user_consent.error_saving_consent")))},[I,i,u,v,a]),U=l(async()=>{const e=v.value;S(null);const n=await a.rejectAll();u.user.shopAccountUuid.value===e&&(n.success?I():S(i.translate("user_consent.error_saving_consent")))},[I,i,u,v,a]),F=c(()=>a.shouldShowBanner.value||$.value),B=j===v.value,E=B&&F.value,N=function(e,a){const c=t(null),i=t(e),s=t(!1),l=t(null);if(i.current&&!e&&"undefined"!=typeof document){const e=c.current,n=document.activeElement,a=e&&n instanceof HTMLElement&&e.contains(n),t=e&&x(e);s.current=Boolean(a),l.current=a&&t?_(t):null}return i.current=e,n(()=>{if(!s.current||!a)return;s.current=!1;const n=e?c.current&&f(c.current):l.current;l.current=null,n?.isConnected&&document.activeElement===document.body&&n.focus({preventScroll:!0})},[a,e]),c}(E,B),O=t(E);s(()=>{const e=!O.current&&E;if(O.current=E,e)return b({content:i.translate("user_consent.title")})},[i,E]);const T=p(m,{gap:"small-300",children:[A&&p(g,{tone:"critical",children:A}),p(h,{when:$,fallback:p(q,{onAcceptAll:R,onManageCookiesClick:M,onRejectAll:U}),children:p(V,{onManageCookiesClick:M})})]}),G=p(H,{open:k,onClose:P,onConsentSaved:I});if(!E)return null;const J=p(y,{ref:N,background:"subdued",borderRadius:"large",padding:"base",children:p(m,{gap:"base",accessibilityRole:"group",accessibilityLabel:i.translate("user_consent.title"),children:T})}),X=o.variant.isPartner();return p(d,{children:[!X&&p(y,{display:"@media (inline-size >= small) none, auto",children:p(w,{blockSize:"base"})}),J,G]})}function q({onManageCookiesClick:e,onAcceptAll:n,onRejectAll:a}){const{i18n:t}=L(),[c,i]=r(null),s=null!==c,o=l(async()=>{s||(i("accept"),await n(),i(null))},[s,n]),u=l(async()=>{s||(i("reject"),await a(),i(null))},[s,a]),d=l(()=>{s||e()},[s,e]);return p(m,{gap:"base",children:[p(v,{type:"strong",children:t.translate("user_consent.accelerated_view.title")}),p(C,{children:p(v,{children:t.translate("user_consent.accelerated_view.description",{cookie_policy_href:p(O,{})})})}),p(m,{direction:"inline",gap:"small-200",children:[p(j,{inlineAlignment:"center",onClick:o,size:"small",variant:"secondary",loading:"accept"===c,disabled:s,children:t.translate("user_consent.accelerated_view.accept_all")}),p(j,{inlineAlignment:"center",onClick:u,size:"small",variant:"secondary",loading:"reject"===c,disabled:s,children:t.translate("user_consent.accelerated_view.reject_all")}),p(k,{onClick:d,accessibilityLabel:t.translate("user_consent.manage"),children:t.translate("user_consent.accelerated_view.manage")})]})]})}function V({onManageCookiesClick:e}){const{i18n:n}=L();return p(y,{autoFocus:!0,children:p(v,{children:n.translate("user_consent.accelerated_view.consent_collected",{manage_cookies_href:p(Z,{onManageCookiesClick:e})})})})}function Z({onManageCookiesClick:e}){const{i18n:n}=L();return p(N,{onClick:e,children:n.translate("user_consent.manage")})}N.displayName="CookiesLink";var K="https://cdn.shopify.com/shop-assets/static_uploads/shop-cash/",W=`${K}checkout_banner_coin_light.png`,Y=`${W} 1x, ${K}checkout_banner_coin_light_2x.png 2x, ${K}checkout_banner_coin_light_4x.png 4x`,D=`${K}checkout_banner_coin_dark.png`,Q=`${D} 1x, ${K}checkout_banner_coin_dark_2x.png 2x, ${K}checkout_banner_coin_dark_4x.png 4x`,ee=({expectedAmount:e,incentives:n,i18n:a,colorScheme:t,incentivePresentation:c})=>{const i=null!=e&&0!==e.amount,s=i?a.formatCurrency(e.amount,{currency:e.currencyCode}):"",l=i?B({i18n:a,incentives:n,formattedTotalAmount:s}):void 0,r=i?l?.title??a.translate("shop_cash.rewards_banner_title",{formattedAmount:s}):"",o=l?.description,d=o?`${r} ${o}`:r,h=i&&(n?.some(e=>F(e)||U(e))??!1);if(I(c,"cashbackBanner",h?d:void 0),!i)return null;const _="dark"===t,g=u("F7fwo",_?"iJGCf":"gXkBh","automatic"===t&&"yeSzn");return p(m,{direction:"inline",alignItems:"center",gap:"small-300",className:g,borderRadius:"large",children:[p("picture",{className:"lZxFl",children:["automatic"===t?p("source",{media:"(prefers-color-scheme: dark)",srcSet:Q}):null,p("img",{src:_?D:W,srcSet:_?Q:Y,alt:""})]}),o?p(m,{direction:"block",gap:"none",className:"VnjPc",children:[p(v,{children:r}),p(v,{type:"small",children:o})]}):p(v,{children:r})]})};function ne(){const{i18n:e}=L(),n=E(),{isEarningCashback:a,cashback:t,incentivePresentation:c}=P();return a&&t?p(y,{children:[p(w,{blockSize:"large-200"}),p(ee,{expectedAmount:t.expectedAmount,incentives:t.incentives,i18n:e,colorScheme:n,incentivePresentation:c})]}):null}function ae(){const e=R();return l(()=>{(e=>{S()?e.bridge.iframeClosed():window.close()})(e)},[e])}export{ne as n,X as r,ae as t};