@gengage/assistant-fe 0.5.0 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/native.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a, i, n as t, r, t as s } from "./native-webview-y3a9R9hH.js";
1
+ import { a, i, n as t, r, t as s } from "./native-webview-BQPhKMli.js";
2
2
  export {
3
3
  s as DEFAULT_NATIVE_TRACKED_EVENTS,
4
4
  t as applyNativeSession,
@@ -134,7 +134,7 @@ var q = class {
134
134
  sku: i,
135
135
  mountTarget: t
136
136
  };
137
- this.options.theme !== void 0 && (o.theme = this.options.theme), this.options.pricing !== void 0 && (o.pricing = this.options.pricing), this.options.simrel?.discountType !== void 0 && (o.discountType = this.options.simrel.discountType), this.options.simrel?.gridColumns !== void 0 && (o.gridColumns = this.options.simrel.gridColumns), this.options.simrel?.renderCardElement !== void 0 && (o.renderCardElement = this.options.simrel.renderCardElement), this.options.simrel?.renderer !== void 0 && (o.renderer = this.options.simrel.renderer), this.options.onAddToCart !== void 0 && (o.onAddToCart = this.options.onAddToCart), this.options.onProductNavigate !== void 0 ? o.onProductNavigate = this.options.onProductNavigate : o.onProductNavigate = (n, u, c) => {
137
+ this.options.theme !== void 0 && (o.theme = this.options.theme), this.options.pricing !== void 0 && (o.pricing = this.options.pricing), this.options.simrel?.discountType !== void 0 && (o.discountType = this.options.simrel.discountType), this.options.simrel?.gridColumns !== void 0 && (o.gridColumns = this.options.simrel.gridColumns), this.options.simrel?.enableProductGroupings !== void 0 && (o.enableProductGroupings = this.options.simrel.enableProductGroupings), this.options.simrel?.renderCardElement !== void 0 && (o.renderCardElement = this.options.simrel.renderCardElement), this.options.simrel?.renderer !== void 0 && (o.renderer = this.options.simrel.renderer), this.options.onAddToCart !== void 0 && (o.onAddToCart = this.options.onAddToCart), this.options.onProductNavigate !== void 0 ? o.onProductNavigate = this.options.onProductNavigate : o.onProductNavigate = (n, u, c) => {
138
138
  g(n) && (this._chat?.saveSession(c ?? this.session.sessionId, u), window.location.href = n);
139
139
  }, await h.init(o), this._simrel = h;
140
140
  }
package/dist/overlay.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { i as t, t as a } from "./context-BBuSsXZ9.js";
2
- import { i as r, n as i, r as o, t as d } from "./overlay-v3nvcGlE.js";
2
+ import { i as r, n as i, r as o, t as d } from "./overlay-C0NSAZoL.js";
3
3
  export {
4
4
  a as bootstrapSession,
5
5
  d as buildOverlayIdempotencyKey,
@@ -1,4 +1,4 @@
1
- import { a, i as r, n, r as t, t as s } from "./runtime-BMNOS2Mq.js";
1
+ import { a, i as r, n, r as t, t as s } from "./runtime-Rp4C5hl9.js";
2
2
  export {
3
3
  s as GengageQNA,
4
4
  t as createDefaultQnaUISpecRegistry,
package/dist/qna.iife.js CHANGED
@@ -44,7 +44,7 @@
44
44
  transform: translateY(0);
45
45
  }
46
46
  }
47
- `,document.head.appendChild(e)}var X=null;function Mn(){if(X!==null)return X;try{X=localStorage.getItem("gengage:debug")==="1"}catch{X=!1}return X}function Te(e,t,n){if(!Mn())return;const r=[`[gengage:${e}]`,t];n!==void 0&&r.push(n),console.debug(...r)}var Fn=("0.5.0".trim(),"0.5.0".trim()),Hn=("iife-build".trim(),"iife-build".trim());function Jn(){if(typeof window>"u")return;const e=window;e.__gengageSdkRuntimeInfoLogged||(e.__gengageSdkRuntimeInfoLogged=!0,console.info(`[gengage] @gengage/assistant-fe v${Fn} (${Hn})`))}var Qn=class{constructor(){this.isVisible=!1,this.isInitialised=!1,this._handlers=new Map,this._cleanups=[],this._ownsRoot=!1,this._destroying=!1}async init(e){if(this.isInitialised){console.warn("[gengage] Widget already initialised. Call update() instead.");return}const t=In(e.theme);Jn(),this.config={...e,theme:t,session:$n(e.session)},this.root=this._resolveMount(e.mountTarget),this._applyTheme(t),Nn();const n=Qe("gengage:context:update",r=>this.update(r));this._cleanups.push(n),Te("lifecycle",`${this.constructor.name}.init`,{accountId:e.accountId,sku:e.pageContext?.sku});try{await this.onInit(this.config)}catch(r){throw this.destroy(),r}this._destroying||(this.isInitialised=!0,Te("lifecycle",`${this.constructor.name} ready`),this.emit("ready"))}update(e){this.isInitialised&&(this.config.pageContext?this.config={...this.config,pageContext:{...this.config.pageContext,...e}}:e.pageType!==void 0&&(this.config={...this.config,pageContext:e}),this.onUpdate(e),this.emit("context-update",this.config.pageContext))}show(){this.isVisible||(this.isVisible=!0,this.root.style.display="",this.onShow(),this.emit("show"))}hide(){this.isVisible&&(this.isVisible=!1,this.root.style.display="none",this.onHide(),this.emit("hide"))}destroy(){this._destroying||(this._destroying=!0,this.emit("destroy"),this._cleanups.forEach(e=>e()),this._cleanups.length=0,this._handlers.clear(),this.onDestroy(),this._cleanupRoot(),this.isInitialised=!1)}_cleanupRoot(){this._ownsRoot?this.root.remove():this.root.innerHTML=""}on(e,t){return this._handlers.has(e)||this._handlers.set(e,new Set),this._handlers.get(e).add(t),()=>this._handlers.get(e)?.delete(t)}emit(e,...t){this._handlers.get(e)?.forEach(n=>n(...t))}addCleanup(e){this._cleanups.push(e)}_resolveMount(e){if(e instanceof HTMLElement)return e;if(typeof e=="string"){const n=document.querySelector(e);if(!n)throw new Error(`[gengage] Mount target not found: "${e}"`);return n}const t=document.createElement("div");return t.dataset.gengageWidget=this.constructor.name.toLowerCase(),document.body.insertBefore(t,document.body.firstChild),this._ownsRoot=!0,t}_applyTheme(e){if(e){for(const[t,n]of Object.entries(e))if(n!==void 0){const r=t.startsWith("--")?t:`--gengage-${Wn(t)}`;this.root.style.setProperty(r,n)}}}};function Wn(e){return e.replace(/([A-Z])/g,"-$1").toLowerCase()}function Xe(e){const t=e?.trim();return t||"tr"}var Vn=8e3,Gn=5e3,Kn="https://www.google.com/favicon.ico",N=new Map,et=!1,W=null,ee=null,M=!1;function Yn(e){return typeof e=="string"&&e.toLowerCase().startsWith("tr")}function tt(e){return Yn(e)?"İnternet bağlantısında sorun var gibi görünüyor. İstek sürerken yeniden deneyeceğiz.":"Your internet connection looks unstable. We'll keep retrying while this request is active."}function nt(){let e;for(const t of N.values())e=t;return e}function $e(){W&&(clearTimeout(W),W=null)}function Xn(){ee&&(clearInterval(ee),ee=null)}async function rt(){try{if(typeof navigator<"u"&&navigator.onLine===!1)return!1;if(typeof window<"u"){const n=window.location.hostname;if(n==="localhost"||n==="127.0.0.1")return navigator.onLine}const e=new AbortController,t=setTimeout(()=>e.abort(),3e3);try{return await fetch(Kn,{method:"HEAD",mode:"no-cors",cache:"no-cache",signal:e.signal}),!0}catch{return navigator.onLine}finally{clearTimeout(t)}}catch{return typeof navigator>"u"?!0:navigator.onLine}}function se(){M=!1,Xn(),Ye()}function ce(){W||M||N.size===0||(W=setTimeout(async()=>{W=null,!(M||N.size===0)&&!await rt()&&N.size>0&&(M=!0,Ae({source:"sdk",message:tt(nt()),sticky:!0}),ee||(ee=setInterval(async()=>{if(N.size===0){se();return}await rt()&&(se(),ce())},Gn)))},Vn))}function er(){et||typeof window>"u"||(et=!0,window.addEventListener("online",()=>{se(),ce()}),window.addEventListener("offline",()=>{N.size===0||M||(M=!0,$e(),Ae({source:"sdk",message:tt(nt()),sticky:!0}))}))}function tr(e){er();const t=Symbol(e.source);N.set(t,e.locale),ce();let n=!1;return()=>{if(!n){if(n=!0,N.delete(t),N.size===0){$e(),se();return}M||($e(),ce())}}}function ot(e){return typeof e=="object"&&e!==null&&typeof e.type=="string"}function nr(e){const t=[];let n=0,r=!1,o=!1,i=0;for(let a=0;a<e.length;a++){const s=e[a];if(o){o=!1;continue}if(s==="\\"&&r){o=!0;continue}if(s==='"'){r=!r;continue}r||(s==="{"&&n++,s==="}"&&(n--,n===0&&(t.push(e.slice(i,a+1)),i=a+1)))}return t.length>0?t:[e]}function it(e,t){const n=e.trim();if(!n||n.startsWith(":"))return!1;const r=n.startsWith("data: ")?n.slice(6):n;if(r==="[DONE]")return t.onDone?.(),!0;try{const o=JSON.parse(r);return ot(o)?(Te("stream",`event: ${o.type}`,o),t.onEvent(o),o.type==="done"?(t.onDone?.(),!0):!1):!1}catch{const o=nr(r);if(o.length>1){for(const i of o)try{const a=JSON.parse(i);if(!ot(a))continue;if(t.onEvent(a),a.type==="done")return t.onDone?.(),!0}catch{}return!1}return!1}}async function rr(e,t){if(!e.ok){t.onError?.(new Error(`HTTP ${e.status}: ${e.statusText}`));return}if(!e.body){t.onError?.(new Error("Response body is null — streaming not supported"));return}const n=e.body.getReader(),r=new TextDecoder("utf-8");let o="";const i=t.idleTimeoutMs??6e4,a=Symbol("idle-timeout");let s=!1;try{for(;;){const c=n.read();let u;const d=await(i>0?Promise.race([c.then(h=>(clearTimeout(u),h)),new Promise(h=>{u=setTimeout(()=>h(a),i)})]):c);if(d===a){s=!0,await n.cancel();break}const{done:g,value:f}=d;if(g)break;o+=r.decode(f,{stream:!0});const p=o.split(`
47
+ `,document.head.appendChild(e)}var X=null;function Mn(){if(X!==null)return X;try{X=localStorage.getItem("gengage:debug")==="1"}catch{X=!1}return X}function Te(e,t,n){if(!Mn())return;const r=[`[gengage:${e}]`,t];n!==void 0&&r.push(n),console.debug(...r)}var Fn=("0.5.2".trim(),"0.5.2".trim()),Hn=("iife-build".trim(),"iife-build".trim());function Jn(){if(typeof window>"u")return;const e=window;e.__gengageSdkRuntimeInfoLogged||(e.__gengageSdkRuntimeInfoLogged=!0,console.info(`[gengage] @gengage/assistant-fe v${Fn} (${Hn})`))}var Qn=class{constructor(){this.isVisible=!1,this.isInitialised=!1,this._handlers=new Map,this._cleanups=[],this._ownsRoot=!1,this._destroying=!1}async init(e){if(this.isInitialised){console.warn("[gengage] Widget already initialised. Call update() instead.");return}const t=In(e.theme);Jn(),this.config={...e,theme:t,session:$n(e.session)},this.root=this._resolveMount(e.mountTarget),this._applyTheme(t),Nn();const n=Qe("gengage:context:update",r=>this.update(r));this._cleanups.push(n),Te("lifecycle",`${this.constructor.name}.init`,{accountId:e.accountId,sku:e.pageContext?.sku});try{await this.onInit(this.config)}catch(r){throw this.destroy(),r}this._destroying||(this.isInitialised=!0,Te("lifecycle",`${this.constructor.name} ready`),this.emit("ready"))}update(e){this.isInitialised&&(this.config.pageContext?this.config={...this.config,pageContext:{...this.config.pageContext,...e}}:e.pageType!==void 0&&(this.config={...this.config,pageContext:e}),this.onUpdate(e),this.emit("context-update",this.config.pageContext))}show(){this.isVisible||(this.isVisible=!0,this.root.style.display="",this.onShow(),this.emit("show"))}hide(){this.isVisible&&(this.isVisible=!1,this.root.style.display="none",this.onHide(),this.emit("hide"))}destroy(){this._destroying||(this._destroying=!0,this.emit("destroy"),this._cleanups.forEach(e=>e()),this._cleanups.length=0,this._handlers.clear(),this.onDestroy(),this._cleanupRoot(),this.isInitialised=!1)}_cleanupRoot(){this._ownsRoot?this.root.remove():this.root.innerHTML=""}on(e,t){return this._handlers.has(e)||this._handlers.set(e,new Set),this._handlers.get(e).add(t),()=>this._handlers.get(e)?.delete(t)}emit(e,...t){this._handlers.get(e)?.forEach(n=>n(...t))}addCleanup(e){this._cleanups.push(e)}_resolveMount(e){if(e instanceof HTMLElement)return e;if(typeof e=="string"){const n=document.querySelector(e);if(!n)throw new Error(`[gengage] Mount target not found: "${e}"`);return n}const t=document.createElement("div");return t.dataset.gengageWidget=this.constructor.name.toLowerCase(),document.body.insertBefore(t,document.body.firstChild),this._ownsRoot=!0,t}_applyTheme(e){if(e){for(const[t,n]of Object.entries(e))if(n!==void 0){const r=t.startsWith("--")?t:`--gengage-${Wn(t)}`;this.root.style.setProperty(r,n)}}}};function Wn(e){return e.replace(/([A-Z])/g,"-$1").toLowerCase()}function Xe(e){const t=e?.trim();return t||"tr"}var Vn=8e3,Gn=5e3,Kn="https://www.google.com/favicon.ico",N=new Map,et=!1,W=null,ee=null,M=!1;function Yn(e){return typeof e=="string"&&e.toLowerCase().startsWith("tr")}function tt(e){return Yn(e)?"İnternet bağlantısında sorun var gibi görünüyor. İstek sürerken yeniden deneyeceğiz.":"Your internet connection looks unstable. We'll keep retrying while this request is active."}function nt(){let e;for(const t of N.values())e=t;return e}function $e(){W&&(clearTimeout(W),W=null)}function Xn(){ee&&(clearInterval(ee),ee=null)}async function rt(){try{if(typeof navigator<"u"&&navigator.onLine===!1)return!1;if(typeof window<"u"){const n=window.location.hostname;if(n==="localhost"||n==="127.0.0.1")return navigator.onLine}const e=new AbortController,t=setTimeout(()=>e.abort(),3e3);try{return await fetch(Kn,{method:"HEAD",mode:"no-cors",cache:"no-cache",signal:e.signal}),!0}catch{return navigator.onLine}finally{clearTimeout(t)}}catch{return typeof navigator>"u"?!0:navigator.onLine}}function se(){M=!1,Xn(),Ye()}function ce(){W||M||N.size===0||(W=setTimeout(async()=>{W=null,!(M||N.size===0)&&!await rt()&&N.size>0&&(M=!0,Ae({source:"sdk",message:tt(nt()),sticky:!0}),ee||(ee=setInterval(async()=>{if(N.size===0){se();return}await rt()&&(se(),ce())},Gn)))},Vn))}function er(){et||typeof window>"u"||(et=!0,window.addEventListener("online",()=>{se(),ce()}),window.addEventListener("offline",()=>{N.size===0||M||(M=!0,$e(),Ae({source:"sdk",message:tt(nt()),sticky:!0}))}))}function tr(e){er();const t=Symbol(e.source);N.set(t,e.locale),ce();let n=!1;return()=>{if(!n){if(n=!0,N.delete(t),N.size===0){$e(),se();return}M||($e(),ce())}}}function ot(e){return typeof e=="object"&&e!==null&&typeof e.type=="string"}function nr(e){const t=[];let n=0,r=!1,o=!1,i=0;for(let a=0;a<e.length;a++){const s=e[a];if(o){o=!1;continue}if(s==="\\"&&r){o=!0;continue}if(s==='"'){r=!r;continue}r||(s==="{"&&n++,s==="}"&&(n--,n===0&&(t.push(e.slice(i,a+1)),i=a+1)))}return t.length>0?t:[e]}function it(e,t){const n=e.trim();if(!n||n.startsWith(":"))return!1;const r=n.startsWith("data: ")?n.slice(6):n;if(r==="[DONE]")return t.onDone?.(),!0;try{const o=JSON.parse(r);return ot(o)?(Te("stream",`event: ${o.type}`,o),t.onEvent(o),o.type==="done"?(t.onDone?.(),!0):!1):!1}catch{const o=nr(r);if(o.length>1){for(const i of o)try{const a=JSON.parse(i);if(!ot(a))continue;if(t.onEvent(a),a.type==="done")return t.onDone?.(),!0}catch{}return!1}return!1}}async function rr(e,t){if(!e.ok){t.onError?.(new Error(`HTTP ${e.status}: ${e.statusText}`));return}if(!e.body){t.onError?.(new Error("Response body is null — streaming not supported"));return}const n=e.body.getReader(),r=new TextDecoder("utf-8");let o="";const i=t.idleTimeoutMs??6e4,a=Symbol("idle-timeout");let s=!1;try{for(;;){const c=n.read();let u;const d=await(i>0?Promise.race([c.then(h=>(clearTimeout(u),h)),new Promise(h=>{u=setTimeout(()=>h(a),i)})]):c);if(d===a){s=!0,await n.cancel();break}const{done:g,value:f}=d;if(g)break;o+=r.decode(f,{stream:!0});const p=o.split(`
48
48
  `);o=p.pop()??"";for(const h of p)if(it(h,t))return}if(o.trim()&&it(o,t))return}catch(c){if(c instanceof DOMException&&c.name==="AbortError")return;t.onError?.(c instanceof Error?c:new Error(String(c)))}finally{s||n.releaseLock()}t.onDone?.()}var or={process_action:"/process_action",launcher_action:"/launcher_action",similar_products:"/similar_products",product_groupings:"/product_groupings"};function ir(e){if(e===void 0)throw new Error("[gengage] middlewareUrl is required. Pass your Gengage backend URL in widget config.");const t=e.trim();return t===""?"":t.replace(/\/+$/,"")}function ar(e,t){return`${ir(t?.middlewareUrl)}/chat${or[e]}`}var at=3,sr=(e,t)=>{const n=e.replace(/\s+/g," ").trim().replace(/^[,.;:!?•-]+|[,.;:!?•-]+$/g,"");if(!n)return"";const r=t?.stripLeadingStopWords?n.replace(/^(?:daha|için)\s+/i,"").trim():n;return r?r.split(/\s+/).slice(0,3).join(" ").trim():""},Ie=(e,t)=>e?e.split(/[•,;:/()]|(?:\sve\s)|(?:\sand\s)|(?:\sile\s)|(?:\sfor\s)|(?:\swith\s)/i).map(n=>sr(n,t)).filter(Boolean):[];function cr(e){const t=(e.display_keywords??[]).flatMap(o=>Ie(o,{stripLeadingStopWords:!0})),n=t.filter((o,i)=>t.indexOf(o)===i);if(n.length>0)return n.slice(0,at);const r=[...Ie(e.chosen_attribute,{stripLeadingStopWords:!0}),...Ie(e.short_name)];return r.filter((o,i)=>r.indexOf(o)===i).slice(0,at)}function ur(e){return cr(e).join(" • ")}var lr=["beauty_consulting","watch_expert"];function dr(e){return typeof e=="string"&&lr.includes(e)}function Pe(...e){for(const t of e){if(typeof t!="string")continue;const n=t.trim();if(n.length>0)return n}}function Ce(e){return Array.isArray(e)?e.filter(t=>typeof t=="string"&&t.trim().length>0).map(t=>t.trim()):[]}function st(e){const t={...e},n=Pe(t.sku),r=Ce(t.group_skus);if(n?t.sku=n:delete t.sku,r.length>0?t.group_skus=r:delete t.group_skus,n||r.length>0)delete t.image_url;else{const o=Pe(t.image_url);o?t.image_url=o:delete t.image_url}return t}function pr(e){if(typeof e.type!="string")return null;if(fr(e))return e;const t=e;switch(t.type){case"outputText":return gr(t);case"suggestedActions":return hr(t);case"productList":return mr(t);case"productDetails":return _r(t);case"productDetailsSimilars":return yr(t);case"comparisonTable":return vr(t);case"context":return zr(t);case"chatStreamEnd":return Sr();case"loading":return Er(t);case"panelLoading":return Ar(t);case"similarLoading":return Tr(t);case"redirect":return $r(t);case"error":return Ir(t);case"dummy":return Pr(t);case"launcherAction":return Cr(t);case"text":return Oe(t);case"productItem":return Or(t);case"text_image":return ct(t);case"quick_qna":return ut(t);case"reviewHighlights":return Zr(t);case"aiProductSuggestions":return Lr(t);case"aiProductGroupings":return Nr(t);case"aiSuggestedSearches":return jr(t);case"prosAndCons":return xr(t);case"getGroundingReview":return Dr(t);case"voice":return Br(t);case"visitorDataResponse":return Rr(t);case"productListPreview":return Ur();case"groupList":return Mr(t);case"formGetInfo":case"formTestDrive":case"formServiceRequest":case"launchFormPage":return Fr(t);case"launcherContent":return Jr(t);case"handoff":return Hr(t);case"uiSpec":return eo(t);default:return null}}function fr(e){const t=e.type;if(typeof t!="string")return!1;switch(t){case"metadata":return typeof e.sessionId=="string"&&typeof e.model=="string";case"text_chunk":return typeof e.content=="string";case"ui_spec":{const n=e.widget;if(n!=="chat"&&n!=="qna"&&n!=="simrel")return!1;const r=C(e.spec);return r?typeof r.root=="string"&&C(r.elements)!==null:!1}case"action":{const n=C(e.action);return n!==null&&typeof n.kind=="string"}case"error":return typeof e.code=="string"&&typeof e.message=="string";case"done":return!0;default:return!1}}function gr(e){const t=y(e.payload.text,e.payload.plain_text)??"",n=y(e.payload.plain_text,e.payload.text)??t;if(e.payload.is_error)return{type:"error",code:"BACKEND_ERROR",message:n||"Backend returned an error"};const r={type:"text_chunk",content:t,final:!0},o=e.payload.product_mentions;Array.isArray(o)&&o.length>0&&(r.productMentions=o.filter(c=>typeof c=="object"&&c!==null&&typeof c.sku=="string"&&typeof c.short_name=="string"));const i=e.payload.sku_to_product_item;i&&typeof i=="object"&&!Array.isArray(i)&&(r.skuToProductItem=i);const a=e.payload.conversation_mode;typeof a=="string"&&a&&(r.conversationMode=a);const s=e.payload.render_hint;return typeof s=="string"&&s&&(r.renderHint=s),e.payload.kvkk===!0&&(r.kvkk=!0),r}function hr(e){return lt((e.payload.actions??[]).map(t=>{const n=y(t.title)??"",r=Z(t.requestDetails,n),o=r?{label:n,action:r}:null;return o?(typeof t.icon=="string"&&(o.icon=t.icon),typeof t.image=="string"&&(o.image=t.image),o):null}).filter(ne),"chat")}function mr(e){const t=(Array.isArray(e.payload.style_variations)?e.payload.style_variations:[]).map(a=>{const s=y(a.style_label);if(!s)return null;const c=y(a.style_mood),u=y(a.image_url??void 0),d=(Array.isArray(a.product_list)?a.product_list:[]).map(f=>{const p=C(f);return p?Ze(C(p.product_detail)??C(p.product)??p):null}).filter(ne),g=Array.isArray(a.recommendation_groups)?a.recommendation_groups.map(f=>({label:y(f.label)??"",reason:y(f.reason)??"",skus:Array.isArray(f.skus)?f.skus.filter(p=>typeof p=="string"&&p.trim().length>0):[]})):[];return{style_label:s,style_mood:c??"",...u?{image_url:u}:{},...typeof a.status=="string"?{status:a.status}:{},product_list:d,recommendation_groups:g}}).filter(ne),n=e.payload.product_list??[],r=dr(e.payload.source)&&t.length>0?t[0].product_list:null,o=r?Qr(r,"chat"):dt(n,"chat");o.panelHint="panel";const i=o.spec.elements[o.spec.root];if(i){const a={};typeof e.payload.offset=="number"&&(a.offset=e.payload.offset),typeof e.payload.end_of_list=="boolean"&&(a.endOfList=e.payload.end_of_list),typeof e.payload.title=="string"&&(a.panelTitle=e.payload.title),typeof e.payload.source=="string"&&(a.source=e.payload.source),t.length>0&&(a.styleVariations=t),e.payload.replace_panel===!0&&(a.replacePanel=!0),(e.payload.ranking_state==="pending"||e.payload.ranking_state==="final")&&(a.rankingState=e.payload.ranking_state);const s=e.payload.sequence_id??e.payload.search_id;typeof s=="string"&&s.length>0&&(a.sequenceId=s),Object.keys(a).length>0&&(i.props={...i.props,...a})}return o}function _r(e){const t=e.payload.productDetails;if(!t)return Vr("chat");const n=V(t);return{type:"ui_spec",widget:"chat",spec:{root:"root",elements:{root:{type:"ProductDetailsPanel",props:{product:{...t,...n}}}}},panelHint:"panel"}}function yr(e){const t=dt(e.payload.similarProducts??[],"chat"),n=t.spec.elements[t.spec.root];return n&&(n.props={...n.props,similarsAppend:!0}),{...t,panelHint:"panel"}}function vr(e){const t=e.payload.multiple_product_details??[],n=e.payload,r={key_differences:n.key_differences,recommended_choice:n.recommended_choice,recommended_choice_sku:n.recommended_choice_sku,special_considerations:n.special_considerations,criteria_view:n.criteria_view,criteria_view_short:n.criteria_view_short,compared_field_names:n.compared_field_names,winner_product:n.winner_product,winner_hits:n.winner_hits,...e.payload.product_comparison_framework??{}},o=e.payload.table,i=e.payload.features_list,a=[];for(const v of t){const S=V(v);a.push(S)}const s=br(o,a,r,i);let c;r?.recommended_choice_sku?c=r.recommended_choice_sku:r?.winner_product&&r.winner_product.length>0&&(c=r.winner_product[0]?.product_detail?.sku??r.winner_product[0]?.sku);const u=c?a.find(v=>v.sku===c)??a[0]:a[0],d=[];if(Array.isArray(r?.key_differences))for(const v of r.key_differences)typeof v=="string"&&d.push(v);const g=Yr(r?.special_considerations),f=r?.recommended_choice,p=r?.winner_hits,h={};for(const v of a){const S=v.sku;S&&(h[S]={title:v.name??S,type:"launchSingleProduct",payload:{sku:S}})}const m={products:a,attributes:s,highlights:d,productActions:h};return u&&(m.recommended=u),g.length>0&&(m.specialCases=g),f&&(m.recommendedText=f),p&&(m.winnerHits=p),typeof r?.key_differences=="string"&&(m.keyDifferencesHtml=r.key_differences),r?.special_considerations&&(m.specialConsiderations=r.special_considerations),{type:"ui_spec",widget:"chat",spec:{root:"root",elements:{root:{type:"ComparisonTable",props:m}}},panelHint:"panel"}}function br(e,t,n,r){if(!e)return[];const o=Object.entries(e);if(o.length===0)return[];const i=o[0]?.[1];if(Array.isArray(i)){const g=n.criteria_view??n.criteria_view_short??{},f=n.compared_field_names??Object.keys(e),p=[];for(const h of f){const m=e[h];if(!m||!Array.isArray(m))continue;const v=g[h]??h;p.push({label:v,values:m.map(S=>typeof S=="string"?S:String(S??""))})}return p}const a=e,s=t.map(g=>String(g.sku??"")).filter(g=>g.length>0),c=n.criteria_view??n.criteria_view_short??{},u=(r&&r.length>0?r:n.compared_field_names&&n.compared_field_names.length>0?n.compared_field_names:wr(a)).filter(g=>g!=="name"&&g!=="name_short"&&!g.endsWith("_short")),d=[];for(const g of u){const f=s.map(h=>{const m=a[h];if(!m||typeof m!="object")return"";const v=m[`${g}_short`],S=m[g];return kr(v??S)});if(f.every(h=>h.length===0))continue;const p=c[g]??g;d.push({label:p,values:f})}return d}function wr(e){const t=[],n=new Set;for(const r of Object.values(e))if(!(!r||typeof r!="object"))for(const o of Object.keys(r))n.has(o)||(n.add(o),t.push(o));return t}function kr(e){return typeof e=="string"?e:typeof e=="number"||typeof e=="boolean"?String(e):""}function zr(e){return{type:"metadata",sessionId:"",model:"",meta:{panel:e.payload.panel,messages:e.payload.messages,message_id:e.payload.message_id}}}function Sr(){return{type:"done"}}function Er(e){return{type:"metadata",sessionId:"",model:"",meta:{loading:!0,loadingText:e.payload.text,thinkingMessages:e.payload.thinking_messages,dynamicLoading:e.payload.is_dynamic===!0}}}function Ar(e){return{type:"metadata",sessionId:"",model:"",meta:{loading:!0,panelLoading:!0,panelPendingType:e.payload?.pending_type,loadingText:e.payload?.text}}}function Tr(e){return{type:"metadata",sessionId:"",model:"",meta:{loading:!0,similarPanelLoading:!0,panelPendingType:e.payload?.pending_type,loadingText:e.payload?.text}}}function $r(e){const t=y(e.payload.url);return t?{type:"action",action:{kind:"navigate",url:t,newTab:e.payload.new_tab===!0}}:{type:"metadata",sessionId:"",model:"",meta:{redirect:e.payload,redirectTarget:y(e.payload.to)}}}function Ir(e){return{type:"error",code:"BACKEND_ERROR",message:y(e.payload?.text,e.payload?.message,e.payload?.error)??"Backend returned an error"}}function Pr(e){return{type:"metadata",sessionId:"",model:"",meta:{noop:!0}}}function Cr(e){const t=e.payload??{};if(Array.isArray(t.action_list)){const o={action_list:t.action_list},i=typeof t.type=="string"?t.type:void 0,a=typeof t.theme=="string"?t.theme:void 0;return i!==void 0&&(o.type=i),a!==void 0&&(o.theme=a),ut({type:"quick_qna",payload:o})}const n=C(t.action);if(n){const o={action:n},i=typeof t.text=="string"?t.text:void 0,a=typeof t.image_url=="string"?t.image_url:void 0,s=typeof t.theme=="string"?t.theme:void 0;return i!==void 0&&(o.text=i),a!==void 0&&(o.image_url=a),s!==void 0&&(o.theme=s),ct({type:"text_image",payload:o})}const r=typeof t.text=="string"?t.text:"";if(r){const o={text:r},i=typeof t.type=="string"?t.type:void 0,a=typeof t.theme=="string"?t.theme:void 0,s=C(t.payload)??void 0;return i!==void 0&&(o.type=i),s!==void 0&&(o.payload=s),a!==void 0&&(o.theme=a),Oe({type:"text",payload:o})}return{type:"metadata",sessionId:"",model:"",meta:{launcherAction:t}}}function Oe(e){const t={text:y(e.payload.text)??""};return typeof e.payload.theme=="string"&&(t.theme=e.payload.theme),e.payload.payload!==void 0&&(t.payload=e.payload.payload),{type:"ui_spec",widget:"qna",spec:{root:"root",elements:{root:{type:"QuestionHeading",props:t}}}}}function Or(e){return Wr(e.payload,"qna")}function ct(e){const t=y(e.payload.text)??"",n=Z(e.payload.action,t);if(n){const o={label:t||n.title,action:n};return typeof e.payload.image_url=="string"&&(o.image=e.payload.image_url),typeof e.payload.theme=="string"&&(o.theme=e.payload.theme),{type:"ui_spec",widget:"qna",spec:{root:"root",elements:{root:{type:"ActionButton",props:o}}}}}const r={text:t};return typeof e.payload.theme=="string"&&(r.theme=e.payload.theme),Oe({type:"text",payload:r})}function ut(e){return lt((e.payload.action_list??[]).map(t=>{const n=y(t.title)??"",r=Z(t.requestDetails,n),o=r?{label:n,action:r}:null;return o?(typeof t.icon=="string"&&(o.icon=t.icon),typeof t.image=="string"&&(o.image=t.image),o):null}).filter(ne),"qna")}function Zr(e){const t={reviews:(e.payload.reviews??[]).map(n=>{const r={};return typeof n.review_class=="string"&&(r.review_class=n.review_class),typeof n.review_text=="string"&&(r.review_text=n.review_text),(typeof n.review_rating=="string"||typeof n.review_rating=="number")&&(r.review_rating=n.review_rating),typeof n.review_tag=="string"&&(r.review_tag=n.review_tag),r})};return typeof e.payload.sku=="string"&&(t.sku=e.payload.sku),{type:"ui_spec",widget:"chat",spec:{root:"root",elements:{root:{type:"ReviewHighlights",props:t}}}}}function xr(e){const t={};return Array.isArray(e.payload.pros)&&(t.pros=e.payload.pros),Array.isArray(e.payload.cons)&&(t.cons=e.payload.cons),typeof e.payload.product_name=="string"&&(t.productName=e.payload.product_name),{type:"ui_spec",widget:"chat",spec:{root:"root",elements:{root:{type:"ProsAndCons",props:t}}}}}function Rr(e){return{type:"metadata",sessionId:"",model:"",meta:{visitorDataResponse:e.payload}}}function Lr(e){const t=e.payload.product_suggestions??[],n=[];for(let r=0;r<t.length;r++){const o=t[r];if(!o)continue;const i=Gr(o);if(!i)continue;const a={product:i},s=Z(o.requestDetails,i.name);s&&(a.action=s),typeof o.role=="string"&&(a.role=o.role),typeof o.reason=="string"&&(a.reason=o.reason),typeof o.review_highlight=="string"&&(a.reviewHighlight=o.review_highlight),Array.isArray(o.labels)&&(a.labels=o.labels),typeof o.expert_quality_score=="number"&&(a.expertQualityScore=o.expert_quality_score),n.push(a)}return n.length===0?{type:"metadata",sessionId:"",model:"",meta:{aiProductSuggestions:e.payload.product_suggestions??[]}}:{type:"ui_spec",widget:"chat",spec:{root:"root",elements:{root:{type:"AITopPicks",props:{suggestions:n}}}}}}function Nr(e){const t=e.payload.product_groupings??[],n=[],r=[];for(let o=0;o<t.length;o++){const i=t[o];if(!i)continue;const a=y(i.name)??"",s=y(i.sku,i.repr_sku),c=y(i.image,i.repr_image),u=qr(i,a,s),d=(Array.isArray(i.group_products)?i.group_products:[]).map(p=>{const h=C(p);return h?Ze(h):null}).filter(ne),g=c??y(...d.map(p=>p.imageUrl));if(a&&d.length>0){const p={groupName:a,products:d};g&&(p.image=g),n.push(p)}if(!u)continue;const f={name:a,action:u};if(Array.isArray(i.labels)){const p=i.labels.filter(h=>typeof h=="string");p.length>0&&(f.labels=p)}c!==void 0&&(f.image=c),r.push(f)}return n.length>0?{type:"ui_spec",widget:"chat",spec:{root:"root",elements:{root:{type:"CategoriesContainer",props:{groups:n}}}},panelHint:"panel"}:r.length===0?{type:"metadata",sessionId:"",model:"",meta:{aiProductGroupings:e.payload.product_groupings??[]}}:{type:"ui_spec",widget:"chat",spec:{root:"root",elements:{root:{type:"AIGroupingCards",props:{entries:r}}}}}}function qr(e,t,n){const r=C(e.requestDetails);if(r){if(r.type!=="findSimilar")return Z(r,t);const a={...C(r.payload)??{}};n&&!Pe(a.sku)&&(a.sku=n);const s=Ce(e.group_skus);return s.length>0&&(a.group_skus=s),Z({...r,payload:st(a)},t)}const o={};n&&(o.sku=n);const i=Ce(e.group_skus);return i.length>0&&(o.group_skus=i),Object.keys(o).length===0?null:Z({type:"findSimilar",payload:st(o)},t)}function jr(e){const t=e.payload.suggested_searches??[],n=[];for(let r=0;r<t.length;r++){const o=t[r];if(!o)continue;const i=y(o.short_name,o.chosen_attribute,o.detailed_user_message)??`Search ${r+1}`,a={},s=y(o.detailed_user_message);s&&(a.text=s);const c=C(C(o.requestDetails)?.payload),u=c?.group_skus;o.group_skus&&Array.isArray(o.group_skus)?a.group_skus=o.group_skus:Array.isArray(u)&&(a.group_skus=u.filter(S=>typeof S=="string"));const d=y(o.sku,o.representative_product_sku,c?.sku);d&&(a.sku=d),a.is_suggested_text=1;const g={type:"inputText",payload:a},f=Z(o.requestDetails,i),p=f?.type==="findSimilar"&&typeof a.text=="string"?Z(g,i):f??Z(g,i);if(!p)continue;const h={shortName:i,action:p},m=y(o.detailed_user_message);m&&m!==i&&(h.detailedMessage=m);const v=ur(o);v&&v!==i&&v!==(m??"")&&(h.whyDifferent=v),typeof o.image=="string"&&(h.image=o.image),n.push(h)}return n.length===0?{type:"metadata",sessionId:"",model:"",meta:{aiSuggestedSearches:e.payload.suggested_searches??[]}}:{type:"ui_spec",widget:"chat",spec:{root:"root",elements:{root:{type:"AISuggestedSearchCards",props:{entries:n}}}}}}function Dr(e){const t=e.payload,n=Z(t.requestDetails??t.request_details,y(t.review_count,t.reviewCount,t.text,t.title)??"Show product reviews");if(!n)return{type:"metadata",sessionId:"",model:"",meta:{groundingReview:t}};const r={action:n};return t.title&&(r.title=t.title),t.text&&(r.text=t.text),t.review_count?r.reviewCount=t.review_count:typeof t.reviewCount=="string"&&t.reviewCount.trim()&&(r.reviewCount=t.reviewCount),{type:"ui_spec",widget:"chat",spec:{root:"root",elements:{root:{type:"GroundingReviewCard",props:r}}}}}function Ur(){return{type:"metadata",sessionId:"",model:"",meta:{analyzeAnimation:!0}}}function Br(e){return{type:"metadata",sessionId:"",model:"",meta:{voice:e.payload}}}function Mr(e){const t=e.payload.group_list??[],n=[];for(const o of t){const i=o.group_name??"",a=(o.product_list??[]).map(V);n.push({groupName:i,products:a})}const r=[];for(const o of e.payload.filter_tags??[]){const i=o.title??"";if(!i)continue;const a=Z(o.requestDetails,i),s={title:i};a&&(s.action=a),r.push(s)}return{type:"ui_spec",widget:"chat",spec:{root:"root",elements:{root:{type:"CategoriesContainer",props:{groups:n,filterTags:r}}}},panelHint:"panel"}}function Fr(e){return{type:"metadata",sessionId:"",model:"",meta:{formType:e.type,formPayload:e.payload??{}}}}function Hr(e){const t={};return typeof e.payload?.summary=="string"&&(t.summary=e.payload.summary),Array.isArray(e.payload?.products_discussed)&&(t.products_discussed=e.payload.products_discussed),typeof e.payload?.user_sentiment=="string"&&(t.user_sentiment=e.payload.user_sentiment),{type:"ui_spec",widget:"chat",spec:{root:"root",elements:{root:{type:"HandoffNotice",props:t}}}}}function Jr(e){return{type:"metadata",sessionId:"",model:"",meta:{launcherContent:e.payload??{}}}}function lt(e,t){const n={},r=[];for(let o=0;o<e.length;o++){const i=e[o];if(!i)continue;const a=`action-${o}`;r.push(a);const s={label:i.label,action:i.action};i.icon!==void 0&&(s.icon=i.icon),i.image!==void 0&&(s.image=i.image),i.description!==void 0&&(s.description=i.description),n[a]={type:"ActionButton",props:s}}return n.root={type:"ActionButtons",props:{buttons:e.map(o=>{const i={label:o.label,action:o.action};return o.image!==void 0&&(i.image=o.image),o.description!==void 0&&(i.description=o.description),o.icon!==void 0&&(i.icon=o.icon),i})},children:r},{type:"ui_spec",widget:t,spec:{root:"root",elements:n}}}function dt(e,t){const n={},r=[];for(let o=0;o<e.length;o++){const i=e[o];if(!i)continue;const a=V(i),s=`product-${o}`;r.push(s);const c={product:a,index:o};a.sku&&(c.action={title:a.name,type:"launchSingleProduct",payload:{sku:a.sku}}),n[s]={type:"ProductCard",props:c}}return n.root={type:"ProductGrid",props:{layout:"grid"},children:r},{type:"ui_spec",widget:t,spec:{root:"root",elements:n}}}function Qr(e,t){const n={},r=[];for(let o=0;o<e.length;o++){const i=e[o];if(!i)continue;const a=`product-${o}`;r.push(a);const s={product:i,index:o},c=i.sku;c&&(s.action={title:i.name??"",type:"launchSingleProduct",payload:{sku:c}}),n[a]={type:"ProductCard",props:s}}return n.root={type:"ProductGrid",props:{layout:"grid"},children:r},{type:"ui_spec",widget:t,spec:{root:"root",elements:n}}}function Wr(e,t){return{type:"ui_spec",widget:t,spec:{root:"root",elements:{root:{type:"ProductCard",props:{product:V(e),index:0}}}}}}function Vr(e){return{type:"ui_spec",widget:e,spec:{root:"root",elements:{root:{type:"ActionButtons",props:{buttons:[]},children:[]}}}}}function Gr(e){const t=y(e.sku),n=y(e.short_name),r={...C(e.product_item)??e},o=y(e.discount_reason,e.discountReason);return o&&!y(r.discount_reason,r.discountReason)&&(r.discount_reason=o),Ze(r,t,n)}function Ze(e,t,n){const r=y(e.sku,t),o=y(e.name,n);if(!r||!o)return null;const i={sku:r,name:o},a=y(e.brand);a&&(i.brand=a);const s=y(e.url);s&&(i.url=s);const c=Kr(e.images);if(c.length>0)i.images=c;else{const m=y(e.image,e.image_url,e.imageUrl);m&&(i.images=[m])}const u=te(e.price_discounted);u!==void 0&&(i.price_discounted=u);const d=te(e.price);d!==void 0&&(i.price=d);const g=te(e.rating);g!==void 0&&(i.rating=g);const f=te(e.review_count)??te(e.reviewCount);f!==void 0&&(i.review_count=f);const p=y(e.cart_code,e.cartCode);p&&(i.cart_code=p),typeof e.in_stock=="boolean"&&(i.in_stock=e.in_stock),typeof e.inStock=="boolean"&&(i.in_stock=e.inStock);const h=y(e.discount_reason,e.discountReason);return h&&(i.discount_reason=h),V(i)}function Z(e,t){const n=C(e);if(!n)return null;const r=n.type;if(typeof r!="string"||r.length===0)return null;const o={title:t||r,type:r};return n.payload!==void 0&&(o.payload=n.payload),o}function C(e){return!e||typeof e!="object"||Array.isArray(e)?null:e}function y(...e){for(const t of e)if(typeof t=="string"){const n=t.trim();if(n.length>0)return n}}function Kr(e){return Array.isArray(e)?e.filter(t=>typeof t=="string"&&t.length>0):[]}function Yr(e){if(typeof e=="string"){const t=e.trim();return t?[t]:[]}return Array.isArray(e)?e.filter(t=>typeof t=="string").map(t=>t.trim()).filter(t=>t.length>0):[]}function te(e){if(typeof e=="number"&&Number.isFinite(e))return e;if(typeof e=="string"){let t;e.includes(".")&&e.includes(",")?t=e.replace(/\./g,"").replace(",","."):t=e.replace(",",".");const n=Number(t);if(Number.isFinite(n))return n}}function ne(e){return e!=null}var Xr=new Set(["sku","name","brand","images","price","price_discounted","price_discount_rate","price_currency","discount_reason","url","rating","review_count","cart_code","in_stock","description","description_html","features","specifications","short_name","category_ids","category_names","variants","facet_hits","promotions"]);function V(e){const t=e.price_discounted!=null&&e.price_discounted>0,n=t?e.price_discounted:e.price,r=t&&e.price!=null?e.price:void 0;let o;r!=null&&n!=null&&r>0?o=Math.round((r-n)/r*100):e.price_discount_rate!=null&&e.price_discount_rate>0&&(o=e.price_discount_rate);const i=y(e.brand),a=y(e.name)??e.sku,s=i&&!a.toLowerCase().startsWith(i.toLowerCase())?`${i} ${a}`:a,c={sku:e.sku,name:s,url:y(e.url)??""},u=e.images?.[0];u&&(c.imageUrl=u),e.images&&e.images.length>1&&(c.images=e.images),n!=null&&n>0&&(c.price=String(n)),r!=null&&r>0&&(c.originalPrice=String(r)),o!==void 0&&(c.discountPercent=o),i!==void 0&&(c.brand=i),e.rating!==void 0&&(c.rating=e.rating),e.review_count!==void 0&&(c.reviewCount=e.review_count),e.cart_code!==void 0&&(c.cartCode=e.cart_code),e.in_stock!==void 0&&(c.inStock=e.in_stock),e.variants&&e.variants.length>0&&(c.variants=e.variants),e.discount_reason!==void 0&&(c.discountReason=e.discount_reason),e.promotions&&e.promotions.length>0&&(c.promotions=e.promotions),e.description!==void 0&&(c.description=e.description),e.description_html!==void 0&&(c.descriptionHtml=e.description_html),e.features&&e.features.length>0&&(c.features=e.features),e.specifications!==void 0&&(c.specifications=e.specifications),e.facet_hits&&(c.facetHits=e.facet_hits),e.category_names&&e.category_names.length>0&&(c.categoryNames=e.category_names),e.short_name!==void 0&&(c.shortName=e.short_name);const d=e,g={};let f=!1;for(const p of Object.keys(d))Xr.has(p)||(g[p]=d[p],f=!0);return f&&(c.extras=g),c}function eo(e){const t=e.payload.type,{type:n,...r}=e.payload;return{type:"ui_spec",widget:"chat",spec:{root:"root",elements:{root:{type:t,props:r}}}}}async function to(e,t,n){const r=ar("launcher_action",t),o={uiSpecs:[],actions:[]},i={method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)};n!==void 0&&(i.signal=n);const a=await fetch(r,i);if(!a.ok)throw new Error(`HTTP ${a.status}: ${a.statusText}`);const s={onEvent:c=>{const u=pr(c);if(u&&(u.type==="ui_spec"&&o.uiSpecs.push(u.spec),u.type==="ui_spec"&&u.spec.elements)){for(const d of Object.values(u.spec.elements))if(d.type==="ActionButton"&&d.props?.action){const g=d.props.action;o.actions.push(g)}}}};return n!==void 0&&(s.signal=n),await rr(a,s),o}function pt(e){const t=document.createElement("div");t.className="gengage-qna-buttons gds-toolbar",t.dataset.gengagePart="qna-button-row",t.setAttribute("role","group"),t.setAttribute("aria-label",e.quickQuestionsAriaLabel??"Quick questions"),e.orientation==="vertical"&&(t.style.flexDirection="column");for(const n of e.actions){const r=document.createElement("button");r.className="gengage-qna-button gds-chip",r.dataset.gengagePart="qna-quick-question",r.textContent=n.title,r.type="button",r.addEventListener("click",()=>{const o={title:n.title,type:n.type};n.payload!==void 0&&(o.payload=n.payload),e.onAction(o)}),t.appendChild(r)}if(e.ctaText||e.onOpenChat){const n=document.createElement("button");n.className="gengage-qna-cta gds-btn gds-btn-secondary",n.dataset.gengagePart="qna-cta",n.textContent=e.ctaText??e.defaultCtaText??"Ask something else",n.type="button",n.addEventListener("click",()=>{e.onOpenChat?.()}),t.appendChild(n)}return t}function no(e){const t=document.createElement("div");t.className="gengage-qna-input-wrapper",t.dataset.gengagePart="qna-input-wrapper";const n=document.createElement("div");n.className="gengage-qna-input-combo",n.dataset.gengagePart="qna-input-combo";const r=document.createElement("input");r.type="text",r.className="gengage-qna-input",r.dataset.gengagePart="qna-input",r.setAttribute("aria-label",e.askQuestionAriaLabel??"Ask a question");const o=Array.isArray(e.placeholders)?e.placeholders:e.placeholders?[e.placeholders]:[e.defaultInputPlaceholder??"Ask a question..."];let i=0,a=o[0]??"";r.placeholder=a;let s=null,c=null,u=!1;const d=()=>{s&&clearInterval(s),s=null,c&&clearTimeout(c),c=null,r.classList.remove("gengage-qna-input--fade")},g=()=>o.length>1&&!u&&r.value.trim().length===0,f=()=>{d(),g()&&(s=setInterval(()=>{g()&&(r.classList.add("gengage-qna-input--fade"),c=setTimeout(()=>{i=(i+1)%o.length,a=o[i]??"",r.placeholder=a,r.classList.remove("gengage-qna-input--fade")},180))},3e3))},p=document.createElement("div");p.className="gengage-qna-input-actions",p.dataset.gengagePart="qna-input-actions";const h=document.createElement("button");h.className="gengage-qna-icon-btn gengage-qna-clear gengage-qna-icon-btn--hidden",h.type="button",h.dataset.gengagePart="qna-clear",h.setAttribute("aria-label","Clear question"),h.innerHTML='<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M18 6L6 18" /><path d="M6 6L18 18" /></svg>';const m=document.createElement("button");m.className="gengage-qna-icon-btn gengage-qna-send gengage-qna-icon-btn--hidden",m.type="button",m.dataset.gengagePart="qna-send",m.setAttribute("aria-label",e.sendQuestionAriaLabel??"Send question"),m.disabled=!0,m.innerHTML=`<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M22 2L11 13" /><path d="M22 2L15 22L11 13L2 9L22 2Z" /></svg><span class="gengage-qna-sr-only">${e.ctaLabel??e.sendButtonText??"Ask"}</span>`;const v=()=>{const w=r.value.trim().length>0;h.classList.toggle("gengage-qna-icon-btn--hidden",!w),m.classList.toggle("gengage-qna-icon-btn--hidden",!w),m.classList.toggle("gengage-qna-send--active",w),m.disabled=!w},S=()=>{const w=r.value.trim();w&&(e.onSubmit({title:w,type:"user_message",payload:w}),r.value="",v(),f())};return h.addEventListener("click",()=>{r.value="",v(),r.focus({preventScroll:!0})}),m.addEventListener("click",S),r.addEventListener("focus",()=>{u=!0,d(),r.placeholder=""}),r.addEventListener("blur",()=>{u=!1,r.value.trim().length===0&&(r.placeholder=a),f()}),r.addEventListener("input",()=>{if(v(),r.value.trim().length>0){d();return}r.placeholder=u?"":a,f()}),r.addEventListener("keydown",w=>{w.key==="Enter"&&(w.preventDefault(),S()),w.key==="Escape"&&r.value.length>0&&(r.value="",v(),f())}),p.appendChild(h),p.appendChild(m),n.appendChild(r),n.appendChild(p),t.appendChild(n),v(),f(),t._cleanup=()=>{d()},t}function ue(e,t){if(!e||typeof e!="object")return null;const n=e,r=n.type;if(typeof r!="string"||r.length===0)return null;const o=n.title,i=n.payload,a=typeof o=="string"&&o.length>0?o:t;if(!a)return null;const s={title:a,type:r};return i!==void 0&&(s.payload=i),s}function ft(e){const t={title:e.title,type:e.type};return e.payload!==void 0&&(t.payload=e.payload),t}function gt(e,t){const n=[],r=e.props?.actions;if(Array.isArray(r))for(const a of r){const s=ue(a);s&&n.push(s)}const o=e.props?.buttons;if(Array.isArray(o))for(const a of o){if(!a||typeof a!="object")continue;const s=a,c=typeof s.label=="string"?s.label:void 0,u=ue(s.action,c);u&&n.push(u)}if(e.children)for(const a of e.children){const s=t.elements[a];if(!s||s.type!=="ActionButton")continue;const c=typeof s.props?.label=="string"?s.props.label:void 0,u=ue(s.props?.action,c);u&&n.push(u)}const i=new Set;return n.filter(a=>i.has(a.title)?!1:(i.add(a.title),!0))}var ht={ButtonRow:({element:e,spec:t,context:n})=>{const r=gt(e,t).map(ft),o=e.props?.orientation,i={actions:r,onAction:n.onAction,defaultCtaText:n.i18n.defaultCtaText,quickQuestionsAriaLabel:n.i18n.quickQuestionsAriaLabel};return n.onOpenChat!==void 0&&(i.onOpenChat=n.onOpenChat),n.ctaText!==void 0&&(i.ctaText=n.ctaText),(o==="horizontal"||o==="vertical")&&(i.orientation=o),pt(i)},ActionButtons:({element:e,spec:t,context:n})=>{const r={actions:gt(e,t).map(ft),onAction:n.onAction,defaultCtaText:n.i18n.defaultCtaText,quickQuestionsAriaLabel:n.i18n.quickQuestionsAriaLabel};return n.onOpenChat!==void 0&&(r.onOpenChat=n.onOpenChat),n.ctaText!==void 0&&(r.ctaText=n.ctaText),pt(r)},ActionButton:({element:e,context:t})=>{const n=document.createElement("button");n.className="gengage-qna-button gds-chip",n.type="button",n.dataset.gengagePart="qna-action-button";const r=e.props?.label;typeof r=="string"?n.textContent=r:n.textContent=t.i18n.defaultCtaText;const o=ue(e.props?.action,typeof r=="string"?r:void 0);return o&&n.addEventListener("click",()=>t.onAction(o)),n},TextInput:({element:e,context:t})=>{const n=e.props?.placeholder,r=typeof n=="string"||Array.isArray(n)?n:t.inputPlaceholder,o=typeof e.props?.ctaLabel=="string"?e.props.ctaLabel:void 0,i={onSubmit:t.onAction,askQuestionAriaLabel:t.i18n.askQuestionAriaLabel,defaultInputPlaceholder:t.i18n.defaultInputPlaceholder,sendButtonText:t.i18n.sendButton,sendQuestionAriaLabel:t.i18n.sendQuestionAriaLabel};return r!==void 0&&(i.placeholders=r),o!==void 0&&(i.ctaLabel=o),no(i)},QuestionHeading:({element:e,context:t})=>{const n=document.createElement("h3");n.className="gengage-qna-heading",n.dataset.gengagePart="qna-heading";const r=e.props?.text,o=t.headingTitleOverride;return n.textContent=typeof o=="string"&&o.trim().length>0?o:typeof r=="string"?r:"",n},ProductCard:()=>null},xe=({element:e,renderElement:t})=>{if(!e.children||e.children.length===0)return null;const n=document.createElement("div");for(const r of e.children){const o=t(r);o&&n.appendChild(o)}return n};function mt(){return{...ht}}function _t(e,t,n=ht,r=xe){return vn({spec:e,context:t,registry:n,containerClassName:"gengage-qna-uispec",unknownRenderer:r})}function ro(e){if(!e)return;const t=e.extra;if(t&&typeof t=="object"&&!Array.isArray(t)){const r=t.visible_skus??t.visibleSkus;if(Array.isArray(r)){const o=r.filter(i=>typeof i=="string"&&i.trim().length>0).map(i=>i.trim()).slice(0,200);if(o.length>0)return o}}const n=typeof e.sku=="string"&&e.sku.trim()?e.sku.trim():void 0;return n?[n]:void 0}function yt(e,t){if(!e)return null;const n=e.action;if(!n||typeof n!="object")return null;const r=n,o=r.type;if(typeof o!="string"||o.length===0)return null;const i=r.title,a=typeof i=="string"&&i.length>0?i:typeof t=="string"&&t.length>0?t:"";if(!a)return null;const s=r.payload,c={title:a,type:o};return s!==void 0&&(c.payload=s),c}function oo(e,t){const n=e.elements[e.root];if(!n)return!1;const r=o=>{if(o.type!=="ActionButton")return!1;const i=o.props;if(!i||typeof i!="object")return!1;const a=typeof i.label=="string"?i.label:void 0;return a===t?!0:yt(i,a)?.title===t};if(n.type==="ActionButton")return r(n);if(n.children)for(const o of n.children){const i=e.elements[o];if(i&&r(i))return!0}if(n.type==="ActionButtons"&&Array.isArray(n.props?.buttons)){for(const o of n.props.buttons)if(o?.label===t||o?.action?.title===t)return!0}return!1}var vt=0;function bt(){return vt+=1,`gengage-merge-${vt}`}function io(e,t){const n=e.elements[e.root];if(!n||n.type!=="ButtonRow")return;const r=bt();e.elements[r]={type:"ActionButton",props:{label:t.title,action:{title:t.title,type:t.type,...t.payload!==void 0?{payload:t.payload}:{}}}},n.children=n.children?[r,...n.children]:[r]}function ao(e,t){const n=e.elements[e.root];if(!n||n.type!=="ActionButtons")return;const r=bt();e.elements[r]={type:"ActionButton",props:{label:t.title,action:{title:t.title,type:t.type,...t.payload!==void 0?{payload:t.payload}:{}}}},n.children=n.children?[r,...n.children]:[r];const o=n.props?.buttons??[],i={label:t.title,action:{title:t.title,type:t.type,...t.payload!==void 0?{payload:t.payload}:{}}};n.props={...n.props,buttons:[i,...o]}}function so(e){const t={},n=[];for(let r=0;r<e.length;r++){const o=e[r],i=`action-${r}`;n.push(i),t[i]={type:"ActionButton",props:{label:o.title,action:{title:o.title,type:o.type,...o.payload!==void 0?{payload:o.payload}:{}}}}}return t.root={type:"ButtonRow",children:n},{root:"root",elements:t}}function co(e){return e.find(t=>{const n=t.elements[t.root];return n?.type==="ActionButtons"||n?.type==="ButtonRow"})}function wt(e,t){const n=e.productContextQuickPillLabel,r={text:n};return t&&t.length>0&&(r.sku_list=t),{title:n,type:"user_message",payload:r}}function uo(e,t,n){const r=n?.skuList,o=[],i=[];for(const c of e){const u=c.elements[c.root];if(u?.type==="ActionButton"){const d=u.props;if(yt(d,typeof d?.label=="string"?d.label:void 0)?.type==="findSimilar"){o.push(wt(t,r));continue}}i.push(c)}if(o.length===0)return e;const a=wt(t,r),s=co(i);if(!s)return[...i,so([a])];if(!oo(s,a.title)){const c=s.elements[s.root];c?.type==="ActionButtons"?ao(s,a):c?.type==="ButtonRow"&&io(s,a)}return i}var kt={quickQuestionsAriaLabel:"Hızlı sorular",askQuestionAriaLabel:"Soru sorun",defaultInputPlaceholder:"Bir soru sorun...",sendButton:"Sor",sendQuestionAriaLabel:"Soruyu gönder",defaultCtaText:"Başka bir şey sor",redirectingToChat:"Sohbete yönlendiriliyor...",productContextQuickPillLabel:"Bu ürün hakkında ne bilmeliyim?"},lo={quickQuestionsAriaLabel:"Quick questions",askQuestionAriaLabel:"Ask a question",defaultInputPlaceholder:"Ask a question...",sendButton:"Ask",sendQuestionAriaLabel:"Send question",defaultCtaText:"Ask something else",redirectingToChat:"Redirecting to chat...",productContextQuickPillLabel:"What should I know about this product?"};function po(e){return e?e.toLowerCase().split("-")[0]??"tr":"tr"}function fo(e){return po(e)==="en"?lo:kt}var zt=class extends Qn{constructor(...e){super(...e),this._abortController=null,this._debounceTimer=null,this._contentEl=null,this._i18n=kt,this._actionHandler=this._handleAction.bind(this),this._openChatHandler=this._handleOpenChat.bind(this)}async onInit(e){this._i18n=this._resolveI18n(e),this._contentEl=document.createElement("div"),this._contentEl.className="gengage-qna-container",this._contentEl.dataset.gengagePart="qna-container",this._contentEl.lang=Xe(e.locale);const t=this._createChrome(e);if(t){const r=document.createElement("div");r.className="gengage-qna-chrome-widget",r.dataset.gengagePart="qna-chrome-widget",r.appendChild(this._contentEl),t.appendChild(r),this.root.appendChild(t)}else this.root.appendChild(this._contentEl);const n=e.pageContext?.sku;n&&(this._lastSku=n,await this._fetchAndRender(n)),Sn("qna")}onUpdate(e){const t=e.sku;!t||t===this._lastSku||(this._debounceTimer&&clearTimeout(this._debounceTimer),this._debounceTimer=setTimeout(()=>{this._debounceTimer=null,this._lastSku=t,this._fetchAndRender(t)},50))}onShow(){this._contentEl&&(this._contentEl.style.opacity="0",this._contentEl.style.transition="opacity 0.2s ease-in",requestAnimationFrame(()=>{this._contentEl&&(this._contentEl.style.opacity="1")}))}onHide(){}onDestroy(){this._abort(),this._debounceTimer&&(clearTimeout(this._debounceTimer),this._debounceTimer=null),this._contentEl&&(this._cleanupTextInputTimers(),this._contentEl.remove(),this._contentEl=null)}_abort(){this._abortController?.abort(),this._abortController=null}_resolvedQnaHeaderTitle(){const e=this.config.headerTitle??this.config.headingTitle;if(typeof e!="string")return;const t=e.trim();return t.length>0?t:void 0}_cleanupTextInputTimers(){if(!this._contentEl)return;const e=this._contentEl.querySelectorAll(".gengage-qna-input-wrapper");for(const t of e)t._cleanup?.()}async _fetchAndRender(e){if(this._abort(),this._abortController=new AbortController,!this._contentEl)return;this._cleanupTextInputTimers(),this._contentEl.innerHTML="";const t=this._createLoadingIndicator();this._contentEl.appendChild(t);const n={middlewareUrl:this.config.middlewareUrl},r=tr({source:"qna",locale:this.config.locale});try{const o=this.config.session?.sessionId??"",i={account_id:this.config.accountId,session_id:o,correlation_id:o,sku:e,locale:Xe(this.config.locale)};this.config.session?.userId!==void 0&&(i.user_id=this.config.session.userId),this.config.session?.viewId!==void 0&&(i.view_id=this.config.session.viewId);const a=this.config.pageContext?.pageType;a!==void 0&&(i.page_type=a);const s=await to(i,n,this._abortController.signal);if(!this._contentEl)return;this._contentEl.innerHTML="";const c=document.createElement("div");c.className="gengage-qna-panel gds-panel",c.dataset.gengagePart="qna-panel",this._contentEl.appendChild(c);const u=this._specIncludesType(s.uiSpecs,"QuestionHeading"),d=this._resolvedQnaHeaderTitle()??(this.config.showStaticQuestion&&this.config.staticQuestionText?this.config.staticQuestionText:void 0);if(!u&&d){const w=document.createElement("h3");w.className="gengage-qna-heading",w.textContent=d,c.appendChild(w)}const g=this.config.inputPlaceholder;let f;if(g!==!0)f=g??this._i18n.defaultInputPlaceholder;else if(s.actions.length>0){const w=s.actions.filter(I=>I.type==="user_message"||I.title.includes("?")).map(I=>I.title);f=w.length>0?w:this._i18n.defaultInputPlaceholder}else f=this._i18n.defaultInputPlaceholder;const p={onAction:this._actionHandler,i18n:this._i18n},h=this._resolvedQnaHeaderTitle();h!==void 0&&(p.headingTitleOverride=h),this.config.hideButtonRowCta||(p.onOpenChat=this._openChatHandler,this.config.ctaText!==void 0&&(p.ctaText=this.config.ctaText)),f!==void 0&&(p.inputPlaceholder=f);const m=this._buildFallbackActionsSpec(s.actions),v=ro(this.config.pageContext),S=(s.uiSpecs.length>0?uo(s.uiSpecs,this._i18n,{skuList:v}):[m]).filter(w=>Object.keys(w.elements).length>0);for(const w of S){const I=this._renderUISpec(w,p);c.appendChild(I)}S.length>0&&En("qna"),this._specIncludesType(S,"TextInput")||this._insertStandaloneInputBeforePills(c,p,f)}catch(o){if(o instanceof DOMException&&o.name==="AbortError")return;if(Se("gengage:global:error",{source:"qna",code:"FETCH_ERROR",message:Ln(this.config.locale,o)}),this._contentEl){this._cleanupTextInputTimers(),this._contentEl.innerHTML="";const i=document.createElement("div");i.className="gengage-qna-panel",this._contentEl.appendChild(i);const a=this.config.inputPlaceholder===!0?this._i18n.defaultInputPlaceholder:this.config.inputPlaceholder??this._i18n.defaultInputPlaceholder,s={onAction:this._actionHandler,i18n:this._i18n,onOpenChat:this._openChatHandler},c=this._resolvedQnaHeaderTitle();c!==void 0&&(s.headingTitleOverride=c),this.config.ctaText!==void 0&&(s.ctaText=this.config.ctaText),this._appendStandaloneInput(s,a,i)}}finally{r()}}_createLoadingIndicator(){const e=document.createElement("div");e.className="gengage-qna-loading";for(let t=0;t<3;t++){const n=document.createElement("div");n.className="gengage-qna-loading-dot",e.appendChild(n)}return e}_resolveI18n(e){return{...fo(e.locale),...e.i18n}}_createChrome(e){const t=e.chrome;if(!t)return null;const n=typeof t.title=="string"?t.title.trim():"",r=typeof t.subtitle=="string"?t.subtitle.trim():"",o=typeof t.startButtonLabel=="string"?t.startButtonLabel.trim():"",i=typeof t.imageUrl=="string"?t.imageUrl.trim():"",a=typeof t.imagePadding=="string"?t.imagePadding.trim():"",s=document.createElement("section");s.className="gengage-qna-chrome",s.dataset.gengagePart="qna-chrome",t.layout==="side-image"&&(s.classList.add("gengage-qna-chrome--side-image"),s.dataset.gengageChromeLayout="side-image"),a&&s.style.setProperty("--gengage-qna-chrome-image-padding",a);const c=document.createElement("div");if(c.className="gengage-qna-chrome-copy",c.dataset.gengagePart="qna-chrome-copy",n){const u=document.createElement("h2");u.className="gengage-qna-chrome-title",u.dataset.gengagePart="qna-chrome-title",u.textContent=n,c.appendChild(u)}if(r){const u=document.createElement("p");u.className="gengage-qna-chrome-subtitle",u.dataset.gengagePart="qna-chrome-subtitle",u.textContent=r,c.appendChild(u)}if(c.children.length>0&&s.appendChild(c),i&&kn(i)){const u=document.createElement("img");u.className="gengage-qna-chrome-image",u.dataset.gengagePart="qna-chrome-image",u.src=i,u.alt=typeof t.imageAlt=="string"?t.imageAlt:"",u.loading="lazy",u.addEventListener("error",()=>{u.style.display="none"},{once:!0}),s.appendChild(u)}if(o){const u=document.createElement("button");u.className="gengage-qna-chrome-start",u.dataset.gengagePart="qna-chrome-start",u.type="button",u.textContent=o,u.addEventListener("click",()=>this._handleOpenChat()),s.appendChild(u)}return s.children.length===0?null:s}_resolveUISpecRegistry(){return bn(mt(),this.config.renderer?.registry)}_renderUISpec(e,t){const n=this._resolveUISpecRegistry(),r=this.config.renderer?.unknownRenderer??xe,o=(a,s)=>_t(a,s,n,r),i=this.config.renderer?.renderUISpec;return i?i(e,t,{registry:n,unknownRenderer:r,defaultRender:o}):o(e,t)}_specIncludesType(e,t){for(const n of e)for(const r of Object.values(n.elements))if(r.type===t)return!0;return!1}_buildFallbackActionsSpec(e){if(e.length===0)return{root:"root",elements:{}};const t={},n=[];for(let r=0;r<e.length;r++){const o=e[r],i=`action-${r}`;n.push(i),t[i]={type:"ActionButton",props:{label:o.title,action:{title:o.title,type:o.type,payload:o.payload}}}}return t.root={type:"ButtonRow",children:n},{root:"root",elements:t}}_insertStandaloneInputBeforePills(e,t,n){const r={root:"root",elements:{root:{type:"TextInput",props:{placeholder:n}}}},o=this._renderUISpec(r,t),i=o.querySelector(".gengage-qna-input-wrapper");if(!i)return;const a=e.querySelector(".gengage-qna-uispec"),s=e.querySelector(".gengage-qna-uispec > .gengage-qna-buttons"),c=this.config.inputAfterPills===!0;if(s)c?s.insertAdjacentElement("afterend",i):s.insertAdjacentElement("beforebegin",i);else if(a){const u=a.querySelector(":scope > .gengage-qna-heading");!c&&u?u.insertAdjacentElement("afterend",i):a.appendChild(i)}else{e.appendChild(o);return}o.remove()}_appendStandaloneInput(e,t,n){if(!this._contentEl)return;const r={root:"root",elements:{root:{type:"TextInput",props:{placeholder:t}}}},o=this._renderUISpec(r,e);(n??this._contentEl).appendChild(o)}_handleAction(e){this._showTransitionIndicator(),An(e.title,e.type),this.config.onActionSelected?.(e),setTimeout(()=>Se("gengage:qna:action",e),350)}_handleOpenChat(){this._showTransitionIndicator(),this.config.onOpenChat?.(),setTimeout(()=>Se("gengage:qna:open-chat",{}),350)}_showTransitionIndicator(){if(!this._contentEl)return;this._contentEl.querySelector(".gengage-qna-transition-indicator")?.remove(),this._contentEl.classList.add("gengage-qna--transitioning");const e=this._i18n.redirectingToChat??"Redirecting to chat...",t=document.createElement("div");t.className="gengage-qna-transition-indicator",t.textContent=e,(this._contentEl.querySelector(".gengage-qna-panel")??this._contentEl).appendChild(t),setTimeout(()=>{this._contentEl?.classList.remove("gengage-qna--transitioning"),t.remove()},600)}};function go(){return new zt}var St;function l(e,t,n){function r(s,c){if(s._zod||Object.defineProperty(s,"_zod",{value:{def:c,constr:a,traits:new Set},enumerable:!1}),s._zod.traits.has(e))return;s._zod.traits.add(e),t(s,c);const u=a.prototype,d=Object.keys(u);for(let g=0;g<d.length;g++){const f=d[g];f in s||(s[f]=u[f].bind(s))}}const o=n?.Parent??Object;class i extends o{}Object.defineProperty(i,"name",{value:e});function a(s){var c;const u=n?.Parent?new i:this;r(u,s),(c=u._zod).deferred??(c.deferred=[]);for(const d of u._zod.deferred)d();return u}return Object.defineProperty(a,"init",{value:r}),Object.defineProperty(a,Symbol.hasInstance,{value:s=>n?.Parent&&s instanceof n.Parent?!0:s?._zod?.traits?.has(e)}),Object.defineProperty(a,"name",{value:e}),a}var G=class extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}},Et=class extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`),this.name="ZodEncodeError"}};(St=globalThis).__zod_globalConfig??(St.__zod_globalConfig={});var le=globalThis.__zod_globalConfig;function F(e){return e&&Object.assign(le,e),le}function At(e){const t=Object.values(e).filter(n=>typeof n=="number");return Object.entries(e).filter(([n,r])=>t.indexOf(+n)===-1).map(([n,r])=>r)}function Re(e,t){return typeof t=="bigint"?t.toString():t}function Le(e){return{get value(){{const t=e();return Object.defineProperty(this,"value",{value:t}),t}throw new Error("cached value already set")}}}function Ne(e){return e==null}function qe(e){const t=e.startsWith("^")?1:0,n=e.endsWith("$")?e.length-1:e.length;return e.slice(t,n)}var Tt=Symbol("evaluating");function b(e,t,n){let r;Object.defineProperty(e,t,{get(){if(r!==Tt)return r===void 0&&(r=Tt,r=n()),r},set(o){Object.defineProperty(e,t,{value:o})},configurable:!0})}function H(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function j(...e){const t={};for(const n of e)Object.assign(t,Object.getOwnPropertyDescriptors(n));return Object.defineProperties({},t)}function $t(e){return JSON.stringify(e)}function ho(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")}var It="captureStackTrace"in Error?Error.captureStackTrace:(...e)=>{};function de(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}var mo=Le(()=>{if(le.jitless||typeof navigator<"u"&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{return new Function(""),!0}catch{return!1}});function re(e){if(de(e)===!1)return!1;const t=e.constructor;if(t===void 0||typeof t!="function")return!0;const n=t.prototype;return!(de(n)===!1||Object.prototype.hasOwnProperty.call(n,"isPrototypeOf")===!1)}function Pt(e){return re(e)?{...e}:Array.isArray(e)?[...e]:e instanceof Map?new Map(e):e instanceof Set?new Set(e):e}var _o=new Set(["string","number","symbol"]);function pe(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function D(e,t,n){const r=new e._zod.constr(t??e._zod.def);return(!t||n?.parent)&&(r._zod.parent=e),r}function _(e){const t=e;if(!t)return{};if(typeof t=="string")return{error:()=>t};if(t?.message!==void 0){if(t?.error!==void 0)throw new Error("Cannot specify both `message` and `error` params");t.error=t.message}return delete t.message,typeof t.error=="string"?{...t,error:()=>t.error}:t}function yo(e){return Object.keys(e).filter(t=>e[t]._zod.optin==="optional"&&e[t]._zod.optout==="optional")}var Fc={safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]};function vo(e,t){const n=e._zod.def,r=n.checks;if(r&&r.length>0)throw new Error(".pick() cannot be used on object schemas containing refinements");return D(e,j(e._zod.def,{get shape(){const o={};for(const i in t){if(!(i in n.shape))throw new Error(`Unrecognized key: "${i}"`);t[i]&&(o[i]=n.shape[i])}return H(this,"shape",o),o},checks:[]}))}function bo(e,t){const n=e._zod.def,r=n.checks;if(r&&r.length>0)throw new Error(".omit() cannot be used on object schemas containing refinements");return D(e,j(e._zod.def,{get shape(){const o={...e._zod.def.shape};for(const i in t){if(!(i in n.shape))throw new Error(`Unrecognized key: "${i}"`);t[i]&&delete o[i]}return H(this,"shape",o),o},checks:[]}))}function wo(e,t){if(!re(t))throw new Error("Invalid input to extend: expected a plain object");const n=e._zod.def.checks;if(n&&n.length>0){const r=e._zod.def.shape;for(const o in t)if(Object.getOwnPropertyDescriptor(r,o)!==void 0)throw new Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.")}return D(e,j(e._zod.def,{get shape(){const r={...e._zod.def.shape,...t};return H(this,"shape",r),r}}))}function ko(e,t){if(!re(t))throw new Error("Invalid input to safeExtend: expected a plain object");return D(e,j(e._zod.def,{get shape(){const n={...e._zod.def.shape,...t};return H(this,"shape",n),n}}))}function zo(e,t){if(e._zod.def.checks?.length)throw new Error(".merge() cannot be used on object schemas containing refinements. Use .safeExtend() instead.");return D(e,j(e._zod.def,{get shape(){const n={...e._zod.def.shape,...t._zod.def.shape};return H(this,"shape",n),n},get catchall(){return t._zod.def.catchall},checks:t._zod.def.checks??[]}))}function So(e,t,n){const r=t._zod.def.checks;if(r&&r.length>0)throw new Error(".partial() cannot be used on object schemas containing refinements");return D(t,j(t._zod.def,{get shape(){const o=t._zod.def.shape,i={...o};if(n)for(const a in n){if(!(a in o))throw new Error(`Unrecognized key: "${a}"`);n[a]&&(i[a]=e?new e({type:"optional",innerType:o[a]}):o[a])}else for(const a in o)i[a]=e?new e({type:"optional",innerType:o[a]}):o[a];return H(this,"shape",i),i},checks:[]}))}function Eo(e,t,n){return D(t,j(t._zod.def,{get shape(){const r=t._zod.def.shape,o={...r};if(n)for(const i in n){if(!(i in o))throw new Error(`Unrecognized key: "${i}"`);n[i]&&(o[i]=new e({type:"nonoptional",innerType:r[i]}))}else for(const i in r)o[i]=new e({type:"nonoptional",innerType:r[i]});return H(this,"shape",o),o}}))}function K(e,t=0){if(e.aborted===!0)return!0;for(let n=t;n<e.issues.length;n++)if(e.issues[n]?.continue!==!0)return!0;return!1}function Ao(e,t=0){if(e.aborted===!0)return!0;for(let n=t;n<e.issues.length;n++)if(e.issues[n]?.continue===!1)return!0;return!1}function Ct(e,t){return t.map(n=>{var r;return(r=n).path??(r.path=[]),n.path.unshift(e),n})}function fe(e){return typeof e=="string"?e:e?.message}function J(e,t,n){const r=e.message?e.message:fe(e.inst?._zod.def?.error?.(e))??fe(t?.error?.(e))??fe(n.customError?.(e))??fe(n.localeError?.(e))??"Invalid input",{inst:o,continue:i,input:a,...s}=e;return s.path??(s.path=[]),s.message=r,t?.reportInput&&(s.input=a),s}function je(e){return Array.isArray(e)?"array":typeof e=="string"?"string":"unknown"}function oe(...e){const[t,n,r]=e;return typeof t=="string"?{message:t,code:"custom",input:n,inst:r}:{...t}}var Ot=(e,t)=>{e.name="$ZodError",Object.defineProperty(e,"_zod",{value:e._zod,enumerable:!1}),Object.defineProperty(e,"issues",{value:t,enumerable:!1}),e.message=JSON.stringify(t,Re,2),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},Zt=l("$ZodError",Ot),xt=l("$ZodError",Ot,{Parent:Error});function To(e,t=n=>n.message){const n={},r=[];for(const o of e.issues)o.path.length>0?(n[o.path[0]]=n[o.path[0]]||[],n[o.path[0]].push(t(o))):r.push(t(o));return{formErrors:r,fieldErrors:n}}function $o(e,t=n=>n.message){const n={_errors:[]},r=(o,i=[])=>{for(const a of o.issues)if(a.code==="invalid_union"&&a.errors.length)a.errors.map(s=>r({issues:s},[...i,...a.path]));else if(a.code==="invalid_key")r({issues:a.issues},[...i,...a.path]);else if(a.code==="invalid_element")r({issues:a.issues},[...i,...a.path]);else{const s=[...i,...a.path];if(s.length===0)n._errors.push(t(a));else{let c=n,u=0;for(;u<s.length;){const d=s[u];u!==s.length-1?c[d]=c[d]||{_errors:[]}:(c[d]=c[d]||{_errors:[]},c[d]._errors.push(t(a))),c=c[d],u++}}}};return r(e),n}var De=e=>(t,n,r,o)=>{const i=r?{...r,async:!1}:{async:!1},a=t._zod.run({value:n,issues:[]},i);if(a instanceof Promise)throw new G;if(a.issues.length){const s=new(o?.Err??e)(a.issues.map(c=>J(c,i,F())));throw It(s,o?.callee),s}return a.value},Ue=e=>async(t,n,r,o)=>{const i=r?{...r,async:!0}:{async:!0};let a=t._zod.run({value:n,issues:[]},i);if(a instanceof Promise&&(a=await a),a.issues.length){const s=new(o?.Err??e)(a.issues.map(c=>J(c,i,F())));throw It(s,o?.callee),s}return a.value},ge=e=>(t,n,r)=>{const o=r?{...r,async:!1}:{async:!1},i=t._zod.run({value:n,issues:[]},o);if(i instanceof Promise)throw new G;return i.issues.length?{success:!1,error:new(e??Zt)(i.issues.map(a=>J(a,o,F())))}:{success:!0,data:i.value}},Io=ge(xt),he=e=>async(t,n,r)=>{const o=r?{...r,async:!0}:{async:!0};let i=t._zod.run({value:n,issues:[]},o);return i instanceof Promise&&(i=await i),i.issues.length?{success:!1,error:new e(i.issues.map(a=>J(a,o,F())))}:{success:!0,data:i.value}},Po=he(xt),Co=e=>(t,n,r)=>{const o=r?{...r,direction:"backward"}:{direction:"backward"};return De(e)(t,n,o)},Oo=e=>(t,n,r)=>De(e)(t,n,r),Zo=e=>async(t,n,r)=>{const o=r?{...r,direction:"backward"}:{direction:"backward"};return Ue(e)(t,n,o)},xo=e=>async(t,n,r)=>Ue(e)(t,n,r),Ro=e=>(t,n,r)=>{const o=r?{...r,direction:"backward"}:{direction:"backward"};return ge(e)(t,n,o)},Lo=e=>(t,n,r)=>ge(e)(t,n,r),No=e=>async(t,n,r)=>{const o=r?{...r,direction:"backward"}:{direction:"backward"};return he(e)(t,n,o)},qo=e=>async(t,n,r)=>he(e)(t,n,r),jo=/^[cC][0-9a-z]{6,}$/,Do=/^[0-9a-z]+$/,Uo=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,Bo=/^[0-9a-vA-V]{20}$/,Mo=/^[A-Za-z0-9]{27}$/,Fo=/^[a-zA-Z0-9_-]{21}$/,Ho=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,Jo=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,Rt=e=>e?new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${e}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/,Qo=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,Wo="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";function Vo(){return new RegExp(Wo,"u")}var Go=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,Ko=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/,Yo=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,Xo=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,ei=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,Lt=/^[A-Za-z0-9_-]*$/,ti=/^https?$/,ni=/^\+[1-9]\d{6,14}$/,Nt="(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))",ri=new RegExp(`^${Nt}$`);function qt(e){const t="(?:[01]\\d|2[0-3]):[0-5]\\d";return typeof e.precision=="number"?e.precision===-1?`${t}`:e.precision===0?`${t}:[0-5]\\d`:`${t}:[0-5]\\d\\.\\d{${e.precision}}`:`${t}(?::[0-5]\\d(?:\\.\\d+)?)?`}function oi(e){return new RegExp(`^${qt(e)}$`)}function ii(e){const t=qt({precision:e.precision}),n=["Z"];e.local&&n.push(""),e.offset&&n.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)");const r=`${t}(?:${n.join("|")})`;return new RegExp(`^${Nt}T(?:${r})$`)}var ai=e=>{const t=e?`[\\s\\S]{${e?.minimum??0},${e?.maximum??""}}`:"[\\s\\S]*";return new RegExp(`^${t}$`)},si=/^(?:true|false)$/i,ci=/^[^A-Z]*$/,ui=/^[^a-z]*$/,L=l("$ZodCheck",(e,t)=>{var n;e._zod??(e._zod={}),e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),li=l("$ZodCheckMaxLength",(e,t)=>{var n;L.init(e,t),(n=e._zod.def).when??(n.when=r=>{const o=r.value;return!Ne(o)&&o.length!==void 0}),e._zod.onattach.push(r=>{const o=r._zod.bag.maximum??Number.POSITIVE_INFINITY;t.maximum<o&&(r._zod.bag.maximum=t.maximum)}),e._zod.check=r=>{const o=r.value;if(o.length<=t.maximum)return;const i=je(o);r.issues.push({origin:i,code:"too_big",maximum:t.maximum,inclusive:!0,input:o,inst:e,continue:!t.abort})}}),di=l("$ZodCheckMinLength",(e,t)=>{var n;L.init(e,t),(n=e._zod.def).when??(n.when=r=>{const o=r.value;return!Ne(o)&&o.length!==void 0}),e._zod.onattach.push(r=>{const o=r._zod.bag.minimum??Number.NEGATIVE_INFINITY;t.minimum>o&&(r._zod.bag.minimum=t.minimum)}),e._zod.check=r=>{const o=r.value;if(o.length>=t.minimum)return;const i=je(o);r.issues.push({origin:i,code:"too_small",minimum:t.minimum,inclusive:!0,input:o,inst:e,continue:!t.abort})}}),pi=l("$ZodCheckLengthEquals",(e,t)=>{var n;L.init(e,t),(n=e._zod.def).when??(n.when=r=>{const o=r.value;return!Ne(o)&&o.length!==void 0}),e._zod.onattach.push(r=>{const o=r._zod.bag;o.minimum=t.length,o.maximum=t.length,o.length=t.length}),e._zod.check=r=>{const o=r.value,i=o.length;if(i===t.length)return;const a=je(o),s=i>t.length;r.issues.push({origin:a,...s?{code:"too_big",maximum:t.length}:{code:"too_small",minimum:t.length},inclusive:!0,exact:!0,input:r.value,inst:e,continue:!t.abort})}}),me=l("$ZodCheckStringFormat",(e,t)=>{var n,r;L.init(e,t),e._zod.onattach.push(o=>{const i=o._zod.bag;i.format=t.format,t.pattern&&(i.patterns??(i.patterns=new Set),i.patterns.add(t.pattern))}),t.pattern?(n=e._zod).check??(n.check=o=>{t.pattern.lastIndex=0,!t.pattern.test(o.value)&&o.issues.push({origin:"string",code:"invalid_format",format:t.format,input:o.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})}):(r=e._zod).check??(r.check=()=>{})}),fi=l("$ZodCheckRegex",(e,t)=>{me.init(e,t),e._zod.check=n=>{t.pattern.lastIndex=0,!t.pattern.test(n.value)&&n.issues.push({origin:"string",code:"invalid_format",format:"regex",input:n.value,pattern:t.pattern.toString(),inst:e,continue:!t.abort})}}),gi=l("$ZodCheckLowerCase",(e,t)=>{t.pattern??(t.pattern=ci),me.init(e,t)}),hi=l("$ZodCheckUpperCase",(e,t)=>{t.pattern??(t.pattern=ui),me.init(e,t)}),mi=l("$ZodCheckIncludes",(e,t)=>{L.init(e,t);const n=pe(t.includes),r=new RegExp(typeof t.position=="number"?`^.{${t.position}}${n}`:n);t.pattern=r,e._zod.onattach.push(o=>{const i=o._zod.bag;i.patterns??(i.patterns=new Set),i.patterns.add(r)}),e._zod.check=o=>{o.value.includes(t.includes,t.position)||o.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:t.includes,input:o.value,inst:e,continue:!t.abort})}}),_i=l("$ZodCheckStartsWith",(e,t)=>{L.init(e,t);const n=new RegExp(`^${pe(t.prefix)}.*`);t.pattern??(t.pattern=n),e._zod.onattach.push(r=>{const o=r._zod.bag;o.patterns??(o.patterns=new Set),o.patterns.add(n)}),e._zod.check=r=>{r.value.startsWith(t.prefix)||r.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:t.prefix,input:r.value,inst:e,continue:!t.abort})}}),yi=l("$ZodCheckEndsWith",(e,t)=>{L.init(e,t);const n=new RegExp(`.*${pe(t.suffix)}$`);t.pattern??(t.pattern=n),e._zod.onattach.push(r=>{const o=r._zod.bag;o.patterns??(o.patterns=new Set),o.patterns.add(n)}),e._zod.check=r=>{r.value.endsWith(t.suffix)||r.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:t.suffix,input:r.value,inst:e,continue:!t.abort})}}),vi=l("$ZodCheckOverwrite",(e,t)=>{L.init(e,t),e._zod.check=n=>{n.value=t.tx(n.value)}}),bi=class{constructor(e=[]){this.content=[],this.indent=0,this&&(this.args=e)}indented(e){this.indent+=1,e(this),this.indent-=1}write(e){if(typeof e=="function"){e(this,{execution:"sync"}),e(this,{execution:"async"});return}const t=e.split(`
49
49
  `).filter(o=>o),n=Math.min(...t.map(o=>o.length-o.trimStart().length)),r=t.map(o=>o.slice(n)).map(o=>" ".repeat(this.indent*2)+o);for(const o of r)this.content.push(o)}compile(){const e=Function,t=this?.args,n=[...(this?.content??[""]).map(r=>` ${r}`)];return new e(...t,n.join(`
50
50
  `))}},wi={major:4,minor:4,patch:3},A=l("$ZodType",(e,t)=>{var n;e??(e={}),e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=wi;const r=[...e._zod.def.checks??[]];e._zod.traits.has("$ZodCheck")&&r.unshift(e);for(const o of r)for(const i of o._zod.onattach)i(e);if(r.length===0)(n=e._zod).deferred??(n.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{const o=(a,s,c)=>{let u=K(a),d;for(const g of s){if(g._zod.def.when){if(Ao(a)||!g._zod.def.when(a))continue}else if(u)continue;const f=a.issues.length,p=g._zod.check(a);if(p instanceof Promise&&c?.async===!1)throw new G;if(d||p instanceof Promise)d=(d??Promise.resolve()).then(async()=>{await p,a.issues.length!==f&&(u||(u=K(a,f)))});else{if(a.issues.length===f)continue;u||(u=K(a,f))}}return d?d.then(()=>a):a},i=(a,s,c)=>{if(K(a))return a.aborted=!0,a;const u=o(s,r,c);if(u instanceof Promise){if(c.async===!1)throw new G;return u.then(d=>e._zod.parse(d,c))}return e._zod.parse(u,c)};e._zod.run=(a,s)=>{if(s.skipChecks)return e._zod.parse(a,s);if(s.direction==="backward"){const u=e._zod.parse({value:a.value,issues:[]},{...s,skipChecks:!0});return u instanceof Promise?u.then(d=>i(d,a,s)):i(u,a,s)}const c=e._zod.parse(a,s);if(c instanceof Promise){if(s.async===!1)throw new G;return c.then(u=>o(u,r,s))}return o(c,r,s)}}b(e,"~standard",()=>({validate:o=>{try{const i=Io(e,o);return i.success?{value:i.data}:{issues:i.error?.issues}}catch{return Po(e,o).then(a=>a.success?{value:a.data}:{issues:a.error?.issues})}},vendor:"zod",version:1}))}),Be=l("$ZodString",(e,t)=>{A.init(e,t),e._zod.pattern=[...e?._zod.bag?.patterns??[]].pop()??ai(e._zod.bag),e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=String(n.value)}catch{}return typeof n.value=="string"||n.issues.push({expected:"string",code:"invalid_type",input:n.value,inst:e}),n}}),k=l("$ZodStringFormat",(e,t)=>{me.init(e,t),Be.init(e,t)}),ki=l("$ZodGUID",(e,t)=>{t.pattern??(t.pattern=Jo),k.init(e,t)}),zi=l("$ZodUUID",(e,t)=>{if(t.version){const n={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[t.version];if(n===void 0)throw new Error(`Invalid UUID version: "${t.version}"`);t.pattern??(t.pattern=Rt(n))}else t.pattern??(t.pattern=Rt());k.init(e,t)}),Si=l("$ZodEmail",(e,t)=>{t.pattern??(t.pattern=Qo),k.init(e,t)}),Ei=l("$ZodURL",(e,t)=>{k.init(e,t),e._zod.check=n=>{try{const r=n.value.trim();if(!t.normalize&&t.protocol?.source===ti.source&&!/^https?:\/\//i.test(r)){n.issues.push({code:"invalid_format",format:"url",note:"Invalid URL format",input:n.value,inst:e,continue:!t.abort});return}const o=new URL(r);t.hostname&&(t.hostname.lastIndex=0,t.hostname.test(o.hostname)||n.issues.push({code:"invalid_format",format:"url",note:"Invalid hostname",pattern:t.hostname.source,input:n.value,inst:e,continue:!t.abort})),t.protocol&&(t.protocol.lastIndex=0,t.protocol.test(o.protocol.endsWith(":")?o.protocol.slice(0,-1):o.protocol)||n.issues.push({code:"invalid_format",format:"url",note:"Invalid protocol",pattern:t.protocol.source,input:n.value,inst:e,continue:!t.abort})),t.normalize?n.value=o.href:n.value=r;return}catch{n.issues.push({code:"invalid_format",format:"url",input:n.value,inst:e,continue:!t.abort})}}}),Ai=l("$ZodEmoji",(e,t)=>{t.pattern??(t.pattern=Vo()),k.init(e,t)}),Ti=l("$ZodNanoID",(e,t)=>{t.pattern??(t.pattern=Fo),k.init(e,t)}),$i=l("$ZodCUID",(e,t)=>{t.pattern??(t.pattern=jo),k.init(e,t)}),Ii=l("$ZodCUID2",(e,t)=>{t.pattern??(t.pattern=Do),k.init(e,t)}),Pi=l("$ZodULID",(e,t)=>{t.pattern??(t.pattern=Uo),k.init(e,t)}),Ci=l("$ZodXID",(e,t)=>{t.pattern??(t.pattern=Bo),k.init(e,t)}),Oi=l("$ZodKSUID",(e,t)=>{t.pattern??(t.pattern=Mo),k.init(e,t)}),Zi=l("$ZodISODateTime",(e,t)=>{t.pattern??(t.pattern=ii(t)),k.init(e,t)}),xi=l("$ZodISODate",(e,t)=>{t.pattern??(t.pattern=ri),k.init(e,t)}),Ri=l("$ZodISOTime",(e,t)=>{t.pattern??(t.pattern=oi(t)),k.init(e,t)}),Li=l("$ZodISODuration",(e,t)=>{t.pattern??(t.pattern=Ho),k.init(e,t)}),Ni=l("$ZodIPv4",(e,t)=>{t.pattern??(t.pattern=Go),k.init(e,t),e._zod.bag.format="ipv4"}),qi=l("$ZodIPv6",(e,t)=>{t.pattern??(t.pattern=Ko),k.init(e,t),e._zod.bag.format="ipv6",e._zod.check=n=>{try{new URL(`http://[${n.value}]`)}catch{n.issues.push({code:"invalid_format",format:"ipv6",input:n.value,inst:e,continue:!t.abort})}}}),ji=l("$ZodCIDRv4",(e,t)=>{t.pattern??(t.pattern=Yo),k.init(e,t)}),Di=l("$ZodCIDRv6",(e,t)=>{t.pattern??(t.pattern=Xo),k.init(e,t),e._zod.check=n=>{const r=n.value.split("/");try{if(r.length!==2)throw new Error;const[o,i]=r;if(!i)throw new Error;const a=Number(i);if(`${a}`!==i)throw new Error;if(a<0||a>128)throw new Error;new URL(`http://[${o}]`)}catch{n.issues.push({code:"invalid_format",format:"cidrv6",input:n.value,inst:e,continue:!t.abort})}}});function jt(e){if(e==="")return!0;if(/\s/.test(e)||e.length%4!==0)return!1;try{return atob(e),!0}catch{return!1}}var Ui=l("$ZodBase64",(e,t)=>{t.pattern??(t.pattern=ei),k.init(e,t),e._zod.bag.contentEncoding="base64",e._zod.check=n=>{jt(n.value)||n.issues.push({code:"invalid_format",format:"base64",input:n.value,inst:e,continue:!t.abort})}});function Bi(e){if(!Lt.test(e))return!1;const t=e.replace(/[-_]/g,n=>n==="-"?"+":"/");return jt(t.padEnd(Math.ceil(t.length/4)*4,"="))}var Mi=l("$ZodBase64URL",(e,t)=>{t.pattern??(t.pattern=Lt),k.init(e,t),e._zod.bag.contentEncoding="base64url",e._zod.check=n=>{Bi(n.value)||n.issues.push({code:"invalid_format",format:"base64url",input:n.value,inst:e,continue:!t.abort})}}),Fi=l("$ZodE164",(e,t)=>{t.pattern??(t.pattern=ni),k.init(e,t)});function Hi(e,t=null){try{const n=e.split(".");if(n.length!==3)return!1;const[r]=n;if(!r)return!1;const o=JSON.parse(atob(r));return!("typ"in o&&o?.typ!=="JWT"||!o.alg||t&&(!("alg"in o)||o.alg!==t))}catch{return!1}}var Ji=l("$ZodJWT",(e,t)=>{k.init(e,t),e._zod.check=n=>{Hi(n.value,t.alg)||n.issues.push({code:"invalid_format",format:"jwt",input:n.value,inst:e,continue:!t.abort})}}),Qi=l("$ZodBoolean",(e,t)=>{A.init(e,t),e._zod.pattern=si,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=!!n.value}catch{}const o=n.value;return typeof o=="boolean"||n.issues.push({expected:"boolean",code:"invalid_type",input:o,inst:e}),n}}),Wi=l("$ZodUnknown",(e,t)=>{A.init(e,t),e._zod.parse=n=>n}),Vi=l("$ZodNever",(e,t)=>{A.init(e,t),e._zod.parse=(n,r)=>(n.issues.push({expected:"never",code:"invalid_type",input:n.value,inst:e}),n)});function Dt(e,t,n){e.issues.length&&t.issues.push(...Ct(n,e.issues)),t.value[n]=e.value}var Gi=l("$ZodArray",(e,t)=>{A.init(e,t),e._zod.parse=(n,r)=>{const o=n.value;if(!Array.isArray(o))return n.issues.push({expected:"array",code:"invalid_type",input:o,inst:e}),n;n.value=Array(o.length);const i=[];for(let a=0;a<o.length;a++){const s=o[a],c=t.element._zod.run({value:s,issues:[]},r);c instanceof Promise?i.push(c.then(u=>Dt(u,n,a))):Dt(c,n,a)}return i.length?Promise.all(i).then(()=>n):n}});function _e(e,t,n,r,o,i){const a=n in r;if(e.issues.length){if(o&&i&&!a)return;t.issues.push(...Ct(n,e.issues))}if(!a&&!o){e.issues.length||t.issues.push({code:"invalid_type",expected:"nonoptional",input:void 0,path:[n]});return}e.value===void 0?a&&(t.value[n]=void 0):t.value[n]=e.value}function Ut(e){const t=Object.keys(e.shape);for(const r of t)if(!e.shape?.[r]?._zod?.traits?.has("$ZodType"))throw new Error(`Invalid element at key "${r}": expected a Zod schema`);const n=yo(e.shape);return{...e,keys:t,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(n)}}function Bt(e,t,n,r,o,i){const a=[],s=o.keySet,c=o.catchall._zod,u=c.def.type,d=c.optin==="optional",g=c.optout==="optional";for(const f in t){if(f==="__proto__"||s.has(f))continue;if(u==="never"){a.push(f);continue}const p=c.run({value:t[f],issues:[]},r);p instanceof Promise?e.push(p.then(h=>_e(h,n,f,t,d,g))):_e(p,n,f,t,d,g)}return a.length&&n.issues.push({code:"unrecognized_keys",keys:a,input:t,inst:i}),e.length?Promise.all(e).then(()=>n):n}var Ki=l("$ZodObject",(e,t)=>{if(A.init(e,t),!Object.getOwnPropertyDescriptor(t,"shape")?.get){const a=t.shape;Object.defineProperty(t,"shape",{get:()=>{const s={...a};return Object.defineProperty(t,"shape",{value:s}),s}})}const n=Le(()=>Ut(t));b(e._zod,"propValues",()=>{const a=t.shape,s={};for(const c in a){const u=a[c]._zod;if(u.values){s[c]??(s[c]=new Set);for(const d of u.values)s[c].add(d)}}return s});const r=de,o=t.catchall;let i;e._zod.parse=(a,s)=>{i??(i=n.value);const c=a.value;if(!r(c))return a.issues.push({expected:"object",code:"invalid_type",input:c,inst:e}),a;a.value={};const u=[],d=i.shape;for(const g of i.keys){const f=d[g],p=f._zod.optin==="optional",h=f._zod.optout==="optional",m=f._zod.run({value:c[g],issues:[]},s);m instanceof Promise?u.push(m.then(v=>_e(v,a,g,c,p,h))):_e(m,a,g,c,p,h)}return o?Bt(u,c,a,s,n.value,e):u.length?Promise.all(u).then(()=>a):a}}),Yi=l("$ZodObjectJIT",(e,t)=>{Ki.init(e,t);const n=e._zod.parse,r=Le(()=>Ut(t)),o=f=>{const p=new bi(["shape","payload","ctx"]),h=r.value,m=I=>{const E=$t(I);return`shape[${E}]._zod.run({ value: input[${E}], issues: [] }, ctx)`};p.write("const input = payload.value;");const v=Object.create(null);let S=0;for(const I of h.keys)v[I]=`key_${S++}`;p.write("const newResult = {};");for(const I of h.keys){const E=v[I],P=$t(I),mn=f[I],_n=mn?._zod?.optin==="optional",Mc=mn?._zod?.optout==="optional";p.write(`const ${E} = ${m(I)};`),_n&&Mc?p.write(`
package/dist/qna.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a, i as r, n as t, r as n, t as o } from "./runtime-BMNOS2Mq.js";
1
+ import { a, i as r, n as t, r as n, t as o } from "./runtime-Rp4C5hl9.js";
2
2
  import { t as p } from "./qna-BNvttR6s.js";
3
3
  export {
4
4
  o as GengageQNA,
@@ -1,9 +1,9 @@
1
- import { a as x, d as L, h as j, i as F, p as z, r as I, t as N } from "./api-paths-y5nkfEBG.js";
2
- import { A as D, E as T, N as H, a as k, l as q, v as $ } from "./context-BBuSsXZ9.js";
3
- import { o as W, t as J } from "./widget-base-Dliq3QAf.js";
4
- import { t as Q } from "./locale-CfqNifrU.js";
5
- import { a as V, n as Y, r as K, t as A } from "./price-formatter-xI3g9Cd4.js";
6
- import { n as X } from "./connection-warning-DJiyLM46.js";
1
+ import { a as x, d as L, h as j, i as q, p as F, r as I, t as N } from "./api-paths-HBfd3rta.js";
2
+ import { A as z, E as S, N as D, a as k, l as H, v as $ } from "./context-BBuSsXZ9.js";
3
+ import { o as W, t as J } from "./widget-base-BcrlFdYt.js";
4
+ import { t as K } from "./locale-CfqNifrU.js";
5
+ import { a as Q, n as V, r as Y, t as A } from "./price-formatter-xI3g9Cd4.js";
6
+ import { n as X } from "./connection-warning-BvPwMY8A.js";
7
7
  function R(e) {
8
8
  const t = [];
9
9
  for (const n of Object.values(e)) if (n.type === "ProductCard" && n.props) {
@@ -76,7 +76,7 @@ async function ne(e, t, n) {
76
76
  const a = await s.text();
77
77
  if (!a) return [];
78
78
  try {
79
- return F(JSON.parse(a));
79
+ return q(JSON.parse(a));
80
80
  } catch {
81
81
  throw new Error("Invalid JSON from product_groupings endpoint");
82
82
  }
@@ -89,20 +89,20 @@ function U(e) {
89
89
  }
90
90
  if (a) {
91
91
  const o = document.createElement("div");
92
- return o.className = "gengage-simrel-card gengage-simrel-card--custom gds-card gds-product-card gds-card-interactive", o.dataset.gengagePart = "simrel-product-card", o.innerHTML = H(a(t, n)), o.addEventListener("click", (c) => {
92
+ return o.className = "gengage-simrel-card gengage-simrel-card--custom gds-card gds-product-card gds-card-interactive", o.dataset.gengagePart = "simrel-product-card", o.innerHTML = D(a(t, n)), o.addEventListener("click", (c) => {
93
93
  c.target.closest(".gengage-simrel-atc") || c.target.closest(".gengage-chat-product-card-atc") || i(t);
94
94
  }), o;
95
95
  }
96
96
  const l = document.createElement("article");
97
97
  l.className = "gengage-simrel-card gengage-chat-product-card gds-card gds-product-card gds-card-interactive", l.dataset.gengagePart = "simrel-product-card", t.inStock === !1 && l.classList.add("gengage-simrel-card--out-of-stock"), l.setAttribute("role", "listitem"), l.dataset.sku = t.sku;
98
98
  const g = document.createElement("div");
99
- if (g.className = "gengage-simrel-card-image gengage-chat-product-card-img-wrapper", g.dataset.gengagePart = "simrel-product-card-image", t.imageUrl && D(t.imageUrl)) {
99
+ if (g.className = "gengage-simrel-card-image gengage-chat-product-card-img-wrapper", g.dataset.gengagePart = "simrel-product-card-image", t.imageUrl && z(t.imageUrl)) {
100
100
  const o = document.createElement("img");
101
- o.className = "gengage-chat-product-card-img", o.src = t.imageUrl, o.alt = t.name, o.loading = "lazy", Y(o), g.appendChild(o);
101
+ o.className = "gengage-chat-product-card-img", o.src = t.imageUrl, o.alt = t.name, o.loading = "lazy", V(o), g.appendChild(o);
102
102
  }
103
103
  if (r === "badge" && t.discountPercent && t.discountPercent > 0) {
104
104
  const o = document.createElement("span");
105
- o.className = "gengage-simrel-badge gengage-chat-product-card-discount-badge", o.textContent = `%${K(t.discountPercent)}`, g.appendChild(o);
105
+ o.className = "gengage-simrel-badge gengage-chat-product-card-discount-badge", o.textContent = `%${Y(t.discountPercent)}`, g.appendChild(o);
106
106
  }
107
107
  l.appendChild(g);
108
108
  const u = document.createElement("div");
@@ -113,22 +113,22 @@ function U(e) {
113
113
  const h = document.createElement("div");
114
114
  if (h.className = "gengage-simrel-card-name gengage-chat-product-card-name", h.textContent = t.name, h.title = t.name, u.appendChild(h), t.rating != null && t.rating > 0) {
115
115
  const o = document.createElement("div");
116
- if (o.className = "gengage-simrel-card-rating gengage-chat-product-card-rating", o.appendChild(V(t.rating)), t.reviewCount != null) {
116
+ if (o.className = "gengage-simrel-card-rating gengage-chat-product-card-rating", o.appendChild(Q(t.rating)), t.reviewCount != null) {
117
117
  const c = document.createElement("span");
118
118
  c.className = "gengage-simrel-card-review-count gengage-chat-product-card-review-count", c.textContent = ` (${t.reviewCount})`, o.appendChild(c);
119
119
  }
120
120
  u.appendChild(o);
121
121
  }
122
- const C = document.createElement("div");
123
- if (C.className = "gengage-simrel-card-price gengage-chat-product-card-price", t.originalPrice && t.originalPrice !== t.price && (r === "strike-through" || !r)) {
122
+ const y = document.createElement("div");
123
+ if (y.className = "gengage-simrel-card-price gengage-chat-product-card-price", t.originalPrice && t.originalPrice !== t.price && (r === "strike-through" || !r)) {
124
124
  const o = document.createElement("span");
125
- o.className = "gengage-simrel-card-price-original gengage-chat-product-card-original-price", o.textContent = A(t.originalPrice, m), C.appendChild(o);
125
+ o.className = "gengage-simrel-card-price-original gengage-chat-product-card-original-price", o.textContent = A(t.originalPrice, m), y.appendChild(o);
126
126
  }
127
127
  if (t.price && parseFloat(t.price) > 0) {
128
128
  const o = document.createElement("span");
129
- o.className = "gengage-simrel-card-price-current gengage-chat-product-card-price-current", o.textContent = A(t.price, m), C.appendChild(o);
129
+ o.className = "gengage-simrel-card-price-current gengage-chat-product-card-price-current", o.textContent = A(t.price, m), y.appendChild(o);
130
130
  }
131
- u.appendChild(C), l.appendChild(u);
131
+ u.appendChild(y), l.appendChild(u);
132
132
  const f = document.createElement("button");
133
133
  if (f.className = "gengage-simrel-card-cta gengage-chat-product-card-cta gds-btn gds-btn-secondary", f.type = "button", f.dataset.gengagePart = "simrel-product-card-cta", f.textContent = d?.ctaLabel ?? "View", f.addEventListener("click", (o) => {
134
134
  o.preventDefault(), o.stopPropagation(), i(t);
@@ -149,7 +149,7 @@ function U(e) {
149
149
  o.target.closest(".gengage-simrel-atc") || o.target.closest(".gengage-chat-product-card-atc") || o.target.closest(".gengage-chat-product-card-cta") || i(t);
150
150
  }), l;
151
151
  }
152
- function P(e) {
152
+ function w(e) {
153
153
  const t = document.createElement("div");
154
154
  t.className = "gengage-simrel-grid", t.setAttribute("role", "list"), t.setAttribute("aria-label", e.i18n?.similarProductsAriaLabel ?? "Similar products"), e.columns && t.style.setProperty("--gengage-simrel-columns", String(e.columns));
155
155
  for (let n = 0; n < e.products.length; n++) {
@@ -175,14 +175,14 @@ function ie(e) {
175
175
  const i = [], s = [];
176
176
  let a = 0;
177
177
  const d = (c) => {
178
- const y = {
178
+ const b = {
179
179
  products: c.products,
180
180
  onClick: e.onClick,
181
181
  onAddToCart: e.onAddToCart
182
182
  };
183
- return e.i18n !== void 0 && (y.i18n = e.i18n), e.discountType !== void 0 && (y.discountType = e.discountType), e.renderCard !== void 0 && (y.renderCard = e.renderCard), e.renderCardElement !== void 0 && (y.renderCardElement = e.renderCardElement), e.columns !== void 0 && (y.columns = e.columns), y;
184
- }, m = (c, y = !1) => {
185
- if (y && c !== a && e.onGroupingActivate) {
183
+ return e.i18n !== void 0 && (b.i18n = e.i18n), e.discountType !== void 0 && (b.discountType = e.discountType), e.renderCard !== void 0 && (b.renderCard = e.renderCard), e.renderCardElement !== void 0 && (b.renderCardElement = e.renderCardElement), e.columns !== void 0 && (b.columns = e.columns), b;
184
+ }, m = (c, b = !1) => {
185
+ if (b && c !== a && e.onGroupingActivate) {
186
186
  const p = e.groups[c];
187
187
  e.onGroupingActivate({
188
188
  grouping_label: p.name,
@@ -194,23 +194,23 @@ function ie(e) {
194
194
  const v = p === c;
195
195
  i[p].classList.toggle("gengage-simrel-tab--active", v), i[p].setAttribute("aria-selected", String(v)), i[p].tabIndex = v ? 0 : -1;
196
196
  }
197
- const S = e.groups[c], _ = s[c];
197
+ const T = e.groups[c], _ = s[c];
198
198
  _.innerHTML = "";
199
- const b = P(d(S));
200
- _.appendChild(b);
199
+ const C = w(d(T));
200
+ _.appendChild(C);
201
201
  for (let p = 0; p < s.length; p++) {
202
202
  const v = p === c;
203
203
  s[p].style.display = v ? "" : "none", s[p].tabIndex = v ? 0 : -1;
204
204
  }
205
205
  };
206
206
  for (let c = 0; c < e.groups.length; c++) {
207
- const y = e.groups[c], S = `gengage-simrel-tab-${t}-${c}`, _ = `gengage-simrel-panel-${t}-${c}`, b = document.createElement("button");
208
- b.className = "gengage-simrel-tab gds-tab", b.type = "button", b.dataset.gengagePart = "simrel-tab", b.id = S, b.textContent = y.name, b.setAttribute("role", "tab"), b.setAttribute("aria-controls", _), b.setAttribute("aria-selected", String(c === 0)), b.tabIndex = c === 0 ? 0 : -1, c === 0 && b.classList.add("gengage-simrel-tab--active"), b.addEventListener("click", () => m(c, !0)), b.addEventListener("keydown", (v) => {
207
+ const b = e.groups[c], T = `gengage-simrel-tab-${t}-${c}`, _ = `gengage-simrel-panel-${t}-${c}`, C = document.createElement("button");
208
+ C.className = "gengage-simrel-tab gds-tab", C.type = "button", C.dataset.gengagePart = "simrel-tab", C.id = T, C.textContent = b.name, C.setAttribute("role", "tab"), C.setAttribute("aria-controls", _), C.setAttribute("aria-selected", String(c === 0)), C.tabIndex = c === 0 ? 0 : -1, c === 0 && C.classList.add("gengage-simrel-tab--active"), C.addEventListener("click", () => m(c, !0)), C.addEventListener("keydown", (v) => {
209
209
  let E = -1;
210
210
  v.key === "ArrowRight" || v.key === "ArrowDown" ? E = (c + 1) % e.groups.length : v.key === "ArrowLeft" || v.key === "ArrowUp" ? E = (c - 1 + e.groups.length) % e.groups.length : v.key === "Home" ? E = 0 : v.key === "End" && (E = e.groups.length - 1), E >= 0 && (v.preventDefault(), m(E, !0), i[E].focus());
211
- }), i.push(b), r.appendChild(b);
211
+ }), i.push(C), r.appendChild(C);
212
212
  const p = document.createElement("div");
213
- p.className = "gengage-simrel-tab-panel", p.dataset.gengagePart = "simrel-tab-panel", p.id = _, p.setAttribute("role", "tabpanel"), p.setAttribute("aria-labelledby", S), p.tabIndex = c === 0 ? 0 : -1, c !== 0 && (p.style.display = "none"), s.push(p);
213
+ p.className = "gengage-simrel-tab-panel", p.dataset.gengagePart = "simrel-tab-panel", p.id = _, p.setAttribute("role", "tabpanel"), p.setAttribute("aria-labelledby", T), p.tabIndex = c === 0 ? 0 : -1, c !== 0 && (p.style.display = "none"), s.push(p);
214
214
  }
215
215
  const l = document.createElement("button");
216
216
  l.type = "button", l.className = "gengage-simrel-tabs-arrow gengage-simrel-tabs-arrow--left", l.setAttribute("aria-label", e.i18n?.scrollTabsLeft ?? "Scroll tabs left"), l.innerHTML = '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="15 18 9 12 15 6"/></svg>';
@@ -229,18 +229,18 @@ function ie(e) {
229
229
  });
230
230
  });
231
231
  const h = () => {
232
- const c = r.scrollLeft <= 4, y = r.scrollLeft + r.clientWidth >= r.scrollWidth - 4;
233
- l.style.display = c ? "none" : "", g.style.display = y ? "none" : "", r.classList.toggle("gengage-simrel-tabs--peek-right", !y), r.classList.toggle("gengage-simrel-tabs--peek-left", !c);
232
+ const c = r.scrollLeft <= 4, b = r.scrollLeft + r.clientWidth >= r.scrollWidth - 4;
233
+ l.style.display = c ? "none" : "", g.style.display = b ? "none" : "", r.classList.toggle("gengage-simrel-tabs--peek-right", !b), r.classList.toggle("gengage-simrel-tabs--peek-left", !c);
234
234
  };
235
235
  r.addEventListener("scroll", h, { passive: !0 }), typeof ResizeObserver < "u" && new ResizeObserver(h).observe(r), l.style.display = "none", g.style.display = "none", requestAnimationFrame(h);
236
- const C = document.createElement("div");
237
- C.className = "gengage-simrel-tabs-wrapper", C.appendChild(l), C.appendChild(r), C.appendChild(g), n.appendChild(C);
238
- const f = s[0], o = P(d(e.groups[0]));
236
+ const y = document.createElement("div");
237
+ y.className = "gengage-simrel-tabs-wrapper", y.appendChild(l), y.appendChild(r), y.appendChild(g), n.appendChild(y);
238
+ const f = s[0], o = w(d(e.groups[0]));
239
239
  f.appendChild(o);
240
240
  for (const c of s) n.appendChild(c);
241
241
  return n;
242
242
  }
243
- function w(e) {
243
+ function P(e) {
244
244
  if (!e || typeof e != "object") return null;
245
245
  const t = e;
246
246
  if (typeof t.sku != "string" || typeof t.name != "string" || typeof t.url != "string") return null;
@@ -297,7 +297,7 @@ var G = {
297
297
  return r;
298
298
  },
299
299
  ProductCard: ({ element: e, context: t }) => {
300
- const n = w(e.props?.product ?? e.props);
300
+ const n = P(e.props?.product ?? e.props);
301
301
  if (!n) return null;
302
302
  const r = e.props?.index, i = typeof r == "number" && Number.isFinite(r) ? r : 0, s = e.props?.discountType, a = s === "strike-through" || s === "badge" ? s : t.discountType, d = {
303
303
  product: n,
@@ -318,7 +318,7 @@ var G = {
318
318
  if (typeof d.name != "string") continue;
319
319
  const m = [];
320
320
  if (Array.isArray(d.products)) for (const g of d.products) {
321
- const u = w(g);
321
+ const u = P(g);
322
322
  u && m.push(u);
323
323
  }
324
324
  const l = {
@@ -431,10 +431,14 @@ function ue(e) {
431
431
  }
432
432
  var pe = class extends J {
433
433
  constructor(...e) {
434
- super(...e), this._abortController = null, this._contentEl = null, this._lastResultCount = -1, this._i18n = B;
434
+ super(...e), this._abortController = null, this._contentEl = null, this._lastResultCount = -1, this._i18n = B, this._pendingAddToCartKeys = /* @__PURE__ */ new Set();
435
+ }
436
+ async init(e) {
437
+ if (!this.isInitialised && (e.mountTarget === void 0 || e.mountTarget === null)) throw new Error("[gengage] SimRel mountTarget is required. Provide a merchant-owned mount before initializing.");
438
+ await super.init(e);
435
439
  }
436
440
  async onInit(e) {
437
- this._i18n = this._resolveI18n(e), this._contentEl = document.createElement("div"), this._contentEl.className = "gengage-simrel-container", this._contentEl.dataset.gengagePart = "simrel-container", this._contentEl.lang = Q(e.locale);
441
+ this._i18n = this._resolveI18n(e), this._contentEl = document.createElement("div"), this._contentEl.className = "gengage-simrel-container", this._contentEl.dataset.gengagePart = "simrel-container", this._contentEl.lang = K(e.locale);
438
442
  const t = this._clampGridColumns(e.gridColumns);
439
443
  t !== void 0 && this._contentEl.style.setProperty("--gengage-simrel-columns", String(t)), this.root.appendChild(this._contentEl), this._lastSku = e.sku, await this._fetchAndRender(e.sku), $("simrel");
440
444
  }
@@ -467,8 +471,23 @@ var pe = class extends J {
467
471
  productName: e.name
468
472
  }), this.config.onProductNavigate?.(e.url, e.sku, n);
469
473
  }
470
- _handleAddToCart(e) {
471
- q(e.sku, e.quantity), this.config.onAddToCart?.(e), k("gengage:similar:add-to-cart", e);
474
+ async _handleAddToCart(e) {
475
+ const t = `${e.sku}\0${e.cartCode}\0${e.quantity}`;
476
+ if (!this._pendingAddToCartKeys.has(t)) {
477
+ this._pendingAddToCartKeys.add(t);
478
+ try {
479
+ if (this.config.onAddToCart === void 0) return;
480
+ try {
481
+ await Promise.resolve(this.config.onAddToCart(e));
482
+ } catch (n) {
483
+ console.error("[gengage] simrel onAddToCart", n);
484
+ return;
485
+ }
486
+ H(e.sku, e.quantity), k("gengage:similar:add-to-cart", e);
487
+ } finally {
488
+ this._pendingAddToCartKeys.delete(t);
489
+ }
490
+ }
472
491
  }
473
492
  _abort() {
474
493
  this._abortController?.abort(), this._abortController = null;
@@ -518,8 +537,8 @@ var pe = class extends J {
518
537
  this.config.domain !== void 0 && (l.domain = this.config.domain);
519
538
  const g = await ee(l, d, n);
520
539
  if (this._lastResultCount = g.length, !this._contentEl) return;
521
- if (this._contentEl.innerHTML = "", g.length > 0) try {
522
- const u = g.map((f) => f.sku), h = new Map(g.map((f) => [f.sku, f])), C = (await ne({
540
+ if (this._contentEl.innerHTML = "", g.length > 0 && this.config.enableProductGroupings !== !1) try {
541
+ const u = g.map((f) => f.sku), h = new Map(g.map((f) => [f.sku, f])), y = (await ne({
523
542
  account_id: this.config.accountId,
524
543
  session_id: this.config.session?.sessionId ?? "",
525
544
  correlation_id: this.config.session?.sessionId ?? "",
@@ -531,9 +550,9 @@ var pe = class extends J {
531
550
  ...o
532
551
  })).filter((o) => typeof o.sku == "string" && typeof o.name == "string" && typeof o.url == "string")
533
552
  })).filter((f) => f.products.length > 0);
534
- if (C.length > 0 && this._contentEl) {
535
- const f = this._buildGroupsSpec(C), o = this._renderUISpec(f);
536
- this._contentEl.appendChild(o), T("simrel"), this._emitSimilarProductsImpression(C.reduce((c, y) => c + y.products.length, 0), !0);
553
+ if (y.length > 0 && this._contentEl) {
554
+ const f = this._buildGroupsSpec(y), o = this._renderUISpec(f);
555
+ this._contentEl.appendChild(o), S("simrel"), this._emitSimilarProductsImpression(y.reduce((c, b) => c + b.products.length, 0), !0);
537
556
  return;
538
557
  }
539
558
  } catch {
@@ -543,7 +562,7 @@ var pe = class extends J {
543
562
  const u = this._buildProductsSpec(g), h = this._renderUISpec(u);
544
563
  this._contentEl.appendChild(h);
545
564
  }
546
- g.length > 0 && T("simrel"), this._emitSimilarProductsImpression(g.length, !1);
565
+ g.length > 0 && S("simrel"), this._emitSimilarProductsImpression(g.length, !1);
547
566
  } catch (l) {
548
567
  const g = ue(l);
549
568
  if (g && this._isSuperseded(n)) return;
@@ -557,10 +576,10 @@ var pe = class extends J {
557
576
  u.className = "gengage-simrel-error";
558
577
  const h = document.createElement("span");
559
578
  h.textContent = this._i18n.errorLoadingMessage, u.appendChild(h);
560
- const C = document.createElement("button");
561
- C.className = "gengage-simrel-retry", C.textContent = this._i18n.retryButtonText, C.addEventListener("click", () => {
579
+ const y = document.createElement("button");
580
+ y.className = "gengage-simrel-retry", y.textContent = this._i18n.retryButtonText, y.addEventListener("click", () => {
562
581
  this._fetchAndRender(this.config.sku);
563
- }), u.appendChild(C), this._contentEl.appendChild(u);
582
+ }), u.appendChild(y), this._contentEl.appendChild(u);
564
583
  }
565
584
  } finally {
566
585
  clearTimeout(i), m();
@@ -577,12 +596,14 @@ var pe = class extends J {
577
596
  };
578
597
  }
579
598
  _resolveUISpecRegistry() {
580
- return z(oe(), this.config.renderer?.registry);
599
+ return F(oe(), this.config.renderer?.registry);
581
600
  }
582
601
  _buildRenderContext() {
583
602
  const e = this.config.renderCard, t = {
584
603
  onClick: (r) => this._handleProductClick(r),
585
- onAddToCart: (r) => this._handleAddToCart(r),
604
+ onAddToCart: (r) => {
605
+ this._handleAddToCart(r);
606
+ },
586
607
  onGroupingActivate: (r) => {
587
608
  k("gengage:similar:grouping-click", {
588
609
  grouping_label: r.grouping_label,
@@ -1,8 +1,8 @@
1
- import { d as x, h as Q, p as R, r as N, t as H } from "./api-paths-y5nkfEBG.js";
1
+ import { d as x, h as Q, p as R, r as N, t as H } from "./api-paths-HBfd3rta.js";
2
2
  import { A as O, D as U, E as j, a as q, v as M } from "./context-BBuSsXZ9.js";
3
- import { o as F, t as W } from "./widget-base-Dliq3QAf.js";
3
+ import { o as F, t as W } from "./widget-base-BcrlFdYt.js";
4
4
  import { t as A } from "./locale-CfqNifrU.js";
5
- import { n as D } from "./connection-warning-DJiyLM46.js";
5
+ import { n as D } from "./connection-warning-BvPwMY8A.js";
6
6
  async function z(e, t, n) {
7
7
  const o = H("launcher_action", t), i = {
8
8
  uiSpecs: [],