"use strict";(self.webpackChunkui=self.webpackChunkui||[]).push([[67],{339:(t,n,o)=>{o.r(n),o.d(n,{default:()=>e});const e={loyaltyPoints:"CVmqa4F0",loginLink:"QLe9Vzj5"}},338:(t,n,o)=>{const e=o(164);(0,o(1).createEntrypoint)("product_yotpo",e.LoyaltyPoints)},164:function(t,n,o){var e=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(n,"__esModule",{value:!0}),n.LoyaltyPoints=void 0;const i=o(0),r=o(0),s=o(7),a=o(165),c=o(166),l=e(o(339));n.LoyaltyPoints=({publicKey:t,defaultMultiplier:n,icon:o})=>{const{selectedVariant:e,product:u}=(0,s.useBentoShared)(),{loggedIn:d}=(0,a.useAccount)(),p=(0,c.useYotpoLoyaltyPoints)(u,t,null==e?void 0:e.variantId,n);return(0,i.jsx)(r.Fragment,{children:(0,i.jsx)("div",{class:l.default.loyaltyPoints,children:"number"==typeof p?(0,i.jsxs)("span",{children:[(0,i.jsx)("img",{src:null==o?void 0:o.url,width:null==o?void 0:o.width,height:null==o?void 0:o.height,alt:null==o?void 0:o.altText})," ",!0===d?(0,i.jsxs)(r.Fragment,{children:["Loyalty Customers: You will earn ",p," points on this purchase"]}):(0,i.jsxs)(r.Fragment,{children:["Earn ",p," points for this product."," ",(0,i.jsx)("a",{href:"/account/login",class:l.default.loginLink,children:"Login or signup"})]})]}):(0,i.jsx)("span",{children:" "})})})}},166:function(t,n,o){var e=this&&this.__awaiter||function(t,n,o,e){return new(o||(o=Promise))((function(i,r){function s(t){try{c(e.next(t))}catch(t){r(t)}}function a(t){try{c(e.throw(t))}catch(t){r(t)}}function c(t){var n;t.done?i(t.value):(n=t.value,n instanceof o?n:new o((function(t){t(n)}))).then(s,a)}c((e=e.apply(t,n||[])).next())}))};Object.defineProperty(n,"__esModule",{value:!0}),n.useYotpoLoyaltyPoints=void 0;const i=o(2);n.useYotpoLoyaltyPoints=(t,n,o,s)=>{var a;const[c,l]=(0,i.useState)([]);(0,i.useEffect)((()=>{(null==t?void 0:t.id)&&n&&e(void 0,void 0,void 0,(function*(){var o;try{const e={product_potential_points:{variants:null===(o=t.variants)||void 0===o?void 0:o.map((t=>({id:t.variantId,price:Math.round(100*Number(t.price))}))),product_id:t.id,product_tags:t.tags,product_type:t.productType}},i=`https://storefront.yotpo.com/loyalty/v3/stores/${n}/product_potential_points`,r=yield fetch(i,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(e)});if(!r.ok)throw new Error(`YOTPO API Request failed with status ${r.status}`);const s=yield r.json();l(s.product_potential_points.variants_with_points)}catch(t){console.error("Failed to fetch Yotpo loyalty points:",t),l([])}}))}),[t,n]);const u=null===(a=null==t?void 0:t.variants)||void 0===a?void 0:a.find((t=>t.variantId===o));return r(o,null==u?void 0:u.price,c,s)};const r=(t,n,o,e)=>{if(!t)return;const i=o.find((n=>n.id===t));return i?i.points:n?Math.round(Number(n)*e):void 0}},165:function(t,n,o){var e=this&&this.__awaiter||function(t,n,o,e){return new(o||(o=Promise))((function(i,r){function s(t){try{c(e.next(t))}catch(t){r(t)}}function a(t){try{c(e.throw(t))}catch(t){r(t)}}function c(t){var n;t.done?i(t.value):(n=t.value,n instanceof o?n:new o((function(t){t(n)}))).then(s,a)}c((e=e.apply(t,n||[])).next())}))};Object.defineProperty(n,"__esModule",{value:!0}),n.useAccount=void 0;const i=o(2);n.useAccount=()=>{const[t,n]=(0,i.useState)({loggedIn:!1,loading:!0}),o=t=>e(void 0,void 0,void 0,(function*(){try{n((t=>Object.assign(Object.assign({},t),{loading:!0,error:void 0})));const o=yield fetch("/api/account",{signal:t});if(!o.ok)throw new Error("Bad response");const e=yield o.json();if(!("loggedIn"in e))throw new Error("Incorrect response shape:"+JSON.stringify(e));n({loggedIn:!0===e.loggedIn,loading:!1})}catch(t){if(t instanceof Error&&"AbortError"===t.name)return;console.error("Failed to fetch account status:",t),n({loggedIn:!1,loading:!1,error:t instanceof Error?t.message:"Unknown error"})}}));return(0,i.useEffect)((()=>{const t=new AbortController;return o(t.signal),()=>{t.abort()}}),[]),Object.assign(Object.assign({},t),{refetch:o})}}},t=>{t.O(0,[1,2,3,4,5,8,7],(()=>t(t.s=338))),t.O()}]);