1import{v as T}from"./v4.js";class d{static set(e,i){window.localStorage.setItem(e,i)}static get(e){return window.localStorage.getItem(e)}static exists(e){return this.get(e)!==null}static getOrAdd(e,i){const a=this.get(e);if(a!==null)return a;const o=i();return this.set(e,o),o}static remove(e){window.localStorage.removeItem(e)}static getAll(){const e=window.localStorage,i={};for(let a=0;a<e.length;a++){const o=e.key(a);if(o!==null){const r=e.getItem(o);r!==null&&(i[o]=r)}}return i}}class A{static set(e,i){window.sessionStorage.setItem(e,i)}static get(e){return window.sessionStorage.getItem(e)}static exists(e){return this.get(e)!==null}static getOrAdd(e,i){const a=this.get(e);if(a!==null)return a;const o=i();return this.set(e,o),o}static remove(e){window.sessionStorage.removeItem(e)}static getAll(){const e=window.sessionStorage,i={};for(let a=0;a<e.length;a++){const o=e.key(a);if(o!==null){const r=e.getItem(o);r!==null&&(i[o]=r)}}return i}}const M="sessionId",f="authlessId",g="authlessIdExpiresAt",X=7*24*60*60*1e3,v=window.envName==="Production",b=v?"eyAic3VwcGxpZXJJZCI6IDI4LCAib3JpZ2luIjogImN1aXNpbmVheiIsICJkb21haW4iOiAibWVhbHouY3Vpc2luZWF6LndlYiIsICJub1N1cHBsaWVyIjogdHJ1ZSB9":"eyAic3VwcGxpZXJJZCI6IDI5LCAib3JpZ2luIjogImN1aXNpbmVheiIsICJkb21haW4iOiAibWlhbS50ZXN0IiwgIm5vU3VwcGxpZXIiOiB0cnVlIH0=",k="https://ssr-api.mealz.ai",z=(v&&k?k:"https://ssr-api-uat.mealz.ai").replace(/\/$/,""),$=`${z}/v2/generate-authless-token`,D=`${z}/v2/styles`,x="cuisineaz-1548",G="coursesu",P=new Map,I="[Mealz]";function l(t){console.log(I,t)}function m(t){console.warn(I,t)}function s(t){console.debug(I,t)}function h(t,e){if(typeof e>"u"){console.error(I,t);return}console.error(I,t,e)}function w(t){var e;return typeof((e=window==null?void 0:window.caz)==null?void 0:e.tasks)!="function"?(t.forEach(i=>i()),Promise.resolve()):new Promise(i=>{window.caz.tasks([...t,i])})}function O(){var t;return typeof((t=window.crypto)==null?void 0:t.randomUUID)=="function"?window.crypto.randomUUID():T()}function R(){const t=A.get(M);if(t!==null&&t!=="")return s("sessionId already present in sessionStorage"),t;const e=O();return A.set(M,e),l("Created missing sessionId in sessionStorage"),e}function K(){const t=d.get(f),e=d.get(g);if(t===null||t==="")return s("No authlessId found in localStorage"),null;if(e===null)return d.remove(f),m("authlessId had no expiration and was removed"),null;const i=Number(e);return Number.isNaN(i)||i<=Date.now()?(d.remove(f),d.remove(g),m("authlessId expired and was removed"),null):(s("authlessId already present in localStorage"),t)}function j(t){d.set(f,t),d.set(g,(Date.now()+X).toString())}async function F(t){var r,n;l("Requesting authlessId from Mealz SSR");const e=await fetch($,{method:"GET",headers:{"Session-id":t,"Supplier-token":b,"Language-id":"fr"}}),i=await e.text();if(!e.ok)throw new Error(`Unable to create Mealz authless id (${e.status}): ${i}`);if(i.trim()==="")throw new Error("Invalid Mealz authless id response");const a=JSON.parse(i),o=(n=(r=a.authlessId)!=null?r:a.authless_id)!=null?n:"";if(o.trim()==="")throw new Error("Invalid Mealz authless id response");return l("Mealz authlessId received"),o}async function Y(t){const e=K();if(e!==null)return{authlessId:e,created:!1};const i=await F(t);return j(i),{authlessId:i,created:!0}}function q(t){const e=t.trim();if(e==="")return"";if(!e.startsWith("{"))return t;try{const i=JSON.parse(t);if(typeof i.html=="string")return i.html}catch{return t}return""}async function C(t,e,i){s(`Loading Mealz style ${t}`);const a=await fetch(`${D}${t}`,{method:"GET",headers:{"Session-id":e,"Authless-id":i,"Supplier-token":b,"Language-id":"fr"}}),o=await a.text();if(!a.ok)throw new Error(`Unable to load Mealz styles (${a.status}): ${o}`);return q(o)}async function _(t,e){l("Loading Mealz styles");const i=await Promise.all([C("/base",t,e),C("/no-supplier-add-to-cart-cta",t,e)]);await w(i.map(a=>()=>{a.trim()!==""&&document.head.insertAdjacentHTML("beforeend",a)})),l("Mealz styles loaded")}function Q(t){var e;return{attributes:Array.from(t.attributes).map(i=>({name:i.name,value:i.value})),textContent:(e=t.textContent)!=null?e:""}}
1function ee(t){return`${t.attributes.map(i=>`${i.name}=${i.value}`).sort().join("|")}|${t.textContent}`}function W(t){const e=document.createElement("script");return t.attributes.forEach(i=>{e.setAttribute(i.name,i.value)}),e.textContent=t.textContent,e}async function te(t){if(t.length===0){s("No Mealz scripts to append");return}const e=document.head||document.body;if(!e){m("Unable to append Mealz scripts because no script host is available");return}l("Appending Mealz scripts"),await w(t.map(i=>()=>e.appendChild(W(i)))),l("Mealz scripts appended")}function ie(t){const e=t.trim();if(e==="")return{html:"",scripts:[]};let i=t;if(e.startsWith("{"))try{const n=JSON.parse(t);typeof n.html=="string"&&(i=n.html)}catch{i=t}const a=document.createElement("template");a.innerHTML=i;const o=Array.from(a.content.querySelectorAll("script")),r=o.map(n=>Q(n));return o.forEach(n=>n.remove()),{html:a.innerHTML,scripts:r}}async function ae(t,e,i){s(`Loading Mealz SSR markup for recipeId ${t}`);const a=await fetch(`${z}/v2/no-supplier-a
1dd-to-cart-cta?recipe_id=${encodeURIComponent(t)}`,{method:"GET",headers:{"Session-id":e,"Authless-id":i,"Supplier-token":b,"Language-id":"fr"}}),o=await a.text();if(!a.ok)throw new Error(`Unable to load Mealz markup (${a.status}): ${o}`);return ie(o)}function V(t,e,i){const a=t.trim(),o=P.get(a);if(o)return o;const r=ae(a,e,i);return P.set(a,r),r}function oe(t){var e;return(e=t.getAttribute("recipeid"))!=null?e:t.getAttribute("recipeId")}function ne(t){const e=document.createElement("template");return e.innerHTML=t,e.content}function re(t,e){var o,r;const i=Array.from(e.classList);if(i.length===0)return;const a=(r=(o=t.firstElementChild)!=null?o:t.querySelector("mealz-no-supplier-add-to-cart-cta"))!=null?r:t.querySelector("button");a==null||a.classList.add(...i)}async function se(t,e){const i=Array.from(document.querySelectorAll("mealz-add-to-cart"));if(i.length===0){m(`No <mealz-add-to-cart> elements found, loading fallback scripts for ${x}`);const n=await V(x,t,e);await te(n.scripts);return}l(`Mealz placeholders found: ${i.length}`);const a=new Map,o=(await Promise.all(i.map(async n=>{const c=oe(n);if(c===null||c.trim()==="")throw new Error("Mealz recipe id is missing");const u=await V(c,t,e);return u.scripts.forEach(S=>a.set(ee(S),S)),u.html.trim()===""?null:{element:n,fragment:ne(u.html),recipeId:c}}))).filter(n=>n!==null),r=[];o.forEach(n=>{r.push(()=>{re(n.fragment,n.element),n.element.replaceWith(n.fragment),s(`Mealz placeholder replaced for recipeId ${n.recipeId}`)})}),a.forEach(n=>{r.push(()=>{const c=document.head||document.body;c==null||c.appendChild(W(n))})}),await w(r),l("Mealz markup and scripts applied")}const y=70,le=100;let J=!1,Z=!1,L=!1,B=!1,p=null;function H(){return window.mealz||null}function U(){var a,o;if(J){s("Mealz basket button already bound");return}const t=document.querySelector(".miam_basket_button"),e=H();if(!t||!((a=e==null?void 0:e.basket)!=null&&a.openPreview)||!((o=e==null?void 0:e.basket)!=null&&o.recipeCount)){s("Mealz basket button not ready yet");return}const i=t.querySelector(".basket_recipe_count");J=!0,l("Mealz basket button bound"),t.addEventListener("click",()=>{s("Mealz basket button clicked"),e.basket.openPreview()}),e.basket.recipeCount().subscribe(r=>{i&&(i.innerHTML=r.toString())})}function N(t){const e=t.querySelector(".mealz-no-supplier-add-to-cart-cta--static");if(!e)return;if(t.getAttribute("in-basket")==="true"){e.innerHTML='<span class="svg_added-to-basket"></span> Voir les ingr\xE9dients';return}const a=t.classList.contains("mealz-no-supplier-cta--below-ingredients");e.innerHTML=a?'<span class="svg_add-to-basket"></span> Ajouter les ingr\xE9dients dans mon panier':'<span class="svg_add-to-basket"></span> Ajouter au panier'}function ce(t,e){if(t.querySelector(".mealz-no-supplier-add-to-cart-cta--static")){e(t);return}const i=new MutationObserver(()=>{t.querySelector(".mealz-no-supplier-add-to-cart-cta--static")&&(i.disconnect(),e(t))});i.observe(t,{childList:!0,subtree:!0})}function E(){if(Z){s("Mealz add to cart buttons already bound");return}const t=document.querySelectorAll("mealz-no-supplier-add-to-cart-cta");if(t.length===0){s("Mealz add to cart buttons not ready yet");return}Z=!0,l("Mealz add to cart buttons bound"),t.forEach(e=>{ce(e,N),e.addEventListener("inBasketStatus",()=>N(e))})}function de(){if(L){s("Mealz supplier selector filter already patched");return}L=!0,customElements.whenDefined("mealz-supplier-selector").then(()=>{var i;const t=customElements.get("mealz-supplier-selector"),e=(i=t==null?void 0:t.prototype)==null?void 0:i.getVisibleSuppliers;if(typeof e!="function"){s("mealz-supplier-selector.getVisibleSuppliers is missing, nothing to patch");return}t.prototype.getVisibleSuppliers=function(){var o;const a=e.call(this);return a.length>0?a:((o=this.supplierList)!=null?o:[]).filter(r=>{var n,c;return((c=(n=r==null?void 0:r.attributes)==null?void 0:n.key)!=null?c:"").trim().toLowerCase()===G})},l("Mealz supplier selector filter patched")}).catch(t=>h("Failed to patch Mealz supplier selector filter",t))}function ue(t,e){var a,o,r,n,c,u;const i=H();return(a=i==null?void 0:i.supplier)!=null&&a.setupWithToken?!((o=i==null?void 0:i.user)!=null&&o.setLanguage)||!((r=i==null?void 0:i.user)!=null&&r.loadWithAuthlessId)?(s("window.mealz.user is not ready"),!1):(n=i==null?void 0:i.basket)!=null&&n.initialize?(c=i==null?void 0:i.hook)!=null&&c.setHookCallback?(l("Initializing Mealz SDK"),i.supplier.setupWithToken(b),i.user.setLanguage("fr"),i.basket.initialize(),e&&((u=i.pos)==null?void 0:u.load)&&i.pos.load(null),i.user.loadWithAuthlessId(t),i.hook.setHookCallback(()=>!0),B=!0,U(),E(),l("Mealz SDK initialized successfully"),!0):(s("window.mealz.hook.setHookCallback is missing"),!1):(s("window.mealz.basket.initialize is missing"),!1):(s("window.mealz.supplier.setupWithToken is missing"),!1)}function pe(t,e){return B?(s("Mealz SDK already initialized"),U(),E(),Promise.resolve(!0)):p?(s("Mealz SDK bootstrap already in progress"),p):(l("Waiting for Mealz SDK"),p=new Promise(i=>{let a=0;const o=()=>
1{if(a++,s(`Mealz SDK bootstrap attempt ${a}/${y}`),ue(t,e)){p=null,i(!0);return}if(a>=y){p=null,m(`Mealz SDK did not become ready after ${y} attempts`),i(!1);return}setTimeout(o,le)};o()}),p)}async function me(){if(l("Starting Mealz initialization"),b.trim()===""){l("Mealz is disabled because the supplier token is empty");return}de();const t=R(),{authlessId:e,created:i}=await Y(t);s(`Mealz authlessId ready: ${String(Boolean(e))}`),l("Loading Mealz styles and SSR markup in parallel"),await Promise.all([_(t,e).catch(o=>h("Failed to load styles",o)),se(t,e).catch(o=>h("Failed to load markup",o))]),l("Mealz styles and markup loaded"),await pe(e,i)||m("window.mealz SDK is not ready")}window.caz.ready(()=>{me().catch(t=>{h("Initialization failed",t)})});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.