(()=>{var __webpack_modules__={307:(e,t,i)=>{const r=i(650),o=i(827);e.exports={trackMetric:async(e,t,i=void 0,n)=>{let s="offer-clicked"===e?localStorage:sessionStorage,a=s.getItem(`lb-${e}`);a=a?JSON.parse(a):{offers:{}};let c=t.recordType+("offer-viewed"===e?"#"+t.triggerItem?.id:"");const l=!!a.offers[c];let d={metricId:t.offerMetricId,configs:t.configs};a.offers[c]={...d,timestamp:(new Date).getTime(),variantIds:i?.map(e=>e.id)||[]};let u=n.accountMetricId,f={offers:a.offers,shop:n.myShopifyDomain,presentmentCurrency:{shopifyCurrency:window.Shopify?.currency,shopCurrencyCode:n.shopCurrencyCode},accountMetricId:u};s.setItem(`lb-${e}`,JSON.stringify(f)),!l&&await o.apiRequest(`${r.HOST_NAME}/v2/metrics`,"POST",{type:e,offer:d,shop:n.myShopifyDomain,accountMetricId:u})}}},326:(e,t,i)=>{const r=i(307),o=i(827),n=i(343),s=i(343),a=i(650);let c,l,d,u=[],f=[],p=[],g=!1,w=[],m={},h=!1,y=!1,v=new WeakSet;const b=e.exports={type:(e,t)=>{switch(t){case"popup":return["widget#atcp","widget#atcf","widget#ccpa","widget#ccpf"].includes(e);case"trigger":return["widget#pal","widget#pac","widget#pag"].includes(e);case"stc":return["widget#cpal","widget#cpac","widget#cpag","widget#icuc"].includes(e)}},addActionOffer:(e=[],t)=>{u=[...u,...e.filter(e=>e)],c=c||t,u.some(e=>e.widget.includes("atc"))&&b.registerListeners("atc")},triggerOffer:e=>{d||(d=e);let t=[];w?.length?(w.forEach(e=>{b.type(e?.type,"trigger")&&t.push(e)}),t?.length?b.processWidgets(t):b.reset()):b.reset()},actionOffer:(e,t)=>{g=!0;let i=u.find(e=>t?e.widget.includes("atc"):["widget#ccpa","widget#ccpf"].includes(e.widget));if(i){let t=c.widgets.find(e=>e.recordType===i.widget),r=t?.configs?.TACSelector?.isEnabled&&document.querySelector(t?.configs?.TACSelector?.selector);d=e,!r||r?.checked?b.handleWidgets([i]):b.reset()}else b.triggerOffer(e)},registerMutationObserver:(e,t)=>{m[t]||(m[t]=!0,new MutationObserver(i=>{i?.length&&i.forEach(({addedNodes:i})=>{i?.length&&i.forEach(i=>{if(!i?.querySelectorAll)return;(i.querySelectorAll(e).length||i.matches(e))&&b.registerListeners(t);let r=f.filter(e=>"widget#icuc"===e.widget);if(r?.length){let e=c.widgets.find(e=>"widget#icuc"===e.recordType);e?.position?.drawer?.isEnabled&&(()=>{let t=window.innerWidth<768?"mobile":"desktop",o=e?.position?.drawer?.[t]?.selector;if(i.querySelectorAll(o)?.length||i.matches(o)){let e=r.filter(e=>!document.querySelector(`lb-upsell-widget[offer="${e.recordType.split("-")[0]}"]`));e?.length&&b.handleWidgets(e,{isDrawer:!0})}})()}})})}).observe(document.body,{childList:!0,subtree:!0}))},getListeners:()=>({checkout:c?.commonConfig?.checkoutSelector||"button[name='checkout'], input[name='checkout'], a[href='/checkout']",atc:c?.commonConfig?.atcSelector||"button[name='add'], input[name='add']"}),registerActionListeners:(e,t)=>{b.registerMutationObserver(e,t);let i=document.querySelectorAll(e);i?.length&&i.forEach(e=>{v.has(e)||(v.add(e),e.setAttribute(`lb-${t}-listener`,!0),e.addEventListener("click",e=>{if("checkout"===t&&p.some(e=>["widget#ccpa","widget#ccpf"].includes(e.widget)))return;if(g)return void(g=!1);e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation();let i=e.target?.parentNode?.closest(`[lb-${t}-listener]`);b.actionOffer(i||e.target,"atc"===t)},{capture:!0}))})},remove:e=>{let t=document.querySelectorAll(`lb-upsell-widget[widget="${e}"]`);t?.length&&t.forEach(e=>e.remove())},reset:async e=>{await(window.lbPreCheckout?.(d)),b.type(e,"popup")?b.triggerOffer(d):d&&(d?.focus(),d?.click(),d=void 0)},registerListeners:(e,t=void 0)=>{switch(c=t||c,e){case"checkout":case"atc":b.registerActionListeners(b.getListeners()[e],e);break;case"event":window.addEventListener("lbPreviewProduct",e=>{if(e.detail?.product)if(e.detail.action&&"preview"!==e.detail.action)["open","newTab"].includes(e.detail.action)&&window.open(`https://${window.location.hostname}${window?.Shopify?.routes?.root||"/"}products/${e.detail.product.handle}`,"newTab"===e.detail.action?"_blank":"_self");else{document?.body?.insertAdjacentHTML("beforeend",'');let t=document.querySelector('lb-upsell-widget[widget="widget#preview"]'),i=c.widgets.find(e=>"widget#preview"===e.recordType),r=window.Shopify?.locale;t&&(t.lbPayload={widget:{offers:[e.detail.product],contents:{actionText:(i?.translations?.[r]||i?.contents)?.actionText||"View more details",currency:{symbol:c.shopEmailCurrencyFormat,format:c.commonConfig?.currencyFormat||c.shopMoneyInEmailsFormat,rate:c.shopCurrencyCode!==Shopify?.currency?.active?Shopify?.currency:void 0}},configs:{...i?.configs,...c?.commonConfig},diy:i?.diy,type:"widget#preview"}})}}),window.addEventListener("lbSECartUpdated",e=>{if(l=e.detail.cart,!e.detail?.isSelleasy&&(p=[]),e.detail?.cart?.items?.length){u=u.filter(e=>e?.widget.includes("atc"));let t=document.querySelector('lb-upsell-widget[widget="widget#icuc"]');t&&!e.detail.cart.items.some(e=>e.id===t.lbPayload?.widget?.triggers?.[0].id)&&b.remove("widget#icuc"),!d&&c?.offers?.length&&window.lbHandlers?.offer(c,void 0,["widget#icuc","widget#ccpa","widget#ccpf"]),!d&&!e.detail.isSelleasy&&n.mutateDiscount(window.lbupsellToken,e.detail.cart,e.detail.isAtc)}else b.remove("widget#icuc")}),window.addEventListener("lbWidgetCta",e=>{let t=e.detail.type.includes("atc");e.detail?.action?.isDismissed&&!t?g=!1:"end"===e.detail?.action?.key&&e.detail?.action?.value?(document.body.classList.remove("lb-popup-prevent-scroll"),y=!0,!h&&(y=!1,t?b.triggerOffer():b.reset())):(h=!0,b.processWidgets([{widgetSrcElement:e.detail.widgetSrcElement}],e.detail.action?.product,t))}),window.addEventListener("lbWidgetRendered",e=>{b.type(e.detail.type,"trigger")&&b.registerListeners("atc");let t=e.detail.widgetSrcElement?.getAttribute("offer");if(!w.some(e=>e.offer===t)&&w.push({...e.detail,offer:t}),t){let e=f.find(e=>e.recordType.startsWith(t));!p.some(e=>e.recordType.startsWith(t))&&p.push(e),e&&r.trackMetric("offer-viewed",e,void 0,c)}})}},processWidgets:(e,t,i=!1)=>{let r=e.map(e=>b.processV2Products(e.widgetSrcElement,t,i));return Promise.all(r).then(async t=>{let i=t.reduce((e,t)=>(t.items&&e.push(...t.items),e),[]);i.length&&await o.apiRequest(`https://${window.location.hostname}${window.Shopify?.routes?.root||"/"}cart/add.js?src=selleasy`,"POST",{items:i}),b.afterActions(t,e)})},afterActions:async(e,t)=>{let i=e.map(e=>e.callback).filter(e=>e);for(let e of i)await e();e.some(e=>e.reset)&&b.reset(),e.reduce((e,t)=>(t.afterAction&&!e.some(e=>e===t.afterAction)&&e.push(t.afterAction),e),[]).forEach(t=>{t&&"stay"!==t?"refresh"===t?location?.reload():window.location.href="/cart"+("checkout"===t?"/checkout":""):window.lbSelleasyUtils?.drawerRefresh(e.some(e=>e.isDrawer))})},processV2Products:async(e,t=void 0,i=!1)=>new Promise((o,a)=>{(t?Promise.resolve([t]):e?.getSelectedProducts()).then(async a=>{if(a?.length){let t=e?.getAttribute("offer"),d=f.find(e=>e.recordType.startsWith(t)),u={items:a.map(i=>({id:i.id,quantity:(i.quantity||1)*(e.lbPayload?.lb_config?.quantity||1),properties:{"_lb-product":d.triggerItem?.lbId+"#"+t},selling_plan:i.sellingPlanId}))},p=e.lbPayload?.widget?.overrides?.isDrawer,g=c.widgets.find(e=>e.recordType===d.widget),w=!g?.configs?.TACSelector?.isEnabled||document.querySelector(g?.configs?.TACSelector?.selector)?.checked;if(t&&d&&g&&w){["widget#atcf","widget#ccpf"].includes(d.widget)&&(a=[...(e.lbPayload?.funnelItems||[]).map(e=>e.lb_config),...a]),b.type(d.widget,"stc")&&(a=[...a,...s.getCode(d)?.discount?.products||[]]);let t=d.discounts?.method?n.handleDiscount(d,d.triggerItem,a,d.discounts,b.type(d.widget,"stc")):Promise.resolve(),f=await t;f&&await n.mutateDiscount(c.storeFrontAccessToken,l,!0),o({items:u.items,callback:async()=>{await r.trackMetric("offer-clicked",d,a,c),f&&await n.mutateDiscount(c.storeFrontAccessToken,void 0,!0),e.updateWidgetState({isLoading:!1})},reset:(h=!1,!b.type(d.widget,"popup")||y&&(y=!1,!i||b.triggerOffer()&&!1)),afterAction:g?.configs?.[p?"drawerAfterAction":"afterAction"],isDrawer:p})}else o({reset:!0})}else e.updateWidgetState({isLoading:!1,product:t}),o({reset:!0})}).catch(e=>{o({reset:!0})})}),getPosition:(e,t)=>{const i=window.innerWidth<768;if(b.type(e.recordType,"popup"))return{selector:"body",insertPosition:"beforeend"};if("widget#icuc"===e.recordType&&!o.checkPage(!0))return e.position?.drawer?.isEnabled?e.position?.drawer?.[i?"mobile":"desktop"]:void 0;if("custom"===e?.position?.type){let t=e.position[i?"mobile":"desktop"];if(document.querySelector(t.selector))return t}return{selector:`.lb-widget-${e.recordType.split("#")[1]}`,insertPosition:"afterbegin"}},formatWidgetContents:(e,t)=>{let i=e?.contents||{},r=t?.contents||{},o={...i,...r},n=window.Shopify?.locale;return c.shopLocales.find(e=>e.primary)?.locale!==n&&(o={...e?.translations?.[n]||i,...t?.translations?.[n]||r}),o},handleWidgets:(e,t,i)=>{try{c=c||i,f=f.filter(t=>!e.some(e=>e.recordType.startsWith(t.recordType))).concat(e),e=e.sort((e,t)=>(t.priority||0)-(e.priority||0));for(let i of e){let e=["widget#ba","widget#bl","widget#bac"].includes(i.widget),r=c.widgets.find(e=>e.recordType===i.widget);if(r&&!r.isDisabled&&i.isEnabled){let n=b.getPosition(r,i);if(!n)continue;i.id=i.recordType.split("-")[0],b.remove(r.recordType);let s=document.querySelector(n.selector);s?(s.insertAdjacentHTML(n.insertPosition,``),o.getOfferedProducts(i,c).then(async n=>{n=(n||[]).reduce((e,t)=>(e.some(e=>e.id===t.id)||e.push(t),e),[]);let s=window.Shopify?.locale;if((e||b.type(i.widget,"trigger"))&&(i.triggerItem.variants=i.triggerItem.variants.filter(e=>e.available),!i.triggerItem.available||!i.triggerItem.variants.length))return;let l=await o.cart(),d=["widget#ccpf","widget#atcf"].includes(i.widget);n=n.map(e=>{if(!e||!e?.available)return!1;if(e.variants=e.variants.filter(e=>e.available),"variant"===i.offerItems.type){let t=i.offerItems?.values?.find(t=>t.id.includes(e.id));e.variants=e.variants.filter(e=>(t.variants||[]).some(t=>t.id.includes(e.id)))}if(d){let t=i.offerItems?.values?.find(t=>t.id.includes(e.id));e.funnelId=t?.funnelId,e.contents={...t?.contents,...t?.translations?.[s]||{}}}return e.variants.length>0&&(!i.offerItems?.configs?.ignoreAlreadyBought||!l?.items?.some(t=>t.product_id===e.id))&&e}).filter(e=>e),i.offerItems?.configs?.isSortedRandomly&&(n=n.sort(()=>Math.random()-.5)),i.offerItems?.configs?.maxItems&&(n=n.slice(0,i.offerItems?.configs?.maxItems));let u=document.querySelector(`lb-upsell-widget[offer="${i.id}"]`),f={...r?.translations?.[s]||r?.contents,...i?.translations?.[s]||i?.contents};u&&n?.length&&(!d||n.find(e=>!e.funnelId))?(e&&(n=[i.triggerItem,...n]),u.lbPayload={widget:{triggers:[i.triggerItem],offers:n,offerCount:"auto"===i.offerItems?.type?i.offerItems?.count:i.offerItems?.values?.length,contents:{...f,currency:{symbol:c.shopEmailCurrencyFormat||c.shopCurrencyCode,format:c.commonConfig?.currencyFormat||c.shopMoneyInEmailsFormat,rate:c.shopCurrencyCode!==Shopify?.currency?.active?Shopify?.currency:void 0}},pitch:i.pitch,type:i.widget,discounts:"none"===i.discounts?.method||i.discounts?.isDisabled?void 0:{...i.discounts,text:f?.discountText||i.discounts?.text,tierLabel:f?.tierLabel||i.discounts?.tierLabel},diy:r?.diy,configs:{...i.offerItems?.configs,...r?.configs,...c?.commonConfig,integrations:c.integrations},overrides:t}},window.lbSelleasyUtils?.productReviews(u,c,a)):(u?.remove(),b.reset(i.widget))}).catch(e=>{b.reset(i.widget)})):b.reset(i.widget)}else b.reset(i.widget)}}catch(e){b.reset()}}}},343:(e,t,i)=>{const r=i(650),o=i(827),n={handleDiscount:async(e,t,i,s,a=!1)=>new Promise(async(c,l)=>{if("none"===s.method||!i?.length)return void c(void 0);let d,u={trigger:{id:t?.lbCart&&t?.id,productId:t?.product_id||t?.id,check:!(s.configs?.ignoreTrigger||a)},products:i.map(e=>({id:e.id,productId:e.productId,price:e.price}))};if(["widget#bl","widget#ba","widget#bac"].includes(e.widget)){let t="auto"===e.offerItems?.type?e.offerItems?.count:e.offerItems?.values?.length;if(t=Math.min(t,e.offerItems?.configs?.maxItems||t)+1,!(t===i.length||(i?.find(e=>e.isTrigger)||s.configs?.ignoreTrigger)&&("function"===s.method&&"product"===s.class?Object.keys(s.tiers||{}).some(e=>Number(e)<=i.length):(s.configs?.minProducts||t)<=i.length)))return void c(void 0)}if(["function","custom"].includes(s?.method))d={discount:{code:e.discounts.code,...u},offer:e.recordType};else if("dynamic"===s?.method){let t=`${r.HOST_NAME}/processOffer`,n={myShopifyDomain:e.myShopifyDomain,widgetType:e.widget,recordType:e.recordType,triggerProduct:u.trigger?.id,products:i.map(e=>({id:e.id,productId:e.productId,price:e.price}))};d={discount:{...await o.apiRequest(t,"POST",n),...u},offer:e.recordType}}d&&n.stackCode(d),c(d)}),stackCode:async e=>{let t=localStorage.getItem("lb-offer-codes");if(t){t=JSON.parse(t);let i=(t||[]).findIndex(t=>t?.offer===e.offer);-1!==i&&(n.deleteCodes([t[i].discount.id]),t.splice(i,1)),t.push(e)}localStorage.setItem("lb-offer-codes",JSON.stringify(t||[e]))},getCode:e=>{let t=localStorage.getItem("lb-offer-codes");return t&&(t=JSON.parse(t)),t?.find(t=>t?.offer===e.recordType)},deleteCodes:e=>{e.filter(e=>e).length&&o.apiRequest(`${r.HOST_NAME}/processOffer`,"POST",{codes:e,type:"delete"})},validateCodes:(e,t=!1)=>{let i=localStorage.getItem("lb-offer-codes");if(i){i=JSON.parse(i);let r=[];return i?.length&&!t&&(i=i.filter(t=>{let i=t?.discount?.trigger;return!(!t?.discount?.products?.every(t=>e.items.some(e=>e.id===t.id))||i&&i?.check&&!e.items.find(e=>i?.id?e.id===i?.id:e.product_id===i?.productId))||(t?.discount?.id&&r.push(t?.discount?.id),!1)})),n.deleteCodes(r),i?.length?i:[]}return[]},mutateDiscount:async(e,t,i=!1)=>{if(!e)return Promise.resolve();let s=t||await o.cart(!0,!0),a=n.validateCodes(s,i);if(a?.length&&s?.token){localStorage.setItem("lb-offer-codes",JSON.stringify(a)),a=a.slice(-5).map(e=>e?.discount?.code).filter(e=>e&&!a.includes(e)),a=[...a,...(window.lbExDiscounts||[]).filter(e=>e)];let t=`gid://shopify/Cart/${s.token}`;if("function"==typeof window.lbDealeasy?.applyDiscountsToCart)return window.lbDealeasy.applyDiscountsToCart(a,"selleasy",t);let i="\n mutation cartDiscountCodesUpdate($id: ID!, $discountCodes:[String!]) {\n cartDiscountCodesUpdate(cartId: $id, discountCodes: $discountCodes) {\n cart { id }\n userErrors { field message }\n }\n }",n={discountCodes:a,id:t},c=`https://${window.location.hostname}/api/${r.API_VERSION}/graphql.json`;return o.apiRequest(c,"POST",{query:i,variables:n},{"X-Shopify-Storefront-Access-Token":e,"Access-Control-Allow-Origin":"*"})}return localStorage.removeItem("lb-offer-codes"),Promise.resolve()}};e.exports=n},410:(e,t,i)=>{const r=i(827),o=i(326);let n,s;const a={isOfferValid:async(e,t)=>{t.lbId=t.product_id||t.id;let i=!1;const o=e?.triggers?.conditions?.rules||[],s="collection"===e?.triggers?.type||o?.some(e=>"collection"===e.class);if((s&&!t.graphQLRes?.collections||o?.some(e=>["category","inventory"].includes(e.class)||["title","type"].includes(e.class)&&n?.shopLocales?.find(e=>1==e.primary)?.locale!==window.Shopify?.locale)&&!t.graphQLRes)&&(t.graphQLRes=await r.getGraphQLProducts([t.lbId],"id",s,void 0,r.getPrimaryLocale(n)).then(e=>e?._0||void 0)),"all"===e?.triggers?.type)i=!0;else{let r=JSON.parse(JSON.stringify(e?.triggers?.values||[]));if(["product","variant"].includes(e?.triggers?.type))i=r.some(i=>(i.handle===t.handle||i.id.includes(t.product_id||t.id))&&("variant"!==e?.triggers?.type||i?.variants?.some(e=>e.id.includes(t.variant_id))));else if("tags"===e?.triggers?.type)i=r.some(e=>t?.tags?.includes(e?.handle));else if("collection"===e?.triggers?.type){const e=t.graphQLRes?.collections?.nodes?.map(e=>e.handle)||[];i=r.some(t=>e.includes(t.handle))}}return i&&a.validateOfferConfigs(e,t)},actionOffers:async function(e){let t,i,s=await r.cart(),c=(s?.items||[]).sort((e,t)=>e.line_price-t.line_price);for(let o of c||[])for(let n of e){const e=o;if("tags"===n?.triggers?.type||n?.triggers?.conditions?.rules?.length>0){const t=await r.getProduct(o.handle);e.tags=t?.tags,e.variants=t?.variants}"widget#icuc"===n.widget?(!i||i.priority!r||e.recordType===r).filter(e=>(i||[s.recordType]).includes(e.widget))?.sort((e,t)=>t.createdAt-e.createdAt);for(let i of n){if(!i.isEnabled)continue;let r=["widget#ccpa","widget#ccpf","widget#icuc"].includes(s.recordType)&&"checkout";if(r)"widget#icuc"===s.recordType?o.registerMutationObserver(void 0,"icuc"):o.registerListeners(r,e),c.push(i);else if(t){const e=l[s.recordType];(!e||e.priorityl[e]).filter(e=>e);o.addActionOffer(d.length>1?[d.reduce((e,t)=>e.priority>t.priority?e:t)]:d,n),["widget#atcp","widget#atcf"].forEach(e=>delete l[e]),a.actionOffers(c);let u=Object.values(l).filter(e=>e);return u.length&&o.handleWidgets(u,void 0,e),u},validateOfferConfigs:async(e,t)=>{const{triggers:i,schedule:o}=e||{},{rules:n=[],match:s}=i?.conditions||{},{startsAt:a,endsAt:c}=o||{},l=(new Date).getTime();if(a&&(lc))return!1;if(!n.length)return!0;const d=await r.cart();let u;for(const e of n){const i=r.validateRule(e,t,d);if("all"===s&&!i||"any"===s&&i)return i;u="all"===s&&void 0!==u?u&&i:u||i}return u}};e.exports=a},650:e=>{e.exports={HOST_NAME:"https://upsell-app.logbase.io",IS_LOGS_REQUIRED:"false",API_VERSION:"2025-07"}},827:(e,t,i)=>{const r=i(650);let o;const n={ROUTE:()=>window.location.origin+(window.Shopify?.routes?.root||"/"),getLocale:function(e){let t=e||Shopify?.locale,i=Shopify?.country;return t&&(t=t.toLocaleUpperCase(),t=["PT-","ZH-"].some(e=>t.startsWith(e))?t.replace("-","_"):t.split("-")[0]),{lang:t,country:i}},getPrimaryLocale:function(e){return e?.shopLocales?.find(e=>!0===e.primary)?.locale},checkPage:function(e){return window.location.pathname.indexOf(e?"/cart":"/products/")>-1},apiRequest:async function(e,t,i,r={}){return new Promise(async(o,n)=>{try{let n=await fetch(e,{method:t,headers:{"Content-Type":"application/json","Access-Control-Allow-Origin":"*",...r},...i?{body:JSON.stringify({...i,myShopifyDomain:window.lbShopDomain})}:{}});o(200===n.status?await n.json():void 0)}catch(e){o(void 0)}})},getHandle:function(e){return e.split("/").filter(e=>e).pop()},getProduct:async function(e,t={}){let i=n.ROUTE()+"products/"+e+".js";return await n.apiRequest(i,"GET",null).then(e=>({...e,...t})).catch(e=>{})},getGraphQLProducts:async function(e,t="handle",i=!1,o=!1,s=!1,a=[]){const{lang:c,country:l}=n.getLocale(s);if(!c&&!s)return e.map(e=>({identifier:e}));const d=n.ROUTE()+`api/${r.API_VERSION}/graphql.json`,u={"X-Shopify-Storefront-Access-Token":window.lbupsellToken},f=`query products @inContext(country: ${l}, language: ${c}) {\n ${e.map((e,r)=>`_${r}: product(${t}: "${"id"===t?`gid://shopify/Product/${e}`:e}") {\n title\n id\n handle\n productType\n category { id } \n totalInventory\n ${o?"variants(first: 250) {\n nodes {\n id\n price { amount currencyCode }\n availableForSale\n quantityAvailable\n }\n pageInfo {\n endCursor\n hasNextPage\n }\n }":""}\n ${i?"collections(first: 250) {\n nodes { handle }\n }":""}\n ${a?.length?`metafields(identifiers: [${a.map(e=>`{key: "${e.key}", namespace: "${e.namespace}"}`).join(",")}]){\n value\n key\n type\n namespace\n }`:""}\n }`).join("\n")}\n }`,p=await n.apiRequest(d,"POST",{query:f},u);if(!p?.data)return null;const g=p.data;return o&&await Promise.all(Object.entries(g).map(async([e,t])=>{if(!t?.variants?.pageInfo?.hasNextPage)return;let i=t.variants.pageInfo.endCursor;const r=async i=>{if(!i)return;const o=`query {\n product(handle: "${t.handle}") {\n variants(first: 250, after: "${i}") {\n nodes {\n id\n price { amount currencyCode }\n availableForSale\n quantityAvailable\n }\n pageInfo {\n endCursor\n hasNextPage\n }\n }\n }\n }`,s=await n.apiRequest(d,"POST",{query:o},u),a=s?.data?.product?.variants;a&&(g[e].variants.nodes.push(...a.nodes),a.pageInfo.hasNextPage&&await r(a.pageInfo.endCursor))};await r(i)})),g},getOfferedProductsAuto:function(e,t,i,r,o){let s=n.ROUTE()+`recommendations/products.json?product_id=${e?.lbId}&limit=${t}`+(i?`&intent=${i}`:"");return n.apiRequest(s,"GET",null).then(e=>e?.products||[]).then(async e=>{const t=r?.offerItems?.conditions?.rules||[];return t?.length>0&&t.some(e=>["collection","category","inventory","type","title"].includes(e.class))&&await n.getGraphQLProducts(e.map(e=>e.handle),"handle",t.some(e=>"collection"===e.class),t.some(e=>"inventory"===e.class),o).then(t=>{t&&(t=Object.values(t),e=e.map((e,i)=>{let r=t.find(t=>t.handle===e.handle);return e.graphQLRes=r,e}))}),e}).catch(e=>{})},populateOfferedProducts:async function(e,t,i=!1){let o=await n.getGraphQLProducts([e.triggerItem?.handle],"handle",!1,!1,!1,[{key:e.offerItems.aiConfig.replace("config#",""),namespace:"$app:selleasy-recommendations"}]),s=JSON.parse(o?._0?.metafields?.[0]?.value||"{}");if(s?.recommendationId){if(!s.products?.length)return;let r=s.products;if(0===(r||[]).filter(e=>e.handle).length){let e=await n.getGraphQLProducts(r.map(e=>e.id),"id",!1,void 0);r=r.map((t,i)=>({...e?.[`_${i}`],pitch:t.pitch}))}return e.pitch=Shopify?.locale===t?.shopLocales?.find(e=>!0===e.primary)?.locale?s?.pitch:void 0,e.configs={recommendationId:s?.recommendationId,rotatable:e.offerItems?.configs?.rotateRecos},i?void window.lbHandlers.offer(t,e.triggerItem,void 0,e.recordType):r.filter(Boolean)}if(!i)return n.apiRequest(r.HOST_NAME+"/validate?shop="+window.lbShopDomain+"&id="+e.triggerItem?.lbId+`-${e.id.split("#")[1]}`,"GET",null),void[1,2,3,4,5].forEach(i=>{setTimeout(()=>{!document.querySelector(`[offer="${e.id}"]`)&&n.populateOfferedProducts(e,t,!0)},5e3*i)})},filterProductByRule:(e,t)=>("price"===t.class?e.variants=e.variants.filter(e=>{const i=100*Number(t.value)*Number(window.Shopify?.currency?.rate||1),r=Number(e.price);return"equal"===t.type?r===i:"greater"===t.type?r>i:r{const r=e.graphQLRes?.variants?.nodes?.find(e=>e.id.includes(i.id));if(!r?.availableForSale)return!1;const o=Number(t.value),n=Number(r.quantityAvailable);return"equal"===t.type?n===o:"greater"===t.type?n>o:n{let r;for(const o of t){let t;if(["price","inventory"].includes(o.class)?(e=n.filterProductByRule(e,o),t=e?.variants?.length>0):t=n.validateRule(o,e),"all"===i&&!t||"any"===i&&t)return t?e:void 0;r="all"===i&&void 0!==r?r&&t:r||t}return r?e:void 0},getOfferedProducts:async function(e,t){return new Promise(async(i,r)=>{let o=e.offerItems;if("auto"===o?.type&&"selleasyAi"===o?.strategy&&o.aiConfig){let r=await n.populateOfferedProducts(e,t);if(!r)return void i([]);o.values=r}if("auto"===e.offerItems?.type&&"selleasyAi"!==e.offerItems?.strategy){const{rules:r,match:o}=e.offerItems?.conditions||{};await n.getOfferedProductsAuto(e.triggerItem,r?.length>0?10:e.offerItems?.count||2,e.offerItems?.intent,e,n.getPrimaryLocale(t)).then(t=>{r?.length>0&&(t=t?.map(e=>n.validateOfferProds(e,r,o))||[]),t=t?.filter(e=>void 0!==e)?.slice(0,e.offerItems?.count||2)||[],i(t)})}else{["icuc","ccp"].some(t=>e.widget.split("#")[1].startsWith(t))||(e.offerItems.values=e.offerItems?.values?.filter(t=>!t?.id?.includes(e.triggerItem?.id)));let r=e.offerItems?.values?.map(e=>e.handle),o=t?.handleMultiLangProductHandle?await n.getGraphQLProducts(r):void 0,s=e.offerItems?.values?.map((e,t)=>(e.handle=o?.[`_${t}`]?.handle||e.handle,n.getProduct(e.handle,{pitch:e.pitch}))),a=await Promise.all(s);i(a)}})},cart:async function(e=!1,t=!1,i=!1){return(e||!o)&&await n.apiRequest("/cart.js","GET",null).then(r=>{r&&(o=r,e&&window.dispatchEvent(new CustomEvent("lbSECartUpdated",{detail:{cart:r,isSelleasy:t,isAtc:i}})))}),o},registerCartListener:function(){const e=["/cart/add","/cart/change","/cart/update","/cart/clear"],t=window.XMLHttpRequest.prototype.open;window.XMLHttpRequest.prototype.open=function(){return this.addEventListener("load",function(){this._url&&e.some(e=>this._url.includes(e))&&n.cart(!0,this._url.includes("selleasy"))}),t.apply(this,arguments)};const{fetch:i}=window;window.fetch=async(...t)=>{let[r,o]=t,s=await i(r,o);try{if("string"==typeof r&&e.some(e=>r.includes(e))){try{const e=s.clone();await e.json()}catch(e){}n.cart(!0,r.includes("selleasy"),r.includes("/add"))}}catch(e){}return s}},validateRule:(e,t,i=void 0)=>{if(!e?.class)return!1;const{class:r,type:o,values:n,value:s}=e,a=(e,t,i)=>"equal"===t?e===i:"greater"===t?e>i:e{const r=t?.some(t=>e?.includes(t));return"has"===i?r:!r};switch(r){case"tags":return c(t?.tags,n?.map(e=>e.handle),o);case"collection":return c(t?.graphQLRes?.collections?.nodes?.map(e=>e.handle)||[],n?.map(e=>e.handle),o);case"title":return((e,t,i)=>{switch(t){case"start":return e?.toLowerCase().startsWith(i?.toLowerCase());case"end":return e?.toLowerCase().endsWith(i?.toLowerCase());case"equal":return e?.toLowerCase()===i?.toLowerCase();case"has":return e?.toLowerCase().includes(i?.toLowerCase());case"notHave":return!e?.toLowerCase().includes(i?.toLowerCase());default:return!1}})(t?.graphQLRes?.originalTitle||t?.graphQLRes?.title||t?.title,o,s?.trim());case"price":return a(t?.price/100,o,parseFloat(s)*("1.0"!==window.Shopify?.currency?.rate?parseFloat(window.Shopify.currency.rate):1));case"type":return c(t?.graphQLRes?.productType||t?.product_type||t?.type,n?.map(e=>e.handle),o);case"category":return c(t?.graphQLRes?.category?.id,n?.map(e=>e.id),o);case"inventory":return a(t?.graphQLRes?.totalInventory,o,Number(s));case"vendor":return c(t?.vendor,n?.map(e=>e.handle),o);case"customer":return c(window.lbUserInfo?.id,n?.map(e=>e.id),o);case"cTags":return c(window.lbUserInfo?.tags,[s],o);case"b2b":return s?window.lbB2b:!window.lbB2b;case"user":return s?Boolean(window.lbUserInfo):!Boolean(window.lbUserInfo);case"country":return c(window.Shopify?.country,n?.map(e=>e.handle),o);case"cartValue":return a(i?.total_price/100,o,parseFloat(s)*("1.0"!==window.Shopify?.currency?.rate?parseFloat(window.Shopify.currency.rate):1));default:return!1}}};e.exports=n},879:(e,t,i)=>{const r=i(650),o=i(827);let n=e.exports={cache:function(e,t){if("set"===e)localStorage.setItem("lb-upsell-setup",JSON.stringify(t)),localStorage.setItem("lb-upsell-setupFetchedAt",(new Date).getTime());else if("clear"===e)localStorage.removeItem("lb-upsell-setup"),localStorage.removeItem("lb-upsell-setupFetchedAt");else if("get"===e){let e=localStorage.getItem("lb-upsell-setup"),t=localStorage.getItem("lb-upsell-setupFetchedAt");return e&&t&&Number(t)>(new Date).getTime()-72e5?JSON.parse(e):void 0}},fetchObject:function(e,t,i=[],s=void 0){return new Promise((a,c)=>{let l={cursor:s||null},d=`https://${window.location.hostname}/api/${r.API_VERSION}/graphql.json`;o.apiRequest(d,"POST",{query:t.queryString,variables:l},{"X-Shopify-Storefront-Access-Token":e,"Access-Control-Allow-Origin":"*"}).then(r=>{let o=r?.data?.metaobjects;if(o?.nodes?.length){!t.paginate&&a(o.nodes);let r=[...i,...o.nodes];o.pageInfo?.hasNextPage?n.fetchObject(e,t,r,o.pageInfo.endCursor).then(e=>{r=[...r,...e],a(r)}).catch(e=>{c(!1)}):a(r)}else c(!1)}).catch(e=>{c(!1)})})},isCached:e=>!(e.createdAt>=(new Date).valueOf()-6048e5)&&(!e.lastAdminActiveAt||e.lastAdminActiveAt<(new Date).valueOf()-72e5),getSFSetup:async function(e,t=!1){return new Promise((i,r)=>{let o=[{queryString:'{\n metaobjects(type: "$app:selleasy-setup", first: 1, sortKey: "updated_at") {\n nodes {\n field(key: "selleasy-setup") {\n value\n key\n }\n id\n handle\n }\n }\n }',paginate:!1}];t||["offer","widget"].forEach(e=>{o.push({queryString:`query getMetaObjects($cursor: String) {\n metaobjects(type: "$app:selleasy-${e}", first: 250, after: $cursor, sortKey: "updated_at") {\n nodes {\n field(key: "selleasy-${e}") {\n value\n key\n }\n id\n handle\n }\n pageInfo {\n hasNextPage\n endCursor\n }\n }\n }`,paginate:!0})});let s=o.map(t=>n.fetchObject(e,t));Promise.all(s).then(e=>{if(e?.length){let r=e[0]?.length&&e[0][0]?.field?.value?.length&&JSON.parse(e[0][0]?.field?.value),o=e[1]?.length&&e[1].map(e=>e?.field?.value?.length&&JSON.parse(e.field.value)),s=e[2]?.length&&e[2].map(e=>e?.field?.value?.length&&JSON.parse(e.field.value));o=(o||[]).filter(e=>!["widget#tup","widget#cupl"].includes(e?.widget));let a={...r,offers:o,widgets:s};n.cache(n.isCached(a)?t?"":"set":"clear",a),i(a)}else i(!1)}).catch(e=>{i(!1)})})},fetchSetup:async function(e){let t=`${r.HOST_NAME}/setup?myShopifyDomain=${e}`;return o.apiRequest(t,"GET",null).then(e=>(window.lbupsellToken=e.storeFrontAccessToken,n.cache(e.isSetupCachedInClientSide?"set":"clear",e),e)).catch(e=>!1)},validateSetup:async function(e){let t;if(window?.lbupsellToken&&(t=await n.getSFSetup(window.lbupsellToken,!0),t))return t;let i=`${r.HOST_NAME}/setupValidate?myShopifyDomain=${e}`;o.apiRequest(i,"GET",null).then(e=>{!e.isSetupCachedInClientSide&&n.cache("clear")})},getSetup:async function(e){return new Promise(async(t,i)=>{let r=n.cache("get");r?n.validateSetup(e):r=await(window?.lbupsellToken?n.getSFSetup(window.lbupsellToken):n.fetchSetup(e)),t(r)})}}}},__webpack_module_cache__={};function __webpack_require__(e){var t=__webpack_module_cache__[e];if(void 0!==t)return t.exports;var i=__webpack_module_cache__[e]={exports:{}};return __webpack_modules__[e](i,i.exports,__webpack_require__),i.exports}const setupHandler=__webpack_require__(879),offerHandler=__webpack_require__(410),utils=__webpack_require__(827),widgetHandler=__webpack_require__(326),discountHandler=__webpack_require__(343),config=__webpack_require__(650);(function(window){window.lbShopDomain=window.Shopify.shop,window.lbShopDomain&&window.lbupsellVersion&&(utils.registerCartListener(),utils.cart(!0),widgetHandler.registerListeners("event"),setupHandler.getSetup(window.lbShopDomain).then(async setup=>{if(setup.isEnabled){if(eval(setup.customJs),setup.customCSS){const e=document.createElement("style");e.textContent=setup.customCSS,document.head.appendChild(e)}if(discountHandler.mutateDiscount(setup.storeFrontAccessToken),setup.offers?.length){let e=utils.getHandle(window.location.pathname),t=utils.checkPage()?await utils.getProduct(e,setup):void 0;window.lbHandlers={triggers:widgetHandler.triggerOffer,action:widgetHandler.actionOffer,offer:offerHandler.getOffers,widget:widgetHandler},window.lbSelleasyUtils?.init?.(),await offerHandler.getOffers(setup,t)}}}))})(window)})();