(()=>{var t=9007199254740991,e=t=>{const e=+t;return e!=e||0===e?0:Number.isFinite(e)?e<0?Math.ceil(e):Math.floor(e):e},o=o=>Math.min(Math.max(e(o.length),0),t),i=t=>{if(null==t)throw new TypeError("Cannot convert null or undefined to object");return Object(t)},n=t=>{if(!Array.isArray(t))return[];let e=t.constructor;return"function"==typeof e&&e!==Array&&Array.isArray(e.prototype)&&Function.prototype.toString.call(e)===Function.prototype.toString.call(Array)&&(e=void 0),null===e||"object"!=typeof e&&"function"!=typeof e||(e=e[Symbol.species],null===e&&(e=void 0)),void 0===e?[]:new e(0)},r=(e,i,n,l,a,s,c)=>{for(let d=0;d0&&Array.isArray(n))a=r(e,n,o(n),l-1,a);else{if(a>=t)throw new TypeError("Flattened array is too large");Object.defineProperty(e,a++,{value:n,writable:!0,enumerable:!0,configurable:!0})}}return a};function l(t){const l=i(this),a=o(l),s=void 0===t?1:e(t),c=n(l);return r(c,l,a,s,0),c}function a(t,e){const l=i(this),a=o(l);if("function"!=typeof t)throw new TypeError("flatMap callback must be a function");const s=n(l);return r(s,l,a,1,0,t,e),s}function s(t){const e=i(this);let o=e.constructor;if(void 0===o)o=Promise;else{if(null===o||"object"!=typeof o&&"function"!=typeof o)throw new TypeError("Promise constructor must be an object");o=o[Symbol.species],null==o&&(o=Promise)}if("function"!=typeof o)throw new TypeError("Promise species must be a constructor");let n=t,r=t;return"function"==typeof t&&(n=e=>Reflect.apply(Promise.resolve,o,[t()]).then(()=>e),r=e=>Reflect.apply(Promise.resolve,o,[t()]).then(()=>{throw e})),e.then(n,r)}var c=t=>{if("symbol"==typeof t)throw new TypeError("Cannot convert Symbol to string");return String(t)};function d(o,i){if(null==this)throw new TypeError("Cannot pad null or undefined");const n=c(this),r=Math.min(Math.max(e(o),0),t);if(r<=n.length)return n;let l=void 0===i?" ":c(i);if(!l.length)return n;const a=r-n.length;for(;l.length"function"==typeof t?Function.prototype.bind.call(t,e):function(){return Reflect.apply(t,e,arguments)};function G(t,e){if(null==t)throw new TypeError("Cannot read method from null or undefined");let o=t[e];return void 0!==o||e in Object(t)||(Array.isArray(t)?"flat"===e?o=l:"flatMap"===e&&(o=a):"finally"===e&&"[object Promise]"===Object.prototype.toString.call(t)?o=s:"padStart"!==e||"string"!=typeof t&&"[object String]"!==Object.prototype.toString.call(t)||(o=d)),M(o,t)}function F(t){const e={};for(const o of t){if(null===o||"object"!=typeof o&&"function"!=typeof o)throw new TypeError("Iterator value is not an entry object");const t=o[0],i=o[1];Object.defineProperty(e,t,{value:i,writable:!0,enumerable:!0,configurable:!0})}return e}function T(t){if(null==t)throw new TypeError("Cannot read fromEntries from null or undefined");let e=t.fromEntries;var o;return void 0!==e||t!==Object||(o=Object,Object.prototype.hasOwnProperty.call(o,"fromEntries"))||(e=F),M(e,t)}u=Object.defineProperty,f=Object.defineProperties,_=Object.getOwnPropertyDescriptors,g=Object.getOwnPropertySymbols,v=Object.prototype.hasOwnProperty,p=Object.prototype.propertyIsEnumerable,h=(t,e,o)=>e in t?u(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o,m=(t,e)=>{for(var o in e||(e={}))v.call(e,o)&&h(t,o,e[o]);if(g)for(var o of g(e))p.call(e,o)&&h(t,o,e[o]);return t},b=(t,e)=>f(t,_(e)),y=(t,e,o)=>new Promise((i,n)=>{var r=t=>{try{a(o.next(t))}catch(e){n(e)}},l=t=>{try{a(o.throw(t))}catch(e){n(e)}},a=t=>t.done?i(t.value):Promise.resolve(t.value).then(r,l);a((o=o.apply(t,e)).next())}),S=["a","b","strong","i","em","u","s","br","span","small","sup","sub","mark","p","div"],P=["class","style"],E=["href","target","rel"],O=["script","style","template","iframe","object","embed","noscript"],A=t=>null==t?t:String(t).replace(//g,">").replace(/"/g,""").replace(/'/g,"'"),C=t=>{const e=document.createElement("template");return e.innerHTML=null!=t?t:"",e.content.textContent.replace(/\s+/g," ").trim().replace(/&/g,"&").replace(//g,">").replace(/"/g,""").replace(/'/g,"'")},function(){var t,e,o,i;const{proxy:n,integration:r,utils:l,customize:a,shopifyFunc:s,storefront:c}=(null==(t=window.FGSECOMAPP)?void 0:t.helper)||{};FGSECOMAPP.variables=b(m({},FGSECOMAPP.variables),{conditions:{collections:!1,locations:!1,function:!1,shipping:!1},isCheckout:!1,isCartPage:window.location.href.includes("/cart"),paymentsConfig:null,failedParseArrOffersAdded:!1,secomappGetCartRunning:!1,fgCallback:[],checkIsBlockCheckout:!1,hasDoneProcessCheckout:!1,giftIds:[],gifts:{originalProducts:[],clonedProducts:[],offers_shipping:[],offer_codes:{}},giftIdsFunction:[],maxOfferPriority:null,maxTodayOfferPriority:null,sections_cart:{},bogos_other_discounts:[],bogos_shipping_discounts:[]}),FGSECOMAPP.CUSTOM_EVENTS=b(m({},FGSECOMAPP.CUSTOM_EVENTS),{RERENDER_GIFT_SLIDER:"bogos:glider",SHOW_GIFT_SLIDER:"fg-gifts:show-slider",PRODUCT_HAS_GIFTS:"fg-gifts:gift-icon",GIFT_UPDATED:"fg-gifts:updated",GIFT_ADDED:"fg-gifts:added",CART_AUTO_UPDATED:"fg-cart:auto-updated",START_PROCESS_CART:"fg-cart:start-process",END_PROCESS_CART:"fg-cart:end-process",START_VALIDATE_CHECKOUT:"fg-checkout:start",END_VALIDATE_CHECKOUT:"fg-checkout:end",START_RENDER_APP:"fg-app:start",END_RENDER_APP:"fg-app:end",FG_OVERRIDE_FETCH:"fg-fetch:override",FG_OVERRIDE_XHR_OPEN:"fg-xhr:open",FG_OVERRIDE_XHR_SEND:"fg-xhr:send",RENDER_TODAY_OFFER:"fg-today-offer:render",TODAY_OFFER_CHANGE:"fg-today-offer:success",RENDER_CART_MESSAGE:"fg-messages:render",BOGOS_FG_PROCESS:"bogos:gifts",BOGOS_FG_INIT:"bogos:gifts-init",BOGOS_FG_CART_MESSAGE:"bogos:message",BOGOS_FG_START:"bogos:gifts-start",BOGOS_FG_END:"bogos:gifts-end",BOGOS_GIFT_OFFER_CHECK:"bogos:gift-check",ACCELIO_END_RENDER_APP:"accelio:end-render"}),FGSECOMAPP.helper.scaCustomLoadingCheckout=null!=(e=null==Shopify?void 0:Shopify.scaCustomLoadingCheckout)?e:void 0;const d=null!=(o=FGSECOMAPP.variables.RATE_PRICE)?o:100,u={cart:new RegExp(/(\/cart\/(add|change|update|clear)(\.js)?)/g),render_cart:new RegExp(/(\/cart\/(add|change|update|clear)(\.js)?(.*)(sca_reload_cart))/g),proxy:new RegExp("/(".concat(SECOMAPP.freegiftProxy,")/g")),graphql:new RegExp(/(cartLinesRemove|cartLinesUpdate|cartLinesAdd|cartDiscountCodesUpdate)/g)},f={OFFER_TYPE:{cloned:"cloned",function:"function",gift_func:"gift"},APP_REVIEW_OPTION:{bundle:"bundle",gift_slider:"gift_slider"},APP_REVIEW:{judgeme:"judgeme",trustoo:"trustoo",yotpo:"yotpo"},CUSTOM_OPTIONS:{equal:"equal_to",not_equal:"not_equal_to",contains:"contains",not_contains:"not_contains"},NARROW_TYPE:{product:"variants_ids",product_types:"product_types",product_vendors:"product_vendors",collection:"product_collections"},DISCOUNT_TYPE:{percentage:"percentage",fixed_amount:"fixed_amount",fixed_price:"fixed_price",free_products:"free_products",cheapest_free:"cheapest_free",shipping:"shipping_discount"},SYNC_QUANTITY:{stop_offer:"stop_offer",continue_selling:"continue_selling"},OBJECT_TYPE:{product:"product",variant:"variant"},RULE_CUSTOMERS_MUST_REACH:{all_rules:"all_rules",any_rule:"any_rule"},RULE_CONDITION:{at_least:"at_least",at_most:"at_most"},GIFT_DISPLAY:{PRODUCT:"by_products",VARIANT:"by_variants"},TRACK_OOSTOCK:{HIDE:"hide",SHOW_OOSTOCK:"show_oostock"}};f.TRIGGER_FUNC={[f.OFFER_TYPE.gift_func]:"GF"};const _="#bogos_section_gift_item",h='
{{ sca_fg_variant_select_section }}
{{ fg_variant_title }} {{ bogos_integration_judgeme }} {{ bogos_integration_trustoo }} {{ bogos_integration_yotpo }}
Sale price {{ fg_gift_price }} Regular price {{ fg_original_price }}
    {{ bogos_gift_quantity_options }}
',M="#sca_fg_gift_icon_section",F='{{ fg_gift_icon_alt }}',w={seq:0,LABEL:{ADDING:"Adding to cart",ADDED:"Added to cart"},status:{announce:(t,e)=>{const o=null==e?void 0:e.closest('[role="dialog"], .bogos-gifts-slider-container');(o?[...o.querySelectorAll(".bogos-gift-status")]:[document.querySelector(".bogos-gift-status")].filter(Boolean)).forEach(e=>{e.textContent=e.textContent===t?"".concat(t," "):t})},busy:t=>{t.setAttribute("aria-busy","true"),w.status.announce(w.LABEL.ADDING,t)},done:t=>{t.removeAttribute("aria-busy"),w.status.announce(w.LABEL.ADDED,t)},idle:t=>t.removeAttribute("aria-busy"),change:(t,e,o)=>{const i=String(null!=o?o:"").replace(/\s+/g," ").trim();if(!t||!i||t.dataset[e]===i)return;const n=void 0!==t.dataset[e];t.dataset[e]=i,n&&w.status.announce(i,t)}},COMBOBOX:{variant:{dropdown:".bogos-gift-select-variant-dropdown",trigger:".bogos-gift-select-variant-title-contain",list:".bogos-gift-select-variant-options",option:".bogos-gift-select-variant-option",openClass:"opened",closeOnTab:!0,synthetic:!0},quantity:{dropdown:".bogos-gift-item-quantity-dropdown",trigger:".bogos-gift-item-quantity-input",list:".bogos-gift-item-quantity-options",option:".bogos-gift-item-quantity-option",openClass:"opened",role:"combobox",label:"Quantity",synthetic:!0,closeOnTab:!0},variantV1:{dropdown:".dropdown",trigger:".select",list:".dropdown-menu",option:"li",openClass:"active",role:"button",synthetic:!0}},combobox:{ACTIVE_CLASS:"bogos-gift-option-active",isOpen:(t,e)=>t.classList.contains(e.openClass),options:(t,e)=>[...t.querySelectorAll(e.option)],sync:(t,e)=>{var o,i,n,r,l;const a=t.querySelector(e.trigger),s=t.querySelector(e.list);if(!a||!s)return;e.role&&a.setAttribute("role",e.role),"button"===e.role&&a.setAttribute("tabindex","0"),e.label&&a.setAttribute("aria-label",e.label);const c=w.combobox.options(t,e);if(s.id||(s.id="bogos-gift-listbox-".concat(++w.seq)),a.setAttribute("aria-controls",s.id),c.length){s.setAttribute("role","listbox"),s.setAttribute("aria-label",null!=(o=e.label)?o:"Variants"),a.setAttribute("aria-haspopup","listbox");const t=(null!=(n=null!=(i=a.value)?i:a.textContent)?n:"").trim();c.forEach(e=>{e.id||(e.id="bogos-gift-option-".concat(++w.seq)),e.setAttribute("role","option"),e.setAttribute("aria-selected",e.textContent.trim()===t?"true":"false")})}else s.querySelector('[role="radiogroup"], .bogos-select-option-name-container')&&(s.setAttribute("role","group"),s.setAttribute("aria-label",null!=(r=e.label)?r:"Variant options"),a.setAttribute("aria-haspopup","true"));w.status.change(a,"bogosSelected",null!=(l=a.value)?l:a.textContent);const d=w.combobox.isOpen(t,e);a.setAttribute("aria-expanded",d?"true":"false"),d||w.combobox.clearActive(t,e)},markActive:(t,e)=>{t&&t.classList.contains(w.combobox.ACTIVE_CLASS)!==e&&t.classList.toggle(w.combobox.ACTIVE_CLASS,e)},clearActive:(t,e)=>{var o;w.combobox.options(t,e).forEach(t=>w.combobox.markActive(t,!1)),null==(o=t.querySelector(e.trigger))||o.removeAttribute("aria-activedescendant")},setActive:(t,e,o)=>{var i,n;o&&(w.combobox.options(t,e).forEach(t=>w.combobox.markActive(t,t===o)),null==(i=t.querySelector(e.trigger))||i.setAttribute("aria-activedescendant",o.id),null==(n=o.scrollIntoView)||n.call(o,{block:"nearest"}))},move:(t,e,o)=>{const i=w.combobox.options(t,e);if(!i.length)return;const n=i.findIndex(t=>t.classList.contains(w.combobox.ACTIVE_CLASS)),r=i.findIndex(t=>"true"===t.getAttribute("aria-selected"));let l=(n>=0?n:r)+o;l<0&&(l=i.length-1),l>=i.length&&(l=0),w.combobox.setActive(t,e,i[l])},close:(t,e,o=!0)=>{const i=t.querySelector(e.trigger);w.combobox.isOpen(t,e)&&(null==i||i.click()),w.combobox.clearActive(t,e),o&&(null==i||i.focus())},bind:(t,e)=>{t&&"1"!==t.dataset.bogosGiftCombo&&(t.dataset.bogosGiftCombo="1",w.combobox.sync(t,e),new MutationObserver(()=>w.combobox.sync(t,e)).observe(t,{subtree:!0,childList:!0,attributes:!0,attributeFilter:["class"]}),t.addEventListener("keydown",o=>{var i,n;if("Escape"!==o.key&&(null==(n=null==(i=o.target)?void 0:i.closest)?void 0:n.call(i,'[role="radiogroup"]')))return;const r=t.querySelector(e.trigger),l=w.combobox.isOpen(t,e);switch(o.key){case"Escape":if(!l)return;return o.preventDefault(),void w.combobox.close(t,e);case"ArrowDown":case"ArrowUp":return o.preventDefault(),l?void w.combobox.move(t,e,"ArrowDown"===o.key?1:-1):void(null==r||r.click());case"Enter":case" ":{if(!l){if(!e.synthetic)return;return o.preventDefault(),void(null==r||r.click())}const i=t.querySelector(".".concat(w.combobox.ACTIVE_CLASS));if(!i)return;return o.preventDefault(),i.click(),void(null==r||r.focus())}case"Tab":return void(l&&e.closeOnTab&&w.combobox.options(t,e).length&&w.combobox.close(t,e,!1));default:return}}))}},radioGroup:{GROUP:'.bogos-select-option-items[role="radiogroup"]',radios:t=>[...t.querySelectorAll(".bogos-select-option-custom-item")],sync:t=>{const e=w.radioGroup.radios(t);if(!e.length)return;e.forEach(t=>t.setAttribute("aria-checked",t.classList.contains("bogos-active")?"true":"false"));const o=e.find(t=>t.classList.contains("bogos-active"));e.forEach(t=>t.setAttribute("tabindex",t===(null!=o?o:e[0])?"0":"-1"))},syncAll:t=>(null!=t?t:document).querySelectorAll(w.radioGroup.GROUP).forEach(w.radioGroup.sync),init:t=>{t&&(w.radioGroup.syncAll(t),"1"!==t.dataset.bogosGiftRadio&&(t.dataset.bogosGiftRadio="1",new MutationObserver(()=>w.radioGroup.syncAll(t)).observe(t,{subtree:!0,childList:!0,attributes:!0,attributeFilter:["class"]}),t.addEventListener("keydown",t=>{var e,o;const i=null==(o=null==(e=t.target)?void 0:e.closest)?void 0:o.call(e,".bogos-select-option-custom-item");if(!i)return;const n=i.closest(w.radioGroup.GROUP);if(n)switch(t.key){case"ArrowRight":case"ArrowDown":return t.preventDefault(),void w.radioGroup.move(n,i,1);case"ArrowLeft":case"ArrowUp":return t.preventDefault(),void w.radioGroup.move(n,i,-1);case" ":case"Enter":return t.preventDefault(),void i.click();default:return}})))},move:(t,e,o)=>{const i=w.radioGroup.radios(t);if(i.length<2)return;const n=i.indexOf(e);let r=n<0?0:n+o;r<0&&(r=i.length-1),r>=i.length&&(r=0);const l=i[r];i.forEach(t=>t.setAttribute("tabindex",t===l?"0":"-1")),l.focus(),l.click()}},dialog:{VISIBLE:"sca-is-visible-fg",FOCUSABLE:["a[href]","button:not([disabled])","input:not([disabled])","select:not([disabled])"].map(t=>"".concat(t,':not([tabindex="-1"])')).concat('[tabindex="0"]').join(","),lastFocused:null,panel:t=>null==t?void 0:t.querySelector('[role="dialog"]'),focusables:t=>[...t.querySelectorAll(w.dialog.FOCUSABLE)].filter(t=>t.offsetWidth||t.offsetHeight||t===document.activeElement),focusWhenReady:(t,e)=>{if(!t)return;const o=null!=e?e:Date.now()+600;t.focus(),document.activeElement===t||Date.now()>o||window.requestAnimationFrame(()=>w.dialog.focusWhenReady(t,o))},open:t=>{w.dialog.lastFocused=document.activeElement;const e=w.dialog.panel(t);e&&w.dialog.focusWhenReady(e)},close:()=>{const t=w.dialog.lastFocused;w.dialog.lastFocused=null,(null==t?void 0:t.isConnected)&&t.focus()},trap:t=>{if("Tab"!==t.key)return;const e=w.dialog.panel(document.querySelector(".sca-modal-fg.".concat(w.dialog.VISIBLE)));if(!e)return;const o=w.dialog.focusables(e);if(!o.length)return;const i=o[0],n=o[o.length-1];e.contains(document.activeElement)?t.shiftKey&&document.activeElement===i?(t.preventDefault(),n.focus()):t.shiftKey||document.activeElement!==n||(t.preventDefault(),i.focus()):(t.preventDefault(),i.focus())},watch:()=>{document.querySelectorAll(".sca-modal-fg").forEach(t=>{if("1"===t.dataset.bogosDialogWatch)return;t.dataset.bogosDialogWatch="1";const e=()=>{const e=t.classList.contains(w.dialog.VISIBLE);if(e===("1"===t.dataset.bogosDialogOpen)){const o=w.dialog.panel(t);return void(e&&o&&!o.contains(document.activeElement)&&"1"===t.dataset.bogosDialogNeedFocus&&o.focus())}t.dataset.bogosDialogOpen=e?"1":"0",e?(t.dataset.bogosDialogNeedFocus="1",w.dialog.open(t)):(delete t.dataset.bogosDialogNeedFocus,w.dialog.close())};new MutationObserver(e).observe(t,{attributes:!0,attributeFilter:["class"],childList:!0}),e()}),"1"!==document.body.dataset.bogosDialogTrap&&(document.body.dataset.bogosDialogTrap="1",document.addEventListener("keydown",w.dialog.trap))}},keys:{SELECTOR:['.glider-prev[role="button"]','.glider-next[role="button"]','.fg-gift-thumbnail-btn[role="button"]','.sca-fg-close-today-offer[role="button"]'].join(","),bind:()=>{document.body&&"1"!==document.body.dataset.bogosGiftKeys&&(document.body.dataset.bogosGiftKeys="1",document.addEventListener("keydown",t=>{var e,o;if("Enter"!==t.key&&" "!==t.key)return;const i=null==(o=null==(e=t.target)?void 0:e.closest)?void 0:o.call(e,w.keys.SELECTOR);i&&(t.preventDefault(),i.click())}))}}};w.keys.bind();const k={addToCart:(t,e,o)=>y(null,null,function*(){var i,n;if(x.empty(o))return new Promise(t=>t({ok:!0}));const r=f.OFFER_TYPE.gift_func,l=o.map(t=>{var e,o,i,n;const{bogos_item_properties:l}=null!=(e=FGSECOMAPP.variables.Shopify)?e:{},a=null!=(n=null==(i=null==(o=null==l?void 0:l.offers)?void 0:o[t.offer_root])?void 0:i[t.variant_id])?n:null==l?void 0:l[t.variant_id],s=j.isSpecificOffer?{_bogos_trigger_id:t.offer_root,_bogos_trigger:"".concat(f.TRIGGER_FUNC[r],"_").concat(t.offer_root),_bogos_trigger_type:r,_bogos_code:FGSECOMAPP.variables.gifts.offer_codes[t.offer_root]}:{};return{quantity:t.quantity,id:t.variant_id,properties:m(m({},s),a)}});if(FGSECOMAPP.variables.isHeadless)return yield c.addCart(l);const a=x.fetch(t,{method:"POST",headers:m({"X-Requested-With":"XMLHttpRequest",Accept:"application/json","Content-Type":"application/json"},e),body:JSON.stringify(m({items:l},k.cartAttributes()))});(null==e?void 0:e.sca_add_gift)&&k.markCartWrite(t.startsWith("http")?t:null!=(n=null==(i=x.routePath)?void 0:i.call(x,t))?n:t,a);const s=yield a;if(null==e?void 0:e.sca_add_gift){const e=t.match(u.cart);k.checkEventCart(["fetch-override:".concat(null==e?void 0:e[0])]).then()}return s}),handleAddGift:(t,e,o)=>y(null,null,function*(){var i,n,r;try{o="".concat(o);const l=FGSECOMAPP.offers.find(t=>o===t.id),a=l.type===f.OFFER_TYPE.function?null==(i=l.shopify_discount_settings)?void 0:i.code:null;console.info("BOGOS track: add gift from slider {".concat(t,"} {").concat(o,"} {").concat(l.type,"}"));const c=FGSECOMAPP.arrOfferAdded.find(e=>{var i;return o===(null==(i=e.belongs_to_offer)?void 0:i.toString())&&t===e.variant_id});c?c.quantity+=e:FGSECOMAPP.arrOfferAdded.unshift({variant_id:t,belongs_to_offer:o,quantity:e,code:a}),x.saveLocal(FGSECOMAPP.variables.constants.sca_offers_added,x.convertObjToString(FGSECOMAPP.arrOfferAdded)),k.renderEventLoading("start");const d=yield k.addToCart("".concat(null!=(r=null==(n=FGSECOMAPP.variables.Shopify)?void 0:n.sca_add_url)?r:"/cart/add.js","?sca_add_gift"),{sca_add_gift:1},[{quantity:e,variant_id:t,offer_root:l.offer_root,offer_id:l.id}]);return d.ok&&(yield s.apply_discounts([a])),d.ok}catch(l){return!1}}),addGiftToCart:(t,e,o)=>y(null,null,function*(){var i;const{general:n}=null==(i=FGSECOMAPP.fgAppearance)?void 0:i.gift_slider,{use_old_version:r,show_gift_type:l}=null!=n?n:{};!1===r&&k.handleQuantityGiftAvailableSession("set",e,"offer"===l?o.split("_")[0]:void 0),o=null==o?void 0:o.toString();const a=document.querySelector("#fg-gift-items .btn-add-to-cart[data-variant='".concat(t,"']")),s=yield k.handleAddGift(t,e,o);s?(a&&a.classList.remove("bogos-gift-adding"),a&&a.classList.add("bogos-gift-added"),R.renderSuccessAddGift(),yield k.refreshCart([],!0),setTimeout(()=>null==a?void 0:a.classList.remove("bogos-gift-added"),500)):a&&(a.innerHTML="Out of stock"),document.dispatchEvent(new CustomEvent(FGSECOMAPP.CUSTOM_EVENTS.GIFT_ADDED,{detail:{gift:s}}))}),processGiftsToCart:(t,e,o)=>y(null,null,function*(){var i,n,r,l,a,s,d;try{const u=JSON.stringify(FGSECOMAPP.arrOfferAdded)!==o;if(x.empty(t)&&x.empty(e)&&!u)return!1;const _={},g={};null==(n=null==(i=FGSECOMAPP.cartItems)?void 0:i.filter(t=>x.checkCartItemIsGift(t)))||n.forEach(t=>{var e,o,i,n;g["".concat(t.variant_id,"_").concat(null==(e=t.properties)?void 0:e._bogos_trigger_id)]={id:t.id,key:t.key,variant_id:t.variant_id,offer_id:null==(o=t.properties)?void 0:o._bogos_trigger_id,offer_root:null==(i=t.properties)?void 0:i._bogos_trigger_id,quantity:t.quantity},(null==(n=t.properties)?void 0:n._bogos_trigger_id)&&t.key&&(_[t.key]=t.quantity)}),null==(t=null==t?void 0:t.filter(t=>!x.empty(t.variant_id)))||t.forEach(t=>{var e,o,i;const n="".concat(t.variant_id,"_").concat(j.isSpecificOffer?t.offer_root:""),r=null!=(e=g[n])?e:{};g[n]=b(m(m({},r),t),{quantity:(null!=(o=r.quantity)?o:0)+(null!=(i=t.quantity)?i:1)})}),null==(r=Object.keys(g))||r.forEach(t=>{var e,o,i,n,r,l;if(g[t]=b(m({},g[t]),{quantity:Math.max(g[t].quantity,0)}),!j.isSpecificOffer&&!FGSECOMAPP.variables.isHeadless){const n=null==(e=g[t])?void 0:e.variant_id;return _[n]=(null==(o=g[t])?void 0:o.quantity)+(null!=(i=_[n])?i:0),void delete g[t]}(null==(n=g[t])?void 0:n.key)&&(_[null==(r=g[t])?void 0:r.key]=null==(l=g[t])?void 0:l.quantity,delete g[t])});const v=Object.values(g),p=!x.empty(_)||!x.empty(g);if(!p&&!u)return!1;null==t||t.forEach(t=>{var e;const o=FGSECOMAPP.arrOfferAdded.find(e=>{var o,i;return(null==(o=t.offer_id)?void 0:o.toString())===(null==(i=e.belongs_to_offer)?void 0:i.toString())&&t.variant_id===e.variant_id});o?o.quantity+=t.quantity:FGSECOMAPP.arrOfferAdded.unshift({variant_id:t.variant_id,belongs_to_offer:null==(e=t.offer_id)?void 0:e.toString(),quantity:t.quantity,code:t.type===f.OFFER_TYPE.function?t.code:null})}),x.saveLocal(FGSECOMAPP.variables.constants.sca_offers_added,x.convertObjToString(FGSECOMAPP.arrOfferAdded)),k.renderEventLoading("start");let h=!1,y=!x.empty(_),S=!x.empty(g);const P=p?"sca_process_gifts".concat(S?"_bogos-ignore":""):u?"sca_attr_cart":"sca_none";if(FGSECOMAPP.variables.isHeadless){const t=v.filter(t=>!t.id);let e=Object.entries(_).map(([t,e])=>({id:t,quantity:e}));yield c.updateCart(e).then(t=>h||(h=t.ok)),yield k.addToCart(null,null,t).then(t=>h||(h=t.ok))}else{const[t,e]=Object.entries(_).reduce(([t,e],[o,i])=>o.startsWith("gid://")?[[...t,{id:o,quantity:i}],e]:[t,[...e,[o,i]]],[[],[]]);x.empty(t)||(yield c.updateCart(t).then()),(y||u)&&(yield x.fetch("".concat(null!=(a=null==(l=FGSECOMAPP.variables.Shopify)?void 0:l.sca_update_url)?a:"/cart/update.js","?").concat(P),{method:"POST",headers:{"X-Requested-With":"XMLHttpRequest",Accept:"application/json","Content-Type":"application/json",sca_process_gifts:"1"},body:JSON.stringify(m({updates:T(Object)(e)},k.cartAttributes()))}).then(t=>h||(h=t.ok))),S&&(yield k.addToCart("".concat(null!=(d=null==(s=FGSECOMAPP.variables.Shopify)?void 0:s.sca_add_url)?d:"/cart/add.js","?").concat(P.replace("_bogos-ignore","")),{sca_process_gifts:1},Object.values(g)).then(t=>h||(h=t.ok)))}return(S||y)&&(yield H.apply_gift_discounts(FGSECOMAPP.arrOfferAdded.map(t=>t.code).filter(Boolean))),h&&t.length&&R.renderSuccessAddGift(),document.dispatchEvent(new CustomEvent(FGSECOMAPP.CUSTOM_EVENTS.CART_AUTO_UPDATED,{detail:{arrGiftsAdd:t,arrGiftsRemove:e}})),FGSECOMAPP.variables.isCheckout&&location.reload(),h}catch(u){return k.renderEventLoading("end"),console.error("BOGOS track: Error processGiftsToCart",u),!1}}),renderEventLoading:t=>{var e;try{if(!(null==(e=FGSECOMAPP.variables.Shopify)?void 0:e.enable_process_offer_loading))return;const{checkout_btn_query:o}=FGSECOMAPP.QUERY_SELECTOR,i=[...null==o?void 0:o.tool,...null==o?void 0:o.integration,...null==o?void 0:o.default].filter(Boolean).join(",");document.querySelectorAll(i).forEach(e=>{N.customLoading(t,e).then()})}catch(o){}},cartAttributes:()=>{var t,e,o,i,n;if(null==(t=FGSECOMAPP.variables.Shopify)?void 0:t.do_not_add_freegift_attribute)return;const r=[];if(!x.empty(FGSECOMAPP.arrOfferAdded)){r.push("SECOMAPP_FREEGIFT");const{bogos_item_properties:t}=null!=(e=FGSECOMAPP.variables.Shopify)?e:{};r.push(...null!=(o=null==t?void 0:t.cart)?o:[]);for(const e of FGSECOMAPP.arrOfferAdded){let{sub_conditions:t}=null!=(i=FGSECOMAPP.offers.find(t=>t.id===e.belongs_to_offer))?i:{},{specific_link_address:o}=null!=t?t:{};x.empty(o)||r.push(o)}}return{attributes:{__freegift_attributes:r.toString(),__bogos_tracking:null==(n=x.aggregateArrOfferAddedIds(FGSECOMAPP.arrOfferAdded))?void 0:n.sort().join("-")}}},priceCartItem:t=>{var e,o,i;const{final_price:n,price:r}=null!=t?t:{};try{return null!=(i=null!=(o=t[null==(e=FGSECOMAPP.variables.Shopify)?void 0:e.sca_fg_price])?o:n)?i:r}catch(l){return null!=n?n:r}},filterProductsSatisfyPackOfProducts:(t,e,o)=>{var i,n;const r=null!=(i=e.product_narrow[0])?i:{track_pack_type:null},l=r.track_pack_type;if(x.empty(l))return t;let a=!0,s=[],c=Object.values(r.value);"variant"===l&&(c=G(c.map(t=>{var e;return null!=(e=t.variants)?e:t.variant}),"flat")());const d="variant"===l?"variant_id":"product_id",u=t.reduce((t,e)=>{var o;const i=e[d],n=null!=(o=t[i])?o:0;return t[i]=n+e.quantity,t},{});for(const f of c){const t=null!=(n=u[f.id])?n:0;if(f.quantity>t){a=!1,s=[];break}s.push(Math.floor(t/f.quantity))}return o.multiply_max=0,a?(o.multiply_max=s.length>0?Math.min(...s):0,t):[]},filterProductsMatchConditionsWithCalculateForOtherRules:(t,e)=>{var o;return null!=(o=null==t?void 0:t.map(t=>{var o,i;if(void 0!==t.cal_gift_for_other_rules){const n=null==(o=FGSECOMAPP.arrOfferAdded)?void 0:o.filter(e=>e.variant_id===t.variant_id);if((null==n?void 0:n.reduce((t,e)=>t+e.quantity,0))===t.quantity){const o=null==(i=null==n?void 0:n.filter(o=>{var i,n,r;if((null==(i=o.belongs_to_offer)?void 0:i.toString())===e.toString())return!1;const l=null!=(r=(null==(n=FGSECOMAPP.offers)?void 0:n.find(t=>{var e,i;return(null==(e=t.id)?void 0:e.toString())===(null==(i=o.belongs_to_offer)?void 0:i.toString())})).gift_settings)?r:{},a=k.priceCartItem(t);return l.cal_gift_for_other_rules&&a>0}))?void 0:i.reduce((t,e)=>t+e.quantity,0);return b(m({},t),{cal_gift_for_other_rules:o>0,quantity:null!=o?o:0})}return b(m({},t),{cal_gift_for_other_rules:!1,quantity:0})}return m({},t)}))?o:[]},filterProductsMatchConditionsWithSettings:(t,e,o,i)=>{var n,r,l,a,s;const c=null==(n=FGSECOMAPP.fgSettings)?void 0:n.compare_gift_price_with_product,u=null==(r=FGSECOMAPP.fgSettings)?void 0:r.not_show_gift_if_already_on_cart;null!=i||(i=FGSECOMAPP.cartItems);let f=t;const _=null==(l=o.gift_products)?void 0:l.map(t=>t.original_product_shopify_id),g=i.filter(t=>!x.checkCartItemIsGift(t)).map(t=>t.product_id);if(u){const t=_.filter(t=>g.every(e=>e!==t));f=t.length?f.filter(e=>!(null==t?void 0:t.includes(e.product_id))):[]}let v=f;if(c){f=t.sort((t,e)=>k.priceCartItem(t)-k.priceCartItem(e));const i=o.gift_items.map(t=>{var e;return null!=(e=null==t?void 0:t.compare_gift_price)?e:0});f=f.filter(t=>i.some(e=>e<=k.priceCartItem(t)/d)),v=JSON.parse(JSON.stringify(f));const n=o.giftsAdded.sort((t,e)=>(null==e?void 0:e.compare_gift_price)-(null==t?void 0:t.compare_gift_price)).map(t=>m({},t)),r=n.reduce((t,e)=>t+e.quantity,0),l=k.calculateMaxGifts(f,e,o),a=Math.max(l-r,0),s=e.is_multiply?o.gift_settings.number_of_gift_can_receive:1;if(v.filter(t=>t.quantity>0).forEach(t=>{t.quantity*=s;const e=k.priceCartItem(t)/d;n.filter(t=>t.quantity>0&&(null==t?void 0:t.compare_gift_price)<=e).forEach(e=>{if(!t.quantity)return 0;const o=t.quantity-e.quantity;e.quantity=Math.max(-o,0),t.quantity=Math.max(o,0)})}),o.giftsAddedInvalid=n.filter(t=>t.quantity>0),!e.is_multiply&&a>0){const[t]=v.slice(-1);!x.empty(t)&&(t.quantity+=a)}v=v.filter(t=>t.quantity>0)}f=f.filter(t=>t.quantity>0);let p=[];(null==(a=FGSECOMAPP.fgSettings)?void 0:a.select_one_gift_price)&&(p=i.filter(t=>x.checkCartItemIsGift(t)).map(t=>t.variant_id));const h=k.optionMatchConfig(o),b=h?k.remainingOptionValues(f,o,e,h.optionName):null;return o.gifts_valid=null==(s=JSON.parse(JSON.stringify(o.gift_products)))?void 0:s.filter(t=>(o.is_offer_shipping&&(t.variants=t.variants.filter(t=>{var e,o,i,n;return null==(n=null==(i=null==(o=null==(e=FGSECOMAPP.productsByID)?void 0:e[t.product_shopify_id])?void 0:o.variants)?void 0:i.find(e=>e.id===t.variant_shopify_id))?void 0:n.available})),t.variants=t.variants.filter(t=>!p.includes(t.variant_shopify_id)),!(u&&(null==g?void 0:g.includes(t.original_product_shopify_id))||(c&&(t.variants=t.variants.filter(t=>v.some(e=>t.compare_gift_price<=k.priceCartItem(e)/d))),h&&(t.variants=k.filterGiftVariantsByOptionValue(t.variants,h,b)),x.empty(t.variants))))),f},countTotalMoneyAmount:t=>t.filter(t=>void 0===t.cal_gift_for_other_rules||t.cal_gift_for_other_rules).reduce((t,e)=>t+e.quantity*k.priceCartItem(e),0)/d,countTotalProducts:t=>t.filter(t=>void 0===t.cal_gift_for_other_rules||t.cal_gift_for_other_rules).reduce((t,e)=>t+e.quantity,0),calculateMaxGifts:(t,e,o)=>{var i;let n=0,r=0;if("money"===e.unit?(r=k.countTotalMoneyAmount(t),o.count_down_value=Math.max(e.min_amount-r,0)):"number_of_products"===e.unit&&(r=k.countTotalProducts(t),o.count_down_quantity=Math.max(e.min_amount-r,0)),!k.checkOfferWithSubConditionProductQtyLimits(o))return 0;if(r>=e.min_amount&&(null===e.max_amount||r<=e.max_amount)){const t=null!=(i=o.multiply_max)?i:Math.floor(100*r/(100*e.min_amount));n=o.gift_settings.number_of_gift_can_receive*(e.is_multiply?t:1)}return n},countMaxGiftsCanGet:(t,e,o)=>{var i;let n=x.findProductsMatchConditions(e,t,null==(i=o.sub_conditions)?void 0:i.subscription_products);return n=k.filterProductsMatchConditionsWithCalculateForOtherRules(n,t.offer_id),n=k.filterProductsMatchConditionsWithSettings(n,t,o,e),n=k.filterProductsSatisfyPackOfProducts(n,t,o),k.calculateMaxGifts(n,t,o)},checkEachConditionList:(t,e)=>{let o={},i=[],n=0;return e.offer_conditions.map(o=>{let r=k.countMaxGiftsCanGet(o,t,e);0!==r&&(n=r),i.push(r>0)}),o.max_gifts_can_get=n,o.condition_result=i,o},isSatisfyCondition:(t,e)=>{let o=!1;return 1===t.length?o=t[0]:2===t.length&&("and"===e&&(o=t[0]&&t[1]),"or"===e&&(o=t[0]||t[1])),o},normalizeOptionValue:t=>"".concat(null!=t?t:"").trim().toLowerCase(),isPrimaryLocale:()=>{var t,e;return!0===(null==(e=null==(t=null==SECOMAPP?void 0:SECOMAPP.current_locale)?void 0:t.shop_locale)?void 0:e.primary)},optionMatchConfig:t=>{var e,o;const i=null!=(e=null==t?void 0:t.gift_should_the_same)?e:{};if(!i.status||"option_value"!==i.type)return null;const n="".concat(null!=(o=i.option_name)?o:"").trim();return""===n?null:{optionName:n,letShopperChoose:"skip"!==i.no_match_rule}},triggerValuesOf:(t,e,o,i)=>new Set((null!=o?o:[]).map(o=>{const n={product_shopify_id:e,variant_shopify_id:o};return x.empty(null==t?void 0:t.options)?k.giftVariantOptionValue(n,i):k.productOptionValue(t,n,i)}).filter(t=>void 0!==t)),matchedOptionValues:(t,e,o)=>{var i;const n=(null!=t?t:[]).filter(t=>!x.checkCartItemIsGift(t)),r=G(null!=(i=e.offer_conditions)?i:[],"flatMap")(t=>{var o;return x.findProductsMatchConditions(n,t,null==(o=e.sub_conditions)?void 0:o.subscription_products)});return new Set(r.map(t=>k.triggerOptionValue(t,o)).filter(t=>void 0!==t))},keptGiftVariantsByOptionValue:(t,{optionName:e,letShopperChoose:o},i)=>(null!=t?t:[]).filter(t=>{var n,r;const l={product_shopify_id:null==t?void 0:t.product_shopify_id,original_product_shopify_id:null==t?void 0:t.original_product_shopify_id},a=null!=(r=null==(n=k.optionSourceProduct(l))?void 0:n.options)?r:[];if(k.optionIndexOf(a,e)<0)return!0;if(!(null==t?void 0:t.available))return!1;if(o)return!0;const s=k.giftVariantOptionValue(m(m({},l),t),e);return void 0!==s&&i.has(s)}),remainingOptionValues:(t,e,o,i)=>{var n,r,l;const a=(null==o?void 0:o.is_multiply)&&null!=(r=null==(n=e.gift_settings)?void 0:n.number_of_gift_can_receive)?r:1,s=new Map,c=(t,e)=>{var o;void 0!==t&&s.set(t,(null!=(o=s.get(t))?o:0)+e)};return(null!=t?t:[]).filter(t=>!x.checkCartItemIsGift(t)).forEach(t=>{var e;return c(k.triggerOptionValue(t,i),(null!=(e=t.quantity)?e:1)*a)}),(null!=(l=e.giftsAdded)?l:[]).forEach(t=>{var e;return c(k.giftVariantOptionValue({product_shopify_id:t.product_id,variant_shopify_id:t.variant_id},i),-(null!=(e=t.quantity)?e:1))}),new Set([...s].filter(([,t])=>t>0).map(([t])=>t))},triggerOptionValue:(t,e)=>{var o;const i={product_shopify_id:null==t?void 0:t.product_id,variant_shopify_id:null==t?void 0:t.variant_id};return k.isPrimaryLocale()?null!=(o=k.cartLineOptionValue(t,e))?o:k.productOptionValue(k.productInPage(null==t?void 0:t.product_id,null==t?void 0:t.handle),i,e):k.giftVariantOptionValue(i,e)},cartLineOptionValue:(t,e)=>{var o,i;const n=null!=(o=null==t?void 0:t.options_with_values)?o:[],r=n.find(t=>{var o;return"".concat(null!=(o=null==t?void 0:t.name)?o:"")===e});if(r)return k.normalizeOptionValue(r.value);const l=k.normalizeOptionValue(e),a=n.filter(t=>k.normalizeOptionValue(null==t?void 0:t.name)===l);return 1===a.length?k.normalizeOptionValue(null==(i=a[0])?void 0:i.value):void 0},productInPage:(t,e)=>{var o,i,n,r;const l=null==(i=null==(o=FGSECOMAPP.productsInPage)?void 0:o[e])?void 0:i.info;return x.empty(null==l?void 0:l.options)?null==(r=Object.values(null!=(n=FGSECOMAPP.productsInPage)?n:{}).find(e=>{var o,i;return(null==(o=null==e?void 0:e.info)?void 0:o.id)===t&&!x.empty(null==(i=null==e?void 0:e.info)?void 0:i.options)}))?void 0:r.info:l},optionIndexOf:(t,e)=>{const o=null!=t?t:[],i=o.indexOf(e);if(i>=0)return i;const n=k.normalizeOptionValue(e),r=[];return o.forEach((t,e)=>{k.normalizeOptionValue(t)===n&&r.push(e)}),1===r.length?r[0]:-1},optionSourceProduct:t=>{var e;const o=k.isPrimaryLocale()?FGSECOMAPP.productsByID:FGSECOMAPP.giftMatchOptionsByID,i=t=>{const e=null==o?void 0:o[t];return x.empty(null==e?void 0:e.options)?void 0:e};return null!=(e=i(null==t?void 0:t.product_shopify_id))?e:i(null==t?void 0:t.original_product_shopify_id)},giftVariantOptionValue:(t,e)=>k.productOptionValue(k.optionSourceProduct(t),t,e),productOptionValue:(t,e,o)=>{var i,n,r;if(x.empty(t))return;const l=(null!=(i=t.variants)?i:[]).find(t=>t.id===(null==e?void 0:e.variant_shopify_id)||t.id===(null==e?void 0:e.original_variant_shopify_id));if(x.empty(l))return;const a=null!=(n=t.options)?n:[],s=null!=(r=l.options)?r:[];if(a.length!==s.length)return;const c=k.optionIndexOf(a,o);return c<0?void 0:k.normalizeOptionValue(s[c])},matchingGiftVariants:(t,e,o,i)=>{var n,r;const l={product_shopify_id:null==t?void 0:t.product_shopify_id,original_product_shopify_id:null==t?void 0:t.original_product_shopify_id},a=null!=(r=null==(n=k.optionSourceProduct(l))?void 0:n.options)?r:[];return k.optionIndexOf(a,o)<0?null:(null!=e?e:[]).filter(t=>(null==t?void 0:t.available)&&i.has(k.giftVariantOptionValue(m(m({},l),t),o)))},filterGiftVariantsByOptionValue:(t,e,o)=>{const i=new Map;return(null!=t?t:[]).forEach(t=>{var e;const o="".concat(null!=(e=null==t?void 0:t.product_shopify_id)?e:null==t?void 0:t.original_product_shopify_id);i.has(o)||i.set(o,{product_shopify_id:null==t?void 0:t.product_shopify_id,original_product_shopify_id:null==t?void 0:t.original_product_shopify_id,variants:[]}),i.get(o).variants.push(t)}),G(k.filterGiftProductsByOptionValue([...i.values()],e,o),"flatMap")(t=>t.variants)},filterGiftProductsByOptionValue:(t,{optionName:e,letShopperChoose:o},i)=>{const n=[];return(null!=t?t:[]).forEach(t=>{var r;const l=k.matchingGiftVariants(t,t.variants,e,i);if(null===l)n.push(t);else if(x.empty(l)){if(o){const o={product_shopify_id:null==t?void 0:t.product_shopify_id,original_product_shopify_id:null==t?void 0:t.original_product_shopify_id},l=(null!=(r=t.variants)?r:[]).filter(t=>(null==t?void 0:t.available)||!i.has(k.giftVariantOptionValue(m(m({},o),t),e)));x.empty(l)||n.push(b(m({},t),{variants:l}))}}else n.push(b(m({},t),{variants:l}))}),n},readGiftMatchSession:()=>{if(!k.isPrimaryLocale())try{const t=x.convertStringToObj(sessionStorage.getItem(FGSECOMAPP.variables.constants.sca_gift_match_options));Object.entries(null!=t?t:{}).forEach(([t,e])=>{var o;null!=(o=FGSECOMAPP.giftMatchOptionsByID)[t]||(o[t]=e)})}catch(t){}},writeGiftMatchSession:()=>{try{sessionStorage.setItem(FGSECOMAPP.variables.constants.sca_gift_match_options,x.convertObjToString(FGSECOMAPP.giftMatchOptionsByID))}catch(t){}},prefetchGiftMatchOptions:(t,...e)=>y(null,[t,...e],function*(t,e=[]){var o,i;if(k.isPrimaryLocale())return;const n=(null!=t?t:[]).filter(t=>{const e=null==t?void 0:t.gift_should_the_same;return(null==e?void 0:e.status)&&"option_value"===e.type});if(x.empty(n))return;const r=Date.now(),l=new Set,a=t=>{var e;if(x.empty(t))return;const o=FGSECOMAPP.giftMatchOptionsByID[t];!x.empty(o)&&r-(null!=(e=o.time)?e:0)<=3e5||l.add(t)};n.forEach(t=>{var e,o;return[...null!=(e=t.gift_products)?e:[],...null!=(o=t.gift_items)?o:[]].forEach(t=>{a(null==t?void 0:t.product_shopify_id),a(null==t?void 0:t.original_product_shopify_id)})});const{current_product:s}=null!=(o=FGSECOMAPP.variables.Shopify)?o:{};[null==s?void 0:s.id,...(null!=(i=FGSECOMAPP.cartItems)?i:[]).map(t=>null==t?void 0:t.product_id),...null!=e?e:[]].forEach(a);const d=[...l];if(!x.empty(d))try{for(let t=0;t{FGSECOMAPP.giftMatchOptionsByID[t.id]=b(m({},t),{time:r}),i.add(t.id)}),e.forEach(t=>{i.has(t)||(FGSECOMAPP.giftMatchOptionsByID[t]={options:[],variants:[],time:r})})}k.writeGiftMatchSession()}catch(u){console.error("BOGOS track: prefetchGiftMatchOptions",u)}}),countGiftAvailableFromOffer:(t,e)=>{let o=k.checkGiftAlreadyAddedToCart(t,e);e.giftsAdded=o;let i=k.checkEachConditionList(t,e),n=k.isSatisfyCondition(i.condition_result,e.condition_relationship);if(n){let t=o.filter(t=>{var o,i;return(null==(o=t.belongs_to_offer)?void 0:o.toString())===(null==(i=e.id)?void 0:i.toString())}).reduce((t,e)=>t+e.quantity,0);i.max_gifts_can_get=i.max_gifts_can_get-t,e.giftsAdded=o,e.giftsAvailable=i.max_gifts_can_get}else e.giftsAdded=o,e.giftsAvailable=0;return!x.empty(FGSECOMAPP.variables.maxOfferPriority)&&e.priority>FGSECOMAPP.variables.maxOfferPriority&&(n=!1),e.stop_lower_priority&&n?FGSECOMAPP.variables.maxOfferPriority=e.priority:!e.stop_lower_priority||n||e.priority!==FGSECOMAPP.variables.maxOfferPriority||x.empty(o)||(FGSECOMAPP.variables.maxOfferPriority=null),e.isReachConditions=n,e},checkGiftAlreadyAddedToCart:(t,e)=>{var o;const i=null==t?void 0:t.map(t=>t.variant_id);FGSECOMAPP.arrOfferAdded=FGSECOMAPP.arrOfferAdded.filter(t=>null==i?void 0:i.includes(t.variant_id));let n=e.gift_items.map(t=>t.variant_shopify_id);const r=k.optionMatchConfig(e);if(r){const o=k.matchedOptionValues(t,e,r.optionName),i=k.keptGiftVariantsByOptionValue(e.gift_items,r,o).map(t=>t.variant_shopify_id);n=n.filter(t=>i.includes(t)),FGSECOMAPP.arrOfferAdded=FGSECOMAPP.arrOfferAdded.filter(t=>{var o,n;return(null==(o=t.belongs_to_offer)?void 0:o.toString())!==(null==(n=e.id)?void 0:n.toString())||i.includes(t.variant_id)})}const l={};e.gift_items.filter(t=>l[t.variant_shopify_id]={fg_original_compare_at_price:t.original_compare_at_price,fg_original_price:t.original_price,compare_gift_price:t.compare_gift_price});const a=FGSECOMAPP.variables.firstEmptyOfferAdded,s=null==(o=FGSECOMAPP.arrOfferAdded.filter(t=>{var o,i;return(null==(o=t.belongs_to_offer)?void 0:o.toString())===(null==(i=e.id)?void 0:i.toString())}))?void 0:o.map(t=>t.variant_id),c=t.filter(t=>{var o;const i=x.checkCartItemIsGift(t),r=null==(o=t.properties)?void 0:o._bogos_trigger_id,l=i&&(r===e.offer_root||!r);return i&&(t.cal_gift_for_other_rules=!1),n.includes(t.variant_id)&&(a||s.includes(t.variant_id))&&l}).map(t=>{var o,i,n,r;let a=e.gift_settings;t.cal_gift_for_other_rules=a.cal_gift_for_other_rules,t.belongs_to_offer=null==(o=e.id)?void 0:o.toString();const s=!x.empty(null==(i=t.properties)?void 0:i._bogos_trigger_id),c=null==(r=null==(n=FGSECOMAPP.arrOfferAdded)?void 0:n.filter(o=>{var i,n;return(null==(i=o.belongs_to_offer)?void 0:i.toString())!==(null==(n=e.id)?void 0:n.toString())&&t.variant_id===o.variant_id}))?void 0:r.reduce((t,e)=>t+e.quantity,0);return m(b(m({},t),{quantity:t.quantity-(s?0:c)}),l[t.variant_id])});return FGSECOMAPP.variables.firstEmptyOfferAdded&&c.filter(t=>t.quantity>0).forEach(t=>{var o,i,n;const r=FGSECOMAPP.arrOfferAdded.find(e=>{var o,i;return(null==(o=t.belongs_to_offer)?void 0:o.toString())===(null==(i=e.belongs_to_offer)?void 0:i.toString())&&t.variant_id===e.variant_id});r?r.quantity=t.quantity:FGSECOMAPP.arrOfferAdded.push({variant_id:t.variant_id,belongs_to_offer:null==(o=t.belongs_to_offer)?void 0:o.toString(),offer_id:null==(i=t.belongs_to_offer)?void 0:i.toString(),quantity:t.quantity,code:e.type===f.OFFER_TYPE.function?null==(n=null==e?void 0:e.shopify_discount_settings)?void 0:n.code:void 0})}),c},filterGiftProducts:t=>{const e=t.giftsAdded.filter(e=>{var o,i;return(null==(o=e.belongs_to_offer)?void 0:o.toString())!==(null==(i=t.id)?void 0:i.toString())}).map(t=>t.product_id);return Object.values(t.gifts_valid).filter(t=>!e.includes(t.product_shopify_id))},checkAutoAddGift:(t,e)=>{var o,i,n,r,l,a,s;try{const c=[],{offer:d}=e;let{code:u}=null!=(o=null==d?void 0:d.shopify_discount_settings)?o:{};const _=null==d?void 0:d.type;u=_===f.OFFER_TYPE.function?u:null;const g=e.gifts;let v=g.reduce((t,e)=>t+e.variants.length,0);if(!t.auto_add_gift&&!d.is_offer_shipping||v<=0)return[];const p=null!=(n=null==(i=e.offer)?void 0:i.gift_settings)?n:{},h=null!=(l=null==(r=e.offer)?void 0:r.gift_should_the_same)?l:{};if(h.status&&"variant"===h.type){const t=g[0].variants[0];0===t.price&&(c.push({variant_id:t.variant_shopify_id,quantity:e.giftsAvailable,offer_id:e.id,offer_root:d.offer_root,type:_,code:u}),console.log("BOGOS track: variant auto add gift {".concat(t.variant_shopify_id,"} {").concat(t.variant_title,"} {").concat(e.id,"} {").concat(_,"}")))}else if(null==p?void 0:p.auto_add_all_gifts){const t=null!=(a=p.auto_add_all_quantity)?a:{};v=G(g,"flatMap")(t=>t.variants).reduce((e,o)=>{var i;return e+(null!=(i=t[o.original_variant_shopify_id])?i:1)},0);const o=(null!=(s=null==e?void 0:e.giftsAvailable)?s:0)/v;g.forEach(i=>{var n;return null==(n=i.variants)?void 0:n.forEach(i=>{var n;return c.push({variant_id:i.variant_shopify_id,quantity:o*(null!=(n=t[i.original_variant_shopify_id])?n:1),offer_id:e.id,offer_root:d.offer_root,type:_,code:u})})}),console.log("BOGOS track: auto add all gifts from {".concat(e.id,"} {").concat(_,"}"))}else if(1===v){const t=g[0].variants[0];0===t.price&&(c.push({variant_id:t.variant_shopify_id,quantity:e.giftsAvailable,offer_id:e.id,offer_root:d.offer_root,type:_,code:u}),console.log("BOGOS track: auto add gift: {".concat(t.variant_shopify_id,"} {").concat(t.variant_title,"} {").concat(e.id,"} {").concat(_,"}")))}return c}catch(c){return console.error("BOGOS track: Error checkAutoAddGift",c),[]}},checkOfferWithSubCondition:(t,e)=>{var o,i,n,r,l,a;if(x.empty(t.sub_conditions))return!0;const s={},{specific_link_address:c,customer_tags:u,customer_locations:f,customer_order_history:_,mobile_app_channel:g,markets:v}=t.sub_conditions,{no_login:p}=null!=u?u:{};if((!x.empty(_)||null!=p&&!p)&&x.empty(e.customer.email))return!1;if(x.empty(c)||(s.specific_link_address=null==(o=FGSECOMAPP.variables.sca_fg_codes)?void 0:o.includes(c)),!x.empty(u)){const{value_customer_tags:t,type_customer_tags:o}=null!=u?u:{};let i=null==t?void 0:t.some(t=>{var o;return null==(o=e.customer.tags)?void 0:o.includes(t)});s.customer_tags="include"===o?i:!i}if(!x.empty(f)){const{value_customer_locations:t,type_customer_locations:e}=null!=f?f:{};let o=null==t?void 0:t.includes(FGSECOMAPP.customerLocation);s.customer_locations="include"===e?o:!o}if(!x.empty(_)){let o=!0;const{order_created_from:a,total_spend_on_order_history:c,total_spent_on_last_order:u,number_of_order:f,have_not_got_gift_from_this_offer:g}=null!=_?_:{};let v=null!=(i=e.customer.orders)?i:[];if(a){const t=Date.parse(a)/1e3;v=v.filter(e=>e.created_at>=t&&["paid","partially_paid"].includes(e.financial_status))}if(!x.empty(c)&&(0!==c.min_amount||0!==c.max_amount)){const{min_amount:t,max_amount:e}=null!=c?c:{},i=v.reduce((t,e)=>t+e.total_price,0)/d;o&=(i>=t||!t)&&(i<=e||!e)}if(!x.empty(u)&&(0!==u.min_amount||0!==u.max_amount)){const t=(null!=(n=e.customer.last_total)?n:0)/d,{min_amount:i,max_amount:r}=null!=u?u:{};o&=v.length>0&&(t>=i||!i)&&(t<=r||!r)}if(!x.empty(f)){const{min_amount:t,max_amount:e}=null!=f?f:{},i=!(0!==t||0!==e),n=v.length;o&=i?x.empty(v):(n>=t||!t)&&(n<=e||!e)}if(g){const i=null!=(r=e.customer.freegifts_v2)?r:[],n=G(t.gift_items.map(t=>["".concat(t.variant_shopify_id),"".concat(t.original_variant_shopify_id,"_").concat(10*(t.original_price-t.price)*10),"".concat(t.original_variant_shopify_id,"_").concat(10*(t.original_compare_at_price-t.price)*10)]),"flat")(),a=i.filter(({gift_item:t})=>n.includes(t));o&=!((null==(l=[...new Set(a.map(({order_id:t})=>t))])?void 0:l.length)>=Number(g))}s.customer_order_history=o}const{sale_channels:h,work_with_only_mobile_app:m}=null!=g?g:{};if(s.sale_channels=!1===m||(null!=h?h:[]).includes("online_store")||x.empty(h),!x.empty(v)){const{market:t}=null!=(a=FGSECOMAPP.variables.Shopify)?a:{},{type:e,value:o}=null!=v?v:{},i=x.getIntShopifyId(null==t?void 0:t.id);let n=null==o?void 0:o.includes("gid://shopify/Market/".concat(i));s.markets="include"!==e?!n:n}return Object.values(s).every(t=>t)},checkOfferWithSubConditionProductQtyLimits:t=>{var e,o,i;if(x.empty(null==(e=null==t?void 0:t.sub_conditions)?void 0:e.product_quantity_limits))return!0;const{customers_must_reach:n,rules:r}=null==(o=null==t?void 0:t.sub_conditions)?void 0:o.product_quantity_limits,l=n===(null==(i=f.RULE_CUSTOMERS_MUST_REACH)?void 0:i.any_rule)?"some":"every";return null==r?void 0:r[l](t=>{const e=x.findProductsMatchConditions(FGSECOMAPP.cartItems,t).filter(t=>void 0===t.cal_gift_for_other_rules||t.cal_gift_for_other_rules).reduce((t,e)=>e.quantity+t,0),{condition:o,quantity:i}=t;return o===f.RULE_CONDITION.at_least?e>=i:e<=i})},processCartWithOffers:(t,e,o)=>{var i,n,r,l,a,s,c;let d,u=[];const f=[],_=[],g=[];for(const v of e){const e=k.countGiftAvailableFromOffer(t,v),o=!e.isReachConditions||e.giftsAvailable<0,s=e.giftsAvailable>0&&(null==(i=e.gift_settings)?void 0:i.auto_add_all_gifts)&&(null==(n=FGSECOMAPP.fgSettings)?void 0:n.auto_add_gift);if((o||s)&&(null==(r=e.giftsAdded)||r.forEach(t=>{_.push({variant_id:t.variant_id,quantity:t.quantity,offer_id:v.id,key:t.key,type:v.type})})),!o){if(0===e.giftsAvailable){const t={};null==(l=e.giftsAdded)||l.forEach(e=>{var o;t[e.variant_id]=(null!=(o=null==t?void 0:t[e.variant_id])?o:0)+e.quantity}),null==(a=FGSECOMAPP.arrOfferAdded)||a.filter(t=>{var e,o;return(null==(e=v.id)?void 0:e.toString())===(null==(o=t.belongs_to_offer)?void 0:o.toString())}).forEach(e=>{var o;return e.quantity=null!=(o=t[e.variant_id])?o:e.quantity});continue}k.checkOfferWithSubCondition(v,SECOMAPP)&&u.push(v)}}if(null==t||t.filter(t=>x.checkCartItemIsGift(t)&&x.empty(t.belongs_to_offer)).forEach(t=>{var e;_.push({variant_id:t.variant_id,quantity:t.quantity,offer_id:null==(e=t.properties)?void 0:e._bogos_trigger_id,key:t.key})}),o||x.empty(_)){let t={};null==(s=u.map(t=>({id:t.id,offerName:t.offer_name,offerPriority:t.priority,stopLowerPriority:t.stop_lower_priority,gifts:k.filterGiftProducts(t),giftsAvailable:t.giftsAvailable,giftsAdded:t.giftsAdded,isReachConditions:t.isReachConditions,offer_root:t.offer_root,offer:t})))||s.forEach(e=>{const o=k.checkAutoAddGift(FGSECOMAPP.fgSettings,e);(null==o?void 0:o.length)>0?f.push(...o):R.handleCheckHiddenGiftSlider("FGSECOMAPP_HIDDEN_GIFT_OFFER_".concat(e.offer_root))||e.gifts.forEach(o=>{var i,n,r;t[o.product_shopify_id]=b(m({},o),{belongs_to_offer:null==(i=e.id)?void 0:i.toString()}),g[e.offer_root]=[...null!=(n=g[e.offer_root])?n:[],b(m({},o),{belongs_to_offer:null==(r=e.id)?void 0:r.toString()})]})}),d=null!=(c=Object.values(t))?c:[]}return{arrGiftsAdd:f,arrGiftsRemove:_,arrGiftsData:d,giftsOfferData:g}},processGiftsInvalid:(t,e)=>{var o;const i=new Set;null==t||t.forEach(t=>i.add(t.offer_id)),i.forEach(t=>{var e,o,i,n,r,l;const a=null==(e=FGSECOMAPP.offers)?void 0:e.find(e=>{var o;return(null==(o=e.id)?void 0:o.toString())===(null==t?void 0:t.toString())});if(x.empty(a)||!a.isReachConditions)return void(FGSECOMAPP.arrOfferAdded=null==(o=FGSECOMAPP.arrOfferAdded)?void 0:o.filter(e=>{var o;return(null==(o=e.belongs_to_offer)?void 0:o.toString())!==(null==t?void 0:t.toString())}));const{auto_add_all_gifts:s}=null!=(i=null==a?void 0:a.gift_settings)?i:{};if(a.giftsAvailable>=0&&!s)return;let c=[];const d=null!=(r=null==(n=FGSECOMAPP.arrOfferAdded)?void 0:n.filter(e=>{var o;return(null==(o=e.belongs_to_offer)?void 0:o.toString())===(null==t?void 0:t.toString())}))?r:[];if(s)c=c.concat([...d]),a.giftsAvailable=0;else{(null==(l=FGSECOMAPP.fgSettings)?void 0:l.compare_gift_price_with_product)&&!x.empty(a.giftsAddedInvalid)&&a.giftsAddedInvalid.forEach(t=>{const e=FGSECOMAPP.arrOfferAdded.find(e=>{var o,i;return(null==(o=e.belongs_to_offer)?void 0:o.toString())===(null==(i=a.id)?void 0:i.toString())&&t.variant_id===e.variant_id});if(x.empty(e))return;const o=e.quantity-t.quantity;a.giftsAvailable+=t.quantity,o>0?e.quantity=o:(e.quantity=0,c.push(m({},e)))});for(const t of d){if(a.giftsAvailable>=0)break;a.giftsAvailable+=t.quantity,a.giftsAvailable<=0?c.push(m({},t)):(t.quantity=a.giftsAvailable,a.giftsAvailable=0)}}null==c||c.forEach(t=>{var e;FGSECOMAPP.arrOfferAdded=null==(e=FGSECOMAPP.arrOfferAdded)?void 0:e.filter(e=>{var o,i;return t.variant_id!==e.variant_id||(null==(o=t.belongs_to_offer)?void 0:o.toString())!==(null==(i=e.belongs_to_offer)?void 0:i.toString())})})});const n={};return null!=(o=null==e?void 0:e.filter(t=>{var e,o,i,r,l;if(x.checkCartItemIsGift(t)){const a=(null==(e=t.properties)?void 0:e._bogos_trigger_type)===f.OFFER_TYPE.gift_func&&!x.empty(null==(o=t.properties)?void 0:o._bogos_trigger_id);let s=null==(i=FGSECOMAPP.arrOfferAdded)?void 0:i.filter(e=>t.variant_id===e.variant_id),c=t.variant_id;a&&(c="".concat(t.variant_id,"_").concat(t.belongs_to_offer),s=s.filter(e=>t.belongs_to_offer===e.belongs_to_offer)),t.quantity=null!=(r=null==s?void 0:s.reduce((t,e)=>t+e.quantity,0))?r:0,t.quantity-=null!=(l=n[c])?l:0,null!=n[c]||(n[c]=t.quantity)}return t.quantity>0}))?o:[]},checkAllOffers:(t,e)=>y(null,null,function*(){var o;const i=JSON.stringify(FGSECOMAPP.arrOfferAdded);let{arrGiftsAdd:n,arrGiftsRemove:r,arrGiftsData:l,giftsOfferData:a}=k.processCartWithOffers(t,e,!1);const s=k.processGiftsInvalid(r,t);if(!x.empty(r)){const i=k.processCartWithOffers(s,e,!0);k.processGiftsInvalid(null==i?void 0:i.arrGiftsRemove,t),n=null==i?void 0:i.arrGiftsAdd,r=null!=(o=null==r?void 0:r.concat(null==i?void 0:i.arrGiftsRemove))?o:[],l=null==i?void 0:i.arrGiftsData,a=null==i?void 0:i.giftsOfferData}const c=yield k.processGiftsToCart(n,r,i);return c||H.apply_discounts_shipping().then(),{giftsOfferData:a,arrGiftsData:l,isUpdated:c&&(!x.empty(n)||!x.empty(r))}}),checkOfferAutoAdd:(t,e)=>{var o,i;const n=t.auto_add_gift||e.is_offer_shipping,r=(null==(o=e.gift_settings)?void 0:o.auto_add_all_gifts)||1===e.gift_items.length&&0===(null==(i=e.gift_items[0])?void 0:i.price);return n&&r},filterOfferGiftSetting:()=>y(null,null,function*(){var t,e,o,i,n,r,l,a;try{let s=JSON.parse(JSON.stringify(null!=(e=null==(t=window.fgData)?void 0:t.offers)?e:[]));for(const t in FGSECOMAPP.productsByID)x.empty(null==(o=FGSECOMAPP.productsByID[t])?void 0:o.id)&&delete FGSECOMAPP.productsByID[t];FGSECOMAPP.variables.conditions.locations&&(yield x.getCustomerLocation());const c=[],u=null!=(i=FGSECOMAPP.fgSettings.offer_process)?i:f.OFFER_TYPE.cloned;s=null==s?void 0:s.map(t=>{var e,o,i,n,r;const l=t.gift_settings||{};t.is_offer_shipping=l.discount_method===f.DISCOUNT_TYPE.shipping,t.type_source=t.type,t.type=t.is_offer_shipping?f.OFFER_TYPE.function:u;const a=k.reorderGiftProducts(t),s=a.reduce((t,e)=>((e.variants||[]).forEach(e=>{t[e.original_variant_shopify_id]=e.thumbnail}),t),{});return b(m({},t),{id:t.id.toString(),offer_root:(null!=(e=t.offer_root)?e:t.id).toString(),gift_products:a,gift_items:null==(o=t.gift_items)?void 0:o.map(e=>{var o;let i={};return t.type!==f.OFFER_TYPE.function||t.is_offer_shipping||(FGSECOMAPP.variables.giftIdsFunction.push(e.original_variant_shopify_id),i={product_shopify_id:e.original_product_shopify_id,variant_shopify_id:e.original_variant_shopify_id}),b(m(m({},e),i),{thumbnail:null!=(o=s[e.original_variant_shopify_id])?o:null==e?void 0:e.thumbnail})}),gift_settings:b(m({},l),{auto_add_all_quantity:T(Object)((l.auto_add_all_gifts_quantity||[]).map(t=>[t.id,t.quantity])),discount:null!=(r=l.discount)?r:{type:null!=(i=l.discount_type)?i:f.DISCOUNT_TYPE.percentage,value:null!=(n=l.discount_value)?n:l.discount_percentage}})})});const _=(t,e,o,i)=>{var n,r;try{const{type:l,value:a,giftItems:s,giftProducts:c}=e;t.offer_conditions[0].product_narrow=[{type:l,value:{[o]:m(m({},a[o]),!x.empty(i)&&{variants:[m({},i)]})}}],t.gift_items=s.filter(t=>{var e;return(null==(e=t.original_product_shopify_id)?void 0:e.toString())===(null==o?void 0:o.toString())&&(x.empty(i)||(null==i?void 0:i.id)===t.original_variant_shopify_id)}),t.gift_products=c.filter(t=>{var e;return(null==(e=t.original_product_shopify_id)?void 0:e.toString())===(null==o?void 0:o.toString())}),t.gift_products[0].variants=[...t.gift_items];let d=t.gift_settings.number_of_gift_can_receive;if(t.gift_settings.auto_add_all_gifts){const e=null!=(n=t.gift_settings.auto_add_all_quantity)?n:{};d=t.gift_items.reduce((t,o)=>{var i;return t+(null!=(i=e[o.original_variant_shopify_id])?i:1)},0)}return JSON.parse(JSON.stringify(b(m({},t),{gift_settings:b(m({},t.gift_settings),{number_of_gift_can_receive:d}),id:"".concat(t.id,"_").concat(a[o].id,"_").concat(null!=(r=null==i?void 0:i.id)?r:""),offer_root:"".concat(t.id)})))}catch(l){console.warn("BOGOS track: Error product-".concat(o),l)}};s.forEach(t=>{var e,o,i,n,r,l,a;try{let s=JSON.parse(JSON.stringify(t));const d=null!=(e=t.gift_should_the_same)?e:{};if(!(null==d?void 0:d.status)||s.is_offer_shipping||"option_value"===(null==d?void 0:d.type))return;let u=null==(o=t.offer_conditions[0])?void 0:o.product_narrow;const f={type:null==(i=u[0])?void 0:i.type,value:null==(n=u[0])?void 0:n.value,giftItems:[...t.gift_items],giftProducts:[...t.gift_products]};for(let t in f.value)if("product"!==(null==d?void 0:d.type)){if("variant"===(null==d?void 0:d.type)){const{variant:e,variants:o}=null!=(l=null==(r=f.value)?void 0:r[t])?l:{};null==(a=null!=o?o:e)||a.forEach(e=>c.push(_(s,f,t,e)))}}else c.push(_(s,f,t))}catch(s){console.error("BOGOS track: Error prepareOfferShouldBeTheSame",s)}}),s=null==(n=null==s?void 0:s.filter(t=>{var e,o;return!(null==(e=null==t?void 0:t.gift_should_the_same)?void 0:e.status)||t.is_offer_shipping||"option_value"===(null==(o=null==t?void 0:t.gift_should_the_same)?void 0:o.type)}))?void 0:n.concat(c.filter(t=>t)),s=null==s?void 0:s.filter(t=>{var e,o,i,n,r,l,a;if(!x.checkValidTimeOffer(t.start_time,t.end_time))return!1;const{customer_order_history:s}=null!=(e=t.sub_conditions)?e:{},{total_spend_on_order_history:c,total_spent_on_last_order:d}=null!=s?s:{};if(!x.empty(c)){const{min_amount:t,max_amount:e}=null!=c?c:{};s.total_spend_on_order_history={min_amount:t?x.convertMultiCurrency(t):void 0,max_amount:e?x.convertMultiCurrency(e):void 0}}if(!x.empty(d)){const{min_amount:t,max_amount:e}=null!=d?d:{};s.total_spent_on_last_order={min_amount:t?x.convertMultiCurrency(t):void 0,max_amount:e?x.convertMultiCurrency(e):void 0}}if(!k.checkOfferWithSubCondition(t,SECOMAPP))return!1;if(t.is_offer_shipping)return t.gift_settings=b(m({},t.gift_settings),{number_of_gift_can_receive:1,cal_gift_for_other_rules:!1}),!0;const u=m({},FGSECOMAPP.productsByID);let _=!1;const g=FGSECOMAPP.fgSettings.sync_quantity===f.SYNC_QUANTITY.stop_offer,v=FGSECOMAPP.fgSettings.track_oostock,p=v===f.TRACK_OOSTOCK.HIDE,h=g?"original_product_shopify_id":"product_shopify_id",y=g?"original_variant_shopify_id":"variant_shopify_id";t.gift_items=null!=(o=null==t?void 0:t.gift_items.map(t=>{var e,o,i;return b(m({},t),{available:null==(i=null==(o=null==(e=u[null==t?void 0:t[h]])?void 0:e.variants)?void 0:o.find(e=>e.id===(null==t?void 0:t[y])))?void 0:i.available})}))?o:[];const S=k.checkOfferAutoAdd(FGSECOMAPP.fgSettings,t);if((p||S&&v)&&(_=!0,t.gift_items=t.gift_items.filter(t=>null==t?void 0:t.available)),_&&(null==(i=t.gift_settings)?void 0:i.auto_add_all_gifts)){const e=null!=(n=t.gift_settings.auto_add_all_quantity)?n:{};t.gift_settings.number_of_gift_can_receive=null==(r=t.gift_items)?void 0:r.reduce((t,o)=>{var i;return t+(null!=(i=e[o.original_variant_shopify_id])?i:1)},0)}const P=null==(l=t.gift_items)?void 0:l.reduce((t,e)=>{var o;return t[null==e?void 0:e[y]]=null!=(o=null==e?void 0:e.available)&&o,t},{});return t.gift_products=null==(a=null==t?void 0:t.gift_products)?void 0:a.filter(t=>{var e,o;return t.variants=null==(e=null==t?void 0:t.variants)?void 0:e.filter(t=>!x.empty(null==P?void 0:P[null==t?void 0:t[y]])).map(t=>b(m({},t),{available:null==P?void 0:P[null==t?void 0:t[y]]})),(null==(o=null==t?void 0:t.variants)?void 0:o.length)>0}),!_||t.gift_items&&t.gift_items.length>0});const g="compare_at_price"===(null==(r=null==FGSECOMAPP?void 0:FGSECOMAPP.fgSettings)?void 0:r.cal_gift_discount)?"original_compare_at_price":"original_price",v=null==(l=FGSECOMAPP.fgSettings)?void 0:l.compare_gift_price_with_product,p="compare_at_price"===v?"original_compare_at_price":"original_price",h={};return s=null==(a=null==s?void 0:s.map(t=>{var e,o,i;const n=t.type===f.OFFER_TYPE.function,r=t.gift_items.map(t=>{var e,o,i,r,l,a,s,c,u,f,_,m,b,y,S;const P=null!=(r=null==(i=null==(o=null==(e=FGSECOMAPP.productsByID)?void 0:e[t.product_shopify_id])?void 0:o.variants)?void 0:i.find(e=>e.id===t.variant_shopify_id))?r:{},E=null!=(c=null==(s=null==(a=null==(l=FGSECOMAPP.productsByID)?void 0:l[t.original_product_shopify_id])?void 0:a.variants)?void 0:s.find(e=>e.id===t.original_variant_shopify_id))?c:{},O=(null==E?void 0:E.price)?E.price/d:null,A=null!=(f=h[u=t.original_variant_shopify_id])?f:h[u]={original_price:O,original_compare_at_price:(null==E?void 0:E.compare_at_price)?E.compare_at_price/d:O},C=null!=(m=h[_=t.variant_shopify_id])?m:h[_]={price:(null==P?void 0:P.price)?(null==P?void 0:P.price)/d:null};return t.price=null!=(b=n?null:null==C?void 0:C.price)?b:x.convertMultiCurrency(t.price),t.cal_gift_price=null!=(y=null==A?void 0:A[g])?y:x.convertMultiCurrency(x.empty(t[g])?null==t?void 0:t.original_price:t[g]),v&&(t.compare_gift_price=null!=(S=null==A?void 0:A[p])?S:x.convertMultiCurrency(x.empty(t[p])?null==t?void 0:t.original_price:t[p])),t.original_product_shopify_id});t.gift_products=null==(e=t.gift_products)?void 0:e.filter(t=>{var e;return null==(e=t.variants)||e.forEach(t=>{var e,o,i,r,l;const a=null!=(e=h[t.original_variant_shopify_id])?e:{},s=null!=(o=h[t.variant_shopify_id])?o:{};t.price=null!=(i=n?null:null==s?void 0:s.price)?i:x.convertMultiCurrency(t.price),t.cal_gift_price=null!=(r=null==a?void 0:a[g])?r:x.convertMultiCurrency(x.empty(t[g])?null==t?void 0:t.original_price:t[g]),v&&(t.compare_gift_price=null!=(l=null==a?void 0:a[p])?l:x.convertMultiCurrency(x.empty(t[p])?null==t?void 0:t.original_price:t[p]))}),r.includes(t.original_product_shopify_id)});const{currency:l}=null!=(o=FGSECOMAPP.variables.Shopify)?o:{};return null==(i=t.offer_conditions)||i.forEach(t=>{var e,o,i,n;if("money"===t.unit){const r=null==(o=null==(e=null==t?void 0:t.other)?void 0:e.currencies)?void 0:o.find(t=>t.currency===(null==l?void 0:l.active));t.min_amount=null!=(i=null==r?void 0:r.min_amount)?i:x.convertMultiCurrency(t.min_amount),t.max_amount=null!=(n=null==r?void 0:r.max_amount)?n:x.empty(t.max_amount)?t.max_amount:x.convertMultiCurrency(t.max_amount)}}),m({},t)}))?void 0:a.sort((t,e)=>t.priority-e.priority),FGSECOMAPP.variables.giftIdsFunction=[...new Set(FGSECOMAPP.variables.giftIdsFunction)],FGSECOMAPP.variables.maxTodayOfferPriority=Math.min(...s.map(t=>t.priority)),k.readGiftMatchSession(),s}catch(s){return console.error("BOGOS track: filterOfferGiftSetting",s),[]}}),isOfferReachable:t=>{var e;if(!x.checkValidTimeOffer(t.start_time,t.end_time))return!1;const o=null!=(e=t.sub_conditions)?e:{},{customer_locations:i}=o,n=((t,e)=>{var o={};for(var i in t)v.call(t,i)&&e.indexOf(i)<0&&(o[i]=t[i]);if(null!=t&&g)for(var i of g(t))e.indexOf(i)<0&&p.call(t,i)&&(o[i]=t[i]);return o})(o,["customer_locations"]),r=x.empty(FGSECOMAPP.customerLocation)?n:b(m({},n),{customer_locations:i});return k.checkOfferWithSubCondition(b(m({},t),{sub_conditions:r}),SECOMAPP)},getInfoCloneProducts:()=>y(null,null,function*(){var t,e,o,i,n;try{const r="option"===(null==(e=null==(t=FGSECOMAPP.fgAppearance)?void 0:t.select_variant)?void 0:e.type);let l=[],a=[],s={sync:[],cache:[]},c=[];const{sync_quantity:d,manual_input_inventory:u,compare_gift_price_with_product:_,track_oostock:g}=null!=(o=null==FGSECOMAPP?void 0:FGSECOMAPP.fgSettings)?o:{};null==(n=null==(i=window.fgData)?void 0:i.offers)||n.filter(k.isOfferReachable).forEach(t=>{const e=[],o=[];let i={sync:[],cache:[]};const n=[],v=t.gift_settings.discount_method===f.DISCOUNT_TYPE.shipping,p=!!g&&!d;t.gift_products.forEach(t=>{var l,a,s,c,g;let h=null!=(l=t.clone_product_handle)?l:null,m=null!=(a=t.original_product_handle)?a:null,b=null!=(s=t.original_product_shopify_id)?s:null,y=null!=(c=t.product_shopify_id)?c:null;n.push(null!=(g=t.original_product_shopify_id)?g:null),(v||r)&&(e.push(h),i.sync.push(y)),d===f.SYNC_QUANTITY.stop_offer?(e.push(m),o.push(h),i.sync.push(b),i.cache.push(y)):u||p?(e.push(h),o.push(m),i.sync.push(y),i.cache.push(b)):(o.push(h,m),i.cache.push(b,y)),_&&(e.push(m),i.sync.push(b))}),l.push(...e),a.push(...o),s.sync.push(...i.sync),s.cache.push(...i.cache),c.push(...n)}),l=l.filter(t=>!x.empty(t)),a=a.filter(t=>!x.empty(t)&&!l.includes(t)),s={sync:s.sync.filter(t=>!x.empty(t)),cache:s.cache.filter(t=>!x.empty(t)&&!s.sync.includes(t))},c=c.filter(Boolean),yield B.cacheProducts(l,{"sca-offer-search":"1"},()=>y(null,null,function*(){console.info("BOGOS track: offer:sync-quantity:".concat(Date.now()))}),{handles:l,ids:s.sync}),B.cacheProducts(a,{"sca-product-cache":"1"},()=>{console.log("BOGOS track: product-cached:".concat(Date.now()))},{handles:a,ids:s.cache}).then(),D.syncStarRating(c).then()}catch(r){console.error("BOGOS track: getInfoCloneProducts",r)}}),validateArrOfferAdded:t=>{var e,o,i,n;const{sca_offers_added:r}=FGSECOMAPP.variables.constants;try{x.empty(t)?(FGSECOMAPP.arrOfferAdded=[],x.saveLocal(r,x.convertObjToString(FGSECOMAPP.arrOfferAdded))):FGSECOMAPP.arrOfferAdded=x.convertStringToObj(localStorage.getItem(r))}catch(c){FGSECOMAPP.arrOfferAdded=t.filter(t=>x.checkCartItemIsGift(t)).map(t=>{var e;return{variant_id:t.variant_id,key:t.key,belongs_to_offer:null==(e=t.properties)?void 0:e._bogos_trigger_id,quantity:t.quantity}}),FGSECOMAPP.variables.failedParseArrOffersAdded=!0,console.warn("BOGOS track: Failed parse offer added",c)}const l={};null==(e=FGSECOMAPP.offers)||e.forEach(t=>{var e;l[t.id]=null==(e=null==t?void 0:t.gift_items)?void 0:e.map(t=>t.variant_shopify_id)});const a=Object.keys(l);FGSECOMAPP.arrOfferAdded=null==(o=FGSECOMAPP.arrOfferAdded)?void 0:o.filter(t=>{var e,o;return(null==a?void 0:a.includes(null==(e=t.belongs_to_offer)?void 0:e.toString()))&&l[null==(o=t.belongs_to_offer)?void 0:o.toString()].includes(t.variant_id)});const s={};null==(i=FGSECOMAPP.arrOfferAdded)||i.forEach(t=>{var e,o,i,n;const r=null!=(e=s["".concat(t.belongs_to_offer,"_").concat(t.variant_id)])?e:{};s["".concat(t.belongs_to_offer,"_").concat(t.variant_id)]=b(m({},t),{belongs_to_offer:null==(o=t.belongs_to_offer)?void 0:o.toString(),quantity:(null!=(i=null==r?void 0:r.quantity)?i:0)+(null!=(n=null==t?void 0:t.quantity)?n:0)})}),FGSECOMAPP.arrOfferAdded=Object.values(s),FGSECOMAPP.variables.firstEmptyOfferAdded=!(null==(n=FGSECOMAPP.arrOfferAdded)?void 0:n.length),x.saveLocal(r,x.convertObjToString(FGSECOMAPP.arrOfferAdded))},refreshCart:(t,e,...o)=>y(null,[t,e,...o],function*(t,e,o={}){k.arrSaveAllFetch=[];const{isCartPage:i,isCheckout:n}=FGSECOMAPP.variables;e&&(i||n)&&location.reload(),e&&D.renderCart().then(()=>k.renderEventLoading("end")),setTimeout(function(){R.fetchRoot(t,o)},250)}),arrSaveAllFetch:[],handledCartWrites:[],markCartWrite:(t,e)=>{const o=performance.now();k.handledCartWrites=k.handledCartWrites.filter(t=>o-t.at<1e4);const i={url:new URL(t,location.href).href,at:o,end:1/0};k.handledCartWrites.push(i),G(e,"finally")(()=>i.end=performance.now()).catch(()=>{})},takeCartWrite:t=>{const e=k.handledCartWrites.findIndex(e=>e.url===t.name&&t.startTime>=e.at-50&&t.startTime<=e.end&&t.startTime-e.at<5e3);return!(e<0||(k.handledCartWrites.splice(e,1),0))},checkEventCart:(t,...e)=>y(null,[t,...e],function*(t,e=[],o=!0){var i,n,r;try{if(k.arrSaveAllFetch.push(t[0]),document.dispatchEvent(new CustomEvent(FGSECOMAPP.CUSTOM_EVENTS.START_PROCESS_CART,{detail:{events:k.arrSaveAllFetch,event:t}})),console.info("BOGOS track: cart-events".concat(o?"":" without update"),[...k.arrSaveAllFetch],t[0]),!o)return yield new Promise(t=>setTimeout(t,100)),void(k.arrSaveAllFetch=[]);x.empty(e)&&!(null==(i=x.hasNoCart)?void 0:i.call(x))&&(yield x.fetchInfoCartUpdate()),yield k.prefetchGiftMatchOptions(FGSECOMAPP.offers);const{giftsOfferData:l,arrGiftsData:a,isUpdated:s}=yield k.checkAllOffers(FGSECOMAPP.cartItems,FGSECOMAPP.offers);FGSECOMAPP.renderPromotionMessage(FGSECOMAPP.offers),yield k.refreshCart(a,s||u.render_cart.test(t[0]),l),(null==a?void 0:a.length)||(k.handleQuantityGiftAvailableSession("remove"),null==(r=null==(n=document.querySelector("#freegifts-main-popup-container.sca-modal-fg.sca-is-visible-fg"))?void 0:n.classList)||r.remove("sca-is-visible-fg")),R.handleCheckedTodayOffer(),document.dispatchEvent(new CustomEvent(FGSECOMAPP.CUSTOM_EVENTS.BOGOS_GIFT_OFFER_CHECK));const{isCartPage:c,isCheckout:d}=FGSECOMAPP.variables,f="bogos:checkout"===t[0];return s&&(c||d||f)&&(k.arrSaveAllFetch=[],location.reload()),["bogos:rollback"].includes(t[0])||document.dispatchEvent(new CustomEvent(FGSECOMAPP.CUSTOM_EVENTS.END_PROCESS_CART,{detail:{events:k.arrSaveAllFetch,event:t}})),FGSECOMAPP.cartItems}catch(l){console.error("BOGOS track: Error check cart event",l)}}),init:(t,e,o)=>y(null,null,function*(){var i,n,r,l,a,s,c,d,u,_,g,v,p,h;document.dispatchEvent(new CustomEvent(FGSECOMAPP.CUSTOM_EVENTS.BOGOS_FG_START));const{using_draft_order:m}=null!=(i=null==FGSECOMAPP?void 0:FGSECOMAPP.fgSettings)?i:{};m&&(FGSECOMAPP.fgSettings.sync_quantity=f.SYNC_QUANTITY.stop_offer,FGSECOMAPP.fgSettings.track_oostock=f.TRACK_OOSTOCK.HIDE);const b="option"===(null==(r=null==(n=FGSECOMAPP.fgAppearance)?void 0:n.select_variant)?void 0:r.type),y=FGSECOMAPP.variables.conditions.function;y&&(FGSECOMAPP.fgSettings.sync_quantity=f.SYNC_QUANTITY.stop_offer);const S=(null==(l=FGSECOMAPP.fgSettings)?void 0:l.manual_input_inventory)||(null==(a=FGSECOMAPP.fgSettings)?void 0:a.sync_quantity)===f.SYNC_QUANTITY.stop_offer;FGSECOMAPP.fgSettings.track_oostock=null!=(c=null==(s=FGSECOMAPP.fgSettings)?void 0:s.track_oostock)?c:!!S&&f.TRACK_OOSTOCK.HIDE,FGSECOMAPP.fgSettings.sync_quantity=!!FGSECOMAPP.fgSettings.sync_quantity&&f.SYNC_QUANTITY.stop_offer;const{sync_quantity:P,manual_input_inventory:E,compare_gift_price_with_product:O,track_oostock:A}=null!=(d=null==FGSECOMAPP?void 0:FGSECOMAPP.fgSettings)?d:{},C=P===f.SYNC_QUANTITY.stop_offer||E||!!O||!!A;o||(C||b?yield k.getInfoCloneProducts(y):k.getInfoCloneProducts(y).then()),FGSECOMAPP.offers=yield k.filterOfferGiftSetting(),"function"==typeof e&&e(),R.filterPageDisplay(null==(_=null==(u=FGSECOMAPP.fgAppearance)?void 0:u.today_offer)?void 0:_.pages_display)&&!(null==(g=FGSECOMAPP.variables)?void 0:g.isTodayOfferBooster)&&R.renderTodayOffer(o);const M=!x.empty(FGSECOMAPP.cartItems)&&(null==(p=null==(v=FGSECOMAPP.cartItems[0])?void 0:v.hasOwnProperty)?void 0:p.call(v,"collections"));!FGSECOMAPP.variables.conditions.collections||M||(null==(h=x.hasNoCart)?void 0:h.call(x))||(yield x.fetchInfoCartUpdate()),k.validateArrOfferAdded(FGSECOMAPP.cartItems),yield k.checkEventCart([t],FGSECOMAPP.cartItems),x.saveLocal(FGSECOMAPP.variables.constants.sca_offers_added,x.convertObjToString(FGSECOMAPP.arrOfferAdded)),FGSECOMAPP.variables.failedParseArrOffersAdded=!1,FGSECOMAPP.variables.firstEmptyOfferAdded=!1,document.dispatchEvent(new CustomEvent(FGSECOMAPP.CUSTOM_EVENTS.BOGOS_FG_END))}),reorderGiftProducts:t=>{let e=t.gift_products;t.type!==f.OFFER_TYPE.function||t.is_offer_shipping||(e=null==e?void 0:e.map(t=>{var e;return b(m({},t),{product_shopify_id:t.original_product_shopify_id,clone_product_handle:t.original_product_handle,variants:null==(e=t.variants)?void 0:e.map(t=>b(m({},t),{product_shopify_id:t.original_product_shopify_id,variant_shopify_id:t.original_variant_shopify_id}))})})),e=R.handleTransformGiftsSliderData(e,t.is_offer_shipping?FGSECOMAPP.variables.Shopify.shipping_product_img:null);const o=t.gift_settings,{original_products_to_clone:i}=o;if(x.empty(i))return e;const n={},r={};return i.forEach((t,e)=>{n[null==t?void 0:t.product_shopify_id]=e;const o={};(Array.isArray(null==t?void 0:t.variants_ids)?t.variants_ids:[]).forEach((t,e)=>{o[String(t)]=e}),r[null==t?void 0:t.product_shopify_id]=o}),e.map(t=>{var e,o;const i=null!=(e=r[t.original_product_shopify_id])?e:{},l=t=>{var e;return null!=(e=i[String(null==t?void 0:t.original_variant_shopify_id)])?e:Number.MAX_SAFE_INTEGER};return b(m({},t),{position:null!=(o=n[t.original_product_shopify_id])?o:0,variants:Array.isArray(t.variants)?[...t.variants].sort((t,e)=>l(t)-l(e)):t.variants})}).sort((t,e)=>t.position-e.position)},handleQuantityGiftAvailableSession:(t,e=0,o="",i=0)=>{var n;try{const r=o?"_".concat(o):"",l="bogos_added_gift".concat(r),a="bogos_total_gift".concat(r);if("set"===t){const t=null!=(n=FGSECOMAPP.variables[l])?n:0,r=FGSECOMAPP.variables[a],s=o?i:FGSECOMAPP.offers.filter(t=>t.isReachConditions&&!t.is_offer_shipping).reduce((t,e)=>t+e.giftsAvailable,0);FGSECOMAPP.variables[l]=t+e,r||(FGSECOMAPP.variables[a]=s),FGSECOMAPP.variables[l]===FGSECOMAPP.variables[a]&&(FGSECOMAPP.variables[l]=void 0,FGSECOMAPP.variables[a]=void 0)}else Object.keys(FGSECOMAPP.variables).forEach(t=>{(t.startsWith("bogos_added_gift")||t.startsWith("bogos_total_gift"))&&(FGSECOMAPP.variables[t]=void 0)})}catch(r){console.log(r)}}},L=t=>{var e,o,i;const n=null!=(i=null==(o=null==(e=FGSECOMAPP.fgAppearance)?void 0:e.select_variant)?void 0:o.color)?i:{},r=t?{"--bogos-sv-active-item-bg":n.active_item_background}:{"--bogos-sv-default-tab-bg":n.default_tab_background,"--bogos-sv-default-tab-text":n.default_tab_text,"--bogos-sv-active-tab-bg":n.active_tab_background,"--bogos-sv-active-tab-text":n.active_tab_text,"--bogos-sv-active-tab-border":n.active_tab_border,"--bogos-sv-active-item-bg":n.active_item_background};return Object.entries(r).filter(([,t])=>!x.empty(t)).map(([t,e])=>"".concat(t,":").concat(e)).join(";")},q=["fg_gift_icon","sca_fg_today_offer_widget"];let I=null;const x=b(m(b(m({},l),{routeLink:null!=(i=null==l?void 0:l.routeLink)?i:t=>t}),function(){const t=t=>{try{const{protocol:e}=new URL(t,window.location.href);return"https:"===e||"http:"===e?A((t=>x.routeLink(t))(t)):"#"}catch(e){return"#"}};return{safeText:A,safeMerchantHTML:(e,o=!1)=>{if("string"!=typeof e||!e.includes("<"))return A(e);const i=document.createElement("template");i.innerHTML=e;const n=e=>Array.from(e.childNodes).forEach(e=>{if(e.nodeType===Node.COMMENT_NODE)return e.remove();if(e.nodeType!==Node.ELEMENT_NODE)return;const i=e.localName;return O.includes(i)?e.remove():S.includes(i)?(Array.from(e.attributes).forEach(({name:n,value:r})=>{o&&(P.includes(n)||"a"===i&&E.includes(n)&&("href"!==n||"#"!==t(r)))||e.removeAttribute(n)}),void n(e)):e.replaceWith(document.createTextNode(e.textContent))});return n(i.content),o?i.innerHTML:i.innerHTML.replace(/"/g,""").replace(/'/g,"'")},safeLink:t,attrText:C}}()),{safeTextView:()=>{var t;const e=null==(t=FGSECOMAPP.variables)?void 0:t.textView;e&&e!==I&&(Object.keys(e).forEach(t=>{e[t]=q.includes(t)?x.safeText(e[t]):x.safeMerchantHTML(e[t])}),I=e)},guardTemplateRender:()=>{var t,e;const o=Object.getPrototypeOf(null!=(e=null==(t=FGSECOMAPP.helper)?void 0:t.templateHTML)?e:{});if("function"!=typeof o.render||o.render.bogosSafeTextView)return;const i=o.render;o.render=function(...t){return x.safeTextView(),i.apply(this,t)},o.render.bogosSafeTextView=!0},saveLocal:(t,e)=>{try{localStorage.setItem(t,e)}catch(o){console.warn("BOGOS track: localStorage write failed",t,o)}},checkCartItemIsGift:(t,e)=>{var o,i,n,r,l,a;const s="-sca_clone_freegift",c="object"==typeof t,d=c&&(FGSECOMAPP.variables.giftIdsFunction.includes(t.variant_id)||FGSECOMAPP.variables.giftIds.includes(t.variant_id))&&(null==(o=t.properties)?void 0:o._bogos_trigger_type)===f.OFFER_TYPE.gift_func&&!x.empty(null==(i=t.properties)?void 0:i._bogos_trigger);return d&&!x.empty(e)?(null==(n=t.properties)?void 0:n._bogos_trigger_id)===e.offer_root:!x.empty(t)&&(c&&((null==(r=t.handle)?void 0:r.includes(s))||(null==(l=t.tags)?void 0:l.includes("bogos-gift"))||(null==(a=FGSECOMAPP.variables.giftIds)?void 0:a.includes(t.variant_id))||d)||"string"==typeof t&&t.includes(s))},checkCartItemIsPurchaseOption:t=>{const{selling_plan_allocation:e}=t||{selling_plan_allocation:{selling_plan:null}};return!x.empty(e)&&!x.empty(null==e?void 0:e.selling_plan)},convertProductEvent:(t,e)=>{var o;return null!=(o=null==t?void 0:t.map(t=>{var o;return{id:t.product_shopify_id,title:x.renderOriginalProductTitle(t.original_product_shopify_id,t.title,t.product_shopify_id),handle:t.original_product_handle,thumbnail:t.thumbnail,belongs_to_offer:null!=(o=t.belongs_to_offer)?o:"".concat(e),variants:t.variants.map(t=>({id:t.variant_shopify_id,title:t.variant_title,price:t.price,original_price:t.cal_gift_price,thumbnail:t.thumbnail,discount_type:t.discount_type,discount_value:t.discount_value}))}}))?o:[]},aggregateArrOfferAddedIds:t=>{const e=[];return t.forEach(t=>{var o,i;const{belongs_to_offer:n}=t;e.push(null!=(i=null==(o=n.split("_"))?void 0:o[0])?i:"")}),[...new Set(e.filter(t=>!x.empty(t)))]},applyGiftDiscount:(t,e,o)=>{const i=null!=t?t:0,n=null!=o?o:0;switch(e){case f.DISCOUNT_TYPE.percentage:return i*(100-n)/100;case f.DISCOUNT_TYPE.fixed_amount:return Math.max(0,i-n*d);default:return null}},renderGiftPrice:t=>{var e,o,i,n,r,l,a,s,c;null!=t||(t={});const u=FGSECOMAPP.variables.conditions.function,_=(null==t?void 0:t.discount_type)===f.DISCOUNT_TYPE.fixed_price,g=null==(i=null==(o=null==(e=FGSECOMAPP.productsByID)?void 0:e[null==t?void 0:t.product_shopify_id])?void 0:o.variants)?void 0:i.find(e=>e.id===t.variant_shopify_id);let v=u||null==g?void 0:g.price;if(u){const e="compare_at_price"===(null==(n=null==FGSECOMAPP?void 0:FGSECOMAPP.fgSettings)?void 0:n.cal_gift_discount)?"compare_at_price":"price",o=null==(a=null==(l=null==(r=FGSECOMAPP.productsByID)?void 0:r[t.original_product_shopify_id])?void 0:l.variants)?void 0:a.find(e=>e.id===t.original_variant_shopify_id),i=null!=(s=null==o?void 0:o[e])?s:null==o?void 0:o.price;_?v=Math.min(i,(null==t?void 0:t.price)*d):i&&(v=null!=(c=x.applyGiftDiscount(i,null==t?void 0:t.discount_type,null==t?void 0:t.discount_value))?c:void 0)}return v?v/=d:v=null==t?void 0:t.price,{price_render:FGSECOMAPP.helper.formatter.format(null!=v?v:0),price:null!=v?v:0}},renderOriginalPrice:t=>{var e,o,i,n,r;null!=t||(t={});const l="compare_at_price"===(null==(e=null==FGSECOMAPP?void 0:FGSECOMAPP.fgSettings)?void 0:e.cal_gift_discount)?"compare_at_price":"price",a=null==(n=null==(i=null==(o=FGSECOMAPP.productsByID)?void 0:o[t.original_product_shopify_id])?void 0:i.variants)?void 0:n.find(e=>e.id===t.original_variant_shopify_id);let s=null!=(r=null==a?void 0:a[l])?r:null==a?void 0:a.price;return s?s/=d:s=null==t?void 0:t.cal_gift_price,{price_render:FGSECOMAPP.helper.formatter.format(null!=s?s:0),price:null!=s?s:0}},renderOriginalProductUrl:(t,e)=>{var o,i;const n=null!=(i=null==(o=FGSECOMAPP.productsByID[t])?void 0:o.handle)?i:null!=e?e:"#";return x.routePath("/products/".concat(n))},renderOriginalProductTitle:(t,e,o)=>{var i,n,r,l,a;return null!=(a=null==(i=FGSECOMAPP.productsByID[t])?void 0:i.title)?a:(null!=(l=null!=(r=null==(n=FGSECOMAPP.productsByID[o])?void 0:n.title)?r:e)?l:"").replace("\xbb","").replace("\ud83c\udf81","").replace(/\(\d*(\.?\d*)% off\)/,"").replace("(Discount)","").replace("(Special Price)","")},handleCountdownTimer:(t,e)=>{try{let o;const i=()=>{const i=new Date,n=Date.parse(t)-i;if(n<0)return void clearInterval(o);const r=Math.floor(n/864e5),l=Math.floor(n/36e5),a=Math.floor(n/6e4),s=Math.floor(n/1e3),c=r,d=l-24*r,u=a-60*l,f=s-60*a,_=".fg-gift-thumbnail-offer[data-fg-offer-id='".concat(e,"'] .fg-gift-thumbnail-offer-time-detail .fg-gift-thumbnail-time-element");document.querySelectorAll("".concat(_,".day")).forEach(t=>{t.innerHTML=G(c.toString(),"padStart")(2,"0")}),document.querySelectorAll("".concat(_,".hour")).forEach(t=>{t.innerHTML=G(d.toString(),"padStart")(2,"0")}),document.querySelectorAll("".concat(_,".minutes")).forEach(t=>{t.innerHTML=G(u.toString(),"padStart")(2,"0")}),document.querySelectorAll("".concat(_,".second")).forEach(t=>{t.innerHTML=G(f.toString(),"padStart")(2,"0")})};o=setInterval(()=>{i()},1e3)}catch(o){}}}),R=b(m({},a),{productsTemp:{},applyGiftIconVars:(t,e)=>{var o,i,n,r,l;const a=null!=(i=null==(o=FGSECOMAPP.fgAppearance)?void 0:o.gift_icon)?i:{},s=e?null==(n=a.collection_page)?void 0:n.size:null==(l=null==(r=a.product_page)?void 0:r.gift_icon)?void 0:l.size;x.empty(s)||CSS.supports("width","".concat(s,"px"))&&(null==t||t.style.setProperty("--bogos-gi-size","".concat(s,"px")))},applyPromotionMessageVars:()=>{var t,e;const o=null!=(e=null==(t=FGSECOMAPP.fgAppearance)?void 0:t.promotion_message)?e:{},i={"--bogos-pm-text":o.text_color,"--bogos-pm-bg":o.background_color};document.querySelectorAll(".sca-promotion-glider").forEach(t=>{Object.entries(i).forEach(([e,o])=>{x.empty(o)||CSS.supports("color",o)&&t.style.setProperty(e,o)})})},applyGiftThumbnailVars:t=>{var e,o,i,n;const r=null!=(n=null==(i=null==(o=null==(e=FGSECOMAPP.fgAppearance)?void 0:e.gift_icon)?void 0:o.product_page)?void 0:i.gift_thumbnail)?n:{},l={"--bogos-gt-offer-name":r.offer_name_color,"--bogos-gt-border":r.border_color,"--bogos-gt-countdown-time":r.countdown_time_color};Object.entries(l).forEach(([e,o])=>{x.empty(o)||CSS.supports("color",o)&&(null==t||t.style.setProperty(e,o))});const a=r.size;!x.empty(a)&&CSS.supports("width","".concat(a,"px"))&&(null==t||t.style.setProperty("--bogos-gt-size","".concat(a,"px")))},applyGiftSliderVars:t=>{var e,o,i;const n=null!=(i=null==(o=null==(e=FGSECOMAPP.fgAppearance)?void 0:e.gift_slider)?void 0:o.color)?i:{},r={"--bogos-gs-title":n.gift_slider_title_color,"--bogos-gs-product-title":n.product_title_color,"--bogos-gs-original-price":n.original_price_color,"--bogos-gs-discounted-price":n.discounted_price_color,"--bogos-gs-atc-text":n.add_to_cart_color,"--bogos-gs-atc-bg":n.add_to_cart_btn_color,"--bogos-gs-badge-bg":n.notify_add_gift_normal_state_color,"--bogos-gs-badge-bg-success":n.notify_add_gift_active_state_color,"--bogos-gs-offer-title":n.offer_title_color,"--bogos-gs-variant-select":n.variant_select_color};(t?[t]:document.querySelectorAll(".freegifts-main-container")).forEach(t=>{Object.entries(r).forEach(([e,o])=>{x.empty(o)||CSS.supports("color",o)&&t.style.setProperty(e,o)})})},applyTodayOfferVars:()=>{var t,e,o,i;const n=null!=(e=null==(t=FGSECOMAPP.fgAppearance)?void 0:t.today_offer)?e:{};if(x.empty(n))return;const r=null!=(o=n.widget_color)?o:{},l=r.offer_success_color,a={"--bogos-to-header-bg":r.header_background_color,"--bogos-to-body-bg":r.body_background_color,"--bogos-to-title":r.widget_title_color,"--bogos-to-subtitle":r.widget_subtitle_color,"--bogos-to-offer-title":r.offer_title_color,"--bogos-to-offer-default":r.offer_default_color,"--bogos-to-offer-success":l,"--bogos-to-offer-success-25":x.empty(l)?null:"".concat(l,"25"),"--bogos-to-product-title":r.product_title_color,"--bogos-to-discount-price":r.discount_price_color,"--bogos-to-original-price":r.original_price_color,"--bogos-to-gift-notification":r.gift_notification_color},s=document.querySelector("#sca-fg-today-offer-iframe");Object.entries(a).forEach(([t,e])=>{x.empty(e)||CSS.supports("color",e)&&(null==s||s.style.setProperty(t,e))});const c=null==(i=n.widget_info)?void 0:i.widget_size;if(x.empty(c))return;if(!CSS.supports("height","".concat(c,"px")))return;const d=document.querySelector("#sca-fg-today-offer-widget");null==d||d.style.setProperty("--bogos-to-widget-h","".concat(c,"px"))},saveGiftSliderData:t=>{FGSECOMAPP.variables.giftSliderData=T(Object)(Object.entries(t).map(([t,e])=>{var o,i,n;return[t,R.convertGiftDisplay(e,null==(n=null==(i=null==(o=FGSECOMAPP.fgAppearance)?void 0:o.gift_slider)?void 0:i.general)?void 0:n.show_gift_for_customer)]}))},normalizeSearchText:t=>{try{return(null!=t?t:"").toString().trim().toLowerCase()}catch(e){return""}},filterGiftProductsBySearch:(t,e)=>{const o=R.normalizeSearchText(e);return o?t.filter(t=>!!R.normalizeSearchText(t.title).includes(o)||(Array.isArray(null==t?void 0:t.variants)?t.variants:[]).some(t=>R.normalizeSearchText(null==t?void 0:t.variant_title).includes(o))):null!=t?t:[]},renderGiftSearchEmptyState:()=>'
\n \n \n \n
',rerenderGiftSliderAllInOneBySearch:(t,e)=>{var o,i,n,r,l;try{const a=FGSECOMAPP.variables.giftSliderData.all;if(!a)return;const s=R.filterGiftProductsBySearch(a,t),c=R.convertGiftDisplay(s,null==(n=null==(i=null==(o=FGSECOMAPP.fgAppearance)?void 0:o.gift_slider)?void 0:i.general)?void 0:n.show_gift_for_customer),d=null!=(l=null==(r=document.querySelector(_))?void 0:r.innerHTML)?l:h,u=x.empty(R.normalizeSearchText(t))||c.length?c.map(t=>R.renderProductHTML(d,t)).join(" \n"):R.renderGiftSearchEmptyState();e.querySelectorAll(".bogos-offer-gift-items-container .glider-track").forEach(t=>{t.innerHTML=u})}catch(a){console.warn("BOGOS track: Failed rerenderGiftSliderAllInOneBySearch",a)}},rerenderGiftSliderOfferBySearch:(t,e,o)=>{var i,n,r,l,a,s;try{const c=FGSECOMAPP.variables.giftSliderData;if(!c)return;const d=null!=(i=c[(null!=t?t:"").toString()])?i:[],u=R.filterGiftProductsBySearch(d,e),f=R.convertGiftDisplay(u,null==(l=null==(r=null==(n=FGSECOMAPP.fgAppearance)?void 0:n.gift_slider)?void 0:r.general)?void 0:l.show_gift_for_customer),g=null!=(s=null==(a=document.querySelector(_))?void 0:a.innerHTML)?s:h,v=o.querySelector(".bogos-offer-gift-items-container .glider-track");if(!v)return;const p=!x.empty(R.normalizeSearchText(e));v.innerHTML=p&&!f.length?R.renderGiftSearchEmptyState():f.map(t=>R.renderProductHTML(g,t)).join(" \n")}catch(c){console.warn("BOGOS track: Failed rerenderGiftSliderOfferBySearch",c)}},renderProductHTML:(t,e)=>{var o,i,n,r,l,a,s,c,d,u,_,g;const v=null==(i=null==(o=e.belongs_to_offer)?void 0:o.some)?void 0:i.call(o,t=>FGSECOMAPP.variables.gifts.offers_shipping.includes(t)),p=null!=(n=null==e?void 0:e.variants[0])?n:{},{original_product_shopify_id:h,product_shopify_id:m,original_product_handle:b,belongs_to_offer:y}=e,S=x.checkIsDefaultTitle(p.variant_title),P=null==(r=e.variants)?void 0:r.length,E=x.renderOriginalProductTitle(h,e.title,m),O=null==(l=FGSECOMAPP.offers.find(t=>{var e;return y===(null==(e=null==t?void 0:t.id)?void 0:e.toString())}))?void 0:l.giftsAvailable,{general:A}=null!=(s=null==(a=FGSECOMAPP.fgAppearance)?void 0:a.gift_slider)?s:{},C=(null==A?void 0:A.show_gift_for_customer)===f.GIFT_DISPLAY.VARIANT,M=D.renderAppReviewEl(h),G=null==(c=D.renderAppReviewEl)?void 0:c.call(D,h,f.APP_REVIEW.trustoo),F=null==(d=D.renderAppReviewEl)?void 0:d.call(D,h,f.APP_REVIEW.yotpo),T=R.renderGiftQuantityOptions(O),w=x.renderGiftPrice(p),k=x.renderOriginalPrice(p);return FGSECOMAPP.helper.templateHTML.render(t,{fg_product_handle:x.renderOriginalProductUrl(h,b),fg_product_img:x.safeText(x.handleResizeGiftImage(1===P?p.thumbnail:e.thumbnail)),fg_offer_type:v?f.DISCOUNT_TYPE.shipping:f.OFFER_TYPE.cloned,fg_product_img_alt:x.safeText(E),fg_product_title:(null==A?void 0:A.show_product_title)?x.safeText(E):"",fg_gifts_check_show_by_variants:C&&(null==A?void 0:A.show_variant_title)&&!S?"":"sca-d-none",fg_gifts_check_show_by_products:C?"sca-d-none":"",fg_check_selected_variant:1===P?"active ".concat(S?"sca-d-none":""):"",fg_variant_title:1!==P?x.safeMerchantHTML(D.convertIntegration(null!=(u=null==A?void 0:A.select_gift_btn)?u:"Select variant","customize.select_variant_button_text","customize.gift_slider.select_gift_btn"),!0):x.safeText(p.variant_title),fg_original_price:k.price_render,fg_gift_price:w.price_render,fg_hide_original_price:w.price>=k.price?"sca-d-none":"",sca_fg_variant_select_section:R.renderVariantSelectOptions(null==e?void 0:e.product_shopify_id,e.variants,e.thumbnail,y),fg_product_belongs_to_offer:e.belongs_to_offer,fg_variant_id:1===P?p.variant_shopify_id:"",fg_product_id:null==e?void 0:e.product_shopify_id,fg_gift_available:(null==p?void 0:p.available)?"true":"false",offer:FGSECOMAPP.offers.find(t=>{var o;return t.id===(null==(o=e.belongs_to_offer)?void 0:o[0])}),bogos_default_select_variant_title:x.safeMerchantHTML(D.convertIntegration(null!=(_=null==A?void 0:A.select_gift_btn)?_:"Select variant","customize.select_variant_button_text","customize.gift_slider.select_gift_btn"),!0),bogos_check_show_select_variant:1===P?"sca-d-none":"",bogos_number_max_gifts:null!=O?O:0,bogos_integration_judgeme:M,bogos_integration_trustoo:G,bogos_integration_yotpo:F,bogos_gift_quantity_options:T,bogos_check_show_quantity_box:(null==(g=FGSECOMAPP.fgSettings)?void 0:g.select_one_gift_price)||!(null==A?void 0:A.enable_add_multiple_gifts)?"sca-d-none":""})},renderGiftsOfferSection:(t,e,o={})=>{var i,n,r,l,a,s,c,d,u,f;const{notify_gift_can_add:_}=null==(i=FGSECOMAPP.fgAppearance)?void 0:i.gift_slider,g=null!=(r=null==(n=document.querySelector("#bogos_section_slider_offer"))?void 0:n.innerHTML)?r:'
{{ bogos_offer_title }}
{{bogos_search_input}}
{{ bogos_number_gift_available }}
{{ sca_fg_disable_slider_section }}
',v=null!=(a=null==(l=document.querySelector("#bogos_section_search_gift"))?void 0:l.innerHTML)?a:'',p=0===(null!=t?t:0),h=p?D.convertIntegration(null!=(s=null==_?void 0:_.number_gifts_can_be_added)?s:"You can add {{number}} gift product(s)","customize.number_gifts_can_be_added_text","customize.gift_slider.number_gifts_can_be_added_text"):D.convertIntegration(null!=(c=null==_?void 0:_.number_gifts_added)?c:"You have added {{number}} gift product(s)","customize.number_gifts_added_text","customize.gift_slider.number_gifts_added_text"),b=null==(d=FGSECOMAPP.variables.Shopify)?void 0:d.enable_search_gift_slider;return FGSECOMAPP.helper.templateHTML.render(g,m({sca_fg_disable_slider_section:R.HIDDEN_GIFT_POPUP(),check_show_number_gift_available:!1===(null==_?void 0:_.enable)?"sca-d-none":"",check_show_number_gift_available_type:0===(null!=t?t:0)?"warning":"success",bogos_number_gift_available:FGSECOMAPP.helper.templateHTML.render(x.safeMerchantHTML(h,!0),{number:p?e:"".concat(t,"/").concat(e)}),bogos_search_input:b?FGSECOMAPP.helper.templateHTML.render(v,{bogos_gift_search_placeholder:x.safeText(null!=(f=null==(u=FGSECOMAPP.variables.Shopify)?void 0:u.sca_text_search_placeholder)?f:"Search for gift by name..."),bogos_search_type:x.empty(null==o?void 0:o.bogos_offer_id)?"bogos-search-all":"bogos-search-offer",bogos_offer_id:null==o?void 0:o.bogos_offer_id}):"",check_show_header:!b&&x.empty(null==o?void 0:o.bogos_offer_id)?"sca-d-none":""},o))},renderTodayOffer:t=>{var e,o,i,n,r,l,a,s,c,d;const{widget_info:u}=null!=(o=null==(e=FGSECOMAPP.fgAppearance)?void 0:e.today_offer)?o:{},f=document.querySelector("#sca-fg-today-offer-widget"),_=document.querySelector("#sca-fg-today-offer-iframe");if(t&&!(null==(i=FGSECOMAPP.offers)?void 0:i.length)&&(f&&(f.innerHTML="",f.className=""),_&&(_.innerHTML="")),!(null==u?void 0:u.show_widget)||!(null==(n=FGSECOMAPP.offers)?void 0:n.length))return;if(!f||!_)return;const g=null!=(l=null==(r=document.querySelector("#sca_fg_today_offer_widget"))?void 0:r.innerHTML)?l:'fg-widget-today-offer {{ sca-fg-title-icon-widget-content }} ',v=null!=(s=null==(a=document.querySelector("#sca_fg_today_offer_section"))?void 0:a.innerHTML)?s:'
{{ sca_fg_today_offer_title }}
{{ sca_fg_today_offer_subtitle }}
',p={};FGSECOMAPP.offers.forEach(t=>{p[t.offer_root]?p[t.offer_root].gift_products.push(...t.gift_products):p[t.offer_root]=JSON.parse(JSON.stringify(t))});let h=Object.values(p);h=h.sort((t,e)=>new Date(t.start_time)-new Date(e.start_time)),FGSECOMAPP.variables.todayOffers=h,f.innerHTML=FGSECOMAPP.helper.templateHTML.render(g),"icon_and_title"===(null==u?void 0:u.widget_icon_style)&&(f.classList.add("sca-fg-today-offer-widget-with-title"),document.querySelector("#sca-fg-today-offer-widget .sca-fg-count-offers").style.right="-5px"),"icon"!==(null==u?void 0:u.widget_icon_style)&&(null==u?void 0:u.widget_icon_style)||(f.classList.remove("sca-fg-today-offer-widget-with-title"),null==(d=null==(c=document.querySelector("#sca-fg-today-offer-widget .sca-fg-title-icon-widget"))?void 0:c.classList)||d.add("sca-hide")),"bottom_left"===(null==u?void 0:u.widget_position)&&(f.classList.add("sca-today-offer-widget-left"),_.classList.add("sca-today-offer-left")),"bottom_right"===(null==u?void 0:u.widget_position)&&(f.classList.add("sca-today-offer-widget-right"),_.classList.add("sca-today-offer-right")),_.innerHTML=FGSECOMAPP.helper.templateHTML.render(v,{sca_fg_today_offer_footer:R.BRAND_MARK_TEMPLATE("today-offer-brand-mark")}),R.handleRenderTodayOfferBody(),document.querySelector("#sca-fg-today-offer-widget .sca-fg-count-offers").innerHTML=h.length.toString();const m=()=>{const t=document.querySelector("#sca-fg-today-offer-iframe");null==t||t.classList.toggle("sca-show"),R.handleRenderTodayOfferBody(),document.querySelectorAll(".sca-fg-icon-success").forEach(t=>{t.classList.toggle("sca-hide")})};document.querySelector(".sca-fg-close-today-offer").addEventListener("click",m),!t&&document.querySelector("#sca-fg-today-offer-widget").addEventListener("click",m),R.handleCheckedTodayOffer(),document.dispatchEvent(new CustomEvent(FGSECOMAPP.CUSTOM_EVENTS.RENDER_TODAY_OFFER,{detail:{todayOffers:h.map(t=>{var e;const o=window.fgData.offers.find(e=>e.id.toString()===t.offer_root);return{id:"".concat(o.id),title:D.convertIntegration(t.offer_name,"offer.offer_title_".concat(t.offer_root),"offers.".concat(t.offer_root,".offer_name")),gifts:x.convertProductEvent(o.gift_products,o.id),success:null!=(e=t.isReachConditions)&&e}})}}))},handleRenderTodayOfferBody:(t=null)=>{var e,o,i,n,r,l,a,s,c,d;const u=!x.empty(t),{widget_info:_}=null!=(o=null==(e=FGSECOMAPP.fgAppearance)?void 0:e.today_offer)?o:{},g=x.empty(null==_?void 0:_.number_gift_show)?2:null==_?void 0:_.number_gift_show,v=(null==_?void 0:_.gift_display)===f.GIFT_DISPLAY.VARIANT,p=null==_?void 0:_.show_gift_preview;let h=[...FGSECOMAPP.variables.todayOffers];u&&(h=[FGSECOMAPP.variables.todayOffers.find(e=>{var o;return(null==(o=e.offer_root)?void 0:o.toString())===t.toString()})]);const m=null!=(n=null==(i=document.querySelector("#sca_fg_today_offer_item_section"))?void 0:i.innerHTML)?n:'
{{ bogos_today_offer_header }}
{{ bogos_today_offer_gift_products }}
{{ bogos_more_gift_product }}
',b=null!=(l=null==(r=document.querySelector("#bogos_today_offer_gift_product"))?void 0:r.innerHTML)?l:'
{{ bogos_today_offer_gift_name }}
{{ bogos_today_offer_gift_name }}
{{ bogos_today_offer_gift_variant_name }}
{{ bogos_today_offer_gift_discount_price }} {{ bogos_today_offer_gift_original_price }}
{{ bogos_variants_selected }}
',y=null!=(s=null==(a=document.querySelector("#bogos_today_offer_item_header_section"))?void 0:a.innerHTML)?s:'
{{ sca_fg_offer_title }} {{ sca_fg_offer_subtitle }}
{{ bogos_offer_link_title }}
',S=null!=(d=null==(c=document.querySelector("#bogos_today_offer_item_header_with_img_section"))?void 0:c.innerHTML)?d:'
{{ sca_fg_offer_title }} {{ sca_fg_offer_subtitle }}
{{ bogos_offer_link_title }}
';document.querySelector("#sca-fg-today-offer-iframe .sca-fg-body .sca-fg-offers").innerHTML=h.map(t=>{var e,o,i,n,r,l,a;const{offer_name:s,offer_root:c,gift_products:d,config:h,gift_settings:P,is_offer_shipping:E}=t,O=E&&P.shipping_discount.create_product,A=null==(e=P.discount)?void 0:e.type,C=A===f.DISCOUNT_TYPE.fixed_amount||A===f.DISCOUNT_TYPE.fixed_price,M="".concat(C?x.renderPrice(x.convertMultiCurrency(null==(o=P.discount)?void 0:o.value)):(null==(i=P.discount)?void 0:i.value)+"%"),G=x.empty(null==h?void 0:h.today_offer_title)?D.convertIntegration(s,"offer.offer_title_".concat(c),"offers.".concat(c,".offer_name")):D.convertIntegration(null==h?void 0:h.today_offer_title,"offer.today_offer_".concat(c),"offers.".concat(c,".today_offer_title")),F=null!=(n=null==h?void 0:h.offer_link)?n:"",T=R.convertGiftDisplay(d,null==_?void 0:_.gift_display),w=null==T?void 0:T.length;let k=T.slice(0,g);return u&&(k=T),FGSECOMAPP.helper.templateHTML.render(m,{sca_fg_offer_id:c,sca_fg_offer_detail:u?"sca-fg-offer-detail":"",bogos_today_offer_header:FGSECOMAPP.helper.templateHTML.render(p?y:S,{sca_fg_offer_title:x.safeMerchantHTML(G,!0),check_show_gift_notification:!0===(null==_?void 0:_.show_gift_notification)?"":"sca-d-none",sca_fg_offer_subtitle:E?"":FGSECOMAPP.helper.templateHTML.render(x.safeMerchantHTML(D.convertIntegration(null!=(r=null==_?void 0:_.gift_notification)?r:A===f.DISCOUNT_TYPE.fixed_price?"Get {{number}} gift at {{discountAmount}}":"Get {{number}} gift for {{discountAmount}} OFF","customize.today_offer_gift_notification","customize.today_offer.gift_notification"),!0),{number:null==P?void 0:P.number_of_gift_can_receive,discountAmount:M}),bogos_offer_link_title:x.safeMerchantHTML(D.convertIntegration(null!=(l=null==_?void 0:_.button_redirect_text)?l:"Get offer","customize.today_offer_button_redirect_text","customize.today_offer.button_redirect_text"),!0),sca_fg_offer_title_tooltip:x.safeMerchantHTML(G),bogos_today_offer_link:x.empty(F)?"":x.safeLink(F),check_show_btn_redirect:x.empty(F)?"sca-d-none":"",sca_fg_offer_img:x.safeText(d[0].thumbnail)}),check_show_gift_product:p?"":"sca-d-none",bogos_more_gift_product:!u&&w>g?FGSECOMAPP.helper.templateHTML.render(x.safeMerchantHTML(D.convertIntegration(null!=(a=null==_?void 0:_.see_more_text)?a:"See more ({{number}} products)","customize.today_offer_see_more_text","customize.today_offer.see_more_text"),!0),{number:w-g}):"",check_show_more_product:(w>g||u)&&p?"":"sca-d-none",sca_bogos_offer_id:c,bogos_today_offer_gift_products:k.map(t=>{var e,o,i,n,r,l,a,s,c,d,u;const f=(null==(e=null==t?void 0:t.variants)?void 0:e.length)>1,{original_product_shopify_id:g,title:p,product_shopify_id:h}=null!=t?t:{},m=E?{}:x.renderGiftPrice(null==t?void 0:t.variants[0]),y=E?{}:x.renderOriginalPrice(null==t?void 0:t.variants[0]);return FGSECOMAPP.helper.templateHTML.render(b,{bogos_today_offer_gift_img:x.safeText(null!=(i=null==t?void 0:t.thumbnail)?i:null==(o=null==t?void 0:t.variants[0])?void 0:o.thumbnail),bogos_today_offer_gift_name:E&&!O?x.safeMerchantHTML(G):x.safeText(x.renderOriginalProductTitle(g,p,h)),bogos_today_offer_gift_discount_price:null!=(n=m.price_render)?n:null,bogos_today_offer_gift_original_price:null!=(r=y.price_render)?r:"",bogos_today_offer_hide_original_price:!E&&(null!=(l=m.price)?l:0)>=(null!=(a=y.price)?a:0)?"sca-d-none":"",bogos_variants_selected:f?FGSECOMAPP.helper.templateHTML.render(x.safeMerchantHTML(D.convertIntegration(null!=(s=null==_?void 0:_.variant_text)?s:"{{number}} variants selected","customize.today_offer_variant_text","customize.today_offer.variant_text"),!0),{number:null==(c=null==t?void 0:t.variants)?void 0:c.length}):"",check_show_selected_variant:f?"":"sca-d-none",check_show_variant_name:v&&!x.checkIsDefaultTitle(null==(d=t.variants[0])?void 0:d.variant_title)?"":"sca-d-none",bogos_today_offer_gift_variant_name:v?x.safeText(null==(u=t.variants[0])?void 0:u.variant_title):""})}).join("\n"),offer:t})}).join("\n"),R.handleCheckedTodayOffer(),R.renderTodayOfferQuerySelectorAll()},handleCheckedTodayOffer:()=>{var t,e;const o=[...new Set(null==(e=null==(t=FGSECOMAPP.offers)?void 0:t.filter(t=>t.isReachConditions))?void 0:e.map(t=>t.offer_root))];document.dispatchEvent(new CustomEvent(FGSECOMAPP.CUSTOM_EVENTS.TODAY_OFFER_CHANGE,{detail:{idOffersSuccess:o}})),document.querySelectorAll("#sca-fg-today-offer-iframe .sca-fg-offers .sca-fg-offer").forEach(t=>{o.includes(t.getAttribute("data-fg-offer-id"))?t.classList.add("sca-offer-archived"):t.classList.remove("sca-offer-archived")})},renderTodayOfferQuerySelectorAll:()=>{document.querySelectorAll(".sca-offer-title").forEach(function(t){t.addEventListener("mouseenter",function(e){const o=t.getAttribute("data-sca-fg-today-offer-title-tooltip");x.createTooltip(o,e.pageX+5,e.pageY+5)}),t.addEventListener("mouseleave",function(){x.removeTooltip()}),t.addEventListener("mousemove",x.moveTooltip)}),document.querySelectorAll("#sca-fg-today-offer-iframe .sca-offer-more-gift-products ").forEach(t=>{t.addEventListener("click",()=>{const e=t.getAttribute("data-bogos-offer-id");R.handleRenderTodayOfferBody(e),document.querySelector("#sca-fg-today-offer-iframe .sca-fg-body").scrollTo(0,0)})}),document.querySelectorAll("#sca-fg-today-offer-iframe .sca-fg-icon-back-offer-detail").forEach(t=>{t.addEventListener("click",()=>{R.handleRenderTodayOfferBody(),document.querySelectorAll(".sca-fg-icon-success").forEach(t=>{t.classList.toggle("sca-hide")})})})},handleTransformGiftsSliderData:(t,e)=>{const o=FGSECOMAPP.productsByID;return t.map(t=>{var i,n;const r=o[t.product_shopify_id];return b(m({},t),{title:x.renderOriginalProductTitle(t.original_product_shopify_id,t.title,t.product_shopify_id),thumbnail:null!=(n=null!=(i=null==r?void 0:r.featured_image)?i:e)?n:t.thumbnail,variants:t.variants.map(o=>{var i,n,l,a,s,c,d;const u=null==(i=null==r?void 0:r.variants)?void 0:i.find(t=>t.id===o.variant_shopify_id);return b(m({},o),{variant_title:null!=(n=null==u?void 0:u.title)?n:o.variant_title,thumbnail:null!=(d=null!=(c=null!=(s=null!=(a=null==(l=null==u?void 0:u.featured_image)?void 0:l.src)?a:null==r?void 0:r.featured_image)?s:e)?c:o.thumbnail)?d:t.thumbnail})})})})},handleConvertGiftsBelongOffer:t=>{const e=G(t.map(t=>t.belongs_to_offer),"flat")().filter((t,e,o)=>o.indexOf(t)===e),o=FGSECOMAPP.offers.filter(t=>e.includes(t.offer_root)).reduce((e,o)=>b(m({},e),{[o.offer_root]:b(m({},o),{gift_items_filter:t.filter(t=>t.belongs_to_offer.includes(o.offer_root))})}),{});return Object.values(o)},filterOfferToGiftThumbnail:t=>{var e,o,i,n,r,l,a;try{const s={},c={},u=FGSECOMAPP.offers;if(x.empty(t)){t=[];const n={},{current_product:r,other_products:l,current_collection:a}=FGSECOMAPP.variables.Shopify;x.empty(r)||(n[r.id]=r),[...null!=l?l:[],...null!=(e=null==a?void 0:a.products)?e:[]].forEach(t=>n[t.id]=t),null==(i=null==(o=Object.values(FGSECOMAPP.productsInPage))?void 0:o.filter(t=>{var e;return!x.empty(t.info)&&(x.empty(null==t?void 0:t.product_has_icon)||(null==t?void 0:t.product_has_icon)&&!(null==(e=null==t?void 0:t.positions)?void 0:e.every(t=>{var e;return null==(e=null==t?void 0:t.classList)?void 0:e.contains("sca-gift-icon-collection-page")})))}))||i.forEach(t=>{n[t.info.id]=m({},t.info)}),t=Object.values(n)}null==t||t.forEach(t=>{var e,o,i,n;const r=FGSECOMAPP.productsInPage[t.handle];FGSECOMAPP.productsInPage[t.handle]=b(m({},r),{info:m({},t),product_has_icon:!!x.empty(u)&&void 0});const l={handle:t.handle,tags:t.tags,variant_id:null!=(i=null==(o=null==(e=t.variants)?void 0:e[0])?void 0:o.id)?i:-1};x.checkCartItemIsGift(l)&&(null==(n=null==r?void 0:r.positions)||n.forEach(t=>null==t?void 0:t.remove()))});const _=null==(n=FGSECOMAPP.fgSettings)?void 0:n.compare_gift_price_with_product,g=(null==(r=FGSECOMAPP.variables.Shopify)?void 0:r.enable_gift_icon_selected_product)||(null==(l=FGSECOMAPP.fgAppearance.gift_icon)?void 0:l.enable_for_all_conditions);null==u||u.forEach(e=>{var o,i,n;const{offer_conditions:r}=e,{is_multiply:l,unit:a,product_narrow:u}=null!=(o=null==r?void 0:r[0])?o:{};let v=1===(null==r?void 0:r.length)&&"number_of_products"===a&&"boolean"==typeof l&&x.empty(null==(i=u[0])?void 0:i.track_pack_type);if(g&&(v=(null==u?void 0:u.length)>0&&"exclude"!==(null==(n=u[0])?void 0:n.filter_option)),!v)return;const p=k.optionMatchConfig(e);let h;null==u||u.forEach(e=>{var o,i,n,r,l,a;switch(e.type){case f.NARROW_TYPE.product:h=Object.values(e.value);break;case f.NARROW_TYPE.product_types:const s=Object.keys(e.value);s.length>0&&(h=null!=(i=null==(o=void 0===h?t:h)?void 0:o.filter(t=>s.includes(t.type)))?i:[]);break;case f.NARROW_TYPE.product_vendors:const c=Object.keys(e.value);c.length>0&&(h=null!=(r=null==(n=void 0===h?t:h)?void 0:n.filter(t=>c.includes(t.vendor)))?r:[]);break;case f.NARROW_TYPE.collection:let d=Object.keys(e.value);d.length>0&&(h=null!=(a=null==(l=void 0===h?t:h)?void 0:l.filter(t=>{var e;const o=null==(e=t.collections)?void 0:e.map(t=>t.id+"");let i=null==o?void 0:o.filter(t=>d.includes(t));return!x.empty(i)}))?a:[])}}),null==h||h.forEach(t=>{var o,i,n,r,l,a,u,f,g,v,h,y,S,P,E,O,A,C;let M=t.handle,G=JSON.parse(JSON.stringify(e.gift_products));const F=null!=(l=null!=(r=null==(o=FGSECOMAPP.productsInPage[M])?void 0:o.info)?r:null==(n=Object.values(null!=(i=FGSECOMAPP.productsInPage)?i:{}).find(e=>{var o;return(null==(o=null==e?void 0:e.info)?void 0:o.id)===t.id}))?void 0:n.info)?l:{price_max:null};if(M=null!=(a=F.handle)?a:M,(null==(u=FGSECOMAPP.fgSettings)?void 0:u.not_show_gift_if_already_on_cart)&&(G=G.filter(t=>t.original_product_shopify_id!==(null==F?void 0:F.id))),_&&(G=G.filter(t=>t.variants.some(t=>(null==t?void 0:t.compare_gift_price)<=(null==F?void 0:F.price_max)/d)),x.empty(G)))return;const T=null!=(f=null==F?void 0:F.id)?f:t.id,w=k.isPrimaryLocale()?F:void 0,L=t=>p?k.filterGiftProductsByOptionValue(G,p,k.triggerValuesOf(w,T,t,p.optionName)):G,q=L((null!=(h=null!=(v=null!=(g=null==F?void 0:F.variants)?g:t.variants)?v:t.variant)?h:[]).map(t=>t.id));if(p&&x.empty(q))return;if(s[M]){const t=s[M];null==q||q.forEach(o=>{var i,n,r,l;const a=t.find(t=>t.original_product_shopify_id===o.original_product_shopify_id);if(x.empty(a))return void t.push(b(m({},o),{belongs_to_offer:[e.offer_root]}));const s=o.variants.map(t=>t.original_variant_shopify_id);!(null==(i=a.belongs_to_offer)?void 0:i.includes(e.offer_root))&&(null==(n=a.belongs_to_offer)||n.push(e.offer_root)),a.variants=null!=(l=null==(r=null==a?void 0:a.variants)?void 0:r.filter(t=>!s.includes(t.original_variant_shopify_id)))?l:[],a.variants=[...a.variants,...o.variants]}),s[M]=t}else s[M]=null==q?void 0:q.map(t=>b(m({},t),{belongs_to_offer:[e.offer_root]}));const I=null!=(P=null==(S=null!=(y=t.variants)?y:t.variant)?void 0:S.map(t=>t.id))?P:[];x.empty(c[M])&&(c[M]={}),null==(C=null==(A=null==(O=null==(E=FGSECOMAPP.productsInPage[M])?void 0:E.info)?void 0:O.variants)?void 0:A.filter(t=>I.includes(t.id)))||C.forEach(t=>{var o;c[M][t.id]=null!=(o=c[M][t.id])?o:[];const i=L([t.id]).filter(e=>{let o=e.variants;return _&&(o=o.filter(e=>(null==e?void 0:e.compare_gift_price)<=t.price/d)),!x.empty(o)}).map(t=>b(m({},t),{belongs_to_offer:[e.offer_root]}));c[M][t.id].push(...i)})})});for(const t in s){const e=FGSECOMAPP.productsInPage[t];FGSECOMAPP.productsInPage[t]=b(m({},e),{gifts_will_receive:[...s[t]],product_has_icon:!0,variants_has_gift:m({},c[t])})}return(null==(a=Object.entries(s))?void 0:a.length)?s:{}}catch(s){return console.warn("BOGOS track: Failed check products have customize",s),null}},renderElementGiftIconCollectionPage:()=>y(null,null,function*(){var t,e,o,i,n,r,l;const a=R.getProductHandleInPage();R.renderGiftIconForProducts(R.filterOfferToGiftThumbnail());const{offer_process:s,delete_gift_after_turn_off_offer:c}=null!=(t=FGSECOMAPP.fgSettings)?t:{},d=s===f.OFFER_TYPE.function,{collection_page:u}=null!=(o=null==(e=FGSECOMAPP.fgAppearance)?void 0:e.gift_icon)?o:{};c&&!(null==(i=fgData.offers)?void 0:i.length)||!(null==u?void 0:u.status)&&d&&x.empty(null==(n=window.SmartifyAppDECO)?void 0:n.products_has_gift)||(null==(l=null==(r=null==FGSECOMAPP?void 0:FGSECOMAPP.variables)?void 0:r.Shopify)?void 0:l.disable_search_product_list_handles)||x.empty(a)||(yield R.fetchProductsInPage(a),R.renderGiftIconForProducts(R.filterOfferToGiftThumbnail()))}),fetchProductsInPage:t=>y(null,null,function*(){var e;const o=null!=(e=FGSECOMAPP.variables)?e:FGSECOMAPP.variables={};let i=t;if(o.fetching_products_in_page&&(yield o.fetching_products_in_page,i=R.getProductHandleInPage(),x.empty(i)))return;const n=G(B.searchProducts(i,{"sca-product-search":"1"},!1,{handles:i}).catch(t=>console.warn("BOGOS track: search products in page",t)),"finally")(()=>{o.fetching_products_in_page===n&&(o.fetching_products_in_page=null)});o.fetching_products_in_page=n,yield n}),convertGiftDisplay:(t,e)=>{let o=t;if(e===f.GIFT_DISPLAY.VARIANT){o=[];for(const e of t){const{variants:t}=null!=e?e:{};null==t||t.forEach(t=>{var i;return o.push(b(m({},e),{thumbnail:null!=(i=t.thumbnail)?i:e.thumbnail,variants:[t]}))})}}return o},initThumbnailSlider:(t,e)=>{var o;const i=t?[...t.children]:[];if(!i.length)return;const{prev:n,next:r,dots:l}=null!=e?e:{},a=Math.max(null!=(o=null==e?void 0:e.perView)?o:4,1),s=Math.ceil(i.length/a);t.classList.add("bogos-thumb-slider"),t.classList.toggle("bogos-thumb-fit",i.length<=a),t.style.setProperty("--bogos-thumb-per-view","".concat(a));const c=()=>Math.max(t.scrollWidth-t.clientWidth,0),d=()=>{var t;const e=i[0].getBoundingClientRect(),o=null==(t=i[1])?void 0:t.getBoundingClientRect();return a*(o?o.left-e.left:e.width)};let u=null;const f=()=>{if(t.scrollLeft>=c()-1)return s-1;const e=d();return e>0?Math.round(t.scrollLeft/e):0},_=e=>(e=>{null!==u&&(cancelAnimationFrame(u),u=null);const o=t.scrollLeft,i=Math.min(Math.max(e,0),c())-o;if(Math.abs(i)<1)return;const n=performance.now(),r=e=>{const l=Math.min((e-n)/300,1),a=1-l;t.scrollLeft=o+i*(1-a*a*a),u=l<1?requestAnimationFrame(r):null};u=requestAnimationFrame(r)})(Math.min(Math.max(e,0),s-1)*d()),g=s>1?Array.from({length:s},(t,e)=>{const o=document.createElement("button");return o.type="button",o.className="glider-dot",o.dataset.index="".concat(e),o.setAttribute("role","tab"),o.setAttribute("aria-label","Page ".concat(e+1)),o.addEventListener("click",()=>_(e)),o}):[];null==l||l.replaceChildren(...g),null==l||l.classList.toggle("sca-d-none",!g.length);const v=()=>{null==n||n.classList.toggle("disabled",t.scrollLeft<=1),null==r||r.classList.toggle("disabled",t.scrollLeft>=c()-1);const e=f();g.forEach((t,o)=>{const i=o===e;t.classList.toggle("active",i),t.setAttribute("aria-selected",i?"true":"false")})};null==n||n.addEventListener("click",()=>_(f()-1)),null==r||r.addEventListener("click",()=>_(f()+1)),t.addEventListener("scroll",v,{passive:!0}),v()},renderElementOldVersionGiftThumbnail:(t,e)=>{var o,i,n,r,l,a;const s=null!=(i=null==(o=document.querySelector("#sca_fg_gift_thumbnail_items_section"))?void 0:o.innerHTML)?i:'',c=R.convertGiftDisplay(t,null==(n=e.gift_thumbnail)?void 0:n.gift_display),d=null==c?void 0:c.map(t=>R.renderProductHTML(s,t)).join(""),u=null!=(l=null==(r=document.querySelector("#sca_fg_gift_thumbnail_section"))?void 0:r.innerHTML)?l:'
{{ fg_gift_thumbnail_title }}
{{ sca_fg_gift_thumbnail_items_section }}
\xab \xbb
';let f=FGSECOMAPP.helper.templateHTML.render(u,{fg_check_show_narrow:(null==c?void 0:c.length)>=4?"":"sca-d-none",sca_fg_gift_thumbnail_items_section:d});const{gift_thumbnail_query:_}=null!=(a=FGSECOMAPP.QUERY_SELECTOR)?a:{},g=[...null==_?void 0:_.tool,...null==_?void 0:_.page_builder].filter(Boolean).join(","),v=[...null==_?void 0:_.integration,...null==_?void 0:_.default].filter(Boolean).join(",");let p=!0;const h=t=>{var o,i,n,r,l;if(!t)return;const a=[...t.classList].some(t=>{var e,o;return null==(o=null==(e=null==_?void 0:_.page_builder)?void 0:e.toString())?void 0:o.includes(t)});a||(t.parentElement.style.width="100%",t.parentElement.style.height="auto",null==(i=null==(o=t.parentElement)?void 0:o.classList)||i.toggle("sca-fg-form-thumbnail-product-page",c.length>0));let s=t.parentNode.querySelector("#sca-gift-thumbnail");if(s)s.innerHTML=f;else{s=document.createElement("div"),s.setAttribute("id","sca-gift-thumbnail");const e=(new DOMParser).parseFromString(f,"text/html");s.innerHTML=e.body.innerHTML,t.parentNode.insertBefore(s,t)}R.applyGiftThumbnailVars(s),a?t.appendChild(s):t.parentNode.insertBefore(s,t);const d=s.querySelector("#fg-gift-thumbnail-title");if(d)switch(null==(n=e.gift_thumbnail)?void 0:n.size){case"32":d.style.maxWidth="50%";break;case"50":default:d.style.maxWidth="60%";break;case"100":d.style.maxWidth="70%";break;case"160":d.style.maxWidth="80%";break;case"240":d.style.maxWidth="100%"}const u=null!=(l=null==(r=FGSECOMAPP.variables.Shopify)?void 0:r.number_gifts_thumbnail)?l:4,g=s.querySelector(".sca-list-gift-thumbnail");(null==c?void 0:c.length)>=u?new FGSECOMAPP.helper.Glider(g,{slidesToShow:Math.max(u-1,1),slidesToScroll:1,draggable:!0,dots:".dots-thumbnail",arrows:{prev:"#fg-gift-thumbnail-title .glider-prev",next:"#fg-gift-thumbnail-title .glider-next"}}):(d&&(d.style.maxWidth="100%"),g&&(g.style.display="flex")),p=!1};return document.querySelectorAll(g).forEach(h),p&&h(document.querySelector(v)),c},renderElementGiftThumbnail:(t,e)=>{var o,i,n,r,l,a,s,c,d;const u=null!=(i=null==(o=document.querySelector("#sca_new_fg_gift_thumbnail_sub_items_section"))?void 0:o.innerHTML)?i:'',{countdown_text:_,number_text:g,show_multiple:v,show_countdown_timer:p,show_number_gift:h}=null!=(n=null==e?void 0:e.gift_thumbnail)?n:{},m=null!=(l=null==(r=document.querySelector("#sca_new_fg_gift_thumbnail_items_section"))?void 0:r.innerHTML)?l:'
{{ fg_offer_time_title }}
{{ fg_offer_time_detail }}
{{ fg_offer_title }}
{{ fg_offer_body }}
',b=null==(a=null==t?void 0:t.sort((t,e)=>t.priority-e.priority))?void 0:a.map(t=>{var o,i;const n=R.convertGiftDisplay(null!=(o=null==t?void 0:t.gift_items_filter)?o:[],null==(i=e.gift_thumbnail)?void 0:i.gift_display),r=null==n?void 0:n.map(e=>FGSECOMAPP.helper.templateHTML.render(u,{fg_product_handle:x.renderOriginalProductUrl(e.original_product_shopify_id,e.original_product_handle),fg_offer_type:t.is_offer_shipping?f.DISCOUNT_TYPE.shipping:t.type,fg_product_img:x.safeText(x.handleResizeGiftImage(e.thumbnail)),fg_product_img_alt:x.safeText(x.renderOriginalProductTitle(e.original_product_shopify_id,e.title))})).join(" ");return FGSECOMAPP.helper.templateHTML.render(m,{fg_offer_id:t.id,fg_offer_title:x.safeMerchantHTML(D.convertIntegration(t.offer_name,"offer.offer_title_".concat(t.offer_root),"offers.".concat(t.offer_root,".offer_name")),!0),fg_offer_time_title:x.safeMerchantHTML(D.convertIntegration(null!=_?_:"Expiring in","customize.gift_thumbnail_countdown_text","customize.gift_icon.gift_thumbnail_countdown_text"),!0),fg_offer_time_detail:t.end_time?FGSECOMAPP.helper.templateHTML.render('
{{ fg_time_day }}
:
{{ fg_time_hour }}
:
{{ fg_time_minutes }}
:
{{ fg_time_second }}
',{fg_time_day:"00",fg_time_hour:"00",fg_time_minutes:"00",fg_time_second:"00"}):"",fg_offer_body:r,fg_offer_footer_total:t.is_offer_shipping?"":"".concat(n.length," ").concat(x.safeMerchantHTML(D.convertIntegration(null!=g?g:"gift items included","customize.gift_thumbnail_number_text","customize.gift_icon.gift_thumbnail_number_text"),!0))})}).join(" "),y=null!=(c=null==(s=document.querySelector("#sca_new_fg_gift_thumbnail_section"))?void 0:s.innerHTML)?c:'
{{ fg_gift_thumbnail_section }}
';let S=FGSECOMAPP.helper.templateHTML.render(y,{fg_gift_thumbnail_section:b});const{gift_thumbnail_query:P}=null!=(d=FGSECOMAPP.QUERY_SELECTOR)?d:{},E=[...null==P?void 0:P.tool,...null==P?void 0:P.page_builder].filter(Boolean).join(","),O=[...null==P?void 0:P.integration,...null==P?void 0:P.default].filter(Boolean).join(",");let A=!0;const C=e=>{var o,i,n;if(!e)return;const r=[...e.classList].some(t=>{var e,o;return null==(o=null==(e=null==P?void 0:P.page_builder)?void 0:e.toString())?void 0:o.includes(t)});r||(e.parentElement.style.width="100%",e.parentElement.style.height="auto",null==(i=null==(o=e.parentElement)?void 0:o.classList)||i.toggle("sca-fg-form-thumbnail-product-page",t.length>0));let l=e.parentNode.querySelector("#sca-gift-thumbnail");if(l)l.innerHTML=S;else{l=document.createElement("div"),l.setAttribute("id","sca-gift-thumbnail");const t=(new DOMParser).parseFromString(S,"text/html");l.innerHTML=t.body.innerHTML,e.parentNode.insertBefore(l,e)}R.applyGiftThumbnailVars(l),r?e.appendChild(l):e.parentNode.insertBefore(l,e);const a="together"===v,s=l.querySelector(".fg-gift-thumbnail-container");a?null==s||s.classList.remove("separated"):null==s||s.classList.add("separated");const c=null==p||p,d=null==h||h;null==(n=l.querySelectorAll(".fg-gift-thumbnail-offer"))||n.forEach(e=>{var o,i;const n=e.getAttribute("data-fg-offer-id"),r=t.find(t=>t.id===n),l=e.querySelectorAll(".fg-gift-thumbnail-offer-slider .product-item"),a=null!=(i=null==(o=FGSECOMAPP.variables.Shopify)?void 0:o.number_gifts_thumbnail)?i:4;(null==l?void 0:l.length)>=a||e.querySelector(".fg-gift-thumbnail-offer-footer .fg-gift-thumbnail-offer-footer-action").classList.add("sca-d-none"),R.initThumbnailSlider(e.querySelector(".glider"),{perView:a,prev:e.querySelector(".fg-gift-thumbnail-btn.glider-prev"),next:e.querySelector(".fg-gift-thumbnail-btn.glider-next")});const s=e.querySelector(".fg-gift-thumbnail-offer-time");(null==r?void 0:r.end_time)&&c?(s.classList.remove("sca-d-none"),x.handleCountdownTimer(r.end_time,n)):s.classList.add("sca-d-none");const u=e.querySelector(".fg-gift-thumbnail-offer-footer"),f=e.querySelector(".fg-gift-thumbnail-offer-footer-quantity");d?(f.classList.remove("sca-d-none"),u.style.justifyContent="space-between"):(f.classList.add("sca-d-none"),u.style.justifyContent="flex-end")}),A=!1};return document.querySelectorAll(E).forEach(C),A&&C(document.querySelector(O)),t},renderElementGiftIconProductPage:()=>{var t,e,o,i,n,r,l;let{product_page:a}=null!=(e=null==(t=FGSECOMAPP.fgAppearance)?void 0:t.gift_icon)?e:{};const s=null==(o=null==a?void 0:a.gift_icon)?void 0:o.status,c=null!=(n=null==(i=document.querySelector(M))?void 0:i.innerHTML)?n:F;let d=FGSECOMAPP.helper.templateHTML.render(c,{fg_class_product_or_collection_page:"sca-gift-icon-img ".concat(s?"":"sca-d-none")});const{gift_icon_product_query:u}=FGSECOMAPP.QUERY_SELECTOR,f=[...null==u?void 0:u.tool,...null==u?void 0:u.page_builder].filter(Boolean).join(","),_=[...null==u?void 0:u.default,...null==u?void 0:u.integration].filter(Boolean).join(",");let g=!0;const v=t=>{var e;if(!t)return;[...t.classList].some(t=>{var e,o;return null==(o=null==(e=null==u?void 0:u.page_builder)?void 0:e.toString())?void 0:o.includes(t)})||(t.style.position="relative",t.style.width="fit-content",null==(e=t.classList)||e.toggle("sca-fg-form-icon-product-page",!0));let o=t.querySelector("#sca-gift-icon");o?o.innerHTML=d:(o=document.createElement("div"),o.setAttribute("id","sca-gift-icon"),o.innerHTML=d,t.appendChild(o)),R.applyGiftIconVars(o),!s&&(o.style.display="none"),g=!1};return document.querySelectorAll(f).forEach(v),g&&v(document.querySelector(_)),null==(l=null==(r=FGSECOMAPP.fgAppearance)?void 0:r.gift_icon)?void 0:l.gift_icon_path},renderGiftIconForProducts:(t,e)=>{var o,i,n,r,l,a;const s=[],c=null==(n=null==(i=null==(o=FGSECOMAPP.fgAppearance)?void 0:o.gift_icon)?void 0:i.collection_page)?void 0:n.status;null==(r=Object.keys(t))||r.forEach(t=>{var o,i,n,r,l;const a=FGSECOMAPP.productsInPage[t],d="href*='/".concat(t,"'"),u=null!=(o=null==a?void 0:a.positions)?o:e?document.querySelectorAll(".fg-secomapp-collection-img[".concat(d,"], .fg-secomapp-collection-img:has([").concat(d,"])")):[];if(x.empty(u)||!Array.isArray(u))return;const f=null!=(n=null==(i=document.querySelector(M))?void 0:i.innerHTML)?n:F;let _=FGSECOMAPP.helper.templateHTML.render(f,{fg_class_product_or_collection_page:"sca-gift-icon-collection-img ".concat(c?"":"sca-d-none")});const g=[...new Set(G((null!=(r=null==a?void 0:a.gifts_will_receive)?r:[]).map(t=>t.belongs_to_offer),"flat")())],v=[];u.forEach(t=>{var e,o;t.style.position="relative",null==(e=t.classList)||e.toggle("sca-fg-icon-collection-page",!0);let i=t.querySelector(".sca-gift-icon-collection-page");if(i){const e=null==(o=i.getAttribute("data-offer-ids"))?void 0:o.split(","),n=g.some(t=>{var o;return!(null==(o=null==e?void 0:e.includes)?void 0:o.call(e,t))});return i.setAttribute("data-offer-ids",g.join(",")),n&&v.push(t),!1}v.push(t),i=document.createElement("div"),i.setAttribute("class","sca-gift-icon-collection-page"),i.setAttribute("data-offer-ids",g.join(","));const n=(new DOMParser).parseFromString(_,"text/html");i.innerHTML=n.body.innerHTML,R.applyGiftIconVars(i,!0),!c&&(i.style.display="none"),t.appendChild(i)}),v.length&&s.push({positions:v,product:b(m({},null==a?void 0:a.info),{handle:t}),gifts:x.convertProductEvent(null!=(l=null==a?void 0:a.gifts_will_receive)?l:[]),belongs_to_offer:[...new Set(g)]})}),s.length&&document.dispatchEvent(new CustomEvent(FGSECOMAPP.CUSTOM_EVENTS.PRODUCT_HAS_GIFTS,{detail:{type:"product-list",icon:null==(a=null==(l=FGSECOMAPP.fgAppearance)?void 0:l.gift_icon)?void 0:a.gift_icon_path,products:s,enable:c}}))},fetchVariantsSelected:()=>{var t;(null==(t=FGSECOMAPP.variables.Shopify)?void 0:t.enable_check_variants_has_gift)&&document.addEventListener("change",function(){x.debounce(()=>{const t=new URL(document.URL),e=parseInt(t.searchParams.get("variant"));R.renderProductPage(e)},500)()})},renderBlockEmptyProductPage:()=>{const t=document.querySelector("#bogos-gift-icon-view-block-preview-mode");t&&R.renderEmpty(t,"There is the placeholder of gift icon.");const e=document.querySelector("#bogos-gift-thumbnail-view-block-preview-mode");e&&R.renderEmpty(e,"There is the placeholder of gift thumbnail.")},renderProductPage:t=>{var e,o,i,n,r,l,a,s,c,d,u,f,_,g,v,p,h,y,S,P;const{enable_check_variants_has_gift:E,current_product:O}=FGSECOMAPP.variables.Shopify;if(x.empty(O))return;null==(e=document.querySelector("#sca-gift-icon"))||e.remove(),null==(o=document.querySelector("#sca-gift-thumbnail"))||o.remove();const A=R.filterOfferToGiftThumbnail(),C=location.pathname.split("/"),M=null==C?void 0:C.indexOf("products"),F=null!=(n=decodeURI(M>=0&&null!=(i=C[M+1])?i:null))?n:null==O?void 0:O.handle;let T=null==A?void 0:A[F];if(x.empty(T))return void R.renderBlockEmptyProductPage();const w=null!=(l=null==(r=FGSECOMAPP.productsInPage[F])?void 0:r.variants_has_gift)?l:{},k=Object.keys(w);let L=!0;if(E&&(x.empty(t)||k.includes("".concat(t))||(L=!1),!x.empty(t)||x.empty(null==O?void 0:O.current_variant)||k.includes(null==(s=null==(a=null==O?void 0:O.current_variant)?void 0:a.id)?void 0:s.toString())||(L=!1),T=null!=(d=w[null!=t?t:null==(c=null==O?void 0:O.current_variant)?void 0:c.id])?d:[]),L){const t=R.handleConvertGiftsBelongOffer(T);let{product_page:e}=null!=(f=null==(u=FGSECOMAPP.fgAppearance)?void 0:u.gift_icon)?f:{};const{use_old_version:o,status:i}=null!=(_=null==e?void 0:e.gift_thumbnail)?_:{};i&&(null==o||o)?R.renderElementOldVersionGiftThumbnail(T,e):i&&R.renderElementGiftThumbnail(t,e),R.renderElementGiftIconProductPage(T)}const q=null==T?void 0:G(T.map(t=>t.belongs_to_offer),"flat")();document.dispatchEvent(new CustomEvent(FGSECOMAPP.CUSTOM_EVENTS.PRODUCT_HAS_GIFTS,{detail:{type:"product",enable:null==(h=null==(p=null==(v=null==(g=FGSECOMAPP.fgAppearance)?void 0:g.gift_icon)?void 0:v.product_page)?void 0:p.gift_icon)?void 0:h.status,icon:null==(S=null==(y=FGSECOMAPP.fgAppearance)?void 0:y.gift_icon)?void 0:S.gift_icon_path,gifts:x.convertProductEvent(T),product:b(m({handle:F},O),{variant:null!=t?t:null==(P=null==O?void 0:O.current_variant)?void 0:P.id}),belongs_to_offer:[...new Set(q)]}}))},renderCustomizeForProduct:(t,e,o)=>y(null,null,function*(){null!=o||(o=yield B.cacheProductsObj(t,e)),yield k.prefetchGiftMatchOptions(FGSECOMAPP.offers,(null!=o?o:[]).map(t=>null==t?void 0:t.id));const i=R.filterOfferToGiftThumbnail(o);return i?((null==e?void 0:e.collection)&&R.renderGiftIconForProducts(i,null==e?void 0:e.isHeadless),e.product&&(FGSECOMAPP.variables.Shopify.current_product=o[0],R.renderProductPage()),Object.keys(i).map(t=>{var e;return{[t]:null==(e=FGSECOMAPP.productsInPage)?void 0:e[t]}})):{}}),fetchRoot:(t,...e)=>y(null,[t,...e],function*(t,e={}){var o,i,n,r;const l=document.querySelector("#bogos-gift-slider-view-block-preview-mode");if((null==t?void 0:t.length)>0){FGSECOMAPP.isDelayShowAdded&&(yield new Promise(t=>setTimeout(t,1500)),FGSECOMAPP.isDelayShowAdded=!1);const r=null==(o=FGSECOMAPP.fgAppearance)?void 0:o.gift_slider,a=!1===(null==(i=null==r?void 0:r.general)?void 0:i.use_old_version);R.filterPageDisplay(null==r?void 0:r.pages_display)&&(R.renderGiftSelectSection(Object.keys(e).length),a&&"offer"===(null==(n=null==r?void 0:r.general)?void 0:n.show_gift_type)?(R.saveGiftSliderData(e),R.renderGiftSliderSeparateByOffer(e)):(R.saveGiftSliderData({all:t}),R.renderGiftSliderViewByAllInOne(t)),document.querySelectorAll("#freegifts-main-popup-container .glider-dots").forEach(t=>{t.children.length<=1&&(t.style.display="none")})),l&&(l.style.display="none !important")}else{const{gift_slider_query:t}=null!=(r=FGSECOMAPP.QUERY_SELECTOR)?r:{},e=[...null==t?void 0:t.page_builder,...null==t?void 0:t.default].filter(Boolean).join(",");document.querySelectorAll(e).forEach(t=>t.innerHTML=""),l&&R.renderEmpty(l,"There is the placeholder of gift slider.")}(null==t?void 0:t.length)>0&&R.renderQuerySelectorAll(),FGSECOMAPP.fetchCheckoutEvents(),setTimeout(()=>{FGSECOMAPP.renderPromotionMessage(FGSECOMAPP.offers)},750),k.arrSaveAllFetch=[]}),renderQuerySelectorAll:()=>{var t,e,o;w.dialog.watch();const i=document.querySelectorAll("[data-open]"),n=document.querySelectorAll("#freegifts-main-popup-container [data-close]"),r="sca-is-visible-fg";for(const d of i)d.addEventListener("click",function(){const t=this.dataset.open;document.getElementById(t).classList.add(r)});for(const d of n)d.addEventListener("click",function(){k.handleQuantityGiftAvailableSession("remove"),this.parentElement.parentElement.classList.remove(r)});document.addEventListener("click",t=>{var e;t.target===document.querySelector("#freegifts-main-popup-container.sca-modal-fg.sca-is-visible-fg")&&(k.handleQuantityGiftAvailableSession("remove"),null==(e=document.querySelector("#freegifts-main-popup-container.sca-modal-fg.sca-is-visible-fg"))||e.classList.remove(r))}),document.addEventListener("click",t=>{var e,o;(null!=(e=t.target)?e:document.createElement("div")).closest(".bogos-slider-close-btn")&&(k.handleQuantityGiftAvailableSession("remove"),null==(o=document.querySelector("#freegifts-main-popup-container.sca-modal-fg.sca-is-visible-fg"))||o.classList.remove(r))}),document.addEventListener("keydown",t=>{if("Escape"!==t.key||t.defaultPrevented)return;const e=document.querySelector("#freegifts-main-popup-container.sca-modal-fg.sca-is-visible-fg");e&&(t.preventDefault(),k.handleQuantityGiftAvailableSession("remove"),e.classList.remove(r))});const{use_old_version:l,show_gift_type:a}=null!=(o=null==(e=null==(t=FGSECOMAPP.fgAppearance)?void 0:t.gift_slider)?void 0:e.general)?o:{},s=!1===l,c=x.debounce(t=>{var e,o,i,n;const r=null!=(e=null==t?void 0:t.value)?e:"",l=null==(o=null==t?void 0:t.closest)?void 0:o.call(t,".bogos-gift-slider-search-inner"),a=null==(i=null==t?void 0:t.closest)?void 0:i.call(t,".bogos-slider-offer");if(!a)return;null==l||l.setAttribute("data-has-value",r?"1":"0");const s=null==(n=null==t?void 0:t.getAttribute)?void 0:n.call(t,"data-offer");s?R.rerenderGiftSliderOfferBySearch(s,r,a):R.rerenderGiftSliderAllInOneBySearch(r,a),R.renderQuerySelectorForGiftItem(a),document.dispatchEvent(new CustomEvent(FGSECOMAPP.CUSTOM_EVENTS.RERENDER_GIFT_SLIDER))},150);document.querySelectorAll(".bogos-gift-slider-search-input").forEach(t=>{var e,o;const i=null!=(e=null==t?void 0:t.value)?e:"",n=null==(o=null==t?void 0:t.closest)?void 0:o.call(t,".bogos-gift-slider-search-inner");null==n||n.setAttribute("data-has-value",i?"1":"0"),t.addEventListener("input",t=>c(t.currentTarget)),t.addEventListener("search",t=>c(t.currentTarget))}),document.querySelectorAll(".bogos-gift-slider-search-toggle").forEach(t=>{t.addEventListener("click",e=>{var o,i;e.preventDefault(),e.stopPropagation();const n=null==(o=t.closest)?void 0:o.call(t,".bogos-gift-slider-search-inner");if(!n)return;n.setAttribute("data-expanded","1");const r=n.querySelector(".bogos-gift-slider-search-input");null==r||r.setAttribute("tabindex","0"),null==(i=null==r?void 0:r.focus)||i.call(r)})}),document.querySelectorAll(".bogos-gift-slider-search-clear").forEach(t=>{t.addEventListener("click",e=>{var o,i,n;e.preventDefault(),e.stopPropagation();const r=null==(o=t.closest)?void 0:o.call(t,".bogos-gift-slider-search-inner"),l=null==(i=null==r?void 0:r.querySelector)?void 0:i.call(r,".bogos-gift-slider-search-input");l&&(l.value="",r.setAttribute("data-has-value","0"),r.setAttribute("data-expanded","0"),l.setAttribute("tabindex","-1"),null==(n=r.querySelector(".bogos-gift-slider-search-toggle"))||n.focus(),c(l))})}),document.querySelectorAll(".freegifts-main-container .bogos-slider-offer").forEach(t=>{const e=t.querySelector("#sca-hidden-gift-popup .sca-disable-checkbox");null==e||e.addEventListener("change",()=>y(null,null,function*(){var o,i,n,l,c,d,u,f;if(e.checked)if(s&&"offer"===a){const e=t.getAttribute("data-offer");if(!e)return;x.saveLocal("FGSECOMAPP_HIDDEN_GIFT_OFFER_".concat(e),"".concat(Date.now())),yield new Promise(t=>setTimeout(t,400)),t.classList.add("sca-d-none"),document.querySelectorAll(".bogos-slider-offers-container .bogos-slider-offer:not(.sca-d-none)").length||(null==(i=null==(o=document.querySelector("#freegifts-main-popup-container.sca-modal-fg.sca-is-visible-fg"))?void 0:o.classList)||i.remove(r),null==(l=null==(n=document.querySelector("#freegifts-main-page-container:not(.sca-modal-fg)"))?void 0:n.classList)||l.add("sca-d-none"))}else x.saveLocal("FGSECOMAPP_HIDDEN_GIFT_POPUP","".concat(Date.now())),yield new Promise(t=>setTimeout(t,400)),null==(d=null==(c=document.querySelector("#freegifts-main-popup-container.sca-modal-fg.sca-is-visible-fg"))?void 0:c.classList)||d.remove(r),null==(f=null==(u=document.querySelector("#freegifts-main-page-container:not(.sca-modal-fg)"))?void 0:u.classList)||f.add("sca-d-none")}))}),document.querySelectorAll(".freegifts-main-container .slide-container.sca-modal-dialog-fg").forEach(t=>{const e=t.querySelector("#sca-hidden-gift-popup .sca-disable-checkbox");null==e||e.addEventListener("change",()=>y(null,null,function*(){var t,o,i,n;e.checked&&(x.saveLocal("FGSECOMAPP_HIDDEN_GIFT_POPUP","".concat(Date.now())),yield new Promise(t=>setTimeout(t,400)),null==(o=null==(t=document.querySelector("#freegifts-main-popup-container.sca-modal-fg.sca-is-visible-fg"))?void 0:t.classList)||o.remove(r),null==(n=null==(i=document.querySelector("#freegifts-main-page-container:not(.sca-modal-fg)"))?void 0:i.classList)||n.add("sca-d-none"))}))}),R.renderQuerySelectorForGiftItem()},renderQuerySelectorForGiftItem:(t=null)=>{var e,o,i,n,r,l;const a=t||document,{type:s="variant"}=null!=(o=null==(e=FGSECOMAPP.fgAppearance)?void 0:e.select_variant)?o:{},{use_old_version:d,out_of_stock_text:u="Out of stock"}=null!=(r=null==(n=null==(i=FGSECOMAPP.fgAppearance)?void 0:i.gift_slider)?void 0:n.general)?r:{},_=!1===d,g=(null==(l=FGSECOMAPP.fgSettings)?void 0:l.track_oostock)===f.TRACK_OOSTOCK.SHOW_OOSTOCK;let v=a.querySelectorAll("#fg-gift-items .btn-add-to-cart"),p=v.length;for(let c=0;c{t.querySelector(".btn-add-to-cart").addEventListener("click",function(){return y(this,null,function*(){var e,o,i;const n=this.getAttribute("data-variant")-0,r=this.getAttribute("data-offer"),l=null==(e=FGSECOMAPP.offers.find(t=>t.id===r))?void 0:e.giftsAvailable;let a=1;if(_){const e=null!=(o=t.querySelector(".bogos-gift-item-quantity-input"))?o:t.querySelector(".bogos-gift-quantity-input"),i=parseInt(e.value);a=isNaN(i)?1:Math.min(i,parseInt(l))}try{this.disabled=!0,this.classList.add("bogos-gift-adding"),w.status.busy(this),yield k.addGiftToCart(n,a,r),this.disabled=!1,w.status.done(this),document.querySelector("#freegifts-main-popup-container.sca-modal-fg.sca-is-visible-fg")&&(FGSECOMAPP.isDelayShowAdded=!0,yield new Promise(t=>setTimeout(t,800))),window.location.href.includes("/cart")?location.reload():"function"==typeof(null==Shopify?void 0:Shopify.getCart)&&(yield null==Shopify?void 0:Shopify.getCart(null==(i=FGSECOMAPP.variables.fgCallback)?void 0:i[0]))}catch(s){w.status.idle(this),console.error("BOGOS track: error event click add-to-cart ",s)}FGSECOMAPP.variables.isHeadless&&document.dispatchEvent(new CustomEvent(FGSECOMAPP.CUSTOM_EVENTS.BOGOS_FG_PROCESS))})})};if(a.querySelectorAll("#fg-gift-items .dropdown").forEach(t=>{w.combobox.bind(t,w.COMBOBOX.variantV1),t.addEventListener("click",function(){this.setAttribute("tabindex",-1),this.focus(),this.classList.toggle("active"),this.querySelector(".dropdown-menu").classList.toggle("d-block")})}),a.querySelectorAll("#fg-gift-items .dropdown").forEach(t=>a.addEventListener("click",function(e){t.contains(e.target)||(t.classList.remove("active"),t.querySelector(".dropdown-menu").classList.remove("d-block")),a.querySelectorAll(".btn-add-to-cart.sca-fg-out-stock").forEach(t=>{t.disabled=!0})})),a.querySelectorAll("#fg-gift-items .product-item").forEach(t=>{t.querySelectorAll(".dropdown > .dropdown-menu > li").forEach(e=>{e.addEventListener("click",function(){var e;const o=this.getAttribute("id"),i=this.getAttribute("data-img"),n=this.getAttribute("data-price"),r=this.getAttribute("data-original-price"),l=this.getAttribute("data-original-id"),a=t.querySelector(".top-content");a.querySelector(".product-item-thumbnail").setAttribute("src",i);const s=new URL(a.querySelector(".gift-original-url").href);s.searchParams.set("variant",l),a.querySelector(".gift-original-url").href=s.toString();const c=t.querySelector(".bottom-content");c.querySelector(".original-price del").textContent=r,c.querySelector(".gift-price").textContent=n;const d=null==(e=FGSECOMAPP.variables.giftItemsChoose)?void 0:e[o],u=c.querySelector(".original-price");if(u&&d){const t=x.renderGiftPrice(d).price,e=x.renderOriginalPrice(d).price;u.classList.toggle("sca-d-none",t>=e)}const f=null==c?void 0:c.querySelector(".btn-add-to-cart");f.setAttribute("data-variant",o),f.disabled=!1,f.style="";let _=c.querySelector(".selected-variant");_.classList.add("active"),_.innerHTML=this.innerText})}),h(t)}),a.querySelectorAll(".bogos-offer-gift-item").forEach(e=>{e.querySelectorAll(".bogos-gift-select-variant-wrapper:has(.bogos-gift-select-variant-option)").forEach(o=>{const i=o.querySelector(".bogos-gift-select-variant-dropdown"),n=o.querySelectorAll(".bogos-gift-select-variant-option"),r=e.querySelector(".bogos-gift-item-bottom-info"),l=e.querySelector(".bogos-gift-select-variant-title"),a=null==r?void 0:r.querySelector(".btn-add-to-cart"),s=null==a?void 0:a.innerHTML,c=t=>{var o;const i=t.currentTarget.getAttribute("data-variant-id")-0,n=t.currentTarget.getAttribute("data-img"),c=t.currentTarget.getAttribute("data-price"),d=t.currentTarget.getAttribute("data-original-price"),_=t.currentTarget.getAttribute("data-original-id");l.textContent=t.currentTarget.textContent.trim();const g=e.querySelector(".bogos-gift-item-image-container");g.querySelector(".bogos-gift-item-image").setAttribute("src",n);const v=new URL(g.querySelector(".gift-original-url").href);v.searchParams.set("variant",_),g.querySelector(".gift-original-url").href=v.toString();const p=r.querySelector(".bogos-gift-item-compare-price");p.textContent=d,r.querySelector(".bogos-gift-item-price").textContent=c;const h=null==(o=FGSECOMAPP.variables.giftItemsChoose)?void 0:o[i];if(p&&h){const t=x.renderGiftPrice(h).price,e=x.renderOriginalPrice(h).price;p.classList.toggle("sca-d-none",t>=e)}a.setAttribute("data-variant",i),a.disabled=!1,a.style="";const m=t.currentTarget.getAttribute("data-available"),b=FGSECOMAPP.fgSettings.track_oostock===f.TRACK_OOSTOCK.SHOW_OOSTOCK,y=D.convertIntegration(u,"customize.out_of_stock_text","customize.gift_slider.out_of_stock_text"),S=null==e?void 0:e.querySelector(".bogos-gift-item-quantity-wrapper");b&&"false"===m?(a.disabled=!0,a.setAttribute("data-available","false"),a.textContent=y,S&&S.classList.add("bogos-disable-btn")):(a.disabled=!1,a.setAttribute("data-available","true"),a.textContent=s,S&&S.classList.remove("bogos-disable-btn"))};!t&&document.addEventListener("click",t=>{!o.contains(t.target)&&i.classList.contains("opened")&&i.classList.remove("opened")}),n.forEach(t=>{t.addEventListener("click",c)}),i.addEventListener("click",()=>{i.classList.toggle("opened")}),w.combobox.bind(i,w.COMBOBOX.variant)}),e.querySelectorAll(".bogos-gift-select-variant-wrapper:not(:has(.bogos-gift-select-variant-option))").forEach(o=>{const i=o.querySelector(".bogos-gift-select-variant-dropdown"),n=e.querySelector(".bogos-gift-item-bottom-info"),r=e.querySelector(".bogos-gift-select-variant-title"),l=null==n?void 0:n.querySelector(".btn-add-to-cart"),a=null==l?void 0:l.innerHTML;o.addEventListener("click",t=>{var i,s,c,d,_,g,v,p,h;const m=null!=(i=t.target)?i:document.createElement("div");if(m.closest(".bogos-select-option-custom-item")){const t=m.closest(".bogos-select-option-custom-item"),i=decodeURIComponent(t.getAttribute("data-option-value")),b=l.getAttribute("data-product"),y=l.getAttribute("data-variant"),S=l.getAttribute("data-offer"),P=null!=(s=R.productsTemp[S][b])?s:{},E=null!=(d=null==(c=null==P?void 0:P.variants)?void 0:c.find(t=>{var e;return(null==(e=t.id)?void 0:e.toString())===y}))?d:null==P?void 0:P.variants[0],O=null!=(_=null==E?void 0:E.options)?_:[],A=null==P?void 0:P.options.findIndex(e=>t.getAttribute("data-option-name")===e);let C=null==O?void 0:O.map((t,e)=>A===e?i:t),M=null==(g=null==P?void 0:P.variants)?void 0:g.find(t=>t.options.length===C.length&&t.options.every((t,e)=>t===C[e]));if(M||y||(M=null==(v=P.variants)?void 0:v.find(t=>{var e;return(null==(e=t.options)?void 0:e[A])===i}),C=null!=(p=null==M?void 0:M.options)?p:C),o.querySelectorAll(".bogos-select-option-custom-item").forEach(t=>{const e=decodeURIComponent(t.getAttribute("data-option-value"));C.includes(e)?t.classList.add("bogos-active"):t.classList.remove("bogos-active"),t.classList.remove("bogos-deactivate")}),!M){l.disabled=!0;let t=[...P.variants];const e=[];return C.forEach((o,i)=>{t.some(t=>t.options[i]===o)?t=t.filter(t=>t.options[i]===o):e.push({position:i,value:o})}),void o.querySelectorAll(".bogos-select-option-name-container").forEach((t,o)=>{t.querySelectorAll(".bogos-select-option-custom-item").forEach(t=>{const i=decodeURIComponent(t.getAttribute("data-option-value"));e.some(t=>t.position===o&&t.value===i)?t.classList.add("bogos-deactivate"):t.classList.remove("bogos-deactivate")})})}const G=FGSECOMAPP.variables.giftItemsChoose[M.id],F=G.variant_shopify_id,T=x.handleResizeGiftImage(null!=(h=G.thumbnail)?h:G.product_img),w=x.renderGiftPrice(G),k=x.renderOriginalPrice(G),L=G.original_variant_shopify_id;r.textContent=G.variant_title.trim();const q=e.querySelector(".bogos-gift-item-image-container");q.querySelector(".bogos-gift-item-image").setAttribute("src",T);const I=new URL(q.querySelector(".gift-original-url").href);I.searchParams.set("variant",L),q.querySelector(".gift-original-url").href=I.toString();const N=n.querySelector(".bogos-gift-item-compare-price");N.textContent=k.price_render,n.querySelector(".bogos-gift-item-price").textContent=w.price_render,N&&N.classList.toggle("sca-d-none",w.price>=k.price);const H=FGSECOMAPP.fgSettings.track_oostock===f.TRACK_OOSTOCK.SHOW_OOSTOCK,B=D.convertIntegration(u,"customize.out_of_stock_text","customize.gift_slider.out_of_stock_text"),V=null==e?void 0:e.querySelector(".bogos-gift-item-quantity-wrapper");H&&!1===G.available?(l.disabled=!0,l.setAttribute("data-available","false"),l.textContent=B,V&&V.classList.add("bogos-disable-btn")):(l.disabled=!1,l.setAttribute("data-available","true"),l.textContent=a,V&&V.classList.remove("bogos-disable-btn")),l.setAttribute("data-variant",F),l.style=""}}),!t&&document.addEventListener("click",t=>{!o.contains(t.target)&&i.classList.contains("opened")&&i.classList.remove("opened")}),i.querySelector(".bogos-gift-select-variant-title-contain").addEventListener("click",()=>y(null,null,function*(){var t;if(i.classList.toggle("opened"),"option"===s&&!i.querySelector(".bogos-select-option-name-container")){const e=l.getAttribute("data-product"),o=l.getAttribute("data-offer"),n=i.querySelector(".bogos-gift-select-variant-options");if(!FGSECOMAPP.productsDefaultByID[e]){const t=yield c.queryProductDefault(e);if(x.empty(t))return}const r=null!=(t=R.productsTemp[o][e])?t:{},a=R.convertProductWithOptionsDefault(FGSECOMAPP.productsDefaultByID[e],r);n.innerHTML=R.renderProductOptionWithValue(a)}})),w.combobox.bind(i,w.COMBOBOX.variant),w.radioGroup.init(o)}),h(e);const o=e.querySelector(".bogos-gift-select-variant");o&&o.addEventListener("change",function(){var t;const i=e.querySelector(".bogos-gift-item-bottom-info"),n=null==i?void 0:i.querySelector(".btn-add-to-cart");if(x.empty(this.value))return n.disabled=!0,void n.setAttribute("data-variant","");const r=this.value-0,l=o.querySelector('[value="'.concat(r,'"]'));if(l){const o=l.getAttribute("data-img"),a=l.getAttribute("data-price"),s=l.getAttribute("data-original-price"),c=l.getAttribute("data-original-id"),d=e.querySelector(".bogos-gift-item-image-container");d.querySelector(".bogos-gift-item-image").setAttribute("src",o);const u=new URL(d.querySelector(".gift-original-url").href);u.searchParams.set("variant",c),d.querySelector(".gift-original-url").href=u.toString();const f=i.querySelector(".bogos-gift-item-compare-price");f.textContent=s,i.querySelector(".bogos-gift-item-price").textContent=a;const _=null==(t=FGSECOMAPP.variables.giftItemsChoose)?void 0:t[r];if(f&&_){const t=x.renderGiftPrice(_).price,e=x.renderOriginalPrice(_).price;f.classList.toggle("sca-d-none",t>=e)}n.setAttribute("data-variant",r),n.disabled=!1,n.style=""}})}),a.querySelectorAll(".bogos-gift-item-quantity-wrapper").forEach(e=>{const o=e.querySelector(".bogos-gift-item-quantity-dropdown"),i=e.querySelector(".bogos-gift-item-quantity-input"),n=e.querySelectorAll(".bogos-gift-item-quantity-option"),r=t=>{i.value=t.currentTarget.getAttribute("data-quantity")};!t&&document.addEventListener("click",t=>{!e.contains(t.target)&&o.classList.contains("opened")&&o.classList.remove("opened")}),n.forEach(t=>{t.addEventListener("click",r)}),o.addEventListener("click",()=>{o.classList.toggle("opened")}),w.combobox.bind(o,w.COMBOBOX.quantity)}),g){const t=D.convertIntegration(u,"customize.out_of_stock_text","customize.gift_slider.out_of_stock_text");a.querySelectorAll("#fg-gift-items .btn-add-to-cart[data-available='false']").forEach(e=>{if(x.empty(e.getAttribute("data-variant")))return;e.disabled=!0,e.textContent=t;const o=e.closest(".bogos-offer-gift-item"),i=null==o?void 0:o.querySelector(".bogos-gift-item-quantity-wrapper");i&&i.classList.add("bogos-disable-btn")})}},renderGiftsIntoPerSlider:(t,e,o,i)=>{t.innerHTML=e.map(t=>R.renderProductHTML(o,t)).join(" \n"),t.setAttribute("data-show-desktop","".concat(i)),R.renderGlider(t,i)},renderGlider:(t,e)=>{var o,i;const{bogos_settings_glider:n}=FGSECOMAPP.variables.Shopify,{general:r}=null==(o=FGSECOMAPP.fgAppearance)?void 0:o.gift_slider,l=null!=(i=null==r?void 0:r.number_product_slider_mobile)?i:1.8,a=t.parentElement.parentElement;t.setAttribute("data-show-mobile","".concat(l)),new FGSECOMAPP.helper.Glider(t,m({slidesToShow:1,slidesToScroll:1,draggable:!1,dots:(null==r?void 0:r.show_pagination)?null==a?void 0:a.querySelector(".dots"):null,arrows:{prev:null==a?void 0:a.querySelector(".glider-prev"),next:null==a?void 0:a.querySelector(".glider-next")},responsive:[{breakpoint:750,settings:{slidesToShow:null!=e?e:4,slidesToScroll:null!=e?e:4}},{breakpoint:300,settings:{slidesToShow:1===l?l:l+.04,slidesToScroll:l}}]},"object"==typeof n?n:{})).refresh()},renderGiftSliderSeparateByOffer:t=>{var e,o,i,n;let r=[];Object.entries(t).forEach(([t,e])=>{var o,i,n,l;const a=R.convertGiftDisplay(e,null==(n=null==(i=null==(o=FGSECOMAPP.fgAppearance)?void 0:o.gift_slider)?void 0:i.general)?void 0:n.show_gift_for_customer),s=FGSECOMAPP.offers.filter(e=>e.offer_root===t.toString()),c=null!=(l=s[0])?l:{};r.push({offer_name:c.offer_name,offer_root:t,priority:c.priority,giftsAvailable:s.reduce((t,e)=>t+e.giftsAvailable,0),arrGiftShow:a})}),r=null==r?void 0:r.sort((t,e)=>t.priority-e.priority);const l=Math.max(...r.map(t=>{var e;return null==(e=null==t?void 0:t.arrGiftShow)?void 0:e.length})),{general:a}=null==(e=FGSECOMAPP.fgAppearance)?void 0:e.gift_slider;let s=null!=(o=null==a?void 0:a.number_product_slider)?o:4,c=s;const d=null!=(n=null==(i=document.querySelector(_))?void 0:i.innerHTML)?n:h;document.querySelectorAll(".bogos-gifts-slider-container .bogos-slider-offers-container").forEach(t=>{t.innerHTML=r.map(t=>{var e,o;k.handleQuantityGiftAvailableSession("set",0,t.offer_root,t.giftsAvailable);const i=FGSECOMAPP.variables["bogos_added_gift_".concat(t.offer_root)],n=FGSECOMAPP.variables["bogos_total_gift_".concat(t.offer_root)];return R.renderGiftsOfferSection(i,n,{bogos_check_show_quantity_box:(null==(e=FGSECOMAPP.fgSettings)?void 0:e.select_one_gift_price)?"sca-d-none":"",bogos_offer_id:null==(o=null==t?void 0:t.offer_root)?void 0:o.toString(),bogos_offer_title:x.safeMerchantHTML(D.convertIntegration(t.offer_name,"offer.offer_title_".concat(t.offer_root),"offers.".concat(t.offer_root,".offer_name")),!0)})}).join(" \n")}),document.querySelectorAll(".bogos-gifts-slider-container .bogos-slider-offer-switch-show").forEach(t=>{(l<=2||s<=2)&&(t.style.position="unset")});const u=document.querySelector(".bogos-gifts-slider-container.bogos-gift-slider-modal");if((l<=s||s<=4)&&u){const t=Math.min(l,s);u.style.setProperty("max-width",Math.min(t,4)*(1===l?350:163)+12*t+50+"px","important"),c=t}document.querySelectorAll(".bogos-gifts-slider-container .bogos-slider-offers-container").forEach(t=>{t.querySelectorAll(".bogos-offer-gift-items-container").forEach((t,e)=>{R.renderGiftsIntoPerSlider(t,r[e].arrGiftShow,d,c)})}),document.dispatchEvent(new CustomEvent(FGSECOMAPP.CUSTOM_EVENTS.SHOW_GIFT_SLIDER,{detail:{addGiftToCartFunc:FGSECOMAPP.helper.addGiftToCart,giftsOffer:r}}))},renderGiftSliderViewByAllInOne:t=>{var e,o,i,n,r,l,a,s,c;const d=R.convertGiftDisplay(t,null==(i=null==(o=null==(e=FGSECOMAPP.fgAppearance)?void 0:e.gift_slider)?void 0:o.general)?void 0:i.show_gift_for_customer),u=d.length,{general:f}=null==(n=FGSECOMAPP.fgAppearance)?void 0:n.gift_slider,g=!1===(null==f?void 0:f.use_old_version);let v=null!=(r=null==f?void 0:f.number_product_slider)?r:4,p=v;const m=g?document.querySelector(".bogos-gifts-slider-container.bogos-gift-slider-modal"):document.querySelector(".slide-container.sca-modal-dialog-fg"),b=g?".bogos-offer-gift-items-container":".bogos-gift-items",y=g?null!=(a=null==(l=document.querySelector(_))?void 0:l.innerHTML)?a:h:null!=(c=null==(s=document.querySelector("#sca_fg_section_gift_item"))?void 0:s.innerHTML)?c:'
{{ bogos_integration_judgeme }} {{ bogos_integration_trustoo }} {{ bogos_integration_yotpo }}
{{ fg_original_price }} {{ fg_gift_price }}
';if(g){k.handleQuantityGiftAvailableSession("set");const t=FGSECOMAPP.variables.bogos_added_gift,e=FGSECOMAPP.variables.bogos_total_gift;document.querySelectorAll(".bogos-gifts-slider-container .bogos-slider-offers-container").forEach(o=>{o.innerHTML=R.renderGiftsOfferSection(t,e,{bogos_check_offer_title:"sca-d-none"})}),document.querySelectorAll(".bogos-gifts-slider-container .bogos-slider-offer-switch-show").forEach(t=>{t&&(u<=2||v<=2)&&(t.style.position="unset")})}if((u<=v||v<=4)&&m){const t=Math.min(u,v);m.style.setProperty("max-width",Math.min(t,4)*(1===u?350:163)+12*t+50+"px","important"),p=t}document.querySelectorAll(b).forEach(t=>{R.renderGiftsIntoPerSlider(t,d,y,p)}),document.dispatchEvent(new CustomEvent(FGSECOMAPP.CUSTOM_EVENTS.SHOW_GIFT_SLIDER,{detail:{addGiftToCartFunc:FGSECOMAPP.helper.addGiftToCart,gifts:x.convertProductEvent(d)}}))},renderGiftSelectSection:t=>{var e,o,i,n,r,l,a,s,c,d,u,f,_,g,v,p,h,m,b,y,S,P,E;const O=null!=(o=null==(e=FGSECOMAPP.fgAppearance)?void 0:e.gift_slider)?o:{},A=x.safeMerchantHTML(D.convertIntegration(null!=(n=null==(i=null==O?void 0:O.notify_offer_available)?void 0:i.text)?n:"\ud83c\udf81 You have qualified for {{qualifiedOffers}} offer(s)!","customize.notify_offer_available_text","customize.gift_slider.notify_offer_available_text"),!0),C=!1===(null==(r=null==O?void 0:O.general)?void 0:r.use_old_version),{gift_slider_query:M}=null!=(l=FGSECOMAPP.QUERY_SELECTOR)?l:{},G=[...null==M?void 0:M.page_builder,...null==M?void 0:M.default].filter(Boolean).join(","),F=x.getDataConfigSetting("sca_fg_gift_slider_position"),T=x.empty(F)?"after":F;let w=null==(a=null==M?void 0:M.tool)?void 0:a.filter(Boolean).join(","),k=null;if((null==(d=null==(c=null==(s=null==window?void 0:window.ACCELIO)?void 0:s.app)?void 0:c.cart_profile)?void 0:d.status)&&!(null==(u=null==window?void 0:window.ACCELIO)?void 0:u.rendered)){const t=w.split(",").filter(t=>!t.includes("accelio"));w=t.join(",")}if(!x.empty(w)){k=document.querySelectorAll(w);const t={after:"afterend",before:"beforebegin",in:"beforeend"};null==(_=x.prepareShadowRootEl)||_.call(x,"gift_slider_query",{slot:"bogos-gift-slider-view",keyEl:".bogos-gift-slider-view",position:null!=(f=t[T])?f:"beforebegin"}),k&&k.forEach(t=>{const e=document.createElement("div");e.classList.add("bogos-gift-slider-view");const o="after"===T&&(!t.nextElementSibling||!t.nextElementSibling.classList.contains("bogos-gift-slider-view"))||"before"===T&&(!t.previousElementSibling||!t.previousElementSibling.classList.contains("bogos-gift-slider-view"))||"in"===T&&!t.querySelector(".bogos-gift-slider-view");"after"===T?o&&t.parentNode.insertBefore(e,t.nextSibling):"before"===T?o&&t.parentNode.insertBefore(e,t):o&&t.appendChild(e)})}let L=document.querySelectorAll(G);if((null==L?void 0:L.length)>0){const e=C?null!=(v=null==(g=document.querySelector("#bogos_cart_section_gifts_slider"))?void 0:g.innerHTML)?v:'
{{fg_slider_title}}
{{bogos_slider_offer_available}}
{{bogos_brand_mark}}
':null!=(h=null==(p=document.querySelector("#sca_fg_cart_section_gifts_slider"))?void 0:p.innerHTML)?h:'
{{ fg_slider_title }}
{{ sca_fg_disable_slider_section }}
';return void L.forEach(o=>{var i,n,r;null==(i=o.classList)||i.toggle("freegifts-main-container",!0),R.applyGiftSliderVars(o),o.innerHTML=FGSECOMAPP.helper.templateHTML.render(e,{sca_fg_disable_slider_section:"".concat(R.BRAND_MARK_TEMPLATE()),bogos_check_show_offer_available:C&&(null==(n=null==O?void 0:O.notify_offer_available)?void 0:n.enable)&&"offer"===(null==(r=null==O?void 0:O.general)?void 0:r.show_gift_type)?"":"sca-d-none",bogos_slider_offer_available:FGSECOMAPP.helper.templateHTML.render(A,{qualifiedOffers:t,totalOffers:FGSECOMAPP.offers.length}),bogos_brand_mark:R.BRAND_MARK_TEMPLATE("bogos-brand-mark-gift-slider-v2")})})}const{FGSECOMAPP_HIDDEN_GIFT_POPUP:q}=FGSECOMAPP.variables.constants;if(R.handleCheckHiddenGiftSlider(q))return;if(L=document.querySelector(M.popup.filter(Boolean).join(",")),!L)return;const I=C?null!=(b=null==(m=document.querySelector("#bogos_section_gifts_popup"))?void 0:m.innerHTML)?b:'':null!=(S=null==(y=document.querySelector("#sca_fg_section_gifts_popup"))?void 0:y.innerHTML)?S:'';L.innerHTML=FGSECOMAPP.helper.templateHTML.render(I,{sca_fg_disable_slider_section:"".concat(R.HIDDEN_GIFT_POPUP()," ").concat(R.BRAND_MARK_TEMPLATE()),bogos_check_show_offer_available:C&&(null==(P=null==O?void 0:O.notify_offer_available)?void 0:P.enable)&&"offer"===(null==(E=null==O?void 0:O.general)?void 0:E.show_gift_type)?"":"sca-d-none",bogos_slider_offer_available:FGSECOMAPP.helper.templateHTML.render(A,{qualifiedOffers:t,totalOffers:FGSECOMAPP.offers.length}),bogos_brand_mark:R.BRAND_MARK_TEMPLATE("bogos-brand-mark-gift-slider-v2")}),L.classList.add("sca-is-visible-fg")},convertProductWithOptions:(t,e)=>{var o;const i=b(m({},t),{variants:e.map(e=>{var o;return null==(o=null==t?void 0:t.variants)?void 0:o.find(t=>String(t.id)===String(e.variant_shopify_id))}).filter(Boolean)});return b(m({},i),{optionsConverted:(null!=(o=null==i?void 0:i.options)?o:[]).map((t,e)=>{var o;return{name:t,values:[...new Set(null==(o=null==i?void 0:i.variants)?void 0:o.map(t=>{var o;return null==(o=null==t?void 0:t.options)?void 0:o[e]}))]}})})},convertProductWithOptionsDefault:(t,e)=>{var o,i;const n=b(m({},e),{optionsDefault:null!=(o=null==t?void 0:t.options)?o:[],variants:e.variants.map(e=>{var o,i;const n=null==(o=null==t?void 0:t.variants)?void 0:o.find(t=>String(t.id)===String(e.id));return b(m({},e),{optionsDefault:null!=(i=null==n?void 0:n.options)?i:[]})})});return b(m({},n),{optionsConvertedDefault:(null!=(i=null==n?void 0:n.optionsDefault)?i:[]).map((t,e)=>{var o;return{name:t,values:[...new Set(null==(o=null==n?void 0:n.variants)?void 0:o.map(t=>{var o;return null==(o=null==t?void 0:t.optionsDefault)?void 0:o[e]}))]}})})},renderProductOptionWithValue:t=>{var e,o,i,n,r;const{configs:l=[]}=null!=(o=null==(e=FGSECOMAPP.fgAppearance)?void 0:e.select_variant)?o:{},a={small:"12px",medium:"20px",large:"32px"},s=null==(i=t.variants[0])?void 0:i.options,c=null!=(n=null==t?void 0:t.optionsConverted)?n:[],d=null!=(r=null==t?void 0:t.optionsConvertedDefault)?r:[];return c.map((t,e)=>{var o;const i=l.find(t=>{var o,i;return(null==(o=t.data)?void 0:o.option_name)===(null==(i=d[e])?void 0:i.name)}),n="color"===(null==i?void 0:i.type),r=i?n?'':'':'',c=null==(o=t.values)?void 0:o.map((o,l)=>{var c,u,f,_;if(i){const g=i.customize,v=x.safeText(null!=(_=null==(f=null==(u=null==(c=null==i?void 0:i.data)?void 0:c.values)?void 0:u.find(t=>{var o,i;return t.name===(null==(i=null==(o=d[e])?void 0:o.values)?void 0:i[l])}))?void 0:f.label)?_:n?"#ffffff":"https://static.bogos.io/assets/bogos-images/1760928468.png");return FGSECOMAPP.helper.templateHTML.render(r,{bogos_option_value:encodeURIComponent(o),bogos_option_value_title:x.safeText(o),bogos_option_value_label:x.attrText(o),bogos_option_custom_data:v,bogos_option_name:x.safeText(t.name),check_activate_aria:(null==s?void 0:s.includes(o))?"true":"false",bogos_option_color_style:"background-color: ".concat(v,"; width: ").concat(a[g.size],";\n height: ").concat(a[g.size],"; border-radius: ").concat("circle"===g.shape?"50%":"4px"),bogos_option_color_container_style:"border-radius: ".concat("circle"!==g.shape||g.show_name?"4px":"50%"),check_show_title:g.show_name?"":"sca-d-none",check_activate:(null==s?void 0:s.includes(o))?"bogos-active":"",bogos_option_image_style:"width: ".concat(a[g.size],"; height: ").concat(a[g.size],"; border-radius: ").concat("circle"===g.shape?"50%":"4px")})}return FGSECOMAPP.helper.templateHTML.render(r,{bogos_option_value:encodeURIComponent(o),bogos_option_value_title:x.safeText(o),bogos_option_name:x.safeText(t.name),check_activate:(null==s?void 0:s.includes(o))?"bogos-active":"",check_activate_aria:(null==s?void 0:s.includes(o))?"true":"false"})}).join("");return FGSECOMAPP.helper.templateHTML.render('
{{bogos_option_name}}
{{bogos_option_items}}
',{bogos_option_name:x.safeText(t.name),bogos_option_uid:"".concat(++w.seq),bogos_option_style_vars:L(),bogos_option_items:c})}).join("")},renderVariantSelectOptions:(t,e,o,i)=>{var n,r,l,a,s,d,u,f,_,g,v;const p=FGSECOMAPP.productsByID[t];FGSECOMAPP.variables.giftItemsChoose=m({},null!=(n=FGSECOMAPP.variables.giftItemsChoose)?n:{}),e.forEach(t=>{FGSECOMAPP.variables.giftItemsChoose[t.variant_shopify_id]=b(m({},t),{product_img:o})});const{type:h="variant"}=null!=(l=null==(r=FGSECOMAPP.fgAppearance)?void 0:r.select_variant)?l:{};if("variant"===h){const t=!1===(null==(d=null==(s=null==(a=FGSECOMAPP.fgAppearance)?void 0:a.gift_slider)?void 0:s.general)?void 0:d.use_old_version)?null!=(f=null==(u=document.querySelector("#bogos_variant_select_section"))?void 0:u.innerHTML)?f:'
{{ fg_variant_title }}
':null!=(g=null==(_=document.querySelector("#sca_fg_variant_select_section"))?void 0:_.innerHTML)?g:'
  • {{ fg_variant_title }}
  • ';return e.map(e=>{var i,n,r,l;return FGSECOMAPP.helper.templateHTML.render(t,{fg_variant_img:x.safeText(x.handleResizeGiftImage(null!=(i=e.thumbnail)?i:o)),fg_variant_id:e.variant_shopify_id,fg_original_variant_id:e.original_variant_shopify_id,fg_variant_price:x.renderGiftPrice(e).price_render,fg_original_variant_price:x.renderOriginalPrice(e).price_render,fg_variant_title:x.safeText(null!=(l=null==(r=null==(n=null==p?void 0:p.variants)?void 0:n.find(t=>String(t.id)===String(e.variant_shopify_id)))?void 0:r.title)?l:e.variant_title),fg_variant_available:e.available,bogos_sv_style:L(!0),variant:e})}).join(" \n")}{const t=R.convertProductWithOptions(p,e);return R.productsTemp[i]=m({},null!=(v=R.productsTemp[i])?v:{}),R.productsTemp[i][t.id]=t,c.queryProductDefault(t.id).then(),'
    '}},renderGiftQuantityOptions:t=>Array.from({length:t},(t,e)=>e+1).map(t=>FGSECOMAPP.helper.templateHTML.render('
  • {{ bogos_gift_quantity }}
  • ',{bogos_gift_quantity:t})).join(" \n"),renderPromotionMessage:t=>{var e,o,i,n,r,l,a,s,c;try{if(!(null==(o=null==(e=FGSECOMAPP.fgAppearance)?void 0:e.promotion_message)?void 0:o.show_on_cart_page))return;const{enable_hidden_message_added:d}=null!=(i=FGSECOMAPP.variables.Shopify)?i:{};x.empty(t)&&(t=[...FGSECOMAPP.offers]);const u=location.href.includes("/cart"),f=[];if(null==t||t.forEach(t=>{var e,o,i,n,r,l;if(t.isReachConditions&&(!d||(null==(e=t.giftsAdded)?void 0:e.length))||x.empty(t.promotion_message)||!x.empty(FGSECOMAPP.variables.maxOfferPriority)&&!t.isReachConditions&&t.priority>FGSECOMAPP.variables.maxOfferPriority||x.empty((null!=(o=t.count_down_value)?o:0)+(null!=(i=t.count_down_quantity)?i:0))&&k.checkOfferWithSubConditionProductQtyLimits(t)&&/({{\s*sca_min_total\s*}})|({{\s*sca_min_quantity\s*}})/gm.test(t.promotion_message))return;const a=null==(l=t.count_down_value)?void 0:l.toFixed(null!=(r=null==(n=FGSECOMAPP.variables.Shopify)?void 0:n.sca_amount_fixed)?r:2);f.push({value:FGSECOMAPP.helper.templateHTML.render(x.safeMerchantHTML(D.convertIntegration(t.promotion_message,"offer.cart_message_".concat(t.offer_root),"offers.".concat(t.offer_root,".promotion_message")),!0),{sca_min_total_with_currency:x.renderPrice(a),sca_min_total:a,sca_min_quantity:t.count_down_quantity}),offer:t})}),document.dispatchEvent(new CustomEvent(FGSECOMAPP.CUSTOM_EVENTS.RENDER_CART_MESSAGE,{detail:{data:f.map(t=>{var e;return{offer:t.value,offer_root:null==(e=t.offer)?void 0:e.offer_root}})}})),x.empty(f)){document.querySelectorAll(".sca-promotion-message-layout").forEach(t=>t.innerHTML="");const t=document.querySelector("#bogos-cart-message-view-block-preview-mode");return void(t&&R.renderEmpty(t,"There is the placeholder of cart message."))}const _=null!=(r=null==(n=document.querySelector("#sca_fg_cart_message_items_section"))?void 0:n.innerHTML)?r:'

    {{ fg_cart_message }}

    ',g=f.map(t=>FGSECOMAPP.helper.templateHTML.render(_,{fg_cart_message:t.value,offer:t.offer})).join(""),v=null!=(a=null==(l=document.querySelector("#sca_fg_cart_message_section"))?void 0:l.innerHTML)?a:'
    {{ sca_fg_cart_message_items_section }}
    ',p=FGSECOMAPP.helper.templateHTML.render(v,{sca_fg_cart_message_items_section:g}),{cart_message_query:h}=FGSECOMAPP.QUERY_SELECTOR;let m=document.querySelector([...null==h?void 0:h.default].filter(Boolean).join(","));const b=[...document.querySelectorAll([...null==h?void 0:h.tool,...null==h?void 0:h.integration,...null==h?void 0:h.page_builder].filter(Boolean).join(",")),...null!=(c=null==(s=x.prepareShadowRootEl)?void 0:s.call(x,"cart_message_query",{slot:"bogos-cart-message-view",keyEl:".bogos-cart-message-view",position:"beforebegin"}))?c:[]];document.querySelectorAll(".sca-promotion-message-layout").forEach(t=>t.innerHTML=p);let y=document.createElement("div");y.setAttribute("id","sca-promotion-message-layout"),y.classList.add("sca-promotion-message-layout");let S=(new DOMParser).parseFromString(p,"text/html");y.innerHTML=S.body.innerHTML,x.empty(b)||null==b||b.forEach(t=>{if(t.querySelector(".sca-promotion-message-layout"))return;const e=y.cloneNode(!0);t.prepend(e)}),(null==m?void 0:m.querySelector(".sca-promotion-message-layout"))||(S=(new DOMParser).parseFromString(p,"text/html"),y.innerHTML=S.body.innerHTML,m&&u&&m.prepend(y)),document.querySelectorAll(".sca-promotion-message-layout").forEach(t=>{t.setAttribute("role","status"),t.setAttribute("aria-live","polite");const e=new Set;t.querySelectorAll(".content-promotion-message").forEach(t=>{const o=t.textContent.replace(/\s+/g," ").trim();o&&(e.has(o)?t.setAttribute("aria-hidden","true"):(e.add(o),t.removeAttribute("aria-hidden")))})}),R.applyPromotionMessageVars(),document.querySelectorAll(".sca-promotion-glider").forEach(t=>{var e,o;((t,e)=>{var o;const i=t.track.childElementCount;let n=null,r=1;function l(){n=setTimeout(()=>{r>=i&&(r=0),t.scrollItem(r++)},e)}null==(o=t.ele)||o.addEventListener("glider-animated",function(){window.clearInterval(n),l()}),l()})(new FGSECOMAPP.helper.Glider(t)||{ele:null,scrollItem:()=>{}},null!=(o=null==(e=FGSECOMAPP.variables.Shopify)?void 0:e.sca_deplay_cart_msg)?o:3e3)})}catch(d){console.warn("BOGOS track: Failed render cart message",d)}},renderSuccessAddGift:()=>{var t,e,o,i;if(!(null==(t=FGSECOMAPP.variables.Shopify)?void 0:t.enable_toast_added))return;const n=document.querySelector(".sca-fg-notifications");if(!n)return;n.innerHTML="";const r=null!=(o=null==(e=FGSECOMAPP.variables.Shopify)?void 0:e.sca_text_notify_success)?o:"Add gift to cart successfully!",l=document.createElement("div");l.className="sca-fg-toast sca-fg-success",l.innerHTML='
    \n \n \n \n \n \n \n '.concat(r,'\n
    \n \n \n \n \n \n '),n.appendChild(l);const a=setTimeout(()=>R.removeToast(l),3e3);null==(i=document.querySelector("#close-fg-toast"))||i.addEventListener("click",()=>R.removeToast(l,a))},removeToast:(t,e)=>{t.classList.add("hide"),e&&clearTimeout(e),setTimeout(()=>t.remove(),500)},HIDDEN_GIFT_POPUP:()=>{var t,e,o,i,n;const r=null!=(o=null==(e=null==(t=FGSECOMAPP.fgAppearance)?void 0:t.gift_slider)?void 0:e.disable_slider_checkbox)?o:{},l=null!=(n=null==(i=document.querySelector("#sca_fg_disable_slider_section"))?void 0:i.innerHTML)?n:'
    {{ fg_text_disable_slider }}
    ';return(null==r?void 0:r.enable)?FGSECOMAPP.helper.templateHTML.render(l):""},handleCheckHiddenGiftSlider:t=>{var e,o,i,n;const r=localStorage.getItem(t)-0,l=null!=(o=null==(e=FGSECOMAPP.fgAppearance)?void 0:e.gift_slider)?o:{},a=null!=(i=null==l?void 0:l.disable_slider_checkbox)?i:{},s=60*(null!=(n=null==a?void 0:a.time)?n:0)*1e3;return!!((null==a?void 0:a.enable)&&!isNaN(r)&&r+s>Date.now())||(localStorage.removeItem(t),!1)},init:()=>{R.fetchVariantsSelected(),R.renderProductPage(),R.renderElementGiftIconCollectionPage().then()}}),D=b(m({},r),{syncStarRating:t=>y(null,null,function*(){yield D.syncRatingProducts(t,f.APP_REVIEW_OPTION.gift_slider,()=>{console.log("BOGOS track: judgeme-synced:".concat(Date.now()))}),yield D.syncRatingProducts(t,f.APP_REVIEW_OPTION.gift_slider,()=>{console.log("BOGOS track: trustoo-synced:".concat(Date.now()))},f.APP_REVIEW.trustoo),yield D.syncRatingProducts(t,f.APP_REVIEW_OPTION.gift_slider,()=>{console.log("BOGOS track: yotpo-synced:".concat(Date.now()))},f.APP_REVIEW.yotpo)}),renderAppReviewEl:(t,e=f.APP_REVIEW.judgeme)=>{var o,i,n,r,l,a,s,c,d;const u=null!=(i=null==(o=FGSECOMAPP.fgIntegration)?void 0:o[e])?i:{},{display_star_rating:_,gift_slider:g,status:v}=null!=(n=null==u?void 0:u.settings)?n:{};if(null==(r=v&&_&&g)||!r)return"";const p="bogos_".concat(e,"_ratings"),h=x.convertStringToObj(null!=(a=localStorage.getItem(null==(l=FGSECOMAPP.variables.constants)?void 0:l[p]))?a:""),{rating:m}=null!=(s=(null!=h?h:[]).find(({product_id:e})=>e===t))?s:{},b={[f.APP_REVIEW.judgeme]:D.renderStarRatingJudgeme,[f.APP_REVIEW.trustoo]:D.renderStarRatingTrustoo,[f.APP_REVIEW.yotpo]:D.renderStarRatingYotpo};return null!=(d=null==(c=b[e])?void 0:c.call(b,m,t))?d:""}}),N={shadowRoot:[],reCallCheckout:(t,e=!0)=>{var o,i,n;try{if(!e)return;const r=null==(o=FGSECOMAPP.fgSettings)?void 0:o.mode_override_checkout;let l=t;if(!(null==l?void 0:l.hasAttribute("sca_handle_checkout"))){const t="[sca_handle_checkout][".concat(N.LOADING_FLAG,"],")+"[sca_handle_checkout]:has(#sca-spinner-checkout)";l=document.querySelector(t),l=N.shadowRoot.reduce((e,o)=>{if(e)return e;const i=document.querySelector(o);return(null==i?void 0:i.shadowRoot)?i.shadowRoot.querySelector(t):null},l)}N.removeLoadingEl(l);const a=l.getAttribute("data-fg-checkout-btn");if(a){const t=JSON.parse(a);l.value=null!=(i=null==t?void 0:t.value)?i:"",l.innerHTML=null!=(n=null==t?void 0:t.innerHTML)?n:""}if(l.disabled=!1,l.removeEventListener("click",N.progressEventCheckout),l.removeEventListener("touchstart",N.progressEventCheckout),l.removeEventListener("touchend",N.progressEventCheckout),l.removeAttribute("sca_handle_checkout"),"clone_checkout"===r)return void l.parentNode.querySelector("[sca_root_checkout]").click();"trigger_body"===r&&window.removeEventListener("click",N.handleEventCheckoutDocument,!0),FGSECOMAPP.variables.checkIsBlockCheckout=!1,l.click()}catch(r){window.location.replace(x.routePath("/checkout")),console.warn("BOGOS track: Error recall root event checkout",r)}},LOADING_FLAG:"data-bogos-checkout-loading",HOST_FLAG:"data-bogos-loading-host",startLoading:t=>{"static"===getComputedStyle(t).position&&(t.style.position="relative",t.setAttribute(N.HOST_FLAG,"")),t.setAttribute(N.LOADING_FLAG,"")},removeLoadingEl:t=>{null==t||t.removeAttribute(N.LOADING_FLAG),(null==t?void 0:t.hasAttribute(N.HOST_FLAG))&&(t.style.removeProperty("position"),t.removeAttribute(N.HOST_FLAG))},customLoading:(t,e,o=!0)=>y(null,null,function*(){var i,n,r,l,a;if("function"==typeof(null==(i=FGSECOMAPP.helper)?void 0:i.scaCustomLoadingCheckout))return void(yield FGSECOMAPP.helper.scaCustomLoadingCheckout(t));if(!o)return;const{sca_fg_value_checkout:s,sca_fg_innerHTML:c}=null!=(n=FGSECOMAPP.variables.Shopify)?n:{},d=null!=(null==(r=null==e?void 0:e.getRootNode())?void 0:r.host)||!x.empty(s)||!x.empty(c);if("start"===t&&e){if(e.disabled=!0,!d)return void N.startLoading(e);e.setAttribute("data-fg-checkout-btn",JSON.stringify({innerHTML:e.innerHTML,value:e.value})),e.value=null!=s?s:"Loading...",e.innerHTML=null!=c?c:'
    \n Loading...\n
    '}else if("end"===t&&e){N.removeLoadingEl(e);const t=e.getAttribute("data-fg-checkout-btn");if(t){const o=JSON.parse(t);e.value=null!=(l=null==o?void 0:o.value)?l:"",e.innerHTML=null!=(a=null==o?void 0:o.innerHTML)?a:""}e.disabled=!1}else"error"===t?window.location.replace(x.routePath("/checkout")):console.warn("BOGOS track: Cannot define custom loading with type: ",t)}),progressEventCheckout:(t,e,...o)=>y(null,[t,e,...o],function*(t,e,o={}){var i,n,r,l,a,s;const c=!!t;let d=!0;try{null==t||t.preventDefault(),null==t||t.stopPropagation(),null==t||t.stopImmediatePropagation();const{using_draft_order:f}=null!=(i=FGSECOMAPP.fgSettings)?i:{},{checkIsBlockCheckout:_,conditions:g}=null!=(n=FGSECOMAPP.variables)?n:{},v="trigger_body"===e?null==t?void 0:t.target:null!=(r=null==t?void 0:t.currentTarget)?r:null==t?void 0:t.target,{form:p}=null!=v?v:{};if(yield N.customLoading("start",v,c),document.dispatchEvent(new CustomEvent(FGSECOMAPP.CUSTOM_EVENTS.START_VALIDATE_CHECKOUT,{detail:{}})),_&&c)return!1;FGSECOMAPP.variables.checkIsBlockCheckout=!0,H.apply_discounts_shipping("checkout").then();try{if(p&&!(null==(l=FGSECOMAPP.variables.Shopify)?void 0:l.disable_fetch_cart_checkout)){const t=new URL(p.action);t.searchParams.append("sca_checkout_form",""),new FormData(p).delete("checkout"),yield x.fetch(t.toString(),{method:"POST",body:new FormData(p)})}}catch(u){console.log("BOGOS track: not type checkout btn")}const h=null==(a=FGSECOMAPP.cartItems)?void 0:a.some(t=>x.checkCartItemIsGift(t));if(x.empty(FGSECOMAPP.offers)&&!h)return console.log("BOGOS track: not have orders and gifts"),N.reCallCheckout(v,c),!0;yield x.fetchInfoCartUpdate();const m=[...FGSECOMAPP.cartItems];let{arrGiftsRemove:b}=k.processCartWithOffers(m,FGSECOMAPP.offers,!1);if(yield k.checkAllOffers(m,FGSECOMAPP.offers),(null==b?void 0:b.length)>0)location.reload();else if(f&&!g.function&&h){const t=yield B.draftOrder(o);FGSECOMAPP.variables.checkIsBlockCheckout=!1;const{invoice_url:e}=null!=(s=null==t?void 0:t.sca_link_checkout)?s:{};x.empty(e)?(console.warn("BOGOS track: error draft-order",t),N.reCallCheckout(v,c)):(window.location.href=e,d=!1)}else console.log("BOGOS track: not using draft order"),FGSECOMAPP.variables.checkIsBlockCheckout=!1,N.reCallCheckout(v,c);yield N.customLoading("end",v,c),document.dispatchEvent(new CustomEvent(FGSECOMAPP.CUSTOM_EVENTS.END_VALIDATE_CHECKOUT,{detail:{status:"done",valid:!(null==b?void 0:b.length)}}))}catch(u){yield N.customLoading("error",null,c),document.dispatchEvent(new CustomEvent(FGSECOMAPP.CUSTOM_EVENTS.END_VALIDATE_CHECKOUT,{detail:{status:"error"}})),console.error("BOGOS track: Error process checkout",u)}return d}),handleEventCheckoutDocument:t=>y(null,null,function*(){var e;(null==(e=t.target)?void 0:e.hasAttribute("sca_handle_checkout"))&&(yield N.progressEventCheckout(t,"trigger_body"))}),bindBtn:t=>{t.addEventListener("click",N.progressEventCheckout),t.addEventListener("touchstart",N.progressEventCheckout),t.addEventListener("touchend",N.progressEventCheckout)},renderEventCheckout:()=>{var t,e;const o=null==(t=FGSECOMAPP.fgSettings)?void 0:t.mode_override_checkout,{checkout_btn_query:i}=FGSECOMAPP.QUERY_SELECTOR,n=[...null==i?void 0:i.tool,...null==i?void 0:i.integration,...null==i?void 0:i.default].filter(Boolean).join(","),r=[...document.querySelectorAll(n)];null==(e=null==i?void 0:i.tool)||e.filter(Boolean).join(", ").split(",").forEach(t=>{var e;const[o,...i]=t.trim().split(" "),n=i.join(" ");if(!o.length||!n.length)return;const l=document.querySelector(o);(null==l?void 0:l.shadowRoot)&&(N.shadowRoot.includes(o)||N.shadowRoot.push(o),null==(e=N.keepAliveObserver)||e.observe(l.shadowRoot,N.OBSERVE_OPTIONS),r.push(...l.shadowRoot.querySelectorAll(n)))}),r.forEach(t=>{var e;const i=t.hasAttribute("sca_root_checkout"),n=t.hasAttribute("sca_clone_checkout"),r=t.hasAttribute("sca_handle_checkout");let l=!0;if("clone_checkout"===o){if(i)return;if(!n&&!r){const o=t.cloneNode(!0);N.bindBtn(o),o.setAttribute("sca_handle_checkout",""),o.setAttribute("sca_clone_checkout",""),t.style.display="none",t.style.visibility="hidden",t.style.opacity="0",t.setAttribute("sca_root_checkout",""),null==(e=t.parentNode)||e.appendChild(o)}l=n}l&&N.bindBtn(t),t.setAttribute("sca_handle_checkout",""),FGSECOMAPP.variables.hasDoneProcessCheckout=!0}),"trigger_body"===o&&(window.addEventListener("click",N.handleEventCheckoutDocument,!0),N.shadowRoot.forEach(t=>{var e,o;null==(o=null==(e=document.querySelector(t))?void 0:e.shadowRoot)||o.addEventListener("click",N.handleEventCheckoutDocument,!0)}))},OBSERVE_OPTIONS:{childList:!0,subtree:!0},REBIND_THROTTLE_MS:150,rebind:()=>{N.rebindTimer||(N.renderEventCheckout(),N.rebindTimer=setTimeout(()=>{N.rebindTimer=null,N.renderEventCheckout()},N.REBIND_THROTTLE_MS))},keepAlive:()=>{!N.keepAliveObserver&&document.body&&(N.keepAliveObserver=new MutationObserver(t=>{t.some(t=>[...t.addedNodes].some(t=>1===t.nodeType&&"sca-spinner-checkout"!==t.id))&&N.rebind()}),N.keepAliveObserver.observe(document.body,N.OBSERVE_OPTIONS))},fetchEvents:()=>{var t,e;if(!(null==(e=null==(t=window.fgData)?void 0:t.offers)?void 0:e.length))return;if(N.keepAlive(),clearInterval(N.sweepTimer),FGSECOMAPP.variables.hasDoneProcessCheckout=!1,N.renderEventCheckout(),FGSECOMAPP.variables.hasDoneProcessCheckout)return;let o=0;N.sweepTimer=setInterval(()=>{N.renderEventCheckout(),(++o>10||FGSECOMAPP.variables.hasDoneProcessCheckout)&&(clearInterval(N.sweepTimer),N.sweepTimer=null)},400)},wallets:t=>y(null,null,function*(){var e;try{let{paymentsConfig:o}=FGSECOMAPP.variables;if(x.empty(o)&&(o=(yield x.fetch("/payments/config?bogos").then(t=>t.json()))||{paymentInstruments:{accessToken:null}},FGSECOMAPP.variables.paymentsConfig=o),x.empty(t))return x.empty(o);const{country:i,currency:n}=FGSECOMAPP.variables.Shopify;return yield x.fetchCartDefault(),yield x.fetch("/wallets/checkouts/?bogos",{method:"POST",headers:{accept:"*/*",authorization:"Basic ".concat(window.btoa(null==(e=null==o?void 0:o.paymentInstruments)?void 0:e.accessToken)),"cache-control":"no-cache","content-type":"application/json",pragma:"no-cache"},body:JSON.stringify({checkout:b(m({},t),{country:i,presentment_currency:null==n?void 0:n.active,line_items:FGSECOMAPP.SHOPIFY_CART.items})})}),!0}catch(o){return console.warn("BOGOS track: wallets/config",o),!1}}),init:()=>{window.addEventListener("pageshow",()=>{N.fetchEvents()}),setTimeout(()=>{FGSECOMAPP.variables.hasDoneProcessCheckout&&N.fetchEvents()})}},H=b(m({},s),{apply_discounts_shipping:(...t)=>y(null,[...t],function*(t="cart",e=[]){var o;const i=(null!=(o=FGSECOMAPP.variables.bogos_shipping_discounts)?o:[]).sort().toString();FGSECOMAPP.variables.bogos_shipping_discounts=FGSECOMAPP.offers.filter(t=>t.is_offer_shipping&&t.isReachConditions).map(t=>{var e;return null==(e=t.shopify_discount_settings)?void 0:e.code}).filter(Boolean).sort(),("checkout"===t||i!==FGSECOMAPP.variables.bogos_shipping_discounts.toString())&&((null==e?void 0:e.length)?yield s.apply_discounts([...FGSECOMAPP.variables.bogos_shipping_discounts,...e],!0):s.apply_discounts([...FGSECOMAPP.variables.bogos_shipping_discounts,...e],!0))}),apply_gift_discounts:(...t)=>y(null,[...t],function*(t=[]){Array.isArray(t)&&(yield H.apply_discounts_shipping(t.length?"checkout":"cart",t))})}),B=b(m({},n),{getInfoProducts:(t,e)=>y(null,null,function*(){yield B.fetch({sca_products_handle:x.convertObjToString(t,"uri")},e).then(t=>y(null,null,function*(){var e,o;const i=yield t.json(),n=[],{currency:r}=FGSECOMAPP.variables.Shopify,l=(null!=(e=i.currency)?e:"USD")!==(null==r?void 0:r.active);null==(o=null==i?void 0:i.products)||o.forEach(t=>{var e;if(x.empty(null==(e=null==t?void 0:t.products)?void 0:e.id))return;const{products:o,collections:i}=t;n.push(b(m({},l?B.convertProductCurrency(o):o),{collections:i}))});const a=R.filterOfferToGiftThumbnail(n);R.renderGiftIconForProducts(a)})).catch(t=>{console.warn("BOGOS track: getInfoProductsByProxy",t)})}),draftOrder:t=>y(null,null,function*(){var e,o,i,n,r,l,a,s;try{const{shop:c,currency:d,add_cart_attributes:u,add_cart_discounts:f,country:_}=FGSECOMAPP.variables.Shopify;let g=yield B.fetch({sca_shop_name:c}).then(t=>t.json()),v=[];return u&&(v=Object.entries(g.cart_attributes).map(([t,e])=>({key:t,value:"".concat(e)}))),g.cart=(null!=(e=g.cart)?e:[]).map(t=>{var e,o,i;t.product.collections=null==(e=t.collections)?void 0:e.map(t=>({id:t.id})),t.product.tags=t.tags;const n=null!=(o=FGSECOMAPP.fgSettings.draft_order)?o:{},r=n.discount_code||f&&"boolean"!=typeof n.discount_code?t.product.discounts:[],l=Object.entries(null!=(i=t.product.properties)?i:{}).map(([t,e])=>({key:t,value:"".concat(e)}));return{id:t.product.id,variant_id:t.product.variant_id,product_id:t.product.product_id,title:t.product.title,handle:t.product.handle,price:k.priceCartItem(t.product),quantity:t.product.quantity,product_type:t.product.product_type,vendor:t.product.vendor,tags:t.product.tags,collections:t.product.collections,selling_plan_allocation:t.product.selling_plan_allocation,discounts:r,properties:l,fingerprint:{key:t.product.key,quantity:t.product.quantity,original_price:t.product.original_price,price:t.product.price,final_price:t.product.final_price}}}),g.others={secomapp:{customer:null!=(o=null==SECOMAPP?void 0:SECOMAPP.customer)?o:{},fg_codes:null!=(i=null==SECOMAPP?void 0:SECOMAPP.fg_codes)?i:[],fgSettings:FGSECOMAPP.fgSettings},cookie_fg_code:FGSECOMAPP.variables.sca_fg_codes,shopify_currency:d,customer_location:FGSECOMAPP.customerLocation||_,cart_attributes:[...v,...null!=(n=null==t?void 0:t.cart_attributes)?n:[]],cart_note:null!=(r=null==t?void 0:t.note)?r:"",arr_offer_added:j.isSpecificOffer?void 0:FGSECOMAPP.arrOfferAdded,max_priority_draft_order:FGSECOMAPP.variables.maxTodayOfferPriority,offers_in_time:[...new Set(FGSECOMAPP.offers.map(t=>Number(t.offer_root)))],other_discount:[...null!=(l=FGSECOMAPP.variables.bogos_shipping_discounts)?l:[],...null!=(a=FGSECOMAPP.variables.bogos_other_discounts)?a:[]],market:null!=(s=SECOMAPP.market)?s:{}},(yield B.fetch({data_checkout:x.convertObjToString(g,"uri")},{is_post:!0}).then(t=>t.json()))||{sca_link_checkout:null}}catch(c){return{error:c.message}}})}),{fetch:V}=window,j={isSpecificOffer:!1,hasValidUpdates:(t,e)=>{try{const o=null==t?void 0:t.includes("/update");if(!t||!e||!o)return!0;const i=t=>"discount"===t||/^updates(\[|$)/.test(t),n=t=>[...t].some(i);if(e instanceof FormData||e instanceof URLSearchParams)return n(e.keys());if("string"==typeof e){const t=e.trim();if(!t)return!1;if(t.startsWith("{")||t.startsWith("[")){const e=JSON.parse(t);return!x.empty(null==e?void 0:e.updates)||(null==e?void 0:e.hasOwnProperty("discount"))}return n(new URLSearchParams(t).keys())}return!0}catch(o){return console.warn("BOGOS track: Error check valid updates",t,e,o),!0}},overrideFetch:()=>{var t;const{disable_override_fetch:e}=FGSECOMAPP.variables.Shopify,{isCheckout:o,isHeadless:i}=null!=(t=FGSECOMAPP.variables)?t:{};o||i||e||(window.fetch=function(){return y(this,arguments,function*(){var t,e,o,i,n,r,l;const a=arguments[0],s=V.apply(this,arguments);"string"==typeof a&&/\/cart\/(add|change|update|clear)/.test(a)&&!a.includes("_bogos-ignore")&&k.markCartWrite(a,s);const c=!(null==(t=FGSECOMAPP.offers)?void 0:t.length);try{const t="string"==typeof arguments[0]&&arguments[0],a="string"==typeof(null==(e=arguments[1])?void 0:e.body)&&(null==(o=arguments[1])?void 0:o.body),d=null==(i=arguments[1])?void 0:i.body,f=u.cart.test(null!=t?t:""),_=(null==(n=null==t?void 0:t.includes)?void 0:n.call(t,"graphql.json"))&&u.graphql.test(null!=a?a:"");if(f||_){const e=["_bogos-ignore"].some(e=>t.includes(e)),o=f?t.match(u.cart):a.match(u.graphql),i=j.hasValidUpdates(t,d),n=()=>s.then(function(t){return y(this,null,function*(){!e&&t.ok&&(yield k.checkEventCart(["fetch-override:".concat(null==o?void 0:o[0])],null,i))})});(null==(l=null==(r=null==FGSECOMAPP?void 0:FGSECOMAPP.variables)?void 0:r.Shopify)?void 0:l.disable_async_process_fg)||!i||c?n().then():yield n()}document.dispatchEvent(new CustomEvent(FGSECOMAPP.CUSTOM_EVENTS.FG_OVERRIDE_FETCH))}catch(d){console.warn("BOGOS track: fetch override error",d)}return s})})},listenAPI:()=>{const t=x.debounce(()=>{R.renderElementGiftIconCollectionPage().then()},1e3);new PerformanceObserver(e=>{let o=!1;e.getEntries().forEach(t=>{var e,i,n;const{initiatorType:r,name:l,responseStatus:a}=t,s=["xmlhttprequest","fetch"].includes(r),c=["sca_attr_cart","_bogos-ignore","bogos_discount"].some(t=>l.includes(t));if(!(a>=400)){if(s&&!c&&u.cart.test(l)){const o=null==(e=l.match(u.cart))?void 0:e[0];!k.takeCartWrite(t)&&k.checkEventCart(["observer:".concat(o)]).then()}(null==(n=null==(i=null==window?void 0:window.Spurit)?void 0:i.global)?void 0:n.loaded)&&document.querySelector("#occ3-drawer .spurit-occ3__slide-drawer")&&(FGSECOMAPP.renderPromotionMessage(),FGSECOMAPP.fetchCheckoutEvents()),o||(o=s&&!l.includes(SECOMAPP.freegiftProxy)&&!l.includes("sca_products_handle"))}}),o&&t()}).observe({entryTypes:["resource"]}),document.addEventListener(FGSECOMAPP.CUSTOM_EVENTS.ACCELIO_END_RENDER_APP,()=>{var t,e;const{gift_slider_query:o}=null!=(t=FGSECOMAPP.QUERY_SELECTOR)?t:{};(null==(e=null==o?void 0:o.tool)?void 0:e.filter(Boolean).some(t=>t.includes("accelio")))&&document.dispatchEvent(new CustomEvent(FGSECOMAPP.CUSTOM_EVENTS.BOGOS_FG_PROCESS)),R.renderPromotionMessage()})},shopify_getCart:()=>{var t,e;try{if(null==(t=FGSECOMAPP.variables.Shopify)?void 0:t.disableShopify_getCart)return;if("function"!=typeof(null==Shopify?void 0:Shopify.getCart))return;Shopify.getCart=function(t){return y(this,null,function*(){if(!FGSECOMAPP.variables.secomappGetCartRunning){FGSECOMAPP.variables.secomappGetCartRunning=!0,yield k.checkEventCart(["Shopify.getCart",{}]);const e=yield x.fetchCartDefault("sca_cart_xhr");"function"==typeof t&&(FGSECOMAPP.variables.fgCallback.push(t),t(e)),FGSECOMAPP.variables.secomappGetCartRunning=!1}FGSECOMAPP.fetchCheckoutEvents()})},"undefined"!=typeof ShopifyAPI&&void 0!==ShopifyAPI.getCart&&(ShopifyAPI.getCart=null==Shopify?void 0:Shopify.getCart),void 0!==(null==Shopify?void 0:Shopify.api)&&void 0!==(null==(e=null==Shopify?void 0:Shopify.api)?void 0:e.getCart)&&(Shopify.api.getCart=null==Shopify?void 0:Shopify.getCart)}catch(o){console.warn("BOGOS track: initializeForXHR Shopify.getCart",o)}},createGlobalVariables:()=>{var t,e,o,i,n;const{cart_and_checkout_validation:r,offer_process:l}=null!=(t=FGSECOMAPP.fgSettings)?t:{};j.isSpecificOffer=(null==r?void 0:r.offer)||l===f.OFFER_TYPE.function,null==(o=null==(e=window.fgData)?void 0:e.offers)||o.forEach(t=>{var e,o,i,n,r,a,s,c,d,u,_,g;FGSECOMAPP.variables.giftIds=FGSECOMAPP.variables.giftIds.concat(t.gift_items.map(t=>t.variant_shopify_id)),FGSECOMAPP.variables.gifts.originalProducts=FGSECOMAPP.variables.gifts.originalProducts.concat(t.gift_products.map(t=>t.original_product_shopify_id)),l!==f.OFFER_TYPE.function&&(FGSECOMAPP.variables.gifts.clonedProducts=FGSECOMAPP.variables.gifts.clonedProducts.concat(t.gift_products.map(t=>t.product_shopify_id))),(o=FGSECOMAPP.variables.conditions).locations||(o.locations=!x.empty(null==(e=t.sub_conditions)?void 0:e.customer_locations)),(u=FGSECOMAPP.variables.conditions).collections||(u.collections=null!=(a=null==(r=null==(n=null==(i=t.offer_conditions)?void 0:i[0])?void 0:n.product_narrow)?void 0:r.some(t=>t.type===f.NARROW_TYPE.collection))&&a||(null==(d=null==(c=null==(s=null==t?void 0:t.sub_conditions)?void 0:s.product_quantity_limits)?void 0:c.rules)?void 0:d.some(t=>{var e,o;return null!=(o=null==(e=null==t?void 0:t.product_narrow)?void 0:e.some(t=>(null==t?void 0:t.type)===f.NARROW_TYPE.collection))&&o})));const v=t.gift_settings.discount_method===f.DISCOUNT_TYPE.shipping;(_=FGSECOMAPP.variables.conditions).shipping||(_.shipping=v),v&&FGSECOMAPP.variables.gifts.offers_shipping.push(t.id.toString()),FGSECOMAPP.variables.gifts.offer_codes[t.id.toString()]=null==(g=t.sub_conditions)?void 0:g.specific_link_address}),FGSECOMAPP.variables.giftIds=[...new Set(FGSECOMAPP.variables.giftIds)].filter(Boolean),FGSECOMAPP.variables.gifts.originalProducts=[...new Set(FGSECOMAPP.variables.gifts.originalProducts)].filter(Boolean),FGSECOMAPP.variables.gifts.clonedProducts=[...new Set(FGSECOMAPP.variables.gifts.clonedProducts)].filter(Boolean),(null==(i=window.BOGOS_CORE)?void 0:i.helper)&&(BOGOS_CORE.helper.gift={renderCustomizeForProduct:R.renderCustomizeForProduct,prepareCheckout:()=>y(null,null,function*(){return yield k.checkEventCart(["bogos:checkout"])}),checkItemIsGift:x.checkCartItemIsGift}),FGSECOMAPP.helper=b(m({},FGSECOMAPP.helper),{initializeForXHR:j.shopify_getCart,customLoadingCheckout:N.customLoading,fetchCheckoutEvents:N.fetchEvents,renderPromotionMessage:R.renderPromotionMessage,renderProductPage:R.renderProductPage,addGiftToCart:k.handleAddGift,progressBogosCheckout:N.progressEventCheckout}),FGSECOMAPP.fetchCheckoutEvents=N.fetchEvents,FGSECOMAPP.renderPromotionMessage=R.renderPromotionMessage,FGSECOMAPP.variables.isCheckout="fg-checkout"===(null==(n=document.querySelector("#secomapp_freegifts_version"))?void 0:n.getAttribute("data-template")),FGSECOMAPP.variables.conditions.function=l===f.OFFER_TYPE.function,document.addEventListener(FGSECOMAPP.CUSTOM_EVENTS.BOGOS_FG_PROCESS,t=>{x.debounce(()=>y(null,null,function*(){var e,o,i,n;if(j.processing)return;j.processing=!0;const r=c.convertStorefrontCart({data:{cart:null==(e=t.detail)?void 0:e.cart}},!0);yield k.checkEventCart([null!=(i=null==(o=t.detail)?void 0:o.event)?i:"bogos:gifts"],null==(n=null==r?void 0:r.shopify_cart)?void 0:n.items).then(),j.processing=!1}),250)()}),document.addEventListener(FGSECOMAPP.CUSTOM_EVENTS.BOGOS_FG_INIT,()=>{k.init("bogos:rollback",null,!0).then()}),document.addEventListener(FGSECOMAPP.CUSTOM_EVENTS.BOGOS_FG_CART_MESSAGE,()=>R.renderPromotionMessage()),document.addEventListener(FGSECOMAPP.CUSTOM_EVENTS.RERENDER_GIFT_SLIDER,()=>{var t;const{general:e}=null==(t=FGSECOMAPP.fgAppearance)?void 0:t.gift_slider,o=!1===(null==e?void 0:e.use_old_version)?".bogos-offer-gift-items-container":".bogos-gift-items";document.querySelectorAll(o).forEach(t=>{const e=parseInt(t.getAttribute("data-show-desktop"));R.renderGlider(t,isNaN(e)?4:e)})})},init:()=>y(null,null,function*(){j.createGlobalVariables(),x.guardTemplateRender(),x.safeTextView(),R.applyGiftSliderVars(),R.applyTodayOfferVars(),N.init(),yield k.init("init-page",()=>{j.listenAPI(),j.overrideFetch(),j.shopify_getCart()}),R.init(),setTimeout(()=>{R.renderPromotionMessage()},2e3)})};j.init().then()}()})();