(self.webpackChunkui=self.webpackChunkui||[]).push([[95],{288:(t,n,o)=>{"use strict";var i=o(0),e=o(199),r=o(2);var a=o(10);function l({publicKey:t,defaultMultiplier:n,icon:o,apps:{product:l}}){const u=(0,a.g)(),c=l.product.value,d=l.selectedVariant.value,{loggedIn:s}=(0,e.a)(),p=((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)})(c,t,null==d?void 0:d.variantId,n);return(0,i.jsx)(i.Fragment,{children:(0,i.jsx)("div",{class:"CVmqa4F0",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===s?(0,i.jsxs)(i.Fragment,{children:["Loyalty Customers: You will earn ",p," points on this purchase"]}):(0,i.jsxs)(i.Fragment,{children:["Earn ",p," points for this product."," ",(0,i.jsx)("a",{href:u("/account/login"),class:"QLe9Vzj5",children:"Login or signup"})]})]}):(0,i.jsx)("span",{children:" "})})})}var u=o(1),c=o(6),d=o(13),s=o(20);const p=[d.a];u.BentoUI.feature({featureId:"product_yotpo",variations:[u.BentoUI.variation({component:l,variationId:"default",hydrate:!0,apps:p,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,c.a)(r.icon),u=yield(0,s.a)(e.byteState),d=null==u?void 0:u.product;return(null==d?void 0:d.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,u.createEntrypoint)("product_yotpo",l,p)},12:()=>{}},t=>{t.O(0,[1,2,3,4,5,6,7,8,9,10,11,12,14,13,17,16,15,18,19,20,21,24,22],(()=>t(t.s=288))),t.O()}]);