(self.webpackChunkui=self.webpackChunkui||[]).push([[93],{290:(t,n,o)=>{"use strict";var i=o(0),e=o(207),r=o(1);function a({publicKey:t,defaultMultiplier:n,icon:o,apps:{product:a}}){const l=a.product.value,u=a.selectedVariant.value,{loggedIn:c}=(0,e.a)(),d=((t,n,o,i)=>{var e;const[a,l]=(0,r.useState)([]);(0,r.useEffect)((()=>{var o,i,e,r;(null==t?void 0:t.id)&&n&&(o=void 0,i=void 0,r=function*(){var o;try{const i={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_type:t.productType}},e=`https://storefront.yotpo.com/loyalty/v3/stores/${n}/product_potential_points`,r=yield fetch(e,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(i)});if(!r.ok)throw new Error(`YOTPO API Request failed with status ${r.status}`);const a=yield r.json();l(a.product_potential_points.variants_with_points)}catch(t){console.error("Failed to fetch Yotpo loyalty points:",t),l([])}},new((e=void 0)||(e=Promise))((function(t,n){function a(t){try{u(r.next(t))}catch(t){n(t)}}function l(t){try{u(r.throw(t))}catch(t){n(t)}}function u(n){var o;n.done?t(n.value):(o=n.value,o instanceof e?o:new e((function(t){t(o)}))).then(a,l)}u((r=r.apply(o,i||[])).next())})))}),[t,n]);const u=null===(e=null==t?void 0:t.variants)||void 0===e?void 0:e.find((t=>t.variantId===o));return((t,n,o,i)=>{if(!t)return;const e=o.find((n=>n.id===t));return e?e.points:n?Math.round(Number(n)*i):void 0})(o,null==u?void 0:u.price,a,i)})(l,t,null==u?void 0:u.variantId,n);return(0,i.jsx)(i.Fragment,{children:(0,i.jsx)("div",{class:"CVmqa4F0",children:"number"==typeof d?(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===c?(0,i.jsxs)(i.Fragment,{children:["Loyalty Customers: You will earn ",d," points on this purchase"]}):(0,i.jsxs)(i.Fragment,{children:["Earn ",d," points for this product."," ",(0,i.jsx)("a",{href:"/account/login",class:"QLe9Vzj5",children:"Login or signup"})]})]}):(0,i.jsx)("span",{children:" "})})})}var l=o(2),u=o(5),c=o(16),d=o(18);const s=[c.a];l.BentoUI.feature({featureId:"product_yotpo",variations:[l.BentoUI.variation({component:a,variationId:"default",hydrate:!0,apps:s,render(t){return n=this,o=arguments,e=function*({globalState:t,context:n}){var o,i;const{props:e}=yield t,r="desktop"===n.device?null===(o=e.desktopHeroBlocks.right_column)||void 0===o?void 0:o.find((t=>"product_yotpo"===t.type)):null===(i=e.heroBlocks)||void 0===i?void 0:i.find((t=>"product_yotpo"===t.type)),a=null==r?void 0:r.public_key;if(!r||!a)return{html:""};const l=(0,u.a)(r.icon),c=yield(0,d.a)(e.byteState),s=null==c?void 0:c.product;return(null==s?void 0:s.id)?{props:{publicKey:a,defaultMultiplier:r.default_multiplier,icon:l}}:{html:""}},new((i=void 0)||(i=Promise))((function(t,r){function a(t){try{u(e.next(t))}catch(t){r(t)}}function l(t){try{u(e.throw(t))}catch(t){r(t)}}function u(n){var o;n.done?t(n.value):(o=n.value,o instanceof i?o:new i((function(t){t(o)}))).then(a,l)}u((e=e.apply(n,o||[])).next())}));var n,o,i,e}})]}),(0,l.createEntrypoint)("product_yotpo",a,s)},14:()=>{}},t=>{t.O(0,[1,2,3,4,5,6,7,8,9,10,11,12,13,14,17,15,16,19,18,20,21,24,23,22,28,26,25],(()=>t(t.s=290))),t.O()}]);