(function(){"use strict";const k=window.ikea.marketingTags,y=window.ikea.marketingTags.utils,h={PAGE_VIEW:"pageView",ADD_TO_CART:"addToCart",ADD_TO_WISHLIST:"addToWishlist",STOCKCHECK:"stockcheck",SEARCH:"search",WISHLIST:"wishlist",VIEW_ITEM:"viewItem",VIEW_CART:"viewCart",VIEW_CATEGORY:"viewCategory",PROFILE_SIGNUP:"profileSignup",PROFILE_LOGIN:"profileLogin",PROFILE_LOGOUT:"profileLogout",PROFILE_UPDATE:"profileUpdate",PROFILE_VIEW:"profileView",PURCHASE:"purchase"},b=["PageView","Search","AddToCart","AddToWishlist","ViewContent","InitiateCheckout","AddPaymentInfo","Purchase","CompleteRegistration","Contact","CustomizeProduct","Donate","FindLocation","Lead","Schedule","StartTrial","SubmitApplication","Subscribe"],w={riig:"3465423686912116",roig:"888079142586440"};function f(s){let t=document.cookie.match(new RegExp("(?:^|; )"+s.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g,"\\$1")+"=([^;]*)"));try{if(t)return decodeURIComponent(t[1])}catch(e){return console.error(`Failed to decode cookie "${s}":`,e),null}}function E(s,t,e,{domain:i,path:n="/",secure:c=!0,samesite:a="lax",expFormat:o}={}){if(!s)return console.error("Failed to set cookie. A cookie must at least have a name.");t=encodeURIComponent(typeof t=="string"?t:JSON.stringify(t));let d=`${s}=${t};path=${n};samesite=${a}`;if(typeof e=="number"){if(e<=0)d+=`;expires=${new Date(null).toUTCString()}`;else if(e>0){o=o==="m"?"Minutes":o==="h"?"Hours":"Date";let l=new Date;l[`set${o}`](l[`get${o}`]()+e),d+=`;expires=${l.toUTCString()}`}}i&&(d+=`;domain=${i}`),c&&(d+=";secure"),document.cookie=d}const u=function(s=[]){return s.length?s.reduce((t,{quantity:e=1})=>Number(t)+Number(e),0):1},p=function(s=[]){const t=s?.reduce((e,{price:i=0,quantity:n=1})=>Number(e)+Number(i)*Number(n),0)?.toFixed(2);return!t||t==="NaN"?0:Number(t)},_=(s={})=>s.client_event_id||k.initial_client_event_id;class C extends y.classes.Pixel{constructor(t,e,{name:i="fb",tagType:n}={}){if(!t)throw new Error('MetaPixel: Failed to initialize pixel. Argument "pixelId" is required');if(!e)throw new Error('MetaPixel: Failed to initialize pixel. Argument "marketType" is required');super(i,t,"https://www.facebook.com/"),this.marketType=e,this.language=this.b.language,this.country=this.b.country||"mx",this.currency=this.b.currency||"MXN",this.tagType=n||"script",this._scriptURL="https://connect.facebook.net/en_US/fbevents.js",this._endpointPath="tr",this._cDomain=".ikea.com",this._cExpiry=30,this.fbp=this._fbp,this.fbc=this._fbc,this.tagType==="script"&&(window.fbq||this._loadScript(),this.fbq=window.fbq,this.fbq("set","autoConfig",!1,this.id),this.fbq("init",this.id))}get _cookiePrefix(){return`fb.1.${Date.now()}.`}get _fbp(){const t=f("_fbp")||`${this._cookiePrefix}${Math.round(2147483647*Math.random())}`;return this._setFbCookie("_fbp",t),t}get _fbc(){const t=f("_fbc"),e=t?.split(".").pop(),i=new URLSearchParams(window.location.search).get("fbclid");if(i&&i!==e){const n=`${this._cookiePrefix}${i}`;return this._setFbCookie("_fbc",n),n}return t||null}_setFbCookie(t,e){E(t,e,this._cExpiry,{domain:this._cDomain})}_getTrackType(t){return b.includes(t)?"trackSingle":"trackSingleCustom"}_loadScript(){const t=window.fbq=function(){t.callMethod?t.callMethod.apply(t,arguments):t.queue.push(arguments)};window._fbq||(window._fbq=t,t.push=t,t.loaded=!0,t.version="2.0",t.queue=[]);const e=document.createElement("script");e.async=!0,e.src=this._scriptURL;const i=document.getElementsByTagName("script")[0];i.parentNode.insertBefore(e,i)}_sendScriptEvent(t,e){const i=this._getTrackType(t);this.fbq(i,this.id,t,e)}_sendImgEvent(t,e,i){let n;try{n=new URL(document.referrer),n=n.origin+n.pathname}catch{n=null}const c={id:this.id,ev:t,dl:`${window.location.origin}${window.location.pathname}`,...n&&{rl:n},ts:Date.now(),fbp:this.fbp,...i&&{eid:i},...this.fbc&&{fbc:this.fbc}};Object.entries(e).forEach(([a,o])=>{o&&(c[`cd[${a}]`]=typeof o!="string"?JSON.stringify(o):o)}),super.send({queryParams:new URLSearchParams(c),path:this._endpointPath})}send(t,e={},i){this.tagType==="script"&&typeof this.fbq=="function"?this._sendScriptEvent(t,e):this._sendImgEvent(t,e,i)}trackEventCB(t,e,i={}){window.addEventListener(t,({detail:n={}})=>{const{metaEvent:c,payload:a={}}=e(n)||{};c&&this.send(c,a,_(n))},i)}getContentCategory(t,e){if(t==="view_item"||e==="pip")return`${this.b.category_local.toLowerCase()||""} - ${this.b.category||""}`;if(e==="plp"&&this.b.page_category_level==="chapter"){const i=this.b.site_level_2.toLowerCase().split("-"),n=i.pop();return`${i.join(" ")} - ${n}`}}getEventPayload({event_action:t,event_label:e,items:i=[],currency:n,value:c,cart_quantity:a}={}){const o={};return this.marketType==="riig"&&(o.country=this.country,o.language=this.language),i.length?(i.length===1&&i[0]?.name&&(o.content_name=i[0].name.toUpperCase()),{...o,currency:n??this.currency,value:Number(c)||p(i),content_type:"product",contents:i.map(({id:d,quantity:l,price:m})=>({id:d,quantity:l||1,...m&&{item_price:m}})),content_category:this.getContentCategory(t,e),...a&&{num_items:a}}):o}trackPageView(){this.tagType!=="script"&&!_()?window.addEventListener("initial_client_event_id_set",({detail:t}={})=>{this.send("PageView",this.getEventPayload(),t.client_event_id)}):this.send("PageView",this.getEventPayload(),_())}trackSearch(t,{detail:{event_label:e,client_event_id:i}}){this.send("Search",{...this.getEventPayload(),search_string:e},i)}trackAddToWishlist(t,{detail:{event_label:e,client_event_id:i}}){this.send("AddToWishlist",this.getEventPayload({items:t,event_label:e}),i)}trackAddToCart(t,{detail:{event_label:e,custom:{cart_value_local:i}={},client_event_id:n}}){this.send("AddToCart",this.getEventPayload({items:t,event_label:e,value:i}),n)}trackViewItem(t,{detail:{client_event_id:e}}){this.send("ViewContent",this.getEventPayload({items:t,event_action:"view_item"}),e)}trackCompleteKitchenAppointments(){new Set(["gb","se"]).has(this.country)||this.trackEventCB("self_serve_actions",({event_action:e,custom:{step:i}={}})=>{if(e==="appointment"&&i==="4")return{metaEvent:"Complete_Appointment_Kitchen",payload:this.getEventPayload()}})}trackInitiateCheckout(){const t={};this.trackEventCB("checkout_progress",({event_label:e,custom:{cart_value:i,cart_quantity:n},params:{currency:c,items:a=[]}}={})=>{e==="cart_view"&&(t.items=a,t.currency=c,t.value=i,t.cart_quantity=n||u(a))}),this.trackEventCB("cart",({event_action:e}={})=>{if(e==="create_checkout_redirect")return{metaEvent:"InitiateCheckout",payload:this.getEventPayload(t)}})}trackPurchase(t,{detail:{currency:e,value:i,transaction_id:n,client_event_id:c}={},custom:{cart_quantity:a}={}}){const o={items:t,value:i,currency:e,order_id:n,cart_quantity:a||u(t)};this.country==="se"&&delete o.order_id,this.send("Purchase",this.getEventPayload(o),c)}}class P extends C{trackInitiateCheckout(){r.trackEventCB("ecommerce",({event_action:t,event_label:e,custom:{cart_value:i,cart_quantity:n},params:{currency:c,items:a=[]}={}}={})=>{if(t==="checkout_progress"&&e==="checkout_step_1"){const o={items:a,currency:c,value:i||p(a),num_items:n||u(a)},d=r.getEventPayload(o);return{metaEvent:"InitiateCheckout",payload:d}}})}trackAddPaymentInfo(){r.trackEventCB("ecommerce",({event_action:t,event_label:e,custom:{cart_value:i,cart_quantity:n},params:{currency:c,items:a=[]}={}}={})=>{if(t==="checkout_progress"&&e==="checkout_step_3"){const o={items:a,currency:c,value:i||p(a),num_items:n||u(a)},d=r.getEventPayload(o);return{metaEvent:"AddPaymentInfo",payload:d}}})}}const g="roig",v="mx",T="MXN",I=w[g],{name:S,tagType:A}=typeof _META_CONFIG<"u"?_META_CONFIG:{},r=new P(I,g,{name:S,countryCode:v,currencyCode:T,tagType:A});r.trackPageView(),r.track(h.SEARCH),r.track(h.ADD_TO_CART),r.track(h.ADD_TO_WISHLIST),r.b.site_level_1==="p"?r.track(h.VIEW_ITEM):r.b.site_level_1==="checkout"&&(r.trackInitiateCheckout(),r.trackAddPaymentInfo(),r.track(h.PURCHASE)),r.trackLocal()})();