(()=>{(function(){let{proxy:V,integration:k,utils:Y,customize:Q,shopifyFunc:x}=window.FGSECOMAPP?.helper||{};FGSECOMAPP.variables={...FGSECOMAPP.variables,conditions:{collections:!1,locations:!1,function:!1},scaHandleConfigValue:{...Shopify?.scaHandleConfigValue},isCheckout:!1,isCartPage:window.location.href.includes("/cart"),paymentsConfig:null,failedParseArrOffersAdded:!1,secomappGetCartRunning:!1,fgCallback:[],scaCountRenderEventCheckout:0,checkIsBlockCheckout:!1,hasDoneProcessCheckout:!1,giftIds:[],gifts:{originalProducts:[],clonedProducts:[]},giftIdsFunction:[],maxOfferPriority:null,maxTodayOfferPriority:null,sections_cart:{}},FGSECOMAPP.CUSTOM_EVENTS={...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"},FGSECOMAPP.helper.scaCustomLoadingCheckout=Shopify?.scaCustomLoadingCheckout??void 0;let R={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(`/(${SECOMAPP.freegiftProxy})/g`),graphql:new RegExp(/(cartLinesRemove|cartLinesUpdate|cartLinesAdd)/g)},T={OFFER_TYPE:{cloned:"cloned",function:"function",gift_func:"gift"},JUDGEME_OPTION:{bundle:"bundle",gift_slider:"gift_slider"},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"},SYNC_QUANTITY:{stop_offer:"stop_offer"},OBJECT_TYPE:{product:"product",variant:"variant"}};T.TRIGGER_FUNC={[T.OFFER_TYPE.gift_func]:"GF"};let P={GIFTS_CART_SECTION_ID:"#sca_fg_cart_section_gifts_slider",GIFTS_CART_SECTION:`
{{ fg_slider_title }}
{{ sca_fg_disable_slider_section }}
`,GIFTS_CART_SECTION_V2_ID:"#bogos_cart_section_gifts_slider",GIFTS_CART_SECTION_V2:`
{{fg_slider_title}}
{{bogos_slider_offer_available}}
{{bogos_brand_mark}}
`,GIFTS_POPUP_SECTION_ID:"#sca_fg_section_gifts_popup",GIFTS_POPUP_SECTION:`
{{ fg_slider_title }}
{{ sca_fg_disable_slider_section }}
`,GIFTS_POPUP_SECTION_V2_ID:"#bogos_section_gifts_popup",GIFTS_POPUP_SECTION_V2:`
{{fg_slider_title}}
{{bogos_slider_offer_available}}
{{bogos_brand_mark}}
`,GIFT_OFFER_SECTION_ID:"#bogos_section_slider_offer",GIFT_OFFER_SECTION:`
{{ bogos_offer_title }}
{{ bogos_number_gift_available }}
{{ sca_fg_disable_slider_section }}
`,GIFT_ITEM_SECTION_ID:"#sca_fg_section_gift_item",GIFT_ITEM_SECTION:`
{{ bogos_integration_judgeme }}
{{ fg_original_price }} {{ fg_gift_price }}
`,GIFT_ITEM_SECTION_V2_ID:"#bogos_section_gift_item",GIFT_ITEM_SECTION_V2:`
{{ fg_product_title }}
{{ bogos_default_select_variant_title }}
    {{ sca_fg_variant_select_section }}
{{ fg_variant_title }} {{ bogos_integration_judgeme }}
{{ fg_gift_price }} {{ fg_original_price }}
    {{ bogos_gift_quantity_options }}
`,GIFT_SELECT_SECTION_ID:"#sca_fg_variant_select_section",GIFT_SELECT_SECTION:`
  • {{ fg_variant_title }}
  • `,GIFT_SELECT_SECTION_V2_ID:"#bogos_variant_select_section",GIFT_SELECT_SECTION_V2:`
  • {{ fg_variant_title }}
  • `,DISABLE_SLIDER_SECTION_ID:"#sca_fg_disable_slider_section",DISABLE_SLIDER_SECTION:`
    {{ fg_text_disable_slider }}
    `,CART_MSG_SECTION_ID:"#sca_fg_cart_message_section",CART_MSG_SECTION:`
    {{ sca_fg_cart_message_items_section }}
    `,CART_MSG_ITEM_SECTION_ID:"#sca_fg_cart_message_items_section",CART_MSG_ITEM_SECTION:`

    {{ fg_cart_message }}

    `,OLD_GIFT_THUMBNAIL_SECTION_ID:"#sca_fg_gift_thumbnail_section",OLD_GIFT_THUMBNAIL_SECTION:`
    {{ fg_gift_thumbnail_title }}
    {{ sca_fg_gift_thumbnail_items_section }}
    \xAB \xBB
    `,OLD_GIFT_THUMBNAIL_ITEMS_SECTION_ID:"#sca_fg_gift_thumbnail_items_section",OLD_GIFT_THUMBNAIL_ITEMS_SECTION:`
    {{ fg_product_img_alt }}
    `,GIFT_THUMBNAIL_SECTION_ID:"#sca_new_fg_gift_thumbnail_section",GIFT_THUMBNAIL_SECTION:'
    {{ fg_gift_thumbnail_section }}
    ',GIFT_THUMBNAIL_ITEMS_SECTION_ID:"#sca_new_fg_gift_thumbnail_items_section",GIFT_THUMBNAIL_ITEMS_SECTION:`
    {{ fg_offer_time_title }}
    {{ fg_offer_time_detail }}
    {{ fg_offer_title }}
    {{ fg_offer_body }}
    `,GIFT_THUMBNAIL_SUB_ITEMS_SECTION_ID:"#sca_new_fg_gift_thumbnail_sub_items_section",GIFT_THUMBNAIL_SUB_ITEMS_SECTION:`
    {{ fg_product_img_alt }}
    `,GIFT_THUMBNAIL_ITEMS_EXPIRED:`
    {{ fg_time_day }}
    :
    {{ fg_time_hour }}
    :
    {{ fg_time_minutes }}
    :
    {{ fg_time_second }}
    `,GIFT_ICON_SECTION_ID:"#sca_fg_gift_icon_section",GIFT_ICON_SECTION:'{{ fg_gift_icon_alt }}',TODAY_OFFER_SECTION_ID:"#sca_fg_today_offer_section",TODAY_OFFER_SECTION:`
    {{ sca_fg_today_offer_title }}
    {{ sca_fg_today_offer_subtitle }}
    `,TODAY_OFFER_ITEM_SECTION_ID:"#sca_fg_today_offer_item_section",TODAY_OFFER_ITEM_SECTION:`
    {{ bogos_today_offer_header }}
    {{ bogos_today_offer_gift_products }}
    {{ bogos_more_gift_product }}
    `,TODAY_OFFER_ITEM_HEADER_SECTION_ID:"#bogos_today_offer_item_header_section",TODAY_OFFER_ITEM_HEADER_SECTION:`
    {{ sca_fg_offer_title }} {{ sca_fg_offer_subtitle }}
    {{ bogos_offer_link_title }}
    `,TODAY_OFFER_ITEM_HEADER_WITH_IMG_SECTION_ID:"#bogos_today_offer_item_header_with_img_section",TODAY_OFFER_ITEM_HEADER_WITH_IMG_SECTION:`
    {{ sca_fg_offer_title }} {{ sca_fg_offer_subtitle }}
    {{ bogos_offer_link_title }}
    `,TODAY_OFFER_GIFT_PRODUCT_ID:"#bogos_today_offer_gift_product",TODAY_OFFER_GIFT_PRODUCT:`
    {{ 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 }}
    `,TODAY_OFFER_WIDGET_ID:"#sca_fg_today_offer_widget",TODAY_OFFER_WIDGET:`fg-widget-today-offer {{ sca-fg-title-icon-widget-content }} `},y={addToCart:(e,t,i)=>{let a=T.OFFER_TYPE.gift_func,s=i.map(o=>{let{bogos_item_properties:l}=FGSECOMAPP.variables.Shopify??{},_=l?.offers?.[o.offer_root]?.[o.variant_id]??l?.[o.variant_id],r=q.isSpecificOffer?{_bogos_trigger_id:o.offer_root,_bogos_trigger:`${T.TRIGGER_FUNC[a]}_${o.offer_root}`,_bogos_trigger_type:a}:{};return{quantity:o.quantity,id:o.variant_id,properties:{...r,..._}}});return(t?.sca_add_gift?window.fetch:d.fetch)(e,{method:"POST",headers:{"X-Requested-With":"XMLHttpRequest",Accept:"application/json","Content-Type":"application/json",...t},body:JSON.stringify({items:s,...y.cartAttributes()})})},handleAddGift:async(e,t,i)=>{try{i=`${i}`;let a=FGSECOMAPP.offers.find(_=>i===_.id),c=a.type===T.OFFER_TYPE.function?a.shopify_discount_settings?.code:null;console.info(`BOGOS track: add gift from slider {${e}} {${i}} {${a.type}}`);let o=FGSECOMAPP.arrOfferAdded.find(_=>i===_.belongs_to_offer?.toString()&&e===_.variant_id);o?o.quantity+=t:FGSECOMAPP.arrOfferAdded.unshift({variant_id:e,belongs_to_offer:i,quantity:t,code:c}),localStorage.setItem(FGSECOMAPP.variables.constants.sca_offers_added,d.convertObjToString(FGSECOMAPP.arrOfferAdded)),y.renderEventLoading("start");let l=await y.addToCart(`${FGSECOMAPP.variables.Shopify?.sca_add_url??"/cart/add.js"}?sca_add_gift`,{sca_add_gift:1},[{quantity:t,variant_id:e,offer_root:a.offer_root,offer_id:a.id}]);return l.ok&&await x.apply_discounts([c]),l.ok}catch{return!1}},addGiftToCart:async(e,t,i)=>{let{general:a}=FGSECOMAPP.fgAppearance?.gift_slider;i=i?.toString();let s=document.querySelector(`#fg-gift-items .btn-add-to-cart[data-variant='${e}']`),c=await y.handleAddGift(e,t,i);if(c){s&&s.classList.remove("bogos-gift-adding"),s&&s.classList.add("bogos-gift-added"),v.renderSuccessAddGift(),await y.refreshCart([],!0);let{use_old_version:o,show_gift_type:l}=a??{};o===!1&&y.handleQuantityGiftAvailableSession("set",t,l==="offer"?i.split("_")[0]:void 0)}else s&&(s.innerHTML="Out of stock");document.dispatchEvent(new CustomEvent(FGSECOMAPP.CUSTOM_EVENTS.GIFT_ADDED,{detail:{gift:c}}))},processGiftsToCart:async(e,t,i)=>{try{let a=JSON.stringify(FGSECOMAPP.arrOfferAdded)!==i;if(d.empty(e)&&d.empty(t)&&!a)return!1;let s={},c={};FGSECOMAPP.cartItems?.filter(n=>d.checkCartItemIsGift(n))?.forEach(n=>{c[`${n.variant_id}_${n.properties?._bogos_trigger_id}`]={key:n.key,variant_id:n.variant_id,offer_id:n.properties?._bogos_trigger_id,offer_root:n.properties?._bogos_trigger_id,quantity:n.quantity},n.properties?._bogos_trigger_id&&n.key&&(s[n.key]=n.quantity)}),e=e?.filter(n=>!d.empty(n.variant_id)),e?.forEach(n=>{let f=c[`${n.variant_id}_${n.offer_root}`]??{};c[`${n.variant_id}_${n.offer_root}`]={...f,...n,quantity:(f.quantity??0)+(n.quantity??1)}}),Object.keys(c)?.forEach(n=>{if(c[n]={...c[n],quantity:Math.max(c[n].quantity,0)},!q.isSpecificOffer){let f=c[n]?.variant_id;s[f]=c[n]?.quantity+(s[f]??0),delete c[n];return}c[n]?.key&&(s[c[n]?.key]=c[n]?.quantity,delete c[n])});let o=!d.empty(s)||!d.empty(c);if(!o&&!a)return!1;e?.forEach(n=>{let f=FGSECOMAPP.arrOfferAdded.find(g=>n.offer_id?.toString()===g.belongs_to_offer?.toString()&&n.variant_id===g.variant_id);f?f.quantity+=n.quantity:FGSECOMAPP.arrOfferAdded.unshift({variant_id:n.variant_id,belongs_to_offer:n.offer_id?.toString(),quantity:n.quantity,code:n.type===T.OFFER_TYPE.function?n.code:null})}),localStorage.setItem(FGSECOMAPP.variables.constants.sca_offers_added,d.convertObjToString(FGSECOMAPP.arrOfferAdded)),y.renderEventLoading("start");let l=!1,_=!d.empty(c),r=o?`sca_process_gifts${_?"_bogos-ignore":""}`:a?"sca_attr_cart":"sca_none";return(!d.empty(s)||a)&&await d.fetch(`${FGSECOMAPP.variables.Shopify?.sca_update_url??"/cart/update"}?${r}`,{method:"POST",headers:{"X-Requested-With":"XMLHttpRequest",Accept:"application/json","Content-Type":"application/json",sca_process_gifts:"1"},body:JSON.stringify({updates:s,...y.cartAttributes()})}).then(n=>l||=n.ok),_&&await y.addToCart(`${FGSECOMAPP.variables.Shopify?.sca_add_url??"/cart/add"}?${r.replace("_bogos-ignore","")}`,{sca_process_gifts:1},Object.values(c)).then(n=>l||=n.ok),_&&await x.apply_discounts(FGSECOMAPP.arrOfferAdded.map(n=>n.code).filter(Boolean)),l&&e.length&&v.renderSuccessAddGift(),document.dispatchEvent(new CustomEvent(FGSECOMAPP.CUSTOM_EVENTS.CART_AUTO_UPDATED,{detail:{arrGiftsAdd:e,arrGiftsRemove:t}})),FGSECOMAPP.variables.isCheckout&&location.reload(),l}catch(a){return y.renderEventLoading("end"),console.error("BOGOS track: Error processGiftsToCart",a),!1}},renderEventLoading:e=>{try{if(!FGSECOMAPP.variables.Shopify?.enable_process_offer_loading)return;let{checkout_btn_query:t}=FGSECOMAPP.QUERY_SELECTOR,i=[...t?.tool,...t?.integration,...t?.default].filter(Boolean).join(",");document.querySelectorAll(i).forEach(a=>{G.customLoading(e,a).then()})}catch{}},cartAttributes:()=>{if(FGSECOMAPP.variables.Shopify?.do_not_add_freegift_attribute)return;let e=[];if(!d.empty(FGSECOMAPP.arrOfferAdded)){e.push("SECOMAPP_FREEGIFT");let{bogos_item_properties:t}=FGSECOMAPP.variables.Shopify??{};e.push(...t?.cart??[]);for(let i of FGSECOMAPP.arrOfferAdded){let{sub_conditions:a}=FGSECOMAPP.offers.find(c=>c.id===i.belongs_to_offer)??{},{specific_link_address:s}=a??{};d.empty(s)||e.push(s)}}return{attributes:{__freegift_attributes:e.toString(),__bogos_tracking:d.aggregateArrOfferAddedIds(FGSECOMAPP.arrOfferAdded)?.sort().join("-")}}},priceCartItem:e=>{let{final_price:t,price:i}=e??{};try{return e[FGSECOMAPP.variables.Shopify?.sca_fg_price]??t??i}catch{return t??i}},filterProductsSatisfyPackOfProducts:(e,t,i)=>{let a=t.product_narrow[0]??{track_pack_type:null},s=a.track_pack_type;if(d.empty(s))return e;let c=!0,o=[],l=Object.values(a.value);s==="variant"&&(l=l.map(n=>n.variants??n.variant).flat());let _=s==="variant"?"variant_id":"product_id",r=e.reduce((n,f)=>{let g=f[_],u=n[g]??0;return n[g]=u+f.quantity,n},{});for(let n of l){let f=r[n.id]??0;if(n.quantity>f){c=!1,o=[];break}o.push(Math.floor(f/n.quantity))}return i.multiply_max=0,c?(i.multiply_max=o.length>0?Math.min(...o):0,e):[]},filterProductsMatchConditionsWithCalculateForOtherRules:(e,t)=>e?.map(i=>{if(typeof i.cal_gift_for_other_rules<"u"){let a=FGSECOMAPP.arrOfferAdded?.filter(c=>c.variant_id===i.variant_id);if(a?.reduce((c,o)=>c+o.quantity,0)===i.quantity){let c=a?.filter(o=>{if(o.belongs_to_offer?.toString()===t.toString())return!1;let _=(FGSECOMAPP.offers?.find(n=>n.id?.toString()===o.belongs_to_offer?.toString())).gift_settings??{},r=y.priceCartItem(i);return _.cal_gift_for_other_rules&&r>0})?.reduce((o,l)=>o+l.quantity,0);return{...i,cal_gift_for_other_rules:c>0,quantity:c??0}}return{...i,cal_gift_for_other_rules:!1,quantity:0}}return{...i}})??[],filterProductsMatchConditionsWithSettings:(e,t,i,a)=>{let s=FGSECOMAPP.fgSettings?.compare_gift_price_with_product,c=FGSECOMAPP.fgSettings?.not_show_gift_if_already_on_cart;a??=FGSECOMAPP.cartItems;let o=e,l=i.gift_products?.map(f=>f.original_product_shopify_id);if(c){let f=o.filter(u=>!d.checkCartItemIsGift(u)),g=l.filter(u=>f.every(m=>m.product_id!==u));o=g.length?o.filter(u=>!g?.includes(u.product_id)):[]}let _=o;if(s){o=e.sort((b,S)=>y.priceCartItem(b)-y.priceCartItem(S));let f=i.gift_items.map(b=>b?.compare_gift_price??0);o=o.filter(b=>f.some(S=>S<=y.priceCartItem(b)/100)),_=JSON.parse(JSON.stringify(o));let g=i.giftsAdded.sort((b,S)=>S?.compare_gift_price-b?.compare_gift_price).map(b=>({...b})),u=g.reduce((b,S)=>b+S.quantity,0),m=y.calculateMaxGifts(o,t,i),p=Math.max(m-u,0),h=t.is_multiply?i.gift_settings.number_of_gift_can_receive:1;if(_.filter(b=>b.quantity>0).forEach(b=>{b.quantity*=h;let S=y.priceCartItem(b)/100;g.filter(C=>C.quantity>0&&C?.compare_gift_price<=S).forEach(C=>{if(!b.quantity)return 0;let E=b.quantity-C.quantity;C.quantity=Math.max(-E,0),b.quantity=Math.max(E,0)})}),i.giftsAddedInvalid=g.filter(b=>b.quantity>0),!t.is_multiply&&p>0){let[b]=_.slice(-1);!d.empty(b)&&(b.quantity+=p)}_=_.filter(b=>b.quantity>0)}o=o.filter(f=>f.quantity>0);let r=a.map(f=>f.product_id),n=[];return FGSECOMAPP.fgSettings?.select_one_gift_price&&(n=a.filter(f=>d.checkCartItemIsGift(f)).map(f=>f.variant_id)),i.gifts_valid=JSON.parse(JSON.stringify(i.gift_products))?.filter(f=>(f.variants=f.variants.filter(g=>!n.includes(g.variant_shopify_id)),c&&r?.includes(f.original_product_shopify_id)?!1:(s&&(f.variants=f.variants.filter(g=>_.some(u=>g.compare_gift_price<=y.priceCartItem(u)/100))),!d.empty(f.variants)))),o},countTotalMoneyAmount:e=>e.filter(t=>t.cal_gift_for_other_rules===void 0||t.cal_gift_for_other_rules===!0).reduce((t,i)=>t+i.quantity*y.priceCartItem(i),0)/100,countTotalProducts:e=>e.filter(t=>t.cal_gift_for_other_rules===void 0||t.cal_gift_for_other_rules).reduce((t,i)=>t+i.quantity,0),calculateMaxGifts:(e,t,i)=>{let a=0,s=0;if(t.unit==="money"?(s=y.countTotalMoneyAmount(e),i.count_down_value=Math.max(t.min_amount-s,0)):t.unit==="number_of_products"&&(s=y.countTotalProducts(e),i.count_down_quantity=Math.max(t.min_amount-s,0)),s>=t.min_amount&&(t.max_amount===null||s<=t.max_amount)){let c=i.multiply_max??Math.floor(s*100/(t.min_amount*100));a=i.gift_settings.number_of_gift_can_receive*(t.is_multiply?c:1)}return a},countMaxGiftsCanGet:(e,t,i)=>{let a=d.findProductsMatchConditions(t,e,i.sub_conditions?.subscription_products);return a=y.filterProductsMatchConditionsWithCalculateForOtherRules(a,e.offer_id),a=y.filterProductsMatchConditionsWithSettings(a,e,i,t),a=y.filterProductsSatisfyPackOfProducts(a,e,i),y.calculateMaxGifts(a,e,i)},checkEachConditionList:(e,t)=>{let i={},a=[],s=0;return t.offer_conditions.map(c=>{let o=y.countMaxGiftsCanGet(c,e,t);o!==0&&(s=o),a.push(o>0)}),i.max_gifts_can_get=s,i.condition_result=a,i},isSatisfyCondition:(e,t)=>{let i=!1;return e.length===1?i=e[0]:e.length===2&&(t==="and"&&(i=e[0]&&e[1]),t==="or"&&(i=e[0]||e[1])),i},countGiftAvailableFromOffer:(e,t)=>{let i=y.checkGiftAlreadyAddedToCart(e,t);t.giftsAdded=i;let a=y.checkEachConditionList(e,t),s=y.isSatisfyCondition(a.condition_result,t.condition_relationship);if(s){let c=i.filter(o=>o.belongs_to_offer?.toString()===t.id?.toString()).reduce((o,l)=>o+l.quantity,0);a.max_gifts_can_get=a.max_gifts_can_get-c,t.giftsAdded=i,t.giftsAvailable=a.max_gifts_can_get}else t.giftsAdded=i,t.giftsAvailable=0;return!d.empty(FGSECOMAPP.variables.maxOfferPriority)&&t.priority>FGSECOMAPP.variables.maxOfferPriority&&(s=!1),t.stop_lower_priority&&s?FGSECOMAPP.variables.maxOfferPriority=t.priority:t.stop_lower_priority&&!s&&t.priority===FGSECOMAPP.variables.maxOfferPriority&&!d.empty(i)&&(FGSECOMAPP.variables.maxOfferPriority=null),t.isReachConditions=s,t},checkGiftAlreadyAddedToCart:(e,t)=>{let i=e?.map(o=>o.variant_id);FGSECOMAPP.arrOfferAdded=FGSECOMAPP.arrOfferAdded.filter(o=>i?.includes(o.variant_id));let a=t.gift_items.map(o=>o.variant_shopify_id),s={};t.gift_items.filter(o=>s[o.variant_shopify_id]={fg_original_compare_at_price:o.original_compare_at_price,fg_original_price:o.original_price,compare_gift_price:o.compare_gift_price});let c=FGSECOMAPP.arrOfferAdded.filter(o=>o.belongs_to_offer?.toString()===t.id?.toString())?.map(o=>o.variant_id);return e.filter(o=>{let l=d.checkCartItemIsGift(o),_=o.properties?._bogos_trigger_id,r=l&&(_===t.offer_root||!_);return l&&(o.cal_gift_for_other_rules=!1),a.includes(o.variant_id)&&c.includes(o.variant_id)&&r}).map(o=>{let l=t.gift_settings;o.cal_gift_for_other_rules=l.cal_gift_for_other_rules,o.belongs_to_offer=t.id?.toString();let _=!d.empty(o.properties?._bogos_trigger_id),r=FGSECOMAPP.arrOfferAdded?.filter(n=>n.belongs_to_offer?.toString()!==t.id?.toString()&&o.variant_id===n.variant_id)?.reduce((n,f)=>n+f.quantity,0);return{...o,quantity:o.quantity-(_?0:r),...s[o.variant_id]}})},filterGiftProducts:e=>{let t=e.giftsAdded.filter(i=>i.belongs_to_offer?.toString()!==e.id?.toString()).map(i=>i.product_id);return Object.values(e.gifts_valid).filter(i=>!t.includes(i.product_shopify_id))},checkAutoAddGift:(e,t)=>{try{let i=[],{offer:a}=t,{code:s}=a?.shopify_discount_settings??{},c=a?.type;s=c===T.OFFER_TYPE.function?s:null;let o=t.gifts,l=o.reduce((n,f)=>n+f.variants.length,0);if(!e.auto_add_gift||l<=0)return[];let _=t.offer?.gift_settings?.auto_add_all_gifts,r=t.offer?.gift_should_the_same??{};if(r.status&&r.type==="variant"){let n=o[0].variants[0];n.price===0&&(i.push({variant_id:n.variant_shopify_id,quantity:t.giftsAvailable,offer_id:t.id,offer_root:a.offer_root,type:c,code:s}),console.log(`BOGOS track: variant auto add gift {${n.variant_shopify_id}} {${n.variant_title}} {${t.id}} {${c}}`))}else if(_){let n=(t?.giftsAvailable??0)/l;o.forEach(f=>f.variants?.forEach(g=>i.push({variant_id:g.variant_shopify_id,quantity:n,offer_id:t.id,offer_root:a.offer_root,type:c,code:s}))),console.log(`BOGOS track: auto add all gifts from {${t.id}} {${c}}`)}else if(l===1){let n=o[0].variants[0];n.price===0&&(i.push({variant_id:n.variant_shopify_id,quantity:t.giftsAvailable,offer_id:t.id,offer_root:a.offer_root,type:c,code:s}),console.log(`BOGOS track: auto add gift: {${n.variant_shopify_id}} {${n.variant_title}} {${t.id}} {${c}}`))}return i}catch(i){return console.error("BOGOS track: Error checkAutoAddGift",i),[]}},checkOfferWithSubCondition:(e,t)=>{let i=!0,a=!0,s=!0,c=!0,o=!0,{specific_link_address:l,customer_tags:_,customer_locations:r,customer_order_history:n,mobile_app_channel:f}=e.sub_conditions;if(d.empty(l)||(i=FGSECOMAPP.variables.sca_fg_codes?.includes(l)),!d.empty(_)){let{value_customer_tags:m,type_customer_tags:p}=_??{},h=m?.some(b=>t.customer.tags?.includes(b));a=p==="include"?h:!h}if(!d.empty(r)){let{value_customer_locations:m,type_customer_locations:p}=r??{},h=m?.includes(FGSECOMAPP.customerLocation);c=p==="include"?h:!h}if(!d.empty(n)){let m=!0,{order_created_from:p,total_spend_on_order_history:h,total_spent_on_last_order:b,number_of_order:S,have_not_got_gift_from_this_offer:C}=n??{},E=t.customer.orders??[];if(p){let O=Date.parse(p)/1e3;E=E.filter(A=>A.created_at>=O&&["paid","partially_paid"].includes(A.financial_status))}if(!d.empty(h)&&(h.min_amount!==0||h.max_amount!==0)){let{min_amount:O,max_amount:A}=h??{},F=E.reduce((I,M)=>I+M.total_price,0)/100;m&=(F>=O||!O)&&(F<=A||!A)}if(!d.empty(b)&&(b.min_amount!==0||b.max_amount!==0)){let O=(t.customer.last_total??0)/100,{min_amount:A,max_amount:F}=b??{};m&=E.length>0&&(O>=A||!A)&&(O<=F||!F)}if(!d.empty(S)){let{min_amount:O,max_amount:A}=S??{},F=!(O!==0||A!==0),I=E.length;m&=F?d.empty(E):(I>=O||!O)&&(I<=A||!A)}if(C){let O=t.customer.freegifts_v2??[],A=e.gift_items.map(M=>[`${M.variant_shopify_id}`,`${M.original_variant_shopify_id}_${10*(M.original_price-M.price)*10}`,`${M.original_variant_shopify_id}_${10*(M.original_compare_at_price-M.price)*10}`]).flat(),F=O.filter(({gift_item:M})=>A.includes(M)),I=[...new Set(F.map(({order_id:M})=>M))].length>=Number(C);m&=!I}s=m}let{sale_channels:g,work_with_only_mobile_app:u}=f??{};return o&=u===!1||(g??[]).includes("online_store")||d.empty(g),i&&a&&s&&c&&o},processCartWithOffers:(e,t,i)=>{let a=[],s,c=[],o=[],l=[];for(let _ of t){let r=y.countGiftAvailableFromOffer(e,_),n=!r.isReachConditions||r.giftsAvailable<0,f=r.giftsAvailable>0&&r.gift_settings?.auto_add_all_gifts&&FGSECOMAPP.fgSettings?.auto_add_gift;if((n||f)&&r.giftsAdded?.forEach(g=>{o.push({variant_id:g.variant_id,quantity:g.quantity,offer_id:_.id,key:g.key,type:_.type})}),!n){if(r.giftsAvailable===0){let g={};r.giftsAdded?.forEach(u=>{g[u.variant_id]=(g?.[u.variant_id]??0)+u.quantity}),FGSECOMAPP.arrOfferAdded?.filter(u=>_.id?.toString()===u.belongs_to_offer?.toString()).forEach(u=>u.quantity=g[u.variant_id]??u.quantity);continue}(_.sub_conditions&&y.checkOfferWithSubCondition(_,SECOMAPP)||d.empty(_.sub_conditions))&&a.push(_)}}if(e?.filter(_=>d.checkCartItemIsGift(_)&&d.empty(_.belongs_to_offer)).forEach(_=>{o.push({variant_id:_.variant_id,quantity:_.quantity,offer_id:_.properties?._bogos_trigger_id,key:_.key})}),i||d.empty(o)){let _={};a.map(r=>({id:r.id,offerName:r.offer_name,offerPriority:r.priority,stopLowerPriority:r.stop_lower_priority,gifts:y.filterGiftProducts(r),giftsAvailable:r.giftsAvailable,giftsAdded:r.giftsAdded,isReachConditions:r.isReachConditions,offer_root:r.offer_root,offer:r}))?.forEach(r=>{let n=y.checkAutoAddGift(FGSECOMAPP.fgSettings,r);if(n?.length>0){c.push(...n);return}v.handleCheckHiddenGiftSlider(`FGSECOMAPP_HIDDEN_GIFT_OFFER_${r.offer_root}`)||r.gifts.forEach(f=>{_[f.product_shopify_id]={...f,belongs_to_offer:r.id?.toString()},l[r.offer_root]=[...l[r.offer_root]??[],{...f,belongs_to_offer:r.id?.toString()}]})}),s=Object.values(_)??[]}return{arrGiftsAdd:c,arrGiftsRemove:o,arrGiftsData:s,giftsOfferData:l}},processGiftsInvalid:(e,t)=>{let i=new Set;e?.forEach(s=>i.add(s.offer_id)),i.forEach(s=>{let c=FGSECOMAPP.offers?.find(r=>r.id?.toString()===s?.toString());if(d.empty(c)||!c.isReachConditions){FGSECOMAPP.arrOfferAdded=FGSECOMAPP.arrOfferAdded?.filter(r=>r.belongs_to_offer?.toString()!==s?.toString());return}let{auto_add_all_gifts:o}=c?.gift_settings??{};if(c.giftsAvailable>=0&&!o)return;let l=[],_=FGSECOMAPP.arrOfferAdded?.filter(r=>r.belongs_to_offer?.toString()===s?.toString())??[];if(o)l=l.concat([..._]),c.giftsAvailable=0;else{FGSECOMAPP.fgSettings?.compare_gift_price_with_product&&!d.empty(c.giftsAddedInvalid)&&c.giftsAddedInvalid.forEach(r=>{let n=FGSECOMAPP.arrOfferAdded.find(g=>g.belongs_to_offer?.toString()===c.id?.toString()&&r.variant_id===g.variant_id);if(d.empty(n))return;let f=n.quantity-r.quantity;c.giftsAvailable+=r.quantity,f>0?n.quantity=f:(n.quantity=0,l.push({...n}))});for(let r of _){if(c.giftsAvailable>=0)break;c.giftsAvailable+=r.quantity,c.giftsAvailable<=0?l.push({...r}):(r.quantity=c.giftsAvailable,c.giftsAvailable=0)}}l?.forEach(r=>{FGSECOMAPP.arrOfferAdded=FGSECOMAPP.arrOfferAdded?.filter(n=>r.variant_id!==n.variant_id||r.belongs_to_offer?.toString()!==n.belongs_to_offer?.toString())})});let a={};return t?.filter(s=>{if(d.checkCartItemIsGift(s)){let c=s.properties?._bogos_trigger_type===T.OFFER_TYPE.gift_func&&!d.empty(s.properties?._bogos_trigger_id),o=FGSECOMAPP.arrOfferAdded?.filter(_=>s.variant_id===_.variant_id),l=s.variant_id;c&&(l=`${s.variant_id}_${s.belongs_to_offer}`,o=o.filter(_=>s.belongs_to_offer===_.belongs_to_offer)),s.quantity=o?.reduce((_,r)=>_+r.quantity,0)??0,s.quantity-=a[l]??0,a[l]??=s.quantity}return s.quantity>0})??[]},checkAllOffers:async(e,t)=>{let i=JSON.stringify(FGSECOMAPP.arrOfferAdded),{arrGiftsAdd:a,arrGiftsRemove:s,arrGiftsData:c,giftsOfferData:o}=y.processCartWithOffers(e,t,!1),l=y.processGiftsInvalid(s,e);if(!d.empty(s)){let r=y.processCartWithOffers(l,t,!0);y.processGiftsInvalid(r?.arrGiftsRemove,e),a=r?.arrGiftsAdd,s=s?.concat(r?.arrGiftsRemove)??[],c=r?.arrGiftsData,o=r?.giftsOfferData}let _=await y.processGiftsToCart(a,s,i);return{giftsOfferData:o,arrGiftsData:c,isUpdated:_&&(!d.empty(a)||!d.empty(s))}},filterOfferGiftSetting:async()=>{try{let e=JSON.parse(JSON.stringify(window.fgData?.offers??[]));for(let l in FGSECOMAPP.productsByID)d.empty(FGSECOMAPP.productsByID[l]?.id)&&delete FGSECOMAPP.productsByID[l];let t=[],i=(l,_,r,n)=>{let{type:f,value:g,giftItems:u,giftProducts:m}=_;l.offer_conditions[0].product_narrow=[{type:f,value:{[r]:{...g[r],...!d.empty(n)&&{variants:[{...n}]}}}}],l.gift_items=u.filter(h=>h.original_product_shopify_id?.toString()===r?.toString()&&(d.empty(n)||n?.id===h.original_variant_shopify_id)),l.gift_products=m.filter(h=>h.original_product_shopify_id?.toString()===r?.toString()),l.gift_products[0].variants=[...l.gift_items];let p=l.gift_settings.number_of_gift_can_receive;return l.gift_settings.auto_add_all_gifts&&(p=l.gift_items.length),JSON.parse(JSON.stringify({...l,gift_settings:{...l.gift_settings,number_of_gift_can_receive:p},id:`${l.id}_${g[r].id}_${n?.id??""}`,offer_root:`${l.id}`}))};e.forEach(l=>{try{let _=JSON.parse(JSON.stringify(l)),r=l.gift_should_the_same??{};if(!r?.status)return;let n=l.offer_conditions[0].product_narrow,f={type:n[0].type,value:n[0].value,giftItems:[...l.gift_items],giftProducts:[...l.gift_products]};for(let g in f.value){if(r?.type==="product"){t.push(i(_,f,g));continue}if(r?.type==="variant"){let{variant:u}=f.value?.[g]??{};u?.forEach(m=>t.push(i(_,f,g,m)))}}}catch(_){console.error("BOGOS track: Error prepareOfferShouldBeTheSame",_)}}),FGSECOMAPP.variables.conditions.locations&&await d.getCustomerLocation(),e=e?.filter(l=>!l?.gift_should_the_same?.status)?.concat(t);let a=FGSECOMAPP.fgSettings.offer_process??"cloned";e=e?.map(l=>(l.type_source=l.type,l.type=a,{...l,id:l.id.toString(),offer_root:(l.offer_root??l.id).toString(),gift_products:y.reorderGiftProducts(l),gift_items:l.gift_items?.map(_=>{let r={};return l.type===T.OFFER_TYPE.function&&(FGSECOMAPP.variables.giftIdsFunction.push(_.original_variant_shopify_id),r={product_shopify_id:_.original_product_shopify_id,variant_shopify_id:_.original_variant_shopify_id}),{..._,...r}})})),e=e?.filter(l=>{if(!d.checkValidTimeOffer(l.start_time,l.end_time))return!1;let{customer_order_history:_,customer_tags:r}=l.sub_conditions??{},{no_login:n}=r??{},f=!d.empty(_)||!(n??!0);if(l.sub_conditions&&(!y.checkOfferWithSubCondition(l,SECOMAPP)||f&&d.empty(SECOMAPP.customer.email)))return!1;let g={...FGSECOMAPP.productsByID},u=!1;if(FGSECOMAPP.fgSettings.sync_quantity===T.SYNC_QUANTITY.stop_offer){l.gift_items=l?.gift_items.filter(p=>{let h=g[p.original_product_shopify_id]??{},b=h?.variants_quantity??{},{available:S}=h?.variants?.find(C=>C.id===p.original_variant_shopify_id)??{};return b[p.original_variant_shopify_id]>0||S})??[];let m=l.gift_items?.map(p=>p.variant_shopify_id);l.gift_products=l?.gift_products?.filter(p=>(p.variants=p?.variants?.filter(h=>m?.includes(h.variant_shopify_id)),p?.variants?.length>0)),u=!0}else if(FGSECOMAPP.fgSettings.manual_input_inventory){l.gift_items=l?.gift_items.filter(p=>(g[p.product_shopify_id]?.variants?.find(h=>h.id===p.variant_shopify_id)?.available??!1)||g[p.product_shopify_id]?.variants_quantity?.[p.variant_shopify_id]>0);let m=l.gift_items?.map(p=>p.variant_shopify_id);l.gift_products=l?.gift_products?.filter(p=>(p.variants=p?.variants?.filter(h=>m?.includes(h.variant_shopify_id)),p?.variants?.length>0)),u=!0}return u&&l.gift_settings?.auto_add_all_gifts&&(l.gift_settings.number_of_gift_can_receive=l.gift_items?.length),u?l.gift_items&&l.gift_items.length>0:!0});let s=FGSECOMAPP?.fgSettings?.cal_gift_discount==="compare_at_price"?"original_compare_at_price":"original_price",c=FGSECOMAPP.fgSettings?.compare_gift_price_with_product,o=c==="compare_at_price"?"original_compare_at_price":"original_price";return e=e?.map(l=>{let _=l.gift_items.map(r=>(r.price=d.convertMultiCurrency(r.price),r.cal_gift_price=d.convertMultiCurrency(d.empty(r[s])?r?.original_price:r[s]),c&&(r.compare_gift_price=d.convertMultiCurrency(d.empty(r[o])?r?.original_price:r[o])),r.original_product_shopify_id));return l.gift_products=l.gift_products?.filter(r=>(r.variants?.forEach(n=>{n.price=d.convertMultiCurrency(n.price),n.cal_gift_price=d.convertMultiCurrency(d.empty(n[s])?n?.original_price:n[s]),c&&(n.compare_gift_price=d.convertMultiCurrency(d.empty(n[o])?n?.original_price:n[o]))}),_.includes(r.original_product_shopify_id))),l.offer_conditions?.forEach(r=>{r.unit==="money"&&(r.min_amount=d.convertMultiCurrency(r.min_amount),r.max_amount=d.empty(r.max_amount)?r.max_amount:d.convertMultiCurrency(r.max_amount))}),{...l}})?.sort((l,_)=>l.priority-_.priority),FGSECOMAPP.variables.giftIdsFunction=[...new Set(FGSECOMAPP.variables.giftIdsFunction)],FGSECOMAPP.variables.maxTodayOfferPriority=Math.min(...e.map(l=>l.priority)),e}catch(e){return console.error("BOGOS track: filterOfferGiftSetting",e),[]}},getInfoCloneProducts:async e=>{try{let t=[],i=[],a=[],{sync_quantity:s,manual_input_inventory:c}=FGSECOMAPP?.fgSettings??{};window.fgData?.offers?.forEach(o=>{let l=[],_=[],r=[];o.gift_products.forEach(n=>{let f=n.clone_product_handle??null,g=n.original_product_handle??null;r.push(n.original_product_shopify_id??null),s===T.SYNC_QUANTITY.stop_offer?(l.push(g),_.push(f)):c?(l.push(e?g:f),_.push(e?f:g)):_.push(f,g)}),t.push(...l),i.push(..._),a.push(...r)}),t=t.filter(o=>!d.empty(o)),i=i.filter(o=>!d.empty(o)),a=a.filter(Boolean),await N.cacheProducts(t,{"sca-offer-search":"1"},async()=>{console.info(`BOGOS track: offer:sync-quantity:${Date.now()}`)}),N.cacheProducts(i,{"sca-product-cache":"1"},()=>{console.log(`BOGOS track: product-cached:${Date.now()}`)}).then(),k.syncRatingProducts(a,T.JUDGEME_OPTION.gift_slider,()=>{console.log(`BOGOS track: judgeme-synced:${Date.now()}`)}).then()}catch(t){console.error("BOGOS track: getInfoCloneProducts",t)}},validateArrOfferAdded:e=>{let{sca_offers_added:t}=FGSECOMAPP.variables.constants;try{d.empty(e)?(FGSECOMAPP.arrOfferAdded=[],localStorage.setItem(t,d.convertObjToString(FGSECOMAPP.arrOfferAdded))):FGSECOMAPP.arrOfferAdded=d.convertStringToObj(localStorage.getItem(t))}catch(c){FGSECOMAPP.arrOfferAdded=e.filter(o=>d.checkCartItemIsGift(o)).map(o=>({variant_id:o.variant_id,key:o.key,belongs_to_offer:o.properties?._bogos_trigger_id,quantity:o.quantity})),FGSECOMAPP.variables.failedParseArrOffersAdded=!0,console.warn("BOGOS track: Failed parse offer added",c)}let i={};FGSECOMAPP.offers?.forEach(c=>{i[c.id]=c?.gift_items?.map(o=>o.variant_shopify_id)});let a=Object.keys(i);FGSECOMAPP.arrOfferAdded=FGSECOMAPP.arrOfferAdded?.filter(c=>a?.includes(c.belongs_to_offer?.toString())&&i[c.belongs_to_offer?.toString()].includes(c.variant_id));let s={};FGSECOMAPP.arrOfferAdded?.forEach(c=>{let o=s[`${c.belongs_to_offer}_${c.variant_id}`]??{};s[`${c.belongs_to_offer}_${c.variant_id}`]={...c,belongs_to_offer:c.belongs_to_offer?.toString(),quantity:(o?.quantity??0)+(c?.quantity??0)}}),FGSECOMAPP.arrOfferAdded=Object.values(s),localStorage.setItem(t,d.convertObjToString(FGSECOMAPP.arrOfferAdded))},refreshCart:async(e,t,i={})=>{y.arrSaveAllFetch=[];let{isCartPage:a,isCheckout:s}=FGSECOMAPP.variables;t&&(a||s)&&location.reload(),t&&k.renderCart().then(()=>y.renderEventLoading("end")),setTimeout(function(){v.fetchRoot(e,i)},250)},arrSaveAllFetch:[],checkEventCart:async(e,t)=>{try{y.arrSaveAllFetch.push(e[0]),document.dispatchEvent(new CustomEvent(FGSECOMAPP.CUSTOM_EVENTS.START_PROCESS_CART,{detail:{events:y.arrSaveAllFetch,event:e}})),d.empty(t)&&await d.fetchInfoCartUpdate();let{giftsOfferData:i,arrGiftsData:a,isUpdated:s}=await y.checkAllOffers(FGSECOMAPP.cartItems,FGSECOMAPP.offers);FGSECOMAPP.renderPromotionMessage(FGSECOMAPP.offers),console.info("BOGOS track: cart-events",[...y.arrSaveAllFetch],e[0]),await y.refreshCart(a,s||R.render_cart.test(e[0]),i),a?.length||(y.handleQuantityGiftAvailableSession("remove"),document.querySelector("#freegifts-main-popup-container.sca-modal-fg.sca-is-visible-fg")?.classList?.remove("sca-is-visible-fg")),v.handleCheckedTodayOffer();let{isCartPage:c,isCheckout:o}=FGSECOMAPP.variables;return s&&(c||o)&&(y.arrSaveAllFetch=[],location.reload()),["bogos:rollback"].includes(e[0])||document.dispatchEvent(new CustomEvent(FGSECOMAPP.CUSTOM_EVENTS.END_PROCESS_CART,{detail:{events:y.arrSaveAllFetch,event:e}})),FGSECOMAPP.cartItems}catch(i){console.error("BOGOS track: Error check cart event",i)}},init:async(e,t,i)=>{document.dispatchEvent(new CustomEvent(FGSECOMAPP.CUSTOM_EVENTS.BOGOS_FG_START));let{using_draft_order:a}=FGSECOMAPP?.fgSettings??{};a&&(FGSECOMAPP.fgSettings.sync_quantity=T.SYNC_QUANTITY.stop_offer);let s=FGSECOMAPP.variables.conditions.function;s&&(FGSECOMAPP.fgSettings.manual_input_inventory=!0);let{sync_quantity:c,manual_input_inventory:o}=FGSECOMAPP?.fgSettings??{},l=c===T.SYNC_QUANTITY.stop_offer||o;i||(l?await y.getInfoCloneProducts(s):y.getInfoCloneProducts(s).then()),FGSECOMAPP.offers=await y.filterOfferGiftSetting(),typeof t=="function"&&t(),v.filterPageDisplay(FGSECOMAPP.fgAppearance?.today_offer?.pages_display)&&v.renderTodayOffer(i),y.validateArrOfferAdded(FGSECOMAPP.cartItems),await y.checkEventCart([e],FGSECOMAPP.cartItems),localStorage.setItem(FGSECOMAPP.variables.constants.sca_offers_added,d.convertObjToString(FGSECOMAPP.arrOfferAdded)),FGSECOMAPP.variables.failedParseArrOffersAdded=!1},reorderGiftProducts:e=>{let t=e.gift_products;e.type===T.OFFER_TYPE.function&&(t=t?.map(c=>({...c,product_shopify_id:c.original_product_shopify_id,clone_product_handle:c.original_product_handle,variants:c.variants?.map(o=>({...o,product_shopify_id:o.original_product_shopify_id,variant_shopify_id:o.original_variant_shopify_id}))})));let i=e.gift_settings,{original_products_to_clone:a}=i;if(d.empty(a))return t;let s={};return a.forEach((c,o)=>{s[c?.product_shopify_id]=o}),t.map(c=>({...c,position:s[c.original_product_shopify_id]??0})).sort((c,o)=>c.position-o.position)},handleQuantityGiftAvailableSession:(e,t=0,i="",a=0)=>{try{let s=i?`_${i}`:"",c=`bogos_added_gift${s}`,o=`bogos_total_gift${s}`;if(e==="set"){let l=FGSECOMAPP.variables[c]??0,_=FGSECOMAPP.variables[o],r=i?a:FGSECOMAPP.offers.filter(n=>n.isReachConditions).reduce((n,f)=>n+f.giftsAvailable,0);FGSECOMAPP.variables[c]=l+t,_||(FGSECOMAPP.variables[o]=r),FGSECOMAPP.variables[c]===FGSECOMAPP.variables[o]&&(FGSECOMAPP.variables[c]=void 0,FGSECOMAPP.variables[o]=void 0)}else Object.keys(FGSECOMAPP.variables).forEach(l=>{(l.startsWith("bogos_added_gift")||l.startsWith("bogos_total_gift"))&&(FGSECOMAPP.variables[l]=void 0)})}catch(s){console.log(s)}}},d={...Y,checkCartItemIsGift:(e,t)=>{let i="-sca_clone_freegift",a=typeof e=="object",s=a&&(FGSECOMAPP.variables.giftIdsFunction.includes(e.variant_id)||FGSECOMAPP.variables.giftIds.includes(e.variant_id))&&e.properties?._bogos_trigger_type===T.OFFER_TYPE.gift_func&&!d.empty(e.properties?._bogos_trigger);return s&&!d.empty(t)?e.properties?._bogos_trigger_id===t.offer_root:!d.empty(e)&&(a&&(e.handle?.includes(i)||e.tags?.includes("bogos-gift")||FGSECOMAPP.variables.giftIds?.includes(e.variant_id)||s)||typeof e=="string"&&e.includes(i))},checkCartItemIsPurchaseOption:e=>{let{selling_plan_allocation:t}=e||{selling_plan_allocation:{selling_plan:null}};return!d.empty(t)&&!d.empty(t?.selling_plan)},convertProductEvent:(e,t)=>e?.map(i=>({id:i.product_shopify_id,title:d.renderOriginalProductTitle(i.original_product_shopify_id,i.title,i.product_shopify_id),handle:i.original_product_handle,thumbnail:i.thumbnail,belongs_to_offer:i.belongs_to_offer??`${t}`,variants:i.variants.map(a=>({id:a.variant_shopify_id,title:a.variant_title,price:a.price,original_price:a.cal_gift_price,thumbnail:a.thumbnail,discount_type:a.discount_type,discount_value:a.discount_value}))}))??[],aggregateArrOfferAddedIds:e=>{let t=[];return e.forEach(i=>{let{belongs_to_offer:a}=i;t.push(a.split("_")?.[0]??"")}),[...new Set(t.filter(i=>!d.empty(i)))]},renderGiftPrice:e=>{let t=FGSECOMAPP.variables.conditions.function,{show_cloned_price:i}=FGSECOMAPP.variables.Shopify??{},a=FGSECOMAPP.productsByID?.[e?.product_shopify_id]?.variants?.find(c=>c.id===e.variant_shopify_id),s=!t&&i?a?.price:void 0;return s?s/=100:s=e?.price,FGSECOMAPP.helper.formatter.format(s??0)},renderOriginalPrice:e=>{let t=FGSECOMAPP?.fgSettings?.cal_gift_discount==="compare_at_price"?"compare_at_price":"price",i=FGSECOMAPP.productsByID?.[e.original_product_shopify_id]?.variants?.find(s=>s.id===e.original_variant_shopify_id),a=i?.[t]??i?.price;return a?a/=100:a=e?.cal_gift_price,FGSECOMAPP.helper.formatter.format(a??0)},renderOriginalProductUrl:(e,t)=>FGSECOMAPP.productsByID[e]?.handle??t??"#",renderOriginalProductTitle:(e,t,i)=>FGSECOMAPP.productsByID[e]?.title??(FGSECOMAPP.productsByID[i]?.title??t??"").replace("\xBB","").replace("\u{1F381}","").replace(/\(\d*(\.?\d*)% off\)/,"").replace("(Discount)",""),handleCountdownTimer:(e,t)=>{try{let i,a=()=>{let s=new Date,o=Date.parse(e)-s;if(o<0){clearInterval(i);return}let l=Math.floor(o/(1e3*60*60*24)),_=Math.floor(o/(1e3*60*60)),r=Math.floor(o/(1e3*60)),n=Math.floor(o/1e3),f=l,g=_-l*24,u=r-_*60,m=n-r*60,p=`.fg-gift-thumbnail-offer[data-fg-offer-id='${t}'] .fg-gift-thumbnail-offer-time-detail .fg-gift-thumbnail-time-element`;document.querySelectorAll(`${p}.day`).forEach(h=>{h.innerHTML=f.toString().padStart(2,"0")}),document.querySelectorAll(`${p}.hour`).forEach(h=>{h.innerHTML=g.toString().padStart(2,"0")}),document.querySelectorAll(`${p}.minutes`).forEach(h=>{h.innerHTML=u.toString().padStart(2,"0")}),document.querySelectorAll(`${p}.second`).forEach(h=>{h.innerHTML=m.toString().padStart(2,"0")})};i=setInterval(()=>{a()},1e3)}catch{}}},v={...Q,renderProductHTML:(e,t)=>{let i=t?.variants[0]??{},{original_product_shopify_id:a,product_shopify_id:s,original_product_handle:c,belongs_to_offer:o}=t,l=d.checkIsDefaultTitle(i.variant_title),_=t.variants?.length,r=d.renderOriginalProductTitle(a,t.title,s),n=FGSECOMAPP.offers.find(F=>o===F?.id?.toString())?.giftsAvailable,{general:f}=FGSECOMAPP.fgAppearance?.gift_slider??{},g=f?.show_gift_for_customer==="by_variants",m=(FGSECOMAPP.fgIntegration?.judgeme??{})?.settings??{},{display_star_rating:p,gift_slider:h,status:b}=m,S=(b&&p&&h)??!1,C=d.convertStringToObj(localStorage.getItem(FGSECOMAPP.variables.constants.bogos_judgeme_ratings)??""),{rating:E}=(C??[]).find(({product_id:F})=>F===a)??{},O=k.renderStarRatingJudgeme(E??null,a),A=v.renderGiftQuantityOptions(n);return FGSECOMAPP.helper.templateHTML.render(e,{fg_product_handle:d.renderOriginalProductUrl(a,c),fg_product_img:d.handleResizeGiftImage(_===1?i.thumbnail:t.thumbnail),fg_product_img_alt:r,fg_product_title:f?.show_product_title?r:"",fg_gifts_check_show_by_variants:g&&f?.show_variant_title&&!l?"":"sca-d-none",fg_gifts_check_show_by_products:g?"sca-d-none":"",fg_check_selected_variant:_===1?`active ${l?"sca-d-none":""}`:"",fg_variant_title:_!==1?k.convertIntegration(f?.select_gift_btn??"Select variant","customize.select_variant_button_text","customize.gift_slider.select_gift_btn"):i.variant_title,fg_original_price:d.renderOriginalPrice(i),fg_gift_price:d.renderGiftPrice(i),sca_fg_variant_select_section:v.renderVariantSelectOptions(t.variants,t.thumbnail),fg_product_belongs_to_offer:t.belongs_to_offer,fg_variant_id:_===1?i.variant_shopify_id:"",offer:FGSECOMAPP.offers.find(F=>F.id===t.belongs_to_offer?.[0]),bogos_default_select_variant_title:k.convertIntegration(f?.select_gift_btn??"Select variant","customize.select_variant_button_text","customize.gift_slider.select_gift_btn"),bogos_check_show_select_variant:_===1?"sca-d-none":"",bogos_number_max_gifts:n??0,bogos_integration_judgeme:S?O:"",bogos_gift_quantity_options:A,bogos_check_show_quantity_box:FGSECOMAPP.fgSettings?.select_one_gift_price||!f?.enable_add_multiple_gifts?"sca-d-none":""})},renderGiftsOfferSection:(e,t,i={})=>{let{notify_gift_can_add:a}=FGSECOMAPP.fgAppearance?.gift_slider,s=document.querySelector(P.GIFT_OFFER_SECTION_ID)?.innerHTML??P.GIFT_OFFER_SECTION,c=(e??0)===0,o=c?k.convertIntegration(a?.number_gifts_can_be_added??"You can add {{number}} gift product(s)","customize.number_gifts_can_be_added_text","customize.gift_slider.number_gifts_can_be_added_text"):k.convertIntegration(a?.number_gifts_added??"You have added {{number}} gift product(s)","customize.number_gifts_added_text","customize.gift_slider.number_gifts_added_text");return FGSECOMAPP.helper.templateHTML.render(s,{sca_fg_disable_slider_section:v.HIDDEN_GIFT_POPUP(),check_show_number_gift_available:a?.enable===!1?"sca-d-none":"",check_show_number_gift_available_type:(e??0)===0?"warning":"success",bogos_number_gift_available:FGSECOMAPP.helper.templateHTML.render(o,{number:c?t:`${e}/${t}`}),...i})},renderTodayOffer:e=>{let{widget_info:t}=FGSECOMAPP.fgAppearance?.today_offer??{},i=document.querySelector("#sca-fg-today-offer-widget"),a=document.querySelector("#sca-fg-today-offer-iframe");if(e&&!FGSECOMAPP.offers?.length&&(i&&(i.innerHTML="",i.className=""),a&&(a.innerHTML="")),!t?.show_widget||!FGSECOMAPP.offers?.length||!i||!a)return;let s=document.querySelector(P.TODAY_OFFER_WIDGET_ID)?.innerHTML??P.TODAY_OFFER_WIDGET,c=document.querySelector(P.TODAY_OFFER_SECTION_ID)?.innerHTML??P.TODAY_OFFER_SECTION,o={};FGSECOMAPP.offers.forEach(r=>{o[r.offer_root]?o[r.offer_root].gift_products.push(...r.gift_products):o[r.offer_root]=JSON.parse(JSON.stringify(r))});let l=Object.values(o);l=l.map(r=>({...r,gift_products:v.handleTransformGiftsSliderData(r.gift_products)})).sort((r,n)=>new Date(r.start_time)-new Date(n.start_time)),FGSECOMAPP.variables.todayOffers=l,i.innerHTML=FGSECOMAPP.helper.templateHTML.render(s),t?.widget_icon_style==="icon_and_title"&&(i.classList.add("sca-fg-today-offer-widget-with-title"),document.querySelector("#sca-fg-today-offer-widget .sca-fg-count-offers").style.right="-5px"),(t?.widget_icon_style==="icon"||!t?.widget_icon_style)&&(i.classList.remove("sca-fg-today-offer-widget-with-title"),document.querySelector("#sca-fg-today-offer-widget .sca-fg-title-icon-widget")?.classList?.add("sca-hide")),t?.widget_position==="bottom_left"&&(i.classList.add("sca-today-offer-widget-left"),a.classList.add("sca-today-offer-left")),t?.widget_position==="bottom_right"&&(i.classList.add("sca-today-offer-widget-right"),a.classList.add("sca-today-offer-right")),a.innerHTML=FGSECOMAPP.helper.templateHTML.render(c,{sca_fg_today_offer_footer:v.BRAND_MARK_TEMPLATE("today-offer-brand-mark")}),v.handleRenderTodayOfferBody(),document.querySelector("#sca-fg-today-offer-widget .sca-fg-count-offers").innerHTML=l.length.toString();let _=()=>{document.querySelector("#sca-fg-today-offer-iframe")?.classList.toggle("sca-show"),v.handleRenderTodayOfferBody(),document.querySelectorAll(".sca-fg-icon-success").forEach(f=>{f.classList.toggle("sca-hide")})};document.querySelector(".sca-fg-close-today-offer").addEventListener("click",_),!e&&document.querySelector("#sca-fg-today-offer-widget").addEventListener("click",_),v.handleCheckedTodayOffer(),document.dispatchEvent(new CustomEvent(FGSECOMAPP.CUSTOM_EVENTS.RENDER_TODAY_OFFER,{detail:{todayOffers:l.map(r=>{let n=window.fgData.offers.find(f=>f.id.toString()===r.offer_root);return{id:`${n.id}`,title:k.convertIntegration(r.offer_name,`offer.offer_title_${r.offer_root}`,`offers.${r.offer_root}.offer_name`),gifts:d.convertProductEvent(n.gift_products,n.id),success:r.isReachConditions??!1}})}}))},handleRenderTodayOfferBody:(e=null)=>{let t=!d.empty(e),{widget_info:i}=FGSECOMAPP.fgAppearance?.today_offer??{},a=d.empty(i?.number_gift_show)?2:i?.number_gift_show,s=i?.gift_display==="by_variants",c=i?.show_gift_preview,o=[...FGSECOMAPP.variables.todayOffers];t&&(o=[FGSECOMAPP.variables.todayOffers.find(f=>f.offer_root?.toString()===e.toString())]);let l=document.querySelector(P.TODAY_OFFER_ITEM_SECTION_ID)?.innerHTML??P.TODAY_OFFER_ITEM_SECTION,_=document.querySelector(P.TODAY_OFFER_GIFT_PRODUCT_ID)?.innerHTML??P.TODAY_OFFER_GIFT_PRODUCT,r=document.querySelector(P.TODAY_OFFER_ITEM_HEADER_SECTION_ID)?.innerHTML??P.TODAY_OFFER_ITEM_HEADER_SECTION,n=document.querySelector(P.TODAY_OFFER_ITEM_HEADER_WITH_IMG_SECTION_ID)?.innerHTML??P.TODAY_OFFER_ITEM_HEADER_WITH_IMG_SECTION;document.querySelector("#sca-fg-today-offer-iframe .sca-fg-body .sca-fg-offers").innerHTML=o.map(f=>{let{offer_name:g,offer_root:u,gift_products:m,config:p,gift_settings:h}=f,S=`${h.discount.type===T.DISCOUNT_TYPE.fixed_amount?d.renderPrice(d.convertMultiCurrency(h.discount.value)):h.discount.value+"%"}`,C=d.empty(p?.today_offer_title)?k.convertIntegration(g,`offer.offer_title_${u}`,`offers.${u}.offer_name`):k.convertIntegration(p?.today_offer_title,`offer.today_offer_${u}`,`offers.${u}.today_offer_title`),E=p?.offer_link??"",O=v.handleTransformGiftsSliderData(m);if(s){let I=[];for(let M of O){let w=M?.variants;w&&w.length&&w.forEach(L=>I.push({...M,thumbnail:L.thumbnail??M?.thumbnail,variants:[L]}))}O=I}let A=O?.length,F=O.slice(0,a);return t&&(F=O),FGSECOMAPP.helper.templateHTML.render(l,{sca_fg_offer_id:u,sca_fg_offer_detail:t?"sca-fg-offer-detail":"",bogos_today_offer_header:FGSECOMAPP.helper.templateHTML.render(c?r:n,{sca_fg_offer_title:C,check_show_gift_notification:i?.show_gift_notification===!0?"":"sca-d-none",sca_fg_offer_subtitle:FGSECOMAPP.helper.templateHTML.render(k.convertIntegration(i?.gift_notification??"Get {{number}} gift for {{discountAmount}} OFF","customize.today_offer_gift_notification","customize.today_offer.gift_notification"),{number:h?.number_of_gift_can_receive,discountAmount:S}),bogos_offer_link_title:k.convertIntegration(i?.button_redirect_text??"Get offer","customize.today_offer_button_redirect_text","customize.today_offer.button_redirect_text"),sca_fg_offer_title_tooltip:C,bogos_today_offer_link:E,check_show_btn_redirect:d.empty(E)?"sca-d-none":"",sca_fg_offer_img:m[0].thumbnail}),check_show_gift_product:c?"":"sca-d-none",bogos_more_gift_product:!t&&A>a?FGSECOMAPP.helper.templateHTML.render(k.convertIntegration(i?.see_more_text??"See more ({{number}} products)","customize.today_offer_see_more_text","customize.today_offer.see_more_text"),{number:A-a}):"",check_show_more_product:(A>a||t)&&c?"":"sca-d-none",sca_bogos_offer_id:u,bogos_today_offer_gift_products:F.map(I=>{let M=I?.variants?.length>1,{original_product_shopify_id:w,title:L,product_shopify_id:D}=I??{};return FGSECOMAPP.helper.templateHTML.render(_,{bogos_today_offer_gift_img:I?.thumbnail??I?.variants[0]?.thumbnail,bogos_today_offer_gift_name:d.renderOriginalProductTitle(w,L,D),bogos_today_offer_gift_discount_price:d.renderGiftPrice(I?.variants[0]),bogos_today_offer_gift_original_price:d.renderOriginalPrice(I?.variants[0]),bogos_variants_selected:M?FGSECOMAPP.helper.templateHTML.render(k.convertIntegration(i?.variant_text??"{{number}} variants selected","customize.today_offer_variant_text","customize.today_offer.variant_text"),{number:I?.variants?.length}):"",check_show_selected_variant:M?"":"sca-d-none",check_show_variant_name:s&&!d.checkIsDefaultTitle(I.variants[0]?.variant_title)?"":"sca-d-none",bogos_today_offer_gift_variant_name:s?I.variants[0]?.variant_title:""})}).join(` `),offer:f})}).join(` `),v.handleCheckedTodayOffer(),v.renderTodayOfferQuerySelectorAll()},handleCheckedTodayOffer:()=>{let e=[...new Set(FGSECOMAPP.offers?.filter(t=>t.isReachConditions)?.map(t=>t.offer_root))];document.dispatchEvent(new CustomEvent(FGSECOMAPP.CUSTOM_EVENTS.TODAY_OFFER_CHANGE,{detail:{idOffersSuccess:e}})),document.querySelectorAll("#sca-fg-today-offer-iframe .sca-fg-offers .sca-fg-offer").forEach(t=>{e.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(e){e.addEventListener("mouseenter",function(t){let i=e.getAttribute("data-sca-fg-today-offer-title-tooltip");d.createTooltip(i,t.pageX+5,t.pageY+5)}),e.addEventListener("mouseleave",function(){d.removeTooltip()}),e.addEventListener("mousemove",d.moveTooltip)}),document.querySelectorAll("#sca-fg-today-offer-iframe .sca-offer-more-gift-products ").forEach(e=>{e.addEventListener("click",()=>{let t=e.getAttribute("data-bogos-offer-id");v.handleRenderTodayOfferBody(t),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(e=>{e.addEventListener("click",()=>{v.handleRenderTodayOfferBody(),document.querySelectorAll(".sca-fg-icon-success").forEach(i=>{i.classList.toggle("sca-hide")})})})},handleTransformGiftsSliderData:e=>{let t=FGSECOMAPP.productsByID;return e.map(i=>{let a=t[i.product_shopify_id];return{...i,thumbnail:a?.featured_image??i.thumbnail,variants:i.variants.map(s=>{let c=a?.variants?.find(o=>o.id===s.variant_shopify_id);return{...s,thumbnail:c?.featured_image?.src??a?.featured_image??s.thumbnail??i.thumbnail}})}})},handleConvertGiftsBelongOffer:e=>{let t=e.map(a=>a.belongs_to_offer).flat().filter((a,s,c)=>c.indexOf(a)===s),i=FGSECOMAPP.offers.filter(a=>t.includes(a.offer_root)).reduce((a,s)=>({...a,[s.offer_root]:{...s,gift_items_filter:e.filter(c=>c.belongs_to_offer.includes(s.offer_root))}}),{});return Object.values(i)},filterOfferToGiftThumbnail:e=>{try{let t={},i={},a=FGSECOMAPP.offers;if(d.empty(e)){e=[];let{current_product:o,other_products:l,current_collection:_}=FGSECOMAPP.variables.Shopify;d.empty(o)||e.push({...o});let r={...l,..._?.products};Object.values(FGSECOMAPP.productsInPage)?.filter(n=>!d.empty(n.info)&&(d.empty(n?.product_has_icon)||n?.product_has_icon&&!n?.positions?.every(f=>f?.classList?.contains("sca-gift-icon-collection-page"))))?.forEach(n=>{r[n.info.id]={...n.info}}),e=e.concat([...Object.values(r)])}e?.forEach(o=>{let l=FGSECOMAPP.productsInPage[o.handle];FGSECOMAPP.productsInPage[o.handle]={...l,info:{...o},product_has_icon:d.empty(a)?void 0:!1};let _={handle:o.handle,tags:o.tags,variant_id:o.variants?.[0]?.id??-1};d.checkCartItemIsGift(_)&&l?.positions?.forEach(r=>r?.remove())});let s=FGSECOMAPP.fgSettings?.compare_gift_price_with_product,c=FGSECOMAPP.variables.Shopify?.enable_gift_icon_selected_product||FGSECOMAPP.fgAppearance.gift_icon?.enable_for_all_conditions;a?.forEach(o=>{let{offer_conditions:l}=o,{is_multiply:_,unit:r,product_narrow:n}=l?.[0]??{},f=l?.length===1&&r==="number_of_products"&&typeof _=="boolean"&&d.empty(n[0]?.track_pack_type);if(c&&(f=n?.length>0&&n[0]?.filter_option!=="exclude"),!f)return;let g;n?.forEach(u=>{switch(u.type){case T.NARROW_TYPE.product:g=Object.values(u.value);break;case T.NARROW_TYPE.product_types:let m=Object.keys(u.value);m.length>0&&(g=(g===void 0?e:g)?.filter(b=>m.includes(b.type))??[]);break;case T.NARROW_TYPE.product_vendors:let p=Object.keys(u.value);p.length>0&&(g=(g===void 0?e:g)?.filter(b=>p.includes(b.vendor))??[]);break;case T.NARROW_TYPE.collection:let h=Object.keys(u.value);h.length>0&&(g=(g===void 0?e:g)?.filter(b=>{let C=b.collections?.map(E=>E.id+"")?.filter(E=>h.includes(E));return!d.empty(C)})??[]);break;default:break}}),g?.forEach(u=>{let m=u.handle,p=JSON.parse(JSON.stringify(o.gift_products)),h=FGSECOMAPP.productsInPage[m]?.info??Object.values(FGSECOMAPP.productsInPage??{}).find(S=>S?.info?.id===u.id)?.info??{price_max:null};if(m=h.handle??m,FGSECOMAPP.fgSettings?.not_show_gift_if_already_on_cart&&(p=p.filter(S=>S.original_product_shopify_id!==h?.id)),s&&(p=p.filter(S=>S.variants.some(C=>C?.compare_gift_price<=h?.price_max/100)),d.empty(p)))return;if(t[m]){let S=t[m];p?.forEach(C=>{let E=S.find(A=>A.original_product_shopify_id===C.original_product_shopify_id);if(d.empty(E)){S.push({...C,belongs_to_offer:[o.offer_root]});return}let O=C.variants.map(A=>A.original_variant_shopify_id);!E.belongs_to_offer?.includes(o.offer_root)&&E.belongs_to_offer?.push(o.offer_root),E.variants=E?.variants?.filter(A=>!O.includes(A.original_variant_shopify_id))??[],E.variants=[...E.variants,...C.variants]}),t[m]=S}else t[m]=p?.map(S=>({...S,belongs_to_offer:[o.offer_root]}));let b=(u.variants??u.variant)?.map(S=>S.id)??[];d.empty(i[m])&&(i[m]={}),FGSECOMAPP.productsInPage[m]?.info?.variants?.filter(S=>b.includes(S.id))?.forEach(S=>{i[m][S.id]=i[m][S.id]??[];let C=p.filter(E=>{let O=E.variants;return s&&(O=O.filter(A=>A?.compare_gift_price<=S.price/100)),!d.empty(O)}).map(E=>({...E,belongs_to_offer:[o.offer_root]}));i[m][S.id].push(...C)})})});for(let o in t){let l=FGSECOMAPP.productsInPage[o];FGSECOMAPP.productsInPage[o]={...l,gifts_will_receive:[...t[o]],product_has_icon:!0,variants_has_gift:{...i[o]}}}return Object.entries(t)?.length?t:{}}catch(t){return console.warn("BOGOS track: Failed check products have customize",t),null}},renderElementGiftIconCollectionPage:()=>{let e=v.getProductHandleInPage(),t=v.filterOfferToGiftThumbnail();v.renderGiftIconForProducts(t),N.searchProducts(e,{"sca-product-search":"1"}).then()},renderElementOldVersionGiftThumbnail:(e,t)=>{let i=document.querySelector(P.OLD_GIFT_THUMBNAIL_ITEMS_SECTION_ID)?.innerHTML??P.OLD_GIFT_THUMBNAIL_ITEMS_SECTION,a=e?.map(f=>v.renderProductHTML(i,f)).join(""),s=document.querySelector(P.OLD_GIFT_THUMBNAIL_SECTION_ID)?.innerHTML??P.OLD_GIFT_THUMBNAIL_SECTION,c=FGSECOMAPP.helper.templateHTML.render(s,{fg_check_show_narrow:e?.length>=4?"":"sca-d-none",sca_fg_gift_thumbnail_items_section:a}),{gift_thumbnail_query:o}=FGSECOMAPP.QUERY_SELECTOR??{},l=[...o?.tool,...o?.page_builder].filter(Boolean).join(","),_=[...o?.integration,...o?.default].filter(Boolean).join(","),r=!0,n=f=>{if(!f)return;let u=[...f.classList].some(S=>o?.page_builder?.toString()?.includes(S));u||(f.parentElement.style.width="100%",f.parentElement.style.height="auto",f.parentElement?.classList?.toggle("sca-fg-form-thumbnail-product-page",e.length>0));let m=f.parentNode.querySelector("#sca-gift-thumbnail");if(m)m.innerHTML=c;else{m=document.createElement("div"),m.setAttribute("id","sca-gift-thumbnail");let S=new DOMParser().parseFromString(c,"text/html");m.innerHTML=S.body.innerHTML,f.parentNode.insertBefore(m,f)}u?f.appendChild(m):f.parentNode.insertBefore(m,f);let p=m.querySelector("#fg-gift-thumbnail-title");if(p)switch(t.gift_thumbnail?.size){case"32":p.style.maxWidth="50%";break;case"50":p.style.maxWidth="60%";break;case"100":p.style.maxWidth="70%";break;case"160":p.style.maxWidth="80%";break;case"240":p.style.maxWidth="100%";break;default:p.style.maxWidth="60%"}let h=FGSECOMAPP.variables.Shopify?.number_gifts_thumbnail??4,b=m.querySelector(".sca-list-gift-thumbnail");e?.length>=h?new FGSECOMAPP.helper.Glider(b,{slidesToShow:Math.max(h-1,1),slidesToScroll:1,draggable:!0,dots:".dots-thumbnail",arrows:{prev:"#fg-gift-thumbnail-title .glider-prev",next:"#fg-gift-thumbnail-title .glider-next"}}):(p&&(p.style.maxWidth="100%"),b&&(b.style.display="flex")),r=!1};return document.querySelectorAll(l).forEach(n),r&&n(document.querySelector(_)),e},renderElementGiftThumbnail:(e,t)=>{let i=document.querySelector(P.GIFT_THUMBNAIL_SUB_ITEMS_SECTION_ID)?.innerHTML??P.GIFT_THUMBNAIL_SUB_ITEMS_SECTION,a=P.GIFT_THUMBNAIL_ITEMS_EXPIRED,{countdown_text:s,number_text:c,show_multiple:o,show_countdown_timer:l,show_number_gift:_}=t?.gift_thumbnail??{},r=document.querySelector(P.GIFT_THUMBNAIL_ITEMS_SECTION_ID)?.innerHTML??P.GIFT_THUMBNAIL_ITEMS_SECTION,n=e?.sort((S,C)=>S.priority-C.priority)?.map(S=>{let C=S?.gift_items_filter??[],E=C?.map(O=>FGSECOMAPP.helper.templateHTML.render(i,{fg_product_handle:d.renderOriginalProductUrl(O.original_product_shopify_id,O.original_product_handle),fg_product_img:d.handleResizeGiftImage(O.thumbnail),fg_product_img_alt:d.renderOriginalProductTitle(O.original_product_shopify_id,O.title)})).join(" ");return FGSECOMAPP.helper.templateHTML.render(r,{fg_offer_id:S.id,fg_offer_title:k.convertIntegration(S.offer_name,`offer.offer_title_${S.offer_root}`,`offers.${S.offer_root}.offer_name`),fg_offer_time_title:k.convertIntegration(s??"Expired in","customize.gift_thumbnail_countdown_text","customize.gift_icon.gift_thumbnail_countdown_text"),fg_offer_time_detail:S.end_time?FGSECOMAPP.helper.templateHTML.render(a,{fg_time_day:"00",fg_time_hour:"00",fg_time_minutes:"00",fg_time_second:"00"}):"",fg_offer_body:E,fg_offer_footer_total:`${C.length} ${k.convertIntegration(c??"gift items included","customize.gift_thumbnail_number_text","customize.gift_icon.gift_thumbnail_number_text")}`})}).join(" "),f=document.querySelector(P.GIFT_THUMBNAIL_SECTION_ID)?.innerHTML??P.GIFT_THUMBNAIL_SECTION,g=FGSECOMAPP.helper.templateHTML.render(f,{fg_gift_thumbnail_section:n}),{gift_thumbnail_query:u}=FGSECOMAPP.QUERY_SELECTOR??{},m=[...u?.tool,...u?.page_builder].filter(Boolean).join(","),p=[...u?.integration,...u?.default].filter(Boolean).join(","),h=!0,b=S=>{if(!S)return;let E=[...S.classList].some(w=>u?.page_builder?.toString()?.includes(w));E||(S.parentElement.style.width="100%",S.parentElement.style.height="auto",S.parentElement?.classList?.toggle("sca-fg-form-thumbnail-product-page",e.length>0));let O=S.parentNode.querySelector("#sca-gift-thumbnail");if(O)O.innerHTML=g;else{O=document.createElement("div"),O.setAttribute("id","sca-gift-thumbnail");let w=new DOMParser().parseFromString(g,"text/html");O.innerHTML=w.body.innerHTML,S.parentNode.insertBefore(O,S)}E?S.appendChild(O):S.parentNode.insertBefore(O,S);let A=o==="together",F=O.querySelector(".fg-gift-thumbnail-container");A?F?.classList.remove("seperated"):F?.classList.add("seperated");let I=l??!0,M=_??!0;O.querySelectorAll(".fg-gift-thumbnail-offer")?.forEach(w=>{let L=w.getAttribute("data-fg-offer-id"),D=e.find(z=>z.id===L),H=w.querySelectorAll(".fg-gift-thumbnail-offer-slider .product-item"),B=FGSECOMAPP.variables.Shopify?.number_gifts_thumbnail??4;H?.length>=B?new FGSECOMAPP.helper.Glider(w.querySelector(".glider"),{slidesToShow:B,slidesToScroll:1,arrows:{prev:`.fg-gift-thumbnail-offer[data-fg-offer-id="${L}"] .fg-gift-thumbnail-btn.glider-prev`,next:`.fg-gift-thumbnail-offer[data-fg-offer-id="${L}"] .fg-gift-thumbnail-btn.glider-next`}}):w.querySelector(".fg-gift-thumbnail-offer-footer .fg-gift-thumbnail-offer-footer-action").classList.add("sca-d-none"),H.length<=4?w.querySelector(".fg-gift-thumbnail-offer-slider").style.width="fit-content":w.querySelector(".fg-gift-thumbnail-offer-slider").style.width="unset";let U=w.querySelector(".fg-gift-thumbnail-offer-time");!D?.end_time||!I?U.classList.add("sca-d-none"):(U.classList.remove("sca-d-none"),d.handleCountdownTimer(D.end_time,L));let $=w.querySelector(".fg-gift-thumbnail-offer-footer"),j=w.querySelector(".fg-gift-thumbnail-offer-footer-quantity");M?(j.classList.remove("sca-d-none"),$.style.justifyContent="space-between"):(j.classList.add("sca-d-none"),$.style.justifyContent="flex-end")}),h=!1};return document.querySelectorAll(m).forEach(b),h&&b(document.querySelector(p)),e},renderElementGiftIconProductPage:()=>{let{product_page:e}=FGSECOMAPP.fgAppearance?.gift_icon??{},t=e?.gift_icon?.status,i=document.querySelector(P.GIFT_ICON_SECTION_ID)?.innerHTML??P.GIFT_ICON_SECTION,a=FGSECOMAPP.helper.templateHTML.render(i,{fg_class_product_or_collection_page:`sca-gift-icon-img ${t?"":"sca-d-none"}`}),{gift_icon_product_query:s}=FGSECOMAPP.QUERY_SELECTOR,c=[...s?.tool,...s?.page_builder].filter(Boolean).join(","),o=[...s?.default,...s?.integration].filter(Boolean).join(","),l=!0,_=r=>{if(!r)return;[...r.classList].some(u=>s?.page_builder?.toString()?.includes(u))||(r.style.position="relative",r.style.width="fit-content",r.classList?.toggle("sca-fg-form-icon-product-page",!0));let g=r.querySelector("#sca-gift-icon");g?g.innerHTML=a:(g=document.createElement("div"),g.setAttribute("id","sca-gift-icon"),g.innerHTML=a,r.appendChild(g)),!t&&(g.style.display="none"),l=!1};return document.querySelectorAll(c).forEach(_),l&&_(document.querySelector(o)),FGSECOMAPP.fgAppearance?.gift_icon?.gift_icon_path},renderGiftIconForProducts:e=>{let t=[],i=FGSECOMAPP.fgAppearance?.gift_icon?.collection_page?.status;Object.keys(e)?.forEach(a=>{let s=FGSECOMAPP.productsInPage[a],c=s?.positions??[];if(d.empty(c)||!Array.isArray(c))return;let o=document.querySelector(P.GIFT_ICON_SECTION_ID)?.innerHTML??P.GIFT_ICON_SECTION,l=FGSECOMAPP.helper.templateHTML.render(o,{fg_class_product_or_collection_page:`sca-gift-icon-collection-img ${i?"":"sca-d-none"}`}),_=(s?.gifts_will_receive??[]).map(n=>n.belongs_to_offer).flat(),r=[];c.forEach(n=>{n.style.position="relative",n.classList?.toggle("sca-fg-icon-collection-page",!0);let f=n.querySelector(".sca-gift-icon-collection-page");if(f){let u=f.getAttribute("data-offer-ids")?.split(","),m=_.some(p=>!u?.includes?.(p));return f.setAttribute("data-offer-ids",_.join(",")),m&&r.push(n),!1}r.push(n),f=document.createElement("div"),f.setAttribute("class","sca-gift-icon-collection-page"),f.setAttribute("data-offer-ids",_.join(","));let g=new DOMParser().parseFromString(l,"text/html");f.innerHTML=g.body.innerHTML,!i&&(f.style.display="none"),n.appendChild(f)}),r.length&&t.push({positions:r,product:{...s?.info,handle:a},gifts:d.convertProductEvent(s?.gifts_will_receive??[]),belongs_to_offer:[...new Set(_)]})}),t.length&&document.dispatchEvent(new CustomEvent(FGSECOMAPP.CUSTOM_EVENTS.PRODUCT_HAS_GIFTS,{detail:{type:"product-list",icon:FGSECOMAPP.fgAppearance?.gift_icon?.gift_icon_path,products:t,enable:i}}))},fetchVariantsSelected:()=>{FGSECOMAPP.variables.Shopify?.enable_check_variants_has_gift&&document.addEventListener("change",function(){let e=new URL(document.URL),t=parseInt(e.searchParams.get("variant"));v.renderProductPage(isNaN(t)?void 0:t)})},renderBlockEmptyProductPage:()=>{let e=document.querySelector("#bogos-gift-icon-view-block-preview-mode");e&&v.renderEmpty(e,"There is the placeholder of gift icon.");let t=document.querySelector("#bogos-gift-thumbnail-view-block-preview-mode");t&&v.renderEmpty(t,"There is the placeholder of gift thumbnail.")},renderProductPage:e=>{if(!location.href.includes("/products/"))return;document.querySelector("#sca-gift-icon")?.remove(),document.querySelector("#sca-gift-thumbnail")?.remove();let t=v.filterOfferToGiftThumbnail();if(d.empty(t)){v.renderBlockEmptyProductPage();return}let i=location.pathname.split("/"),a=i?.indexOf("products"),s=decodeURI(a>=0?i[a+1]??null:null);if(!Object.keys(t)?.includes(s)){v.renderBlockEmptyProductPage();return}let c=t[s],o=FGSECOMAPP.productsInPage[s]?.variants_has_gift??{},l=Object.keys(o),_=!0,{enable_check_variants_has_gift:r,current_product:n}=FGSECOMAPP.variables.Shopify;if(r&&(!d.empty(e)&&!l.includes(`${e}`)&&(_=!1),d.empty(e)&&!d.empty(n?.current_variant)&&!l.includes(n?.current_variant?.id?.toString())&&(_=!1),c=o[e??n?.current_variant?.id]??[]),_){let g=v.handleConvertGiftsBelongOffer(c),{product_page:u}=FGSECOMAPP.fgAppearance?.gift_icon??{},{use_old_version:m,status:p}=u?.gift_thumbnail??{};p&&(m??!0)?v.renderElementOldVersionGiftThumbnail(c,u):p&&v.renderElementGiftThumbnail(g,u),v.renderElementGiftIconProductPage(c)}let f=c?.map(g=>g.belongs_to_offer).flat();document.dispatchEvent(new CustomEvent(FGSECOMAPP.CUSTOM_EVENTS.PRODUCT_HAS_GIFTS,{detail:{type:"product",enable:FGSECOMAPP.fgAppearance?.gift_icon?.product_page?.gift_icon?.status,icon:FGSECOMAPP.fgAppearance?.gift_icon?.gift_icon_path,gifts:d.convertProductEvent(c),product:{handle:s,...n,variant:e??n?.current_variant?.id},belongs_to_offer:[...new Set(f)]}}))},fetchRoot:async(e,t={})=>{let i=document.querySelector("#bogos-gift-slider-view-block-preview-mode");if(e&&e.length>0){FGSECOMAPP.isDelayShowAdded&&(await new Promise(o=>setTimeout(o,1500)),FGSECOMAPP.isDelayShowAdded=!1);let a=FGSECOMAPP.fgAppearance?.gift_slider,s=a?.general?.use_old_version===!1;v.filterPageDisplay(a?.pages_display)&&(v.renderGiftSelectSection(Object.keys(t).length),s&&a?.general?.show_gift_type==="offer"?v.renderGiftSliderSeparateByOffer(t):v.renderGiftSliderViewByAllInOne(e),document.querySelectorAll("#freegifts-main-popup-container .glider-dots").forEach(o=>{o.children.length<=1&&(o.style.display="none")})),i&&(i.style.display="none !important")}else{let{gift_slider_query:a}=FGSECOMAPP.QUERY_SELECTOR??{},s=[...a?.page_builder,...a?.default].filter(Boolean).join(",");document.querySelectorAll(s).forEach(c=>c.innerHTML=""),i&&v.renderEmpty(i,"There is the placeholder of gift slider.")}v.renderQuerySelectorAll(),FGSECOMAPP.fetchCheckoutEvents(),FGSECOMAPP.renderPromotionMessage(FGSECOMAPP.offers),y.arrSaveAllFetch=[]},renderQuerySelectorAll:()=>{let e=document.querySelectorAll("[data-open]"),t=document.querySelectorAll("#freegifts-main-popup-container [data-close]"),i="sca-is-visible-fg",a=document.querySelectorAll("#fg-gift-items .btn-add-to-cart"),s=a.length;for(let r=0;r{r.target===document.querySelector("#freegifts-main-popup-container.sca-modal-fg.sca-is-visible-fg")&&(y.handleQuantityGiftAvailableSession("remove"),document.querySelector("#freegifts-main-popup-container.sca-modal-fg.sca-is-visible-fg").classList.remove(i))}),document.addEventListener("click",r=>{r.target.closest(".bogos-slider-close-btn")&&(y.handleQuantityGiftAvailableSession("remove"),document.querySelector("#freegifts-main-popup-container.sca-modal-fg.sca-is-visible-fg").classList.remove(i))}),document.addEventListener("keyup",r=>{r.key==="Escape"&&document.querySelector("#freegifts-main-popup-container.sca-modal-fg.sca-is-visible-fg")&&(y.handleQuantityGiftAvailableSession("remove"),document.querySelector("#freegifts-main-popup-container.sca-modal-fg.sca-is-visible-fg").classList.remove(i))});let{use_old_version:c,show_gift_type:o}=FGSECOMAPP.fgAppearance?.gift_slider?.general??{},l=c===!1,_=r=>{r.querySelector(".btn-add-to-cart").addEventListener("click",async function(){let f=this.getAttribute("data-variant")-0,g=this.getAttribute("data-offer"),u=FGSECOMAPP.offers.find(p=>p.id===g)?.giftsAvailable,m=1;if(l){let p=r.querySelector(".bogos-gift-item-quantity-input")??r.querySelector(".bogos-gift-quantity-input"),h=parseInt(p.value);m=isNaN(h)?1:Math.min(h,parseInt(u))}try{this.disabled=!0,this.classList.add("bogos-gift-adding"),this.innerHTML="",await y.addGiftToCart(f,m,g),this.disabled=!1,document.querySelector("#freegifts-main-popup-container.sca-modal-fg.sca-is-visible-fg")&&(FGSECOMAPP.isDelayShowAdded=!0,await new Promise(h=>setTimeout(h,800))),window.location.href.includes("/cart")?location.reload():typeof Shopify?.getCart=="function"&&await Shopify?.getCart(FGSECOMAPP.variables.fgCallback?.[0])}catch(p){console.error("BOGOS track: error event click add-to-cart ",p)}})};document.querySelectorAll("#fg-gift-items .dropdown").forEach(r=>r.addEventListener("click",function(){this.setAttribute("tabindex",1),this.focus(),this.classList.toggle("active"),this.querySelector(".dropdown-menu").classList.toggle("d-block")})),document.querySelectorAll("#fg-gift-items .dropdown").forEach(r=>document.addEventListener("click",function(n){r.contains(n.target)||(r.classList.remove("active"),r.querySelector(".dropdown-menu").classList.remove("d-block")),document.querySelectorAll(".btn-add-to-cart.sca-fg-out-stock").forEach(g=>{g.disabled=!0})})),document.querySelectorAll("#fg-gift-items .product-item").forEach(r=>{r.querySelectorAll(".dropdown > .dropdown-menu > li").forEach(n=>{n.addEventListener("click",function(){let f=this.getAttribute("id"),g=this.getAttribute("data-img"),u=this.getAttribute("data-price"),m=this.getAttribute("data-original-price"),p=this.getAttribute("data-original-id"),h=r.querySelector(".top-content");h.querySelector(".product-item-thumbnail").setAttribute("src",g);let b=new URL(h.querySelector(".gift-original-url").href);b.searchParams.set("variant",p),h.querySelector(".gift-original-url").href=b.toString();let S=r.querySelector(".bottom-content");S.querySelector(".original-price del").textContent=m,S.querySelector(".gift-price").textContent=u;let C=S?.querySelector(".btn-add-to-cart");C.setAttribute("data-variant",f),C.disabled=!1,C.style="";let E=S.querySelector(".selected-variant");E.classList.add("active"),E.innerHTML=this.innerText})}),_(r)}),document.querySelectorAll(".bogos-gifts-slider-container .bogos-offer-gift-item").forEach(r=>{r.querySelectorAll(".bogos-gift-select-variant-wrapper").forEach(f=>{let g=f.querySelector(".bogos-gift-select-variant-dropdown"),u=f.querySelectorAll(".bogos-gift-select-variant-option"),m=r.querySelector(".bogos-gift-item-bottom-info"),p=r.querySelector(".bogos-gift-select-variant-title"),h=m?.querySelector(".btn-add-to-cart"),b=()=>{g.classList.toggle("opened")},S=E=>{let O=E.currentTarget.getAttribute("data-variant-id")-0,A=E.currentTarget.getAttribute("data-img"),F=E.currentTarget.getAttribute("data-price"),I=E.currentTarget.getAttribute("data-original-price"),M=E.currentTarget.getAttribute("data-original-id");p.textContent=E.currentTarget.textContent.trim();let w=r.querySelector(".bogos-gift-item-image-container");w.querySelector(".bogos-gift-item-image").setAttribute("src",A);let L=new URL(w.querySelector(".gift-original-url").href);L.searchParams.set("variant",M),w.querySelector(".gift-original-url").href=L.toString(),m.querySelector(".bogos-gift-item-compare-price").textContent=I,m.querySelector(".bogos-gift-item-price").textContent=F,h.setAttribute("data-variant",O),h.disabled=!1,h.style=""},C=E=>{!f.contains(E.target)&&g.classList.contains("opened")&&g.classList.remove("opened")};document.addEventListener("click",C),u.forEach(E=>{E.addEventListener("click",S)}),g.addEventListener("click",b)}),_(r);let n=r.querySelector(".bogos-gift-select-variant");n&&n.addEventListener("change",function(){let f=r.querySelector(".bogos-gift-item-bottom-info"),g=f?.querySelector(".btn-add-to-cart");if(d.empty(this.value)){g.disabled=!0,g.setAttribute("data-variant","");return}let u=this.value-0,m=n.querySelector(`[value="${u}"]`);if(m){let p=m.getAttribute("data-img"),h=m.getAttribute("data-price"),b=m.getAttribute("data-original-price"),S=m.getAttribute("data-original-id"),C=r.querySelector(".bogos-gift-item-image-container");C.querySelector(".bogos-gift-item-image").setAttribute("src",p);let E=new URL(C.querySelector(".gift-original-url").href);E.searchParams.set("variant",S),C.querySelector(".gift-original-url").href=E.toString(),f.querySelector(".bogos-gift-item-compare-price").textContent=b,f.querySelector(".bogos-gift-item-price").textContent=h,g.setAttribute("data-variant",u),g.disabled=!1,g.style=""}})}),document.querySelectorAll(".bogos-gifts-slider-container .bogos-gift-item-quantity-wrapper").forEach(r=>{let n=r.querySelector(".bogos-gift-item-quantity-dropdown"),f=r.querySelector(".bogos-gift-item-quantity-input"),g=r.querySelectorAll(".bogos-gift-item-quantity-option"),u=()=>{n.classList.toggle("opened")},m=h=>{f.value=h.currentTarget.getAttribute("data-quantity")},p=h=>{!r.contains(h.target)&&n.classList.contains("opened")&&n.classList.remove("opened")};document.addEventListener("click",p),g.forEach(h=>{h.addEventListener("click",m)}),n.addEventListener("click",u)}),document.querySelectorAll(".freegifts-main-container .bogos-slider-offer").forEach(r=>{let n=r.querySelector("#sca-hidden-gift-popup .sca-disable-checkbox");n?.addEventListener("change",async()=>{if(n.checked)if(l&&o==="offer"){let f=r.getAttribute("data-offer");f&&(localStorage.setItem(`FGSECOMAPP_HIDDEN_GIFT_OFFER_${f}`,`${Date.now()}`),await new Promise(g=>setTimeout(g,400)),r.classList.add("sca-d-none"),document.querySelectorAll(".bogos-slider-offers-container .bogos-slider-offer:not(.sca-d-none)").length||(document.querySelector("#freegifts-main-popup-container.sca-modal-fg.sca-is-visible-fg")?.classList?.remove(i),document.querySelector("#freegifts-main-page-container:not(.sca-modal-fg)")?.classList?.add("sca-d-none")))}else localStorage.setItem("FGSECOMAPP_HIDDEN_GIFT_POPUP",`${Date.now()}`),await new Promise(f=>setTimeout(f,400)),document.querySelector("#freegifts-main-popup-container.sca-modal-fg.sca-is-visible-fg")?.classList?.remove(i),document.querySelector("#freegifts-main-page-container:not(.sca-modal-fg)")?.classList?.add("sca-d-none")})}),document.querySelectorAll(".freegifts-main-container .slide-container.sca-modal-dialog-fg").forEach(r=>{let n=r.querySelector("#sca-hidden-gift-popup .sca-disable-checkbox");n?.addEventListener("change",async()=>{n.checked&&(localStorage.setItem("FGSECOMAPP_HIDDEN_GIFT_POPUP",`${Date.now()}`),await new Promise(f=>setTimeout(f,400)),document.querySelector("#freegifts-main-popup-container.sca-modal-fg.sca-is-visible-fg")?.classList?.remove(i),document.querySelector("#freegifts-main-page-container:not(.sca-modal-fg)")?.classList?.add("sca-d-none"))})})},renderGiftsIntoPerSlider:(e,t,i,a)=>{e.innerHTML=t.map(s=>v.renderProductHTML(i,s)).join(` `),e.setAttribute("data-show-desktop",`${a}`),v.renderGlider(e,a)},renderGlider:(e,t)=>{let{bogos_settings_glider:i}=FGSECOMAPP.variables.Shopify,{general:a}=FGSECOMAPP.fgAppearance?.gift_slider,s=a?.number_product_slider_mobile??1.8,c=e.parentElement.parentElement;e.setAttribute("data-show-mobile",`${s}`),new FGSECOMAPP.helper.Glider(e,{slidesToShow:1,slidesToScroll:1,draggable:!1,dots:a?.show_pagination?c?.querySelector(".dots"):null,arrows:{prev:c?.querySelector(".glider-prev"),next:c?.querySelector(".glider-next")},responsive:[{breakpoint:750,settings:{slidesToShow:t??4,slidesToScroll:t??4}},{breakpoint:300,settings:{slidesToShow:s===1?s:s+.04,slidesToScroll:s}}],...typeof i=="object"?i:{}}).refresh()},renderGiftSliderSeparateByOffer:e=>{let t=[];Object.entries(e).forEach(([r,n])=>{let f=v.handleTransformGiftsSliderData(n),g=f;if(FGSECOMAPP.fgAppearance?.gift_slider?.general?.show_gift_for_customer==="by_variants"){g=[];for(let p of f){let h=p.variants;h&&h.length&&h.forEach(b=>g.push({...p,thumbnail:b.thumbnail,variants:[b]}))}}let u=FGSECOMAPP.offers.filter(p=>p.offer_root===r.toString()),m=u[0]??{};t.push({offer_name:m.offer_name,offer_root:r,priority:m.priority,giftsAvailable:u.reduce((p,h)=>p+h.giftsAvailable,0),arrGiftShow:g})}),t=t?.sort((r,n)=>r.priority-n.priority);let i=Math.max(...t.map(r=>r?.arrGiftShow?.length)),{general:a}=FGSECOMAPP.fgAppearance?.gift_slider,s=a?.number_product_slider??4,c=s,o=document.querySelector(P.GIFT_ITEM_SECTION_V2_ID)?.innerHTML??P.GIFT_ITEM_SECTION_V2;document.querySelectorAll(".bogos-gifts-slider-container .bogos-slider-offers-container").forEach(r=>{r.innerHTML=t.map(n=>{y.handleQuantityGiftAvailableSession("set",0,n.offer_root,n.giftsAvailable);let f=FGSECOMAPP.variables[`bogos_added_gift_${n.offer_root}`],g=FGSECOMAPP.variables[`bogos_total_gift_${n.offer_root}`];return v.renderGiftsOfferSection(f,g,{bogos_check_show_quantity_box:FGSECOMAPP.fgSettings?.select_one_gift_price?"sca-d-none":"",bogos_offer_id:n?.offer_root?.toString(),bogos_offer_title:k.convertIntegration(n.offer_name,`offer.offer_title_${n.offer_root}`,`offers.${n.offer_root}.offer_name`)})}).join(` `)}),document.querySelectorAll(".bogos-gifts-slider-container .bogos-slider-offer-switch-show").forEach(r=>{(i<=2||s<=2)&&(r.style.position="unset")});let _=document.querySelector(".bogos-gifts-slider-container.bogos-gift-slider-modal");if((i<=s||s<=4)&&_){let r=Math.min(i,s);_.style.setProperty("max-width",Math.min(r,4)*(i===1?350:163)+12*r+50+"px","important"),c=r}document.querySelectorAll(".bogos-gifts-slider-container .bogos-slider-offers-container").forEach(r=>{r.querySelectorAll(".bogos-offer-gift-items-container").forEach((n,f)=>{v.renderGiftsIntoPerSlider(n,t[f].arrGiftShow,o,c)})}),document.dispatchEvent(new CustomEvent(FGSECOMAPP.CUSTOM_EVENTS.SHOW_GIFT_SLIDER,{detail:{addGiftToCartFunc:FGSECOMAPP.helper.addGiftToCart,giftsOffer:t}}))},renderGiftSliderViewByAllInOne:e=>{let t=v.handleTransformGiftsSliderData(e),i=t;if(FGSECOMAPP.fgAppearance?.gift_slider?.general?.show_gift_for_customer==="by_variants"){i=[];for(let f of t){let g=f.variants;g&&g.length&&g.forEach(u=>i.push({...f,thumbnail:u.thumbnail,variants:[u]}))}}let a=i.length,{general:s}=FGSECOMAPP.fgAppearance?.gift_slider,c=s?.use_old_version===!1,o=s?.number_product_slider??4,l=o,_=c?document.querySelector(".bogos-gifts-slider-container.bogos-gift-slider-modal"):document.querySelector(".slide-container.sca-modal-dialog-fg"),r=c?".bogos-offer-gift-items-container":".bogos-gift-items",n=c?document.querySelector(P.GIFT_ITEM_SECTION_V2_ID)?.innerHTML??P.GIFT_ITEM_SECTION_V2:document.querySelector(P.GIFT_ITEM_SECTION_ID)?.innerHTML??P.GIFT_ITEM_SECTION;if(c){y.handleQuantityGiftAvailableSession("set");let f=FGSECOMAPP.variables.bogos_added_gift,g=FGSECOMAPP.variables.bogos_total_gift;document.querySelectorAll(".bogos-gifts-slider-container .bogos-slider-offers-container").forEach(u=>{u.innerHTML=v.renderGiftsOfferSection(f,g,{bogos_check_offer_title:"sca-d-none"})}),document.querySelectorAll(".bogos-gifts-slider-container .bogos-slider-offer-switch-show").forEach(u=>{u&&(a<=2||o<=2)&&(u.style.position="unset")})}if((a<=o||o<=4)&&_){let f=Math.min(a,o);_.style.setProperty("max-width",Math.min(f,4)*(a===1?350:163)+12*f+50+"px","important"),l=f}document.querySelectorAll(r).forEach(f=>{v.renderGiftsIntoPerSlider(f,i,n,l)}),document.dispatchEvent(new CustomEvent(FGSECOMAPP.CUSTOM_EVENTS.SHOW_GIFT_SLIDER,{detail:{addGiftToCartFunc:FGSECOMAPP.helper.addGiftToCart,gifts:d.convertProductEvent(i)}}))},renderGiftSelectSection:e=>{let t=FGSECOMAPP.fgAppearance?.gift_slider??{},i=k.convertIntegration(t?.notify_offer_available?.text??"\u{1F381} You have qualified for {{qualifiedOffers}} offer(s)!","customize.notify_offer_available_text","customize.gift_slider.notify_offer_available_text"),a=t?.general?.use_old_version===!1,{gift_slider_query:s}=FGSECOMAPP.QUERY_SELECTOR??{},c=[...s?.page_builder,...s?.default].filter(Boolean).join(","),o=document.querySelectorAll(c);if(o?.length>0){let r=a?document.querySelector(P.GIFTS_CART_SECTION_V2_ID)?.innerHTML??P.GIFTS_CART_SECTION_V2:document.querySelector(P.GIFTS_CART_SECTION_ID)?.innerHTML??P.GIFTS_CART_SECTION;o.forEach(n=>{n.classList?.toggle("freegifts-main-container",!0),n.innerHTML=FGSECOMAPP.helper.templateHTML.render(r,{sca_fg_disable_slider_section:`${v.BRAND_MARK_TEMPLATE()}`,bogos_check_show_offer_available:a&&t?.notify_offer_available?.enable&&t?.general?.show_gift_type==="offer"?"":"sca-d-none",bogos_slider_offer_available:FGSECOMAPP.helper.templateHTML.render(i,{qualifiedOffers:e,totalOffers:FGSECOMAPP.offers.length}),bogos_brand_mark:v.BRAND_MARK_TEMPLATE("bogos-brand-mark-gift-slider-v2")})});return}let{FGSECOMAPP_HIDDEN_GIFT_POPUP:l}=FGSECOMAPP.variables.constants;if(v.handleCheckHiddenGiftSlider(l)||(o=document.querySelector(s.popup.filter(Boolean).join(",")),!o))return;let _=a?document.querySelector(P.GIFTS_POPUP_SECTION_V2_ID)?.innerHTML??P.GIFTS_POPUP_SECTION_V2:document.querySelector(P.GIFTS_POPUP_SECTION_ID)?.innerHTML??P.GIFTS_POPUP_SECTION;o.innerHTML=FGSECOMAPP.helper.templateHTML.render(_,{sca_fg_disable_slider_section:`${v.HIDDEN_GIFT_POPUP()} ${v.BRAND_MARK_TEMPLATE()}`,bogos_check_show_offer_available:a&&t?.notify_offer_available?.enable&&t?.general?.show_gift_type==="offer"?"":"sca-d-none",bogos_slider_offer_available:FGSECOMAPP.helper.templateHTML.render(i,{qualifiedOffers:e,totalOffers:FGSECOMAPP.offers.length}),bogos_brand_mark:v.BRAND_MARK_TEMPLATE("bogos-brand-mark-gift-slider-v2")}),o.classList.add("sca-is-visible-fg")},renderVariantSelectOptions:(e,t)=>{let a=FGSECOMAPP.fgAppearance?.gift_slider?.general?.use_old_version===!1?document.querySelector(P.GIFT_SELECT_SECTION_V2_ID)?.innerHTML??P.GIFT_SELECT_SECTION_V2:document.querySelector(P.GIFT_SELECT_SECTION_ID)?.innerHTML??P.GIFT_SELECT_SECTION;return e.map(s=>FGSECOMAPP.helper.templateHTML.render(a,{fg_variant_img:d.handleResizeGiftImage(s.thumbnail??t),fg_variant_id:s.variant_shopify_id,fg_original_variant_id:s.original_variant_shopify_id,fg_variant_price:d.renderGiftPrice(s),fg_original_variant_price:d.renderOriginalPrice(s),fg_variant_title:s.variant_title,variant:s})).join(` `)},renderGiftQuantityOptions:e=>{let t='
  • {{ bogos_gift_quantity }}
  • ';return Array.from({length:e},(i,a)=>a+1).map(i=>FGSECOMAPP.helper.templateHTML.render(t,{bogos_gift_quantity:i})).join(` `)},renderPromotionMessage:e=>{try{if(!FGSECOMAPP.fgAppearance?.promotion_message?.show_on_cart_page)return;let{enable_hidden_message_added:t}=FGSECOMAPP.variables.Shopify??{};d.empty(e)&&(e=[...FGSECOMAPP.offers]);let i=location.href.includes("/cart"),a=[];if(e?.forEach(u=>{if(u.isReachConditions&&(!t||u.giftsAdded?.length)||d.empty(u.promotion_message)||!d.empty(FGSECOMAPP.variables.maxOfferPriority)&&!u.isReachConditions&&u.priority>FGSECOMAPP.variables.maxOfferPriority||d.empty((u.count_down_value??0)+(u.count_down_quantity??0))&&/({{\s*sca_min_total\s*}})|({{\s*sca_min_quantity\s*}})/gm.test(u.promotion_message))return;let m=u.count_down_value?.toFixed(FGSECOMAPP.variables.Shopify?.sca_amount_fixed??2);a.push({value:FGSECOMAPP.helper.templateHTML.render(k.convertIntegration(u.promotion_message,`offer.cart_message_${u.offer_root}`,`offers.${u.offer_root}.promotion_message`),{sca_min_total_with_currency:d.renderPrice(m),sca_min_total:m,sca_min_quantity:u.count_down_quantity}),offer:u})}),document.dispatchEvent(new CustomEvent(FGSECOMAPP.CUSTOM_EVENTS.RENDER_CART_MESSAGE,{detail:{data:a.map(u=>({offer:u.value,offer_root:u.offer?.offer_root}))}})),d.empty(a)){document.querySelectorAll(".sca-promotion-message-layout").forEach(m=>m.innerHTML="");let u=document.querySelector("#bogos-cart-message-view-block-preview-mode");u&&v.renderEmpty(u,"There is the placeholder of cart message.");return}let s=document.querySelector(P.CART_MSG_ITEM_SECTION_ID)?.innerHTML??P.CART_MSG_ITEM_SECTION,c=a.map(u=>FGSECOMAPP.helper.templateHTML.render(s,{fg_cart_message:u.value,offer:u.offer})).join(""),o=document.querySelector(P.CART_MSG_SECTION_ID)?.innerHTML??P.CART_MSG_SECTION,l=FGSECOMAPP.helper.templateHTML.render(o,{sca_fg_cart_message_items_section:c}),{cart_message_query:_}=FGSECOMAPP.QUERY_SELECTOR,r=document.querySelector([..._?.default].filter(Boolean).join(",")),n=document.querySelectorAll([..._?.tool,..._?.integration,..._?.page_builder].filter(Boolean).join(",")),f=document.querySelectorAll(".sca-promotion-message-layout");d.empty(f)||f.forEach(u=>u.innerHTML=l),f=document.createElement("div"),f.setAttribute("id","sca-promotion-message-layout"),f.classList.add("sca-promotion-message-layout");let g=new DOMParser().parseFromString(l,"text/html");f.innerHTML=g.body.innerHTML,d.empty(n)||n?.forEach(u=>{if(u.querySelector(".sca-promotion-message-layout"))return;let m=f.cloneNode(!0);u.prepend(m)}),r?.querySelector(".sca-promotion-message-layout")||(g=new DOMParser().parseFromString(l,"text/html"),f.innerHTML=g.body.innerHTML,r&&i&&r.prepend(f)),document.querySelectorAll(".sca-promotion-glider").forEach(u=>{let m=new FGSECOMAPP.helper.Glider(u)||{ele:null,scrollItem:()=>{}};((h,b)=>{let S=h.track.childElementCount,C=null,E=1;function O(){C=setTimeout(()=>{E>=S&&(E=0),h.scrollItem(E++)},b)}h.ele?.addEventListener("glider-animated",function(){window.clearInterval(C),O()}),O()})(m,FGSECOMAPP.variables.Shopify?.sca_deplay_cart_msg??3e3)})}catch(t){console.warn("BOGOS track: Failed render cart message",t)}},renderSuccessAddGift:()=>{if(!FGSECOMAPP.variables.Shopify?.enable_toast_added)return;let e=document.querySelector(".sca-fg-notifications");if(!e)return;e.innerHTML="";let t=FGSECOMAPP.variables.Shopify?.sca_text_notify_success??"Add gift to cart successfully!",i=document.createElement("li");i.className="sca-fg-toast sca-fg-success",i.innerHTML=`
    ${t}
    `,e.appendChild(i);let a=setTimeout(()=>v.removeToast(i),3e3);document.querySelector("#close-fg-toast")?.addEventListener("click",()=>v.removeToast(i,a))},removeToast:(e,t)=>{e.classList.add("hide"),t&&clearTimeout(t),setTimeout(()=>e.remove(),500)},HIDDEN_GIFT_POPUP:()=>{let e=FGSECOMAPP.fgAppearance?.gift_slider?.disable_slider_checkbox??{},t=document.querySelector(P.DISABLE_SLIDER_SECTION_ID)?.innerHTML??P.DISABLE_SLIDER_SECTION;return e?.enable?FGSECOMAPP.helper.templateHTML.render(t):""},handleCheckHiddenGiftSlider:e=>{let t=localStorage.getItem(e)-0,a=(FGSECOMAPP.fgAppearance?.gift_slider??{})?.disable_slider_checkbox??{},s=(a?.time??0)*60*1e3;return a?.enable&&!isNaN(t)&&t+s>Date.now()?!0:(localStorage.removeItem(e),!1)},init:()=>{v.fetchVariantsSelected(),v.renderProductPage(),v.renderElementGiftIconCollectionPage()}},G={reCallCheckout:e=>{try{let t=FGSECOMAPP.fgSettings?.mode_override_checkout,i=t==="trigger_body"?e.target:e.currentTarget??e.target;i?.hasAttribute("sca_handle_checkout")||(i=document.querySelector("#sca-spinner-checkout")?.parentNode);let a=JSON.parse(i.getAttribute("data-fg-checkout-btn"));if(i.value=a?.value??"",i.innerHTML=a?.innerHTML??"",i.disabled=!1,i.removeEventListener("click",G.progressEventCheckout),i.removeEventListener("touchstart",G.progressEventCheckout),i.removeAttribute("sca_handle_checkout"),t==="clone_checkout"){i.parentNode.querySelector("[sca_root_checkout]").click();return}t==="trigger_body"&&window.removeEventListener("click",G.handleEventCheckoutDocument,!0),FGSECOMAPP.variables.checkIsBlockCheckout=!1,i.click()}catch(t){window.location.replace(d.routePath("/checkout")),console.warn("BOGOS track: Error recall root event checkout",t)}},customLoading:async(e,t)=>{if(typeof FGSECOMAPP.helper?.scaCustomLoadingCheckout=="function"){await FGSECOMAPP.helper.scaCustomLoadingCheckout(e);return}if(e==="start"&&t)t.disabled=!0,t.setAttribute("data-fg-checkout-btn",JSON.stringify({innerHTML:t.innerHTML,value:t.value})),t.value=FGSECOMAPP.variables.Shopify?.sca_fg_value_checkout??"Loading...",t.innerHTML=FGSECOMAPP.variables.Shopify?.sca_fg_innerHTML??`
    Loading...
    `;else if(e==="end"&&t){let i=JSON.parse(t.getAttribute("data-fg-checkout-btn"));t.value=i?.value??"",t.innerHTML=i?.innerHTML??"",t.disabled=!1}else e==="error"?window.location.replace(d.routePath("/checkout")):console.warn("BOGOS track: Cannot define custom loading with type: ",e)},progressEventCheckout:async e=>{try{e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation();let{using_draft_order:t,mode_override_checkout:i}=FGSECOMAPP.fgSettings??{},{checkIsBlockCheckout:a,conditions:s}=FGSECOMAPP.variables??{},c=i==="trigger_body"?e.target:e.currentTarget??e.target,{form:o}=c;if(await G.customLoading("start",c),document.dispatchEvent(new CustomEvent(FGSECOMAPP.CUSTOM_EVENTS.START_VALIDATE_CHECKOUT,{detail:{}})),a)return!1;FGSECOMAPP.variables.checkIsBlockCheckout=!0;try{if(o&&!FGSECOMAPP.variables.Shopify?.disable_fetch_cart_checkout){let n=new URL(o.action);n.searchParams.append("sca_checkout_form",""),await d.fetch(n.toString(),{method:"POST",body:new FormData(o)})}}catch{console.log("BOGOS track: not type checkout btn")}let l=FGSECOMAPP.cartItems?.some(n=>d.checkCartItemIsGift(n));if(d.empty(FGSECOMAPP.offers)&&!l)return console.log("BOGOS track: not have orders and gifts"),G.reCallCheckout(e),!1;await d.fetchInfoCartUpdate();let _=[...FGSECOMAPP.cartItems],{arrGiftsRemove:r}=y.processCartWithOffers(_,FGSECOMAPP.offers,!1);if(await y.checkAllOffers(_,FGSECOMAPP.offers),r?.length>0)location.reload();else if(t&&!s.function&&l){let n=await N.draftOrder();FGSECOMAPP.variables.checkIsBlockCheckout=!1;let{invoice_url:f}=n?.sca_link_checkout??{};d.empty(f)?(console.warn("BOGOS track: error draft-order",n),G.reCallCheckout(e)):window.location.href=f}else console.log("BOGOS track: not using draft order"),FGSECOMAPP.variables.checkIsBlockCheckout=!1,G.reCallCheckout(e);c=i==="trigger_body"?e.target:e.currentTarget??e.target,await G.customLoading("end",c),document.dispatchEvent(new CustomEvent(FGSECOMAPP.CUSTOM_EVENTS.END_VALIDATE_CHECKOUT,{detail:{status:"done",valid:!r?.length}}))}catch(t){await G.customLoading("error"),document.dispatchEvent(new CustomEvent(FGSECOMAPP.CUSTOM_EVENTS.END_VALIDATE_CHECKOUT,{detail:{status:"error"}})),console.error("BOGOS track: Error process checkout",t)}},handleEventCheckoutDocument:async e=>{e.target?.hasAttribute("sca_handle_checkout")&&await G.progressEventCheckout(e)},renderEventCheckout:()=>{let e=FGSECOMAPP.fgSettings?.mode_override_checkout,{checkout_btn_query:t}=FGSECOMAPP.QUERY_SELECTOR,i=[...t?.tool,...t?.integration,...t?.default].filter(Boolean).join(",");document.querySelectorAll(i).forEach(a=>{let s=a.hasAttribute("sca_root_checkout"),c=a.hasAttribute("sca_clone_checkout"),o=a.hasAttribute("sca_handle_checkout"),l=!o;if(e==="clone_checkout"){if(s)return;if(!c&&!o){let _=a.cloneNode(!0);_.addEventListener("click",G.progressEventCheckout),_.addEventListener("touchstart",G.progressEventCheckout),_.addEventListener("touchend",G.progressEventCheckout),_.setAttribute("sca_handle_checkout",""),_.setAttribute("sca_clone_checkout",""),a.style.display="none",a.style.visibility="hidden",a.style.opacity="0",a.setAttribute("sca_root_checkout",""),a.parentNode?.appendChild(_)}l=c&&!o}l&&(a.addEventListener("click",G.progressEventCheckout),a.addEventListener("touchstart",G.progressEventCheckout),a.addEventListener("touchend",G.progressEventCheckout)),a.setAttribute("sca_handle_checkout",""),FGSECOMAPP.variables.hasDoneProcessCheckout=!0}),e==="trigger_body"&&window.addEventListener("click",G.handleEventCheckoutDocument,!0)},fetchEvents:()=>{FGSECOMAPP.variables.scaCountRenderEventCheckout=0,FGSECOMAPP.variables.hasDoneProcessCheckout=!1;let e=setInterval(()=>{G.renderEventCheckout(),FGSECOMAPP.variables.scaCountRenderEventCheckout++,(FGSECOMAPP.variables.scaCountRenderEventCheckout>10||FGSECOMAPP.variables.hasDoneProcessCheckout)&&(FGSECOMAPP.variables.scaCountRenderEventCheckout=0,clearInterval(e))},400)},wallets:async e=>{try{let{paymentsConfig:t}=FGSECOMAPP.variables;if(d.empty(t)&&(t=await d.fetch("/payments/config?bogos").then(s=>s.json())||{paymentInstruments:{accessToken:null}},FGSECOMAPP.variables.paymentsConfig=t),d.empty(e))return d.empty(t);let{country:i,currency:a}=FGSECOMAPP.variables.Shopify;return await d.fetchCartDefault(),await d.fetch("/wallets/checkouts/?bogos",{method:"POST",headers:{accept:"*/*",authorization:`Basic ${window.btoa(t?.paymentInstruments?.accessToken)}`,"cache-control":"no-cache","content-type":"application/json",pragma:"no-cache"},body:JSON.stringify({checkout:{...e,country:i,presentment_currency:a?.active,line_items:FGSECOMAPP.SHOPIFY_CART.items}})}),!0}catch(t){return console.warn("BOGOS track: wallets/config",t),!1}},init:()=>{G.fetchEvents()}},N={...V,getInfoProducts:async(e,t)=>{await N.fetch({sca_products_handle:d.convertObjToString(e,"uri")},t).then(async i=>{let a=await i.json(),s=[],{currency:c}=FGSECOMAPP.variables.Shopify,l=(a.currency??"USD")!==c.active;a?.products?.forEach(r=>{if(d.empty(r?.products?.id))return;let{products:n,collections:f,variants_quantity:g}=r;s.push({...l?N.convertProductCurrency(n):n,collections:f,variants_quantity:g})});let _=v.filterOfferToGiftThumbnail(s);v.renderGiftIconForProducts(_)}).catch(i=>{console.warn("BOGOS track: getInfoProductsByProxy",i)})},draftOrder:async()=>{try{let{shop:e,currency:t,add_cart_attributes:i,add_cart_discounts:a}=FGSECOMAPP.variables.Shopify,s=await N.fetch({sca_shop_name:e}).then(o=>o.json()),c=[];return i&&(c=Object.entries(s.cart[0]?.cart_attributes).map(([o,l])=>({key:o,value:`${l}`}))),s.cart=(s.cart??[]).map(o=>{o.product.collections=o.collections?.map(n=>({id:n.id})),o.product.tags=o.tags;let l=FGSECOMAPP.fgSettings.draft_order??{},_=l.discount_code||a&&typeof l.discount_code!="boolean"?o.product.discounts:[],r=Object.entries(o.product.properties??{}).map(([n,f])=>({key:n,value:`${f}`}));return{id:o.product.id,variant_id:o.product.variant_id,product_id:o.product.product_id,title:o.product.title,handle:o.product.handle,price:y.priceCartItem(o.product),quantity:o.product.quantity,product_type:o.product.product_type,vendor:o.product.vendor,tags:o.product.tags,collections:o.product.collections,selling_plan_allocation:o.product.selling_plan_allocation,discounts:_,properties:r}}),s.others={secomapp:{customer:SECOMAPP?.customer??{},fg_codes:SECOMAPP?.fg_codes??[],fgSettings:FGSECOMAPP.fgSettings},cookie_fg_code:FGSECOMAPP.variables.sca_fg_codes,shopify_currency:t,customer_location:FGSECOMAPP.customerLocation,cart_attributes:c,arr_offer_added:q.isSpecificOffer?void 0:FGSECOMAPP.arrOfferAdded,max_priority_draft_order:FGSECOMAPP.variables.maxTodayOfferPriority},await N.fetch({data_checkout:d.convertObjToString(s,"uri")}).then(o=>o.json())||{sca_link_checkout:null}}catch(e){return{error:e.message}}}},{fetch:W}=window,q={isSpecificOffer:!1,overrideFetch:()=>{let{disable_override_fetch:e,disable_async_process_fg:t}=FGSECOMAPP.variables.Shopify;FGSECOMAPP.variables.isCheckout||e||(window.fetch=async function(){let i=W.apply(this,arguments);try{let a=typeof arguments[0]=="string"&&arguments[0],s=typeof arguments[1]?.body=="string"&&arguments[1]?.body,c=R.cart.test(a??""),o=a?.includes("graphql.json")&&R.graphql.test(s??"");if(c||o){let l=c?a.match(R.cart):s.match(R.graphql),_=()=>i.then(async function(r){r.ok&&await y.checkEventCart([`fetch-override:${l?.[0]}`])});t?_().then():await _()}document.dispatchEvent(new CustomEvent(FGSECOMAPP.CUSTOM_EVENTS.FG_OVERRIDE_FETCH))}catch(a){console.warn("BOGOS track: fetch override error",a)}return i})},listenAPI:()=>{let e=d.debounce(function(){v.renderElementGiftIconCollectionPage()},1e3);new PerformanceObserver(t=>{let i=!1;t.getEntries().forEach(a=>{let{initiatorType:s,name:c,responseStatus:o}=a,l=["xmlhttprequest","fetch"].includes(s),_=["sca_attr_cart","_bogos-ignore","bogos_discount"].some(n=>c.includes(n));if(o>=400)return;let[r]=y.arrSaveAllFetch.slice(-1);if(l&&!_&&R.cart.test(c)){let n=c.match(R.cart)?.[0];!(r===`fetch-override:${n}`)&&y.checkEventCart([`observer:${n}`]).then()}window?.Spurit?.global?.loaded&&document.querySelector("#occ3-drawer .spurit-occ3__slide-drawer")&&(FGSECOMAPP.renderPromotionMessage(),FGSECOMAPP.fetchCheckoutEvents()),i||=l&&!c.includes(SECOMAPP.freegiftProxy)}),i&&e()}).observe({entryTypes:["resource"]})},shopify_getCart:()=>{try{if(FGSECOMAPP.variables.Shopify?.disableShopify_getCart||typeof Shopify?.getCart!="function")return;Shopify.getCart=async function(e){if(!FGSECOMAPP.variables.secomappGetCartRunning){FGSECOMAPP.variables.secomappGetCartRunning=!0,await y.checkEventCart(["Shopify.getCart",{}]);let t=await d.fetchCartDefault("sca_cart_xhr");typeof e=="function"&&(FGSECOMAPP.variables.fgCallback.push(e),e(t)),FGSECOMAPP.variables.secomappGetCartRunning=!1}FGSECOMAPP.fetchCheckoutEvents()},typeof ShopifyAPI<"u"&&typeof ShopifyAPI.getCart<"u"&&(ShopifyAPI.getCart=Shopify?.getCart),typeof Shopify?.api<"u"&&typeof Shopify?.api?.getCart<"u"&&(Shopify.api.getCart=Shopify?.getCart)}catch(e){console.warn("BOGOS track: initializeForXHR Shopify.getCart",e)}},createGlobalVariables:()=>{let{cart_and_checkout_validation:e,offer_process:t}=FGSECOMAPP.fgSettings??{};q.isSpecificOffer=e?.offer||t===T.OFFER_TYPE.function,window.fgData?.offers?.forEach(i=>{FGSECOMAPP.variables.giftIds=FGSECOMAPP.variables.giftIds.concat(i.gift_items.map(a=>a.variant_shopify_id)),FGSECOMAPP.variables.gifts.originalProducts=FGSECOMAPP.variables.gifts.originalProducts.concat(i.gift_products.map(a=>a.original_product_shopify_id)),t!==T.OFFER_TYPE.function&&(FGSECOMAPP.variables.gifts.clonedProducts=FGSECOMAPP.variables.gifts.clonedProducts.concat(i.gift_products.map(a=>a.product_shopify_id))),FGSECOMAPP.variables.conditions.locations||=!d.empty(i.sub_conditions?.customer_locations),FGSECOMAPP.variables.conditions.collections||=i.offer_conditions?.[0]?.product_narrow?.some(a=>a.type===T.NARROW_TYPE.collection)??!1}),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),FGSECOMAPP.helper={...FGSECOMAPP.helper,initializeForXHR:q.shopify_getCart,customLoadingCheckout:G.customLoading,fetchCheckoutEvents:G.fetchEvents,renderPromotionMessage:v.renderPromotionMessage,renderProductPage:v.renderProductPage,addGiftToCart:y.handleAddGift},FGSECOMAPP.fetchCheckoutEvents=G.fetchEvents,FGSECOMAPP.renderPromotionMessage=v.renderPromotionMessage,FGSECOMAPP.variables.isCheckout=document.querySelector("#secomapp_freegifts_version")?.getAttribute("data-template")==="fg-checkout",FGSECOMAPP.variables.conditions.function=t===T.OFFER_TYPE.function,document.addEventListener(FGSECOMAPP.CUSTOM_EVENTS.BOGOS_FG_PROCESS,i=>{y.checkEventCart([i.detail?.event??"bogos:gifts"]).then()}),document.addEventListener(FGSECOMAPP.CUSTOM_EVENTS.BOGOS_FG_INIT,()=>{y.init("bogos:rollback",null,!0).then()}),document.addEventListener(FGSECOMAPP.CUSTOM_EVENTS.BOGOS_FG_CART_MESSAGE,()=>v.renderPromotionMessage()),document.addEventListener(FGSECOMAPP.CUSTOM_EVENTS.RERENDER_GIFT_SLIDER,()=>{let{general:i}=FGSECOMAPP.fgAppearance?.gift_slider,s=i?.use_old_version===!1?".bogos-offer-gift-items-container":".bogos-gift-items";document.querySelectorAll(s).forEach(c=>{let o=parseInt(c.getAttribute("data-show-desktop"));v.renderGlider(c,isNaN(o)?4:o)})})},init:async()=>{q.createGlobalVariables(),G.init(),await y.init("init-page",()=>{q.listenAPI(),q.overrideFetch(),q.shopify_getCart()}),v.init(),setTimeout(()=>{v.renderPromotionMessage()},2e3)}};q.init().then()})();})();