@gengage/assistant-fe 0.1.0 → 0.1.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.
Files changed (150) hide show
  1. package/LICENSE +2 -2
  2. package/README.md +2 -2
  3. package/dist/assistant-fe.css +1 -1
  4. package/dist/chat/api.d.ts +12 -2
  5. package/dist/chat/api.d.ts.map +1 -1
  6. package/dist/chat/catalog.d.ts +246 -896
  7. package/dist/chat/catalog.d.ts.map +1 -1
  8. package/dist/chat/components/AIGroupingCards.d.ts.map +1 -1
  9. package/dist/chat/components/AISuggestedSearchCards.d.ts.map +1 -1
  10. package/dist/chat/components/AITopPicks.d.ts.map +1 -1
  11. package/dist/chat/components/CategoriesContainer.d.ts.map +1 -1
  12. package/dist/chat/components/ChatDrawer.d.ts +16 -3
  13. package/dist/chat/components/ChatDrawer.d.ts.map +1 -1
  14. package/dist/chat/components/ComparisonTable.d.ts +9 -0
  15. package/dist/chat/components/ComparisonTable.d.ts.map +1 -1
  16. package/dist/chat/components/GroundingReviewCard.d.ts.map +1 -1
  17. package/dist/chat/components/HandoffNotice.d.ts +5 -0
  18. package/dist/chat/components/HandoffNotice.d.ts.map +1 -0
  19. package/dist/chat/components/KvkkBanner.d.ts +1 -0
  20. package/dist/chat/components/KvkkBanner.d.ts.map +1 -1
  21. package/dist/chat/components/ProactivePopup.d.ts +9 -0
  22. package/dist/chat/components/ProactivePopup.d.ts.map +1 -1
  23. package/dist/chat/components/ProductSummaryCard.d.ts +4 -0
  24. package/dist/chat/components/ProductSummaryCard.d.ts.map +1 -0
  25. package/dist/chat/components/ReviewHighlights.d.ts +3 -1
  26. package/dist/chat/components/ReviewHighlights.d.ts.map +1 -1
  27. package/dist/chat/components/ThumbnailsColumn.d.ts.map +1 -1
  28. package/dist/chat/components/renderUISpec.d.ts +4 -3
  29. package/dist/chat/components/renderUISpec.d.ts.map +1 -1
  30. package/dist/chat/heartbeat.d.ts +71 -0
  31. package/dist/chat/heartbeat.d.ts.map +1 -0
  32. package/dist/chat/index.d.ts +39 -78
  33. package/dist/chat/index.d.ts.map +1 -1
  34. package/dist/chat/kvkk.d.ts +21 -0
  35. package/dist/chat/kvkk.d.ts.map +1 -0
  36. package/dist/chat/locales/en.d.ts.map +1 -1
  37. package/dist/chat/locales/tr.d.ts.map +1 -1
  38. package/dist/chat/panel-manager.d.ts +81 -0
  39. package/dist/chat/panel-manager.d.ts.map +1 -0
  40. package/dist/chat/session-persistence.d.ts +56 -0
  41. package/dist/chat/session-persistence.d.ts.map +1 -0
  42. package/dist/chat/types.d.ts +39 -1
  43. package/dist/chat/types.d.ts.map +1 -1
  44. package/dist/chat.cjs +1 -1
  45. package/dist/chat.iife.js +48 -10
  46. package/dist/chat.iife.js.map +1 -1
  47. package/dist/chat.js +9 -8
  48. package/dist/chat.js.map +1 -1
  49. package/dist/common/analytics-events.d.ts +2 -0
  50. package/dist/common/analytics-events.d.ts.map +1 -1
  51. package/dist/common/analytics.d.ts.map +1 -1
  52. package/dist/common/api-paths.d.ts +5 -0
  53. package/dist/common/api-paths.d.ts.map +1 -1
  54. package/dist/common/client.d.ts +4 -1
  55. package/dist/common/client.d.ts.map +1 -1
  56. package/dist/common/communication-bridge.d.ts.map +1 -1
  57. package/dist/common/config-schema.d.ts +33 -195
  58. package/dist/common/config-schema.d.ts.map +1 -1
  59. package/dist/common/ga-datalayer.d.ts +62 -0
  60. package/dist/common/ga-datalayer.d.ts.map +1 -0
  61. package/dist/common/index.d.ts +7 -0
  62. package/dist/common/index.d.ts.map +1 -1
  63. package/dist/common/indexed-db.d.ts +1 -1
  64. package/dist/common/indexed-db.d.ts.map +1 -1
  65. package/dist/common/merchant-configs.d.ts +22 -0
  66. package/dist/common/merchant-configs.d.ts.map +1 -0
  67. package/dist/common/overlay.d.ts +5 -0
  68. package/dist/common/overlay.d.ts.map +1 -1
  69. package/dist/common/page-detect.d.ts +31 -0
  70. package/dist/common/page-detect.d.ts.map +1 -0
  71. package/dist/common/preflight.d.ts +3 -1
  72. package/dist/common/preflight.d.ts.map +1 -1
  73. package/dist/common/price-formatter.d.ts +33 -0
  74. package/dist/common/price-formatter.d.ts.map +1 -0
  75. package/dist/common/product-utils.d.ts +26 -0
  76. package/dist/common/product-utils.d.ts.map +1 -0
  77. package/dist/common/quantity-stepper.d.ts +22 -0
  78. package/dist/common/quantity-stepper.d.ts.map +1 -0
  79. package/dist/common/safe-html.d.ts +10 -6
  80. package/dist/common/safe-html.d.ts.map +1 -1
  81. package/dist/common/streaming.d.ts +6 -0
  82. package/dist/common/streaming.d.ts.map +1 -1
  83. package/dist/common/tts-player.d.ts +12 -0
  84. package/dist/common/tts-player.d.ts.map +1 -0
  85. package/dist/common/types.d.ts +51 -0
  86. package/dist/common/types.d.ts.map +1 -1
  87. package/dist/common/v1-protocol-adapter.d.ts +9 -0
  88. package/dist/common/v1-protocol-adapter.d.ts.map +1 -1
  89. package/dist/common/voice-input.d.ts +74 -0
  90. package/dist/common/voice-input.d.ts.map +1 -0
  91. package/dist/common/widget-base.d.ts +18 -1
  92. package/dist/common/widget-base.d.ts.map +1 -1
  93. package/dist/common.cjs +1 -1
  94. package/dist/common.cjs.map +1 -1
  95. package/dist/common.js +564 -244
  96. package/dist/common.js.map +1 -1
  97. package/dist/index-CXbH-cw8.js +4337 -0
  98. package/dist/index-CXbH-cw8.js.map +1 -0
  99. package/dist/index-DHfTHscz.cjs +13 -0
  100. package/dist/index-DHfTHscz.cjs.map +1 -0
  101. package/dist/index.cjs +1 -1
  102. package/dist/index.d.ts +2 -2
  103. package/dist/index.d.ts.map +1 -1
  104. package/dist/index.js +61 -53
  105. package/dist/qna/catalog.d.ts +30 -96
  106. package/dist/qna/catalog.d.ts.map +1 -1
  107. package/dist/qna/components/TextInput.d.ts.map +1 -1
  108. package/dist/qna/components/renderUISpec.d.ts.map +1 -1
  109. package/dist/qna/index.d.ts +2 -0
  110. package/dist/qna/index.d.ts.map +1 -1
  111. package/dist/qna.cjs +1 -1
  112. package/dist/qna.cjs.map +1 -1
  113. package/dist/qna.iife.js +46 -8
  114. package/dist/qna.iife.js.map +1 -1
  115. package/dist/qna.js +94 -86
  116. package/dist/qna.js.map +1 -1
  117. package/dist/quantity-stepper-B8kX8GbN.js +209 -0
  118. package/dist/quantity-stepper-B8kX8GbN.js.map +1 -0
  119. package/dist/quantity-stepper-UbAp53Ow.cjs +2 -0
  120. package/dist/quantity-stepper-UbAp53Ow.cjs.map +1 -0
  121. package/dist/schemas-CPkzbgia.js +4572 -0
  122. package/dist/schemas-CPkzbgia.js.map +1 -0
  123. package/dist/schemas-tCxs1sED.cjs +86 -0
  124. package/dist/schemas-tCxs1sED.cjs.map +1 -0
  125. package/dist/simrel/api.d.ts.map +1 -1
  126. package/dist/simrel/catalog.d.ts +32 -240
  127. package/dist/simrel/catalog.d.ts.map +1 -1
  128. package/dist/simrel/components/GroupTabs.d.ts.map +1 -1
  129. package/dist/simrel/components/ProductCard.d.ts +2 -0
  130. package/dist/simrel/components/ProductCard.d.ts.map +1 -1
  131. package/dist/simrel/components/renderUISpec.d.ts.map +1 -1
  132. package/dist/simrel/index.d.ts.map +1 -1
  133. package/dist/simrel/types.d.ts +5 -0
  134. package/dist/simrel/types.d.ts.map +1 -1
  135. package/dist/simrel.cjs +1 -1
  136. package/dist/simrel.cjs.map +1 -1
  137. package/dist/simrel.css +1 -1
  138. package/dist/simrel.iife.js +46 -8
  139. package/dist/simrel.iife.js.map +1 -1
  140. package/dist/simrel.js +319 -279
  141. package/dist/simrel.js.map +1 -1
  142. package/package.json +28 -8
  143. package/dist/index-CFA70IGF.js +0 -3626
  144. package/dist/index-CFA70IGF.js.map +0 -1
  145. package/dist/index-Dfl89zpe.cjs +0 -13
  146. package/dist/index-Dfl89zpe.cjs.map +0 -1
  147. package/dist/types-CeON7iBO.cjs +0 -48
  148. package/dist/types-CeON7iBO.cjs.map +0 -1
  149. package/dist/types-yxW8WA7u.js +0 -4132
  150. package/dist/types-yxW8WA7u.js.map +0 -1
@@ -1,15 +1,15 @@
1
- (function(z){"use strict";const dt=({element:t,renderElement:e})=>{if(!t.children||t.children.length===0)return null;const n=document.createElement("div");for(const r of t.children){const i=e(r);i&&n.appendChild(i)}return n};function ut(t){const e=document.createElement("div");if(e.className=t.containerClassName,!t.spec.elements[t.spec.root])return e;const r=t.unknownRenderer??dt,i=a=>{const o=t.spec.elements[a];if(!o)return null;const c=t.registry[o.type];return c?c({elementId:a,element:o,spec:t.spec,context:t.context,renderElement:i}):r({elementId:a,element:o,spec:t.spec,context:t.context,renderElement:i})},s=i(t.spec.root);return s&&e.appendChild(s),e}function lt(t,e){if(!e)return t;const n={...t};for(const[r,i]of Object.entries(e))i&&(n[r]=i);return n}function ft(t,e){const n={event_name:"stream.start",account_id:t.account_id,session_id:t.session_id,correlation_id:t.correlation_id,payload:{endpoint:e.endpoint,request_id:e.request_id}};return t.view_id!==void 0&&(n.view_id=t.view_id),t.user_id!==void 0&&(n.user_id=t.user_id),e.widget!==void 0&&(n.widget=e.widget),t.page_type!==void 0&&(n.page_type=t.page_type),t.sku!==void 0&&(n.sku=t.sku),n}function pt(t,e){const n={event_name:"stream.done",account_id:t.account_id,session_id:t.session_id,correlation_id:t.correlation_id,payload:{request_id:e.request_id,latency_ms:e.latency_ms,chunk_count:e.chunk_count}};return t.view_id!==void 0&&(n.view_id=t.view_id),t.user_id!==void 0&&(n.user_id=t.user_id),e.widget!==void 0&&(n.widget=e.widget),t.page_type!==void 0&&(n.page_type=t.page_type),t.sku!==void 0&&(n.sku=t.sku),n}function ht(t,e){const n={event_name:"stream.error",account_id:t.account_id,session_id:t.session_id,correlation_id:t.correlation_id,payload:{request_id:e.request_id,error_code:e.error_code,error_message:e.error_message}};return t.view_id!==void 0&&(n.view_id=t.view_id),t.user_id!==void 0&&(n.user_id=t.user_id),e.widget!==void 0&&(n.widget=e.widget),t.page_type!==void 0&&(n.page_type=t.page_type),t.sku!==void 0&&(n.sku=t.sku),n}function mt(t,e){const n={event_name:"metering.summary",account_id:t.account_id,session_id:t.session_id,correlation_id:t.correlation_id,payload:{meter_key:e.meter_key,quantity:e.quantity,unit:e.unit}};return t.view_id!==void 0&&(n.view_id=t.view_id),t.user_id!==void 0&&(n.user_id=t.user_id),t.page_type!==void 0&&(n.page_type=t.page_type),t.sku!==void 0&&(n.sku=t.sku),n}function gt(t,e){const n={event_name:"widget.history.snapshot",account_id:t.account_id,session_id:t.session_id,correlation_id:t.correlation_id,widget:e.widget,payload:{message_count:e.message_count,history_ref:e.history_ref,redaction_level:e.redaction_level}};return t.view_id!==void 0&&(n.view_id=t.view_id),t.user_id!==void 0&&(n.user_id=t.user_id),t.page_type!==void 0&&(n.page_type=t.page_type),t.sku!==void 0&&(n.sku=t.sku),n}function yt(t,e){const n={event_name:"basket.add",account_id:t.account_id,session_id:t.session_id,correlation_id:t.correlation_id,widget:e.attribution_source,payload:{attribution_source:e.attribution_source,attribution_action_id:e.attribution_action_id,cart_value:e.cart_value,currency:e.currency,line_items:e.line_items,sku:e.sku}};return t.view_id!==void 0&&(n.view_id=t.view_id),t.user_id!==void 0&&(n.user_id=t.user_id),t.page_type!==void 0&&(n.page_type=t.page_type),t.sku!==void 0&&(n.sku=t.sku),n}function _t(t,e){const n={event_name:"checkout.start",account_id:t.account_id,session_id:t.session_id,correlation_id:t.correlation_id,widget:e.attribution_source,payload:{attribution_source:e.attribution_source,attribution_action_id:e.attribution_action_id,cart_value:e.cart_value,currency:e.currency,line_items:e.line_items}};return t.view_id!==void 0&&(n.view_id=t.view_id),t.user_id!==void 0&&(n.user_id=t.user_id),t.page_type!==void 0&&(n.page_type=t.page_type),t.sku!==void 0&&(n.sku=t.sku),n}function vt(t,e){const n={event_name:"checkout.complete",account_id:t.account_id,session_id:t.session_id,correlation_id:t.correlation_id,widget:e.attribution_source,payload:{attribution_source:e.attribution_source,attribution_action_id:e.attribution_action_id,cart_value:e.cart_value,currency:e.currency,line_items:e.line_items}};return t.view_id!==void 0&&(n.view_id=t.view_id),t.user_id!==void 0&&(n.user_id=t.user_id),t.page_type!==void 0&&(n.page_type=t.page_type),t.sku!==void 0&&(n.sku=t.sku),n}function ce(t,e){window.dispatchEvent(new CustomEvent(t,{detail:e,bubbles:!1}))}function we(t,e){const n=r=>{e(r.detail)};return window.addEventListener(t,n),()=>window.removeEventListener(t,n)}function kt(){const e=window.__gengageSessionId??sessionStorage.getItem("gengage_session_id")??null??crypto.randomUUID();return window.__gengageSessionId=e,sessionStorage.setItem("gengage_session_id",e),window.gengage||(window.gengage={}),window.gengage.sessionId=e,e}function bt(t){return{sessionId:t?.sessionId??kt(),...t}}const xe={"--gengage-chat-offset":"20px","--gengage-chat-launcher-size":"56px","--gengage-chat-width":"400px","--gengage-chat-shell-radius":"12px","--gengage-chat-header-height":"60px","--gengage-chat-conversation-width":"396px","--gengage-chat-panel-min-width":"320px","--gengage-chat-panel-max-width":"860px","--gengage-chat-input-height":"48px","--gengage-qna-pill-radius":"999px","--gengage-qna-input-radius":"14px","--gengage-simrel-card-radius":"14px"};function wt(t){return t?{...xe,...t}:{...xe}}const O="gengage-global-toast-root",Ce="gengage-global-toast-style",de="gengage-global-toast-root--visible",xt=4200,Ct=1500,Tt=15e3;let Te=!1,V=null;function St(t){return typeof t=="string"&&t.toLowerCase().startsWith("tr")?"Baglanti sorunu olustu. Lutfen tekrar deneyin.":"Connection issue. Please try again."}function Et(){Te||typeof window>"u"||typeof document>"u"||(Te=!0,we("gengage:global:error",t=>{At(t)}))}function At(t){if(typeof document>"u")return;const e=t.message.trim();if(!e)return;Pt();const n=Rt();n.innerHTML="";const r=document.createElement("section");r.className="gengage-global-toast gengage-global-toast--error",r.setAttribute("role","status"),r.setAttribute("aria-live","polite");const i=document.createElement("div");i.className="gengage-global-toast-title",i.textContent=Nt(t.source);const s=document.createElement("div");s.className="gengage-global-toast-message",s.textContent=e,r.appendChild(i),r.appendChild(s),n.appendChild(r),n.classList.add(de),V&&(clearTimeout(V),V=null),V=setTimeout(()=>{It()},Ot(t.durationMs))}function It(){if(typeof document>"u")return;const t=document.getElementById(O);t&&(t.classList.remove(de),t.innerHTML="",V&&(clearTimeout(V),V=null))}function Nt(t){switch(t){case"chat":return"Chat warning";case"qna":return"QnA warning";case"simrel":return"Widget warning";default:return"Connection warning"}}function Rt(){const t=document.getElementById(O);if(t instanceof HTMLElement)return t;const e=document.createElement("div");return e.id=O,e.className="gengage-global-toast-root",document.body.appendChild(e),e}function Ot(t){return typeof t!="number"||!Number.isFinite(t)?xt:Math.min(Tt,Math.max(Ct,Math.round(t)))}function Pt(){if(document.getElementById(Ce))return;const t=document.createElement("style");t.id=Ce,t.textContent=`
2
- #${O} {
1
+ (function(U){"use strict";const on=({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 sn(e){const t=document.createElement("div");if(t.className=e.containerClassName,!e.spec.elements[e.spec.root])return t;const r=e.unknownRenderer??on,o=i=>{const a=e.spec.elements[i];if(!a)return null;const c=e.registry[a.type];return c?c({elementId:i,element:a,spec:e.spec,context:e.context,renderElement:o}):r({elementId:i,element:a,spec:e.spec,context:e.context,renderElement:o})},s=o(e.spec.root);return s&&t.appendChild(s),t}function an(e,t){if(!t)return e;const n={...e};for(const[r,o]of Object.entries(t))o&&(n[r]=o);return n}function cn(e,t){const n={event_name:"stream.start",account_id:e.account_id,session_id:e.session_id,correlation_id:e.correlation_id,payload:{endpoint:t.endpoint,request_id:t.request_id}};return e.view_id!==void 0&&(n.view_id=e.view_id),e.user_id!==void 0&&(n.user_id=e.user_id),t.widget!==void 0&&(n.widget=t.widget),e.page_type!==void 0&&(n.page_type=e.page_type),e.sku!==void 0&&(n.sku=e.sku),n}function Oe(e,t){const n={event_name:"stream.done",account_id:e.account_id,session_id:e.session_id,correlation_id:e.correlation_id,payload:{request_id:t.request_id,latency_ms:t.latency_ms,chunk_count:t.chunk_count}};return e.view_id!==void 0&&(n.view_id=e.view_id),e.user_id!==void 0&&(n.user_id=e.user_id),t.widget!==void 0&&(n.widget=t.widget),e.page_type!==void 0&&(n.page_type=e.page_type),e.sku!==void 0&&(n.sku=e.sku),n}function un(e,t){const n={event_name:"stream.error",account_id:e.account_id,session_id:e.session_id,correlation_id:e.correlation_id,payload:{request_id:t.request_id,error_code:t.error_code,error_message:t.error_message}};return e.view_id!==void 0&&(n.view_id=e.view_id),e.user_id!==void 0&&(n.user_id=e.user_id),t.widget!==void 0&&(n.widget=t.widget),e.page_type!==void 0&&(n.page_type=e.page_type),e.sku!==void 0&&(n.sku=e.sku),n}function dn(e,t){const n={event_name:"metering.summary",account_id:e.account_id,session_id:e.session_id,correlation_id:e.correlation_id,payload:{meter_key:t.meter_key,quantity:t.quantity,unit:t.unit}};return e.view_id!==void 0&&(n.view_id=e.view_id),e.user_id!==void 0&&(n.user_id=e.user_id),e.page_type!==void 0&&(n.page_type=e.page_type),e.sku!==void 0&&(n.sku=e.sku),n}function Ze(e,t){const n={event_name:"widget.history.snapshot",account_id:e.account_id,session_id:e.session_id,correlation_id:e.correlation_id,widget:t.widget,payload:{message_count:t.message_count,history_ref:t.history_ref,redaction_level:t.redaction_level}};return e.view_id!==void 0&&(n.view_id=e.view_id),e.user_id!==void 0&&(n.user_id=e.user_id),e.page_type!==void 0&&(n.page_type=e.page_type),e.sku!==void 0&&(n.sku=e.sku),n}function ln(e,t){const n={event_name:"basket.add",account_id:e.account_id,session_id:e.session_id,correlation_id:e.correlation_id,widget:t.attribution_source,payload:{attribution_source:t.attribution_source,attribution_action_id:t.attribution_action_id,cart_value:t.cart_value,currency:t.currency,line_items:t.line_items,sku:t.sku}};return e.view_id!==void 0&&(n.view_id=e.view_id),e.user_id!==void 0&&(n.user_id=e.user_id),e.page_type!==void 0&&(n.page_type=e.page_type),e.sku!==void 0&&(n.sku=e.sku),n}function pn(e,t){const n={event_name:"checkout.start",account_id:e.account_id,session_id:e.session_id,correlation_id:e.correlation_id,widget:t.attribution_source,payload:{attribution_source:t.attribution_source,attribution_action_id:t.attribution_action_id,cart_value:t.cart_value,currency:t.currency,line_items:t.line_items}};return e.view_id!==void 0&&(n.view_id=e.view_id),e.user_id!==void 0&&(n.user_id=e.user_id),e.page_type!==void 0&&(n.page_type=e.page_type),e.sku!==void 0&&(n.sku=e.sku),n}function fn(e,t){const n={event_name:"checkout.complete",account_id:e.account_id,session_id:e.session_id,correlation_id:e.correlation_id,widget:t.attribution_source,payload:{attribution_source:t.attribution_source,attribution_action_id:t.attribution_action_id,cart_value:t.cart_value,currency:t.currency,line_items:t.line_items}};return e.view_id!==void 0&&(n.view_id=e.view_id),e.user_id!==void 0&&(n.user_id=e.user_id),e.page_type!==void 0&&(n.page_type=e.page_type),e.sku!==void 0&&(n.sku=e.sku),n}function pe(e,t){window.dispatchEvent(new CustomEvent(e,{detail:t,bubbles:!1}))}function Ne(e,t){const n=r=>{t(r.detail)};return window.addEventListener(e,n),()=>window.removeEventListener(e,n)}function mn(){const t=window.__gengageSessionId??sessionStorage.getItem("gengage_session_id")??null??crypto.randomUUID();return window.__gengageSessionId=t,sessionStorage.setItem("gengage_session_id",t),window.gengage||(window.gengage={}),window.gengage.sessionId=t,t}function gn(e){return{sessionId:e?.sessionId??mn(),...e}}const Re={"--gengage-chat-offset":"20px","--gengage-chat-launcher-size":"56px","--gengage-chat-width":"400px","--gengage-chat-shell-radius":"12px","--gengage-chat-header-height":"60px","--gengage-chat-conversation-width":"396px","--gengage-chat-panel-min-width":"320px","--gengage-chat-panel-max-width":"860px","--gengage-chat-input-height":"48px","--gengage-qna-pill-radius":"999px","--gengage-qna-input-radius":"14px","--gengage-simrel-card-radius":"14px"};function hn(e){return e?{...Re,...e}:{...Re}}const N="gengage-global-toast-root",De="gengage-global-toast-style",fe="gengage-global-toast-root--visible",_n=4200,yn=1500,vn=15e3;let je=!1,M=null;function bn(e){return typeof e=="string"&&e.toLowerCase().startsWith("tr")?"Baglanti sorunu olustu. Lutfen tekrar deneyin.":"Connection issue. Please try again."}function wn(){je||typeof window>"u"||typeof document>"u"||(je=!0,Ne("gengage:global:error",e=>{kn(e)}))}function kn(e){if(typeof document>"u")return;const t=e.message.trim();if(!t)return;Tn();const n=En();n.innerHTML="";const r=document.createElement("section");r.className="gengage-global-toast gengage-global-toast--error",r.setAttribute("role","status"),r.setAttribute("aria-live","polite");const o=document.createElement("div");o.className="gengage-global-toast-title",o.textContent=zn(e.source);const s=document.createElement("div");s.className="gengage-global-toast-message",s.textContent=t,r.appendChild(o),r.appendChild(s),n.appendChild(r),n.classList.add(fe),M&&(clearTimeout(M),M=null),M=setTimeout(()=>{Sn()},Cn(e.durationMs))}function Sn(){if(typeof document>"u")return;const e=document.getElementById(N);e&&(e.classList.remove(fe),e.innerHTML="",M&&(clearTimeout(M),M=null))}function zn(e){switch(e){case"chat":return"Chat warning";case"qna":return"QnA warning";case"simrel":return"Widget warning";default:return"Connection warning"}}function En(){const e=document.getElementById(N);if(e instanceof HTMLElement)return e;const t=document.createElement("div");return t.id=N,t.className="gengage-global-toast-root",document.body.appendChild(t),t}function Cn(e){return typeof e!="number"||!Number.isFinite(e)?_n:Math.min(vn,Math.max(yn,Math.round(e)))}function Tn(){if(document.getElementById(De))return;const e=document.createElement("style");e.id=De,e.textContent=`
2
+ #${N} {
3
3
  position: fixed;
4
4
  top: 16px;
5
5
  right: 16px;
6
6
  z-index: 2147483646;
7
7
  pointer-events: none;
8
8
  }
9
- #${O}.${de} {
9
+ #${N}.${fe} {
10
10
  pointer-events: auto;
11
11
  }
12
- #${O} .gengage-global-toast {
12
+ #${N} .gengage-global-toast {
13
13
  min-width: 260px;
14
14
  max-width: min(92vw, 420px);
15
15
  border-radius: 12px;
@@ -24,12 +24,12 @@
24
24
  line-height: 1.4;
25
25
  animation: gengage-global-toast-in 180ms ease-out forwards;
26
26
  }
27
- #${O} .gengage-global-toast-title {
27
+ #${N} .gengage-global-toast-title {
28
28
  margin: 0 0 4px;
29
29
  font-size: 12px;
30
30
  font-weight: 700;
31
31
  }
32
- #${O} .gengage-global-toast-message {
32
+ #${N} .gengage-global-toast-message {
33
33
  margin: 0;
34
34
  font-weight: 500;
35
35
  }
@@ -43,6 +43,44 @@
43
43
  transform: translateY(0);
44
44
  }
45
45
  }
46
- `,document.head.appendChild(t)}class Lt{constructor(){this.isVisible=!1,this.isInitialised=!1,this._handlers=new Map,this._cleanups=[],this._ownsRoot=!1}async init(e){if(this.isInitialised){console.warn("[gengage] Widget already initialised. Call update() instead.");return}const n=wt(e.theme);this.config={...e,theme:n,session:bt(e.session)},this.root=this._resolveMount(e.mountTarget),this._applyTheme(n),Et();const r=we("gengage:context:update",i=>this.update(i));this._cleanups.push(r),await this.onInit(this.config),this.isInitialised=!0,this.emit("ready")}update(e){this.isInitialised&&(this.config.pageContext?this.config={...this.config,pageContext:{...this.config.pageContext,...e}}:this.config={...this.config,pageContext:e},this.onUpdate(e))}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._cleanups.forEach(e=>e()),this._cleanups.length=0,this._handlers.clear(),this.onDestroy(),this._ownsRoot?this.root.remove():this.root.innerHTML="",this.isInitialised=!1}on(e,n){return this._handlers.has(e)||this._handlers.set(e,new Set),this._handlers.get(e).add(n),()=>this._handlers.get(e)?.delete(n)}trackCheckout(e,n){const r=e==="start"?_t:vt;this.track(r(this.analyticsContext(),n))}flushMeteringSummary(e){this.track(mt(this.analyticsContext(),e))}emit(e,...n){this._handlers.get(e)?.forEach(r=>r(...n))}addCleanup(e){this._cleanups.push(e)}track(e){this.config.analyticsClient?.track(e)}analyticsContext(){const e={account_id:this.config.accountId,session_id:this.config.session?.sessionId??"",correlation_id:this.config.session?.sessionId??""};return this.config.session?.viewId!==void 0&&(e.view_id=this.config.session.viewId),this.config.session?.userId!==void 0&&(e.user_id=this.config.session.userId),this.config.pageContext?.pageType!==void 0&&(e.page_type=this.config.pageContext.pageType),this.config.pageContext?.sku!==void 0&&(e.sku=this.config.pageContext.sku),e}_resolveMount(e){if(e instanceof HTMLElement)return e;if(typeof e=="string"){const r=document.querySelector(e);if(!r)throw new Error(`[gengage] Mount target not found: "${e}"`);return r}const n=document.createElement("div");return n.dataset.gengageWidget=this.constructor.name.toLowerCase(),document.body.appendChild(n),this._ownsRoot=!0,n}_applyTheme(e){if(e){for(const[n,r]of Object.entries(e))if(r!==void 0){const i=n.startsWith("--")?n:`--gengage-${jt(n)}`;this.root.style.setProperty(i,r)}}}}function jt(t){return t.replace(/([A-Z])/g,"-$1").toLowerCase()}const Zt={process_action:"/process_action",launcher_action:"/launcher_action",similar_products:"/similar_products",product_groupings:"/product_groupings",proactive_action:"/proactive_action"};function $t(t){if(t===void 0)throw new Error("[gengage] middlewareUrl is required. Pass your Gengage backend URL in widget config.");const e=t.trim();return e===""?"":e.replace(/\/+$/,"")}function Se(t,e){return`${$t(e?.middlewareUrl)}/chat${Zt[t]}`}function Mt(t){const e=[];let n=0,r=!1,i=!1,s=0;for(let a=0;a<t.length;a++){const o=t[a];if(i){i=!1;continue}if(o==="\\"&&r){i=!0;continue}if(o==='"'){r=!r;continue}r||(o==="{"&&n++,o==="}"&&(n--,n===0&&(e.push(t.slice(s,a+1)),s=a+1)))}return e.length>0?e:[t]}function Ee(t,e){const n=t.trim();if(!n||n.startsWith(":"))return!1;const r=n.startsWith("data: ")?n.slice(6):n;if(r==="[DONE]")return!0;try{const i=JSON.parse(r);return e.onEvent(i),i.type==="done"?(e.onDone?.(),!0):!1}catch{const i=Mt(r);if(i.length>1){for(const s of i)try{const a=JSON.parse(s);if(e.onEvent(a),a.type==="done")return e.onDone?.(),!0}catch{}return!1}return!1}}async function Ae(t,e){if(!t.ok){e.onError?.(new Error(`HTTP ${t.status}: ${t.statusText}`));return}if(!t.body){e.onError?.(new Error("Response body is null — streaming not supported"));return}const n=t.body.getReader(),r=new TextDecoder("utf-8");let i="";try{for(;;){const{done:s,value:a}=await n.read();if(s)break;i+=r.decode(a,{stream:!0});const o=i.split(`
47
- `);i=o.pop()??"";for(const c of o)if(Ee(c,e))return}i.trim()&&Ee(i,e)}catch(s){if(s instanceof DOMException&&s.name==="AbortError")return;e.onError?.(s instanceof Error?s:new Error(String(s)))}finally{n.releaseLock()}e.onDone?.()}function Ie(t){if(typeof t.type!="string")return null;if(Dt(t))return t;const n=t;switch(n.type){case"outputText":return Ut(n);case"suggestedActions":return zt(n);case"productList":return Vt(n);case"productDetails":return qt(n);case"productDetailsSimilars":return Bt(n);case"comparisonTable":return Gt(n);case"context":return Ft(n);case"chatStreamEnd":return Ht();case"loading":return Wt(n);case"panelLoading":return Jt(n);case"similarLoading":return Qt(n);case"redirect":return Yt(n);case"error":return Xt(n);case"dummy":return Kt();case"launcherAction":return en(n);case"text":return ue(n);case"productItem":return tn(n);case"text_image":return Ne(n);case"quick_qna":return Re(n);case"reviewHighlights":return nn(n);case"aiProductSuggestions":return an(n);case"aiProductGroupings":return on(n);case"aiSuggestedSearches":return cn(n);case"prosAndCons":return rn(n);case"getGroundingReview":return dn(n);case"voice":return ln(n);case"visitorDataResponse":return sn(n);case"productListPreview":return un();case"groupList":return fn(n);case"formGetInfo":case"formTestDrive":case"formServiceRequest":case"launchFormPage":return pn(n);case"launcherContent":return hn(n);default:return null}}function Dt(t){const e=t.type;if(typeof e!="string")return!1;switch(e){case"metadata":return typeof t.sessionId=="string"&&typeof t.model=="string";case"text_chunk":return typeof t.content=="string";case"ui_spec":{const n=t.widget;if(n!=="chat"&&n!=="qna"&&n!=="simrel")return!1;const r=q(t.spec);return r?typeof r.root=="string"&&q(r.elements)!==null:!1}case"action":{const n=q(t.action);return n!==null&&typeof n.kind=="string"}case"error":return typeof t.code=="string"&&typeof t.message=="string";case"done":return!0;default:return!1}}function Ut(t){const e=w(t.payload.text,t.payload.plain_text)??"",n=w(t.payload.plain_text,t.payload.text)??e;if(t.payload.is_error)return{type:"error",code:"BACKEND_ERROR",message:n||"Backend returned an error"};const r={type:"text_chunk",content:e,final:!0},i=t.payload.product_mentions;Array.isArray(i)&&i.length>0&&(r.productMentions=i.filter(o=>typeof o=="object"&&o!==null&&typeof o.sku=="string"&&typeof o.short_name=="string"));const s=t.payload.sku_to_product_item;s&&typeof s=="object"&&!Array.isArray(s)&&(r.skuToProductItem=s);const a=t.payload.conversation_mode;return typeof a=="string"&&a&&(r.conversationMode=a),r}function zt(t){const e=(t.payload.actions??[]).map(n=>{const r=w(n.title)??"",i=P(n.requestDetails,r),s=i?{label:r,action:i}:null;return s?(typeof n.icon=="string"&&(s.icon=n.icon),typeof n.image=="string"&&(s.image=n.image),s):null});return Oe(e.filter(Le),"chat")}function Vt(t){const e=Pe(t.payload.product_list??[],"chat");e.panelHint="panel";const n=e.spec.elements[e.spec.root];return n&&(typeof t.payload.offset=="number"&&(n.props={...n.props,offset:t.payload.offset}),typeof t.payload.end_of_list=="boolean"&&(n.props={...n.props,endOfList:t.payload.end_of_list})),e}function qt(t){const e=t.payload.productDetails;return e?{type:"ui_spec",widget:"chat",spec:{root:"root",elements:{root:{type:"ProductDetailsPanel",props:{product:L(e)}}}},panelHint:"panel"}:gn("chat")}function Bt(t){const e=Pe(t.payload.similarProducts??[],"chat"),n=e.spec.elements[e.spec.root];return n&&(n.props={...n.props,similarsAppend:!0}),{...e,panelHint:"panel"}}function Gt(t){const e=t.payload.multiple_product_details??[],n=t.payload.product_comparison_framework,r=t.payload.table,i=[];for(const m of e){const E=L(m);i.push(E)}const s=[];if(r){const m=n?.criteria_view??n?.criteria_view_short??{},E=n?.compared_field_names??Object.keys(r);for(const G of E){const ke=r[G];if(!ke||!Array.isArray(ke))continue;const pr=m[G]??G;s.push({label:pr,values:ke.map(be=>typeof be=="string"?be:String(be??""))})}}let a;n?.recommended_choice_sku?a=n.recommended_choice_sku:n?.winner_product&&n.winner_product.length>0&&(a=n.winner_product[0]?.sku);const o=a?i.find(m=>m.sku===a)??i[0]:i[0],c=[];if(n?.key_differences)for(const m of n.key_differences)typeof m=="string"&&c.push(m);const d=[];if(n?.special_considerations)for(const m of n.special_considerations)typeof m=="string"&&d.push(m);const p=n?.recommended_choice,v=n?.winner_hits,C={};for(const m of i){const E=m.sku;E&&(C[E]={title:m.name??E,type:"launchSingleProduct",payload:{sku:E}})}const T={products:i,attributes:s,highlights:c,productActions:C};return o&&(T.recommended=o),d.length>0&&(T.specialCases=d),p&&(T.recommendedText=p),v&&(T.winnerHits=v),typeof n?.key_differences=="string"&&(T.keyDifferencesHtml=n.key_differences),n?.special_considerations&&(T.specialConsiderations=n.special_considerations),{type:"ui_spec",widget:"chat",spec:{root:"root",elements:{root:{type:"ComparisonTable",props:T}}},panelHint:"panel"}}function Ft(t){return{type:"metadata",sessionId:"",model:"",meta:{panel:t.payload.panel,messages:t.payload.messages,message_id:t.payload.message_id}}}function Ht(){return{type:"done"}}function Wt(t){return{type:"metadata",sessionId:"",model:"",meta:{loading:!0,loadingText:t.payload.text,thinkingMessages:t.payload.thinking_messages,dynamicLoading:t.payload.is_dynamic===!0}}}function Jt(t){return{type:"metadata",sessionId:"",model:"",meta:{loading:!0,panelLoading:!0,panelPendingType:t.payload?.pending_type,loadingText:t.payload?.text}}}function Qt(t){return{type:"metadata",sessionId:"",model:"",meta:{loading:!0,similarPanelLoading:!0,panelPendingType:t.payload?.pending_type,loadingText:t.payload?.text}}}function Yt(t){const e=w(t.payload.url);return e?{type:"action",action:{kind:"navigate",url:e,newTab:t.payload.new_tab===!0}}:{type:"metadata",sessionId:"",model:"",meta:{redirect:t.payload,redirectTarget:w(t.payload.to)}}}function Xt(t){return{type:"error",code:"BACKEND_ERROR",message:w(t.payload?.text,t.payload?.message,t.payload?.error)??"Backend returned an error"}}function Kt(t){return{type:"metadata",sessionId:"",model:"",meta:{noop:!0}}}function en(t){const e=t.payload??{};if(Array.isArray(e.action_list)){const s={action_list:e.action_list},a=typeof e.type=="string"?e.type:void 0,o=typeof e.theme=="string"?e.theme:void 0;return a!==void 0&&(s.type=a),o!==void 0&&(s.theme=o),Re({payload:s})}const r=q(e.action);if(r){const s={action:r},a=typeof e.text=="string"?e.text:void 0,o=typeof e.image_url=="string"?e.image_url:void 0,c=typeof e.theme=="string"?e.theme:void 0;return a!==void 0&&(s.text=a),o!==void 0&&(s.image_url=o),c!==void 0&&(s.theme=c),Ne({payload:s})}const i=typeof e.text=="string"?e.text:"";if(i){const s={text:i},a=typeof e.type=="string"?e.type:void 0,o=typeof e.theme=="string"?e.theme:void 0,c=q(e.payload)??void 0;return a!==void 0&&(s.type=a),c!==void 0&&(s.payload=c),o!==void 0&&(s.theme=o),ue({payload:s})}return{type:"metadata",sessionId:"",model:"",meta:{launcherAction:e}}}function ue(t){const e={text:w(t.payload.text)??""};return typeof t.payload.theme=="string"&&(e.theme=t.payload.theme),t.payload.payload!==void 0&&(e.payload=t.payload.payload),{type:"ui_spec",widget:"qna",spec:{root:"root",elements:{root:{type:"QuestionHeading",props:e}}}}}function tn(t){return mn(t.payload,"qna")}function Ne(t){const e=w(t.payload.text)??"",n=P(t.payload.action,e);if(n){const i={label:e||n.title,action:n};return typeof t.payload.image_url=="string"&&(i.image=t.payload.image_url),typeof t.payload.theme=="string"&&(i.theme=t.payload.theme),{type:"ui_spec",widget:"qna",spec:{root:"root",elements:{root:{type:"ActionButton",props:i}}}}}const r={text:e};return typeof t.payload.theme=="string"&&(r.theme=t.payload.theme),ue({payload:r})}function Re(t){const e=(t.payload.action_list??[]).map(n=>{const r=w(n.title)??"",i=P(n.requestDetails,r),s=i?{label:r,action:i}:null;return s?(typeof n.icon=="string"&&(s.icon=n.icon),typeof n.image=="string"&&(s.image=n.image),s):null});return Oe(e.filter(Le),"qna")}function nn(t){const n={reviews:(t.payload.reviews??[]).map(r=>{const i={};return typeof r.review_class=="string"&&(i.review_class=r.review_class),typeof r.review_text=="string"&&(i.review_text=r.review_text),(typeof r.review_rating=="string"||typeof r.review_rating=="number")&&(i.review_rating=r.review_rating),typeof r.review_tag=="string"&&(i.review_tag=r.review_tag),i})};return typeof t.payload.sku=="string"&&(n.sku=t.payload.sku),{type:"ui_spec",widget:"chat",spec:{root:"root",elements:{root:{type:"ReviewHighlights",props:n}}}}}function rn(t){const e={};return Array.isArray(t.payload.pros)&&(e.pros=t.payload.pros),Array.isArray(t.payload.cons)&&(e.cons=t.payload.cons),typeof t.payload.product_name=="string"&&(e.productName=t.payload.product_name),{type:"ui_spec",widget:"chat",spec:{root:"root",elements:{root:{type:"ProsAndCons",props:e}}}}}function sn(t){return{type:"metadata",sessionId:"",model:"",meta:{visitorDataResponse:t.payload}}}function an(t){const e=t.payload.product_suggestions??[],n=[];for(let r=0;r<e.length;r++){const i=e[r];if(!i)continue;const s=yn(i);if(!s)continue;const a={product:s},o=P(i.requestDetails,s.name);o&&(a.action=o),typeof i.role=="string"&&(a.role=i.role),typeof i.reason=="string"&&(a.reason=i.reason),typeof i.review_highlight=="string"&&(a.reviewHighlight=i.review_highlight),Array.isArray(i.labels)&&(a.labels=i.labels),typeof i.expert_quality_score=="number"&&(a.expertQualityScore=i.expert_quality_score),n.push(a)}return n.length===0?{type:"metadata",sessionId:"",model:"",meta:{aiProductSuggestions:t.payload.product_suggestions??[]}}:{type:"ui_spec",widget:"chat",spec:{root:"root",elements:{root:{type:"AITopPicks",props:{suggestions:n}}}}}}function on(t){const e=t.payload.product_groupings??[],n=[];for(let r=0;r<e.length;r++){const i=e[r];if(!i)continue;const s=w(i.name)??"",a=i.sku&&i.sku.length>0?{type:"findSimilar",payload:{sku:i.sku}}:void 0,o=P(i.requestDetails??a,s);if(!o)continue;const c={name:s,action:o};if(Array.isArray(i.labels)){const d=i.labels.filter(p=>typeof p=="string");d.length>0&&(c.labels=d)}typeof i.image=="string"&&(c.image=i.image),n.push(c)}return n.length===0?{type:"metadata",sessionId:"",model:"",meta:{aiProductGroupings:t.payload.product_groupings??[]}}:{type:"ui_spec",widget:"chat",spec:{root:"root",elements:{root:{type:"AIGroupingCards",props:{entries:n}}}}}}function cn(t){const e=t.payload.suggested_searches??[],n=[];for(let r=0;r<e.length;r++){const i=e[r];if(!i)continue;const s=w(i.short_name,i.chosen_attribute,i.detailed_user_message)??`Arama ${r+1}`,a={},o=w(i.detailed_user_message);o&&(a.text=o),i.group_skus&&Array.isArray(i.group_skus)&&(a.group_skus=i.group_skus);const c=w(i.sku,i.representative_product_sku);c&&(a.sku=c),a.is_suggested_text=1;const d={type:"inputText",payload:a},p=P(i.requestDetails??d,s);if(!p)continue;const v={shortName:s,action:p},C=w(i.detailed_user_message);C&&C!==s&&(v.detailedMessage=C);const T=w(i.why_different);T&&(v.whyDifferent=T),typeof i.image=="string"&&(v.image=i.image),n.push(v)}return n.length===0?{type:"metadata",sessionId:"",model:"",meta:{aiSuggestedSearches:t.payload.suggested_searches??[]}}:{type:"ui_spec",widget:"chat",spec:{root:"root",elements:{root:{type:"AISuggestedSearchCards",props:{entries:n}}}}}}function dn(t){const e=P(t.payload.requestDetails,w(t.payload.review_count,t.payload.text,t.payload.title)??"Urun yorumlarini goster");if(!e)return{type:"metadata",sessionId:"",model:"",meta:{groundingReview:t.payload}};const n={action:e};return t.payload.title&&(n.title=t.payload.title),t.payload.text&&(n.text=t.payload.text),t.payload.review_count&&(n.reviewCount=t.payload.review_count),{type:"ui_spec",widget:"chat",spec:{root:"root",elements:{root:{type:"GroundingReviewCard",props:n}}}}}function un(){return{type:"metadata",sessionId:"",model:"",meta:{analyzeAnimation:!0}}}function ln(t){return{type:"metadata",sessionId:"",model:"",meta:{voice:t.payload}}}function fn(t){const e=t.payload.group_list??[],n=[];for(const i of e){const s=i.group_name??"",a=(i.product_list??[]).map(L);n.push({groupName:s,products:a})}const r=[];for(const i of t.payload.filter_tags??[]){const s=i.title??"";if(!s)continue;const a=P(i.requestDetails,s),o={title:s};a&&(o.action=a),r.push(o)}return{type:"ui_spec",widget:"chat",spec:{root:"root",elements:{root:{type:"CategoriesContainer",props:{groups:n,filterTags:r}}}},panelHint:"panel"}}function pn(t){return{type:"metadata",sessionId:"",model:"",meta:{formType:t.type,formPayload:t.payload??{}}}}function hn(t){return{type:"metadata",sessionId:"",model:"",meta:{launcherContent:t.payload??{}}}}function Oe(t,e){const n={},r=[];for(let i=0;i<t.length;i++){const s=t[i];if(!s)continue;const a=`action-${i}`;r.push(a);const o={label:s.label,action:s.action};s.icon!==void 0&&(o.icon=s.icon),s.image!==void 0&&(o.image=s.image),s.description!==void 0&&(o.description=s.description),n[a]={type:"ActionButton",props:o}}return n.root={type:"ActionButtons",props:{buttons:t.map(i=>{const s={label:i.label,action:i.action};return i.image!==void 0&&(s.image=i.image),i.description!==void 0&&(s.description=i.description),i.icon!==void 0&&(s.icon=i.icon),s})},children:r},{type:"ui_spec",widget:e,spec:{root:"root",elements:n}}}function Pe(t,e){const n={},r=[];for(let i=0;i<t.length;i++){const s=t[i];if(!s)continue;const a=`product-${i}`;r.push(a),n[a]={type:"ProductCard",props:{product:L(s),index:i}}}return n.root={type:"ProductGrid",props:{layout:"grid"},children:r},{type:"ui_spec",widget:e,spec:{root:"root",elements:n}}}function mn(t,e){return{type:"ui_spec",widget:e,spec:{root:"root",elements:{root:{type:"ProductCard",props:{product:L(t),index:0}}}}}}function gn(t){return{type:"ui_spec",widget:t,spec:{root:"root",elements:{root:{type:"ActionButtons",props:{buttons:[]},children:[]}}}}}function yn(t){const e=w(t.sku),n=w(t.short_name),r=q(t.product_item)??t;return _n(r,e,n)}function _n(t,e,n){const r=w(t.sku,e),i=w(t.name,n);if(!r||!i)return null;const s={sku:r,name:i},a=w(t.brand);a&&(s.brand=a);const o=w(t.url);o&&(s.url=o);const c=vn(t.images);if(c.length>0)s.images=c;else{const m=w(t.image,t.image_url,t.imageUrl);m&&(s.images=[m])}const d=X(t.price_discounted);d!==void 0&&(s.price_discounted=d);const p=X(t.price);p!==void 0&&(s.price=p);const v=X(t.rating);v!==void 0&&(s.rating=v);const C=X(t.review_count)??X(t.reviewCount);C!==void 0&&(s.review_count=C);const T=w(t.cart_code,t.cartCode);return T&&(s.cart_code=T),typeof t.in_stock=="boolean"&&(s.in_stock=t.in_stock),typeof t.inStock=="boolean"&&(s.in_stock=t.inStock),L(s)}function P(t,e){const n=q(t);if(!n)return null;const r=n.type;if(typeof r!="string"||r.length===0)return null;const i={title:e||r,type:r};return n.payload!==void 0&&(i.payload=n.payload),i}function q(t){return!t||typeof t!="object"||Array.isArray(t)?null:t}function w(...t){for(const e of t)if(typeof e=="string"){const n=e.trim();if(n.length>0)return n}}function vn(t){return Array.isArray(t)?t.filter(e=>typeof e=="string"&&e.length>0):[]}function X(t){if(typeof t=="number"&&Number.isFinite(t))return t;if(typeof t=="string"){const e=t.replace(",","."),n=Number(e);if(Number.isFinite(n))return n}}function Le(t){return t!=null}function L(t){const e=t.price_discounted!=null&&t.price_discounted>0?t.price_discounted:t.price,n=t.price_discounted!=null&&t.price_discounted>0&&t.price!=null?t.price:void 0;let r;n!=null&&e!=null&&n>0&&(r=Math.round((n-e)/n*100));const i=w(t.brand),s=w(t.name)??t.sku,a=i&&!s.startsWith(i)?`${i} ${s}`:s,o={sku:t.sku,name:a,url:w(t.url)??""},c=t.images?.[0];return c&&(o.imageUrl=c),t.images&&t.images.length>1&&(o.images=t.images),e!=null&&(o.price=String(e)),n!=null&&(o.originalPrice=String(n)),r!==void 0&&(o.discountPercent=r),i!==void 0&&(o.brand=i),t.rating!==void 0&&(o.rating=t.rating),t.review_count!==void 0&&(o.reviewCount=t.review_count),t.cart_code!==void 0&&(o.cartCode=t.cart_code),t.in_stock!==void 0&&(o.inStock=t.in_stock),t.variants&&t.variants.length>0&&(o.variants=t.variants),t.discount_reason!==void 0&&(o.discountReason=t.discount_reason),t.promotions&&t.promotions.length>0&&(o.promotions=t.promotions),o}function kn(t){return t.results.map(L)}function bn(t){return t.product_groupings.map(e=>{const n={name:e.name,products:(e.group_products??[]).map(L)};return e.highlight!==void 0&&(n.highlight=e.highlight),n})}function je(t){const e=t.headers.get("Content-Type")??"";return e.includes("application/x-ndjson")||e.includes("text/event-stream")}async function wn(t,e){const n=[],r={onEvent:i=>{const s=Ie(i);if(!(!s||s.type!=="ui_spec")){for(const a of Object.values(s.spec.elements))if(a.type==="ProductCard"&&a.props){const o=a.props.product??a.props;typeof o.sku=="string"&&typeof o.name=="string"&&n.push(o)}}}};return e!==void 0&&(r.signal=e),await Ae(t,r),n}async function xn(t,e,n){const r=Se("similar_products",e),i={method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)};n!==void 0&&(i.signal=n);const s=await fetch(r,i);if(!s.ok)throw new Error(`HTTP ${s.status}: ${s.statusText}`);if(je(s))return wn(s,n);const a=await s.text();return a?kn(JSON.parse(a)):[]}async function Cn(t,e){const n=[];let r=null;const i={onEvent:s=>{const a=Ie(s);if(a){if(a.type==="metadata"&&a.meta){const o=a.meta.group_name;if(typeof o=="string"){r={name:o,products:[]};const c=a.meta.highlight;typeof c=="string"&&(r.highlight=c),n.push(r)}}if(a.type==="ui_spec"&&r){for(const o of Object.values(a.spec.elements))if(o.type==="ProductCard"&&o.props){const c=o.props.product??o.props;typeof c.sku=="string"&&typeof c.name=="string"&&r.products.push(c)}}}}};return e!==void 0&&(i.signal=e),await Ae(t,i),n}async function Tn(t,e,n){const r=Se("product_groupings",e),i={method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)};n!==void 0&&(i.signal=n);const s=await fetch(r,i);if(!s.ok)throw new Error(`HTTP ${s.status}: ${s.statusText}`);if(je(s))return Cn(s,n);const a=await s.text();return a?bn(JSON.parse(a)):[]}function Ze(t){const{product:e,index:n,discountType:r,onClick:i,onAddToCart:s,renderCard:a}=t,o=t.i18n,c=o?.priceSuffix??" TL";if(a){const m=document.createElement("div");return m.className="gengage-simrel-card gengage-simrel-card--custom",m.innerHTML=a(e,n),m.addEventListener("click",E=>{E.target.closest(".gengage-simrel-atc")||i(e)}),m}const d=document.createElement("article");d.className="gengage-simrel-card",d.setAttribute("role","listitem"),d.dataset.sku=e.sku;const p=document.createElement("div");if(p.className="gengage-simrel-card-image",e.imageUrl){const m=document.createElement("img");m.src=e.imageUrl,m.alt=e.name,m.loading="lazy",p.appendChild(m)}if(r==="badge"&&e.discountPercent&&e.discountPercent>0){const m=document.createElement("span");m.className="gengage-simrel-badge",m.textContent=`%${e.discountPercent}`,p.appendChild(m)}d.appendChild(p);const v=document.createElement("div");if(v.className="gengage-simrel-card-info",e.brand){const m=document.createElement("div");m.className="gengage-simrel-card-brand",m.textContent=e.brand,v.appendChild(m)}const C=document.createElement("div");if(C.className="gengage-simrel-card-name",C.textContent=e.name,v.appendChild(C),e.rating!=null&&e.rating>0){const m=document.createElement("div");m.className="gengage-simrel-card-rating";const E="★".repeat(Math.round(e.rating))+"☆".repeat(5-Math.round(e.rating));if(m.textContent=E,e.reviewCount!=null){const G=document.createElement("span");G.className="gengage-simrel-card-review-count",G.textContent=` (${e.reviewCount})`,m.appendChild(G)}v.appendChild(m)}const T=document.createElement("div");if(T.className="gengage-simrel-card-price",e.originalPrice&&e.originalPrice!==e.price&&(r==="strike-through"||!r)){const m=document.createElement("span");m.className="gengage-simrel-card-price-original",m.textContent=e.originalPrice+c,T.appendChild(m)}if(e.price){const m=document.createElement("span");m.className="gengage-simrel-card-price-current",m.textContent=e.price+c,T.appendChild(m)}if(v.appendChild(T),d.appendChild(v),e.cartCode){const m=document.createElement("button");m.className="gengage-simrel-atc",m.type="button",m.textContent=o?.addToCartButton??"Sepete Ekle",m.addEventListener("click",E=>{E.stopPropagation(),s({sku:e.sku,quantity:1,cartCode:e.cartCode})}),d.appendChild(m)}return d.addEventListener("click",m=>{m.target.closest(".gengage-simrel-atc")||i(e)}),d}function $e(t){const e=document.createElement("div");e.className="gengage-simrel-grid",e.setAttribute("role","list"),e.setAttribute("aria-label",t.i18n?.similarProductsAriaLabel??"Similar products"),t.columns&&e.style.setProperty("--gengage-simrel-columns",String(t.columns));for(let n=0;n<t.products.length;n++){const i={product:t.products[n],index:n,onClick:t.onClick,onAddToCart:t.onAddToCart};t.i18n!==void 0&&(i.i18n=t.i18n),t.discountType!==void 0&&(i.discountType=t.discountType),t.renderCard!==void 0&&(i.renderCard=t.renderCard);const s=Ze(i);e.appendChild(s)}if(t.products.length===0){const n=document.createElement("div");n.className="gengage-simrel-empty",n.textContent=t.i18n?.emptyStateMessage??"Benzer ürün bulunamadı.",e.appendChild(n)}return e}function Sn(t){const e=document.createElement("div");if(e.className="gengage-simrel-groups",t.groups.length===0){const o=document.createElement("div");return o.className="gengage-simrel-empty",o.textContent=t.i18n?.emptyStateMessage??"Benzer ürün bulunamadı.",e.appendChild(o),e}const n=document.createElement("div");n.className="gengage-simrel-tabs",n.setAttribute("role","tablist");const r=document.createElement("div");r.className="gengage-simrel-tab-content";for(let o=0;o<t.groups.length;o++){const c=t.groups[o],d=document.createElement("button");d.className="gengage-simrel-tab",d.type="button",d.textContent=c.name,d.setAttribute("role","tab"),d.setAttribute("aria-selected",o===0?"true":"false"),o===0&&d.classList.add("gengage-simrel-tab--active"),d.addEventListener("click",()=>{const p=n.querySelector(".gengage-simrel-tab--active");p?.classList.remove("gengage-simrel-tab--active"),p?.setAttribute("aria-selected","false"),d.classList.add("gengage-simrel-tab--active"),d.setAttribute("aria-selected","true"),r.innerHTML="";const v={products:c.products,onClick:t.onClick,onAddToCart:t.onAddToCart};t.i18n!==void 0&&(v.i18n=t.i18n),t.discountType!==void 0&&(v.discountType=t.discountType),t.renderCard!==void 0&&(v.renderCard=t.renderCard);const C=$e(v);r.appendChild(C)}),n.appendChild(d)}e.appendChild(n);const s={products:t.groups[0].products,onClick:t.onClick,onAddToCart:t.onAddToCart};t.i18n!==void 0&&(s.i18n=t.i18n),t.discountType!==void 0&&(s.discountType=t.discountType),t.renderCard!==void 0&&(s.renderCard=t.renderCard);const a=$e(s);return r.appendChild(a),e.appendChild(r),e}function Me(t){if(!t||typeof t!="object")return null;const e=t;if(typeof e.sku!="string"||typeof e.name!="string"||typeof e.url!="string")return null;const n={sku:e.sku,name:e.name,url:e.url},r=e.imageUrl;typeof r=="string"&&(n.imageUrl=r);const i=e.price;typeof i=="string"&&(n.price=i);const s=e.originalPrice;typeof s=="string"&&(n.originalPrice=s);const a=e.discountPercent;typeof a=="number"&&(n.discountPercent=a);const o=e.brand;typeof o=="string"&&(n.brand=o);const c=e.rating;typeof c=="number"&&(n.rating=c);const d=e.reviewCount;typeof d=="number"&&(n.reviewCount=d);const p=e.cartCode;typeof p=="string"&&(n.cartCode=p);const v=e.inStock;return typeof v=="boolean"&&(n.inStock=v),n}function En(t){if(!t||typeof t!="object")return null;const e=t,n=e.title,r=e.type;if(typeof n!="string"||typeof r!="string")return null;const i={title:n,type:r};return e.payload!==void 0&&(i.payload=e.payload),i}const De={ProductGrid:({element:t,renderElement:e})=>{const n=document.createElement("div");n.className="gengage-simrel-grid",n.setAttribute("role","list");const r=t.props?.columns;typeof r=="number"&&Number.isFinite(r)&&r>0&&n.style.setProperty("--gengage-simrel-columns",String(r));for(const i of t.children??[]){const s=e(i);s&&n.appendChild(s)}if(n.children.length===0){const i=document.createElement("div");i.className="gengage-simrel-empty",i.textContent="Benzer ürün bulunamadı.",n.appendChild(i)}return n},ProductCard:({element:t,context:e})=>{const n=t.props?.product??t.props,r=Me(n);if(!r)return null;const i=t.props?.index,s=typeof i=="number"&&Number.isFinite(i)?i:0,a=t.props?.discountType,o=a==="strike-through"||a==="badge"?a:e.discountType,c={product:r,index:s,onClick:e.onClick,onAddToCart:e.onAddToCart,i18n:e.i18n};return o!==void 0&&(c.discountType=o),e.renderCard!==void 0&&(c.renderCard=e.renderCard),Ze(c)},GroupTabs:({element:t,context:e})=>{const n=t.props?.groups;if(!Array.isArray(n))return null;const r=[];for(const s of n){if(!s||typeof s!="object")continue;const a=s;if(typeof a.name!="string")continue;const o=[];if(Array.isArray(a.products))for(const d of a.products){const p=Me(d);p&&o.push(p)}const c={name:a.name,products:o};typeof a.highlight=="string"&&(c.highlight=a.highlight),r.push(c)}const i={groups:r,onClick:e.onClick,onAddToCart:e.onAddToCart,i18n:e.i18n};return e.discountType!==void 0&&(i.discountType=e.discountType),e.renderCard!==void 0&&(i.renderCard=e.renderCard),Sn(i)},EmptyState:({element:t,context:e})=>{const n=document.createElement("div");n.className="gengage-simrel-empty";const r=t.props?.message;return n.textContent=typeof r=="string"?r:e.i18n.emptyStateMessage,n},AddToCartButton:({element:t,context:e})=>{const n=t.props?.sku,r=t.props?.cartCode;if(typeof n!="string"||typeof r!="string")return null;const i=document.createElement("button");i.className="gengage-simrel-atc",i.type="button";const s=t.props?.label;return i.textContent=typeof s=="string"?s:e.i18n.addToCartButton,i.addEventListener("click",a=>{a.preventDefault(),a.stopPropagation(),e.onAddToCart({sku:n,quantity:1,cartCode:r})}),i},QuickActions:({element:t,context:e})=>{const n=document.createElement("div");n.className="gengage-simrel-quick-actions";const r=t.props?.actions;if(!Array.isArray(r)||!e.onAction)return n;for(const i of r){if(!i||typeof i!="object")continue;const s=i,a=s.label,o=En(s.action);if(typeof a!="string"||!o)continue;const c=document.createElement("button");c.className="gengage-simrel-quick-action",c.type="button",c.textContent=a,c.addEventListener("click",d=>{d.preventDefault(),d.stopPropagation(),e.onAction?.(o)}),n.appendChild(c)}return n}},le=({element:t,renderElement:e})=>{if(!t.children||t.children.length===0)return null;const n=document.createElement("div");for(const r of t.children){const i=e(r);i&&n.appendChild(i)}return n};function Ue(){return{...De}}function ze(t,e,n=De,r=le){return ut({spec:t,context:e,registry:n,containerClassName:"gengage-simrel-uispec",unknownRenderer:r})}const Ve={similarProductsAriaLabel:"Benzer ürünler",emptyStateMessage:"Benzer ürün bulunamadı.",addToCartButton:"Sepete Ekle",priceSuffix:" TL"},An={similarProductsAriaLabel:"Similar products",emptyStateMessage:"No similar products found.",addToCartButton:"Add to cart",priceSuffix:""};function In(t){return t?t.toLowerCase().split("-")[0]??"tr":"tr"}function Nn(t){return In(t)==="en"?An:Ve}var b;(function(t){t.assertEqual=i=>{};function e(i){}t.assertIs=e;function n(i){throw new Error}t.assertNever=n,t.arrayToEnum=i=>{const s={};for(const a of i)s[a]=a;return s},t.getValidEnumValues=i=>{const s=t.objectKeys(i).filter(o=>typeof i[i[o]]!="number"),a={};for(const o of s)a[o]=i[o];return t.objectValues(a)},t.objectValues=i=>t.objectKeys(i).map(function(s){return i[s]}),t.objectKeys=typeof Object.keys=="function"?i=>Object.keys(i):i=>{const s=[];for(const a in i)Object.prototype.hasOwnProperty.call(i,a)&&s.push(a);return s},t.find=(i,s)=>{for(const a of i)if(s(a))return a},t.isInteger=typeof Number.isInteger=="function"?i=>Number.isInteger(i):i=>typeof i=="number"&&Number.isFinite(i)&&Math.floor(i)===i;function r(i,s=" | "){return i.map(a=>typeof a=="string"?`'${a}'`:a).join(s)}t.joinValues=r,t.jsonStringifyReplacer=(i,s)=>typeof s=="bigint"?s.toString():s})(b||(b={}));var qe;(function(t){t.mergeShapes=(e,n)=>({...e,...n})})(qe||(qe={}));const f=b.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),j=t=>{switch(typeof t){case"undefined":return f.undefined;case"string":return f.string;case"number":return Number.isNaN(t)?f.nan:f.number;case"boolean":return f.boolean;case"function":return f.function;case"bigint":return f.bigint;case"symbol":return f.symbol;case"object":return Array.isArray(t)?f.array:t===null?f.null:t.then&&typeof t.then=="function"&&t.catch&&typeof t.catch=="function"?f.promise:typeof Map<"u"&&t instanceof Map?f.map:typeof Set<"u"&&t instanceof Set?f.set:typeof Date<"u"&&t instanceof Date?f.date:f.object;default:return f.unknown}},u=b.arrayToEnum(["invalid_type","invalid_literal","custom","invalid_union","invalid_union_discriminator","invalid_enum_value","unrecognized_keys","invalid_arguments","invalid_return_type","invalid_date","invalid_string","too_small","too_big","invalid_intersection_types","not_multiple_of","not_finite"]);class R extends Error{get errors(){return this.issues}constructor(e){super(),this.issues=[],this.addIssue=r=>{this.issues=[...this.issues,r]},this.addIssues=(r=[])=>{this.issues=[...this.issues,...r]};const n=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,n):this.__proto__=n,this.name="ZodError",this.issues=e}format(e){const n=e||function(s){return s.message},r={_errors:[]},i=s=>{for(const a of s.issues)if(a.code==="invalid_union")a.unionErrors.map(i);else if(a.code==="invalid_return_type")i(a.returnTypeError);else if(a.code==="invalid_arguments")i(a.argumentsError);else if(a.path.length===0)r._errors.push(n(a));else{let o=r,c=0;for(;c<a.path.length;){const d=a.path[c];c===a.path.length-1?(o[d]=o[d]||{_errors:[]},o[d]._errors.push(n(a))):o[d]=o[d]||{_errors:[]},o=o[d],c++}}};return i(this),r}static assert(e){if(!(e instanceof R))throw new Error(`Not a ZodError: ${e}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,b.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(e=n=>n.message){const n={},r=[];for(const i of this.issues)if(i.path.length>0){const s=i.path[0];n[s]=n[s]||[],n[s].push(e(i))}else r.push(e(i));return{formErrors:r,fieldErrors:n}}get formErrors(){return this.flatten()}}R.create=t=>new R(t);const fe=(t,e)=>{let n;switch(t.code){case u.invalid_type:t.received===f.undefined?n="Required":n=`Expected ${t.expected}, received ${t.received}`;break;case u.invalid_literal:n=`Invalid literal value, expected ${JSON.stringify(t.expected,b.jsonStringifyReplacer)}`;break;case u.unrecognized_keys:n=`Unrecognized key(s) in object: ${b.joinValues(t.keys,", ")}`;break;case u.invalid_union:n="Invalid input";break;case u.invalid_union_discriminator:n=`Invalid discriminator value. Expected ${b.joinValues(t.options)}`;break;case u.invalid_enum_value:n=`Invalid enum value. Expected ${b.joinValues(t.options)}, received '${t.received}'`;break;case u.invalid_arguments:n="Invalid function arguments";break;case u.invalid_return_type:n="Invalid function return type";break;case u.invalid_date:n="Invalid date";break;case u.invalid_string:typeof t.validation=="object"?"includes"in t.validation?(n=`Invalid input: must include "${t.validation.includes}"`,typeof t.validation.position=="number"&&(n=`${n} at one or more positions greater than or equal to ${t.validation.position}`)):"startsWith"in t.validation?n=`Invalid input: must start with "${t.validation.startsWith}"`:"endsWith"in t.validation?n=`Invalid input: must end with "${t.validation.endsWith}"`:b.assertNever(t.validation):t.validation!=="regex"?n=`Invalid ${t.validation}`:n="Invalid";break;case u.too_small:t.type==="array"?n=`Array must contain ${t.exact?"exactly":t.inclusive?"at least":"more than"} ${t.minimum} element(s)`:t.type==="string"?n=`String must contain ${t.exact?"exactly":t.inclusive?"at least":"over"} ${t.minimum} character(s)`:t.type==="number"?n=`Number must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${t.minimum}`:t.type==="bigint"?n=`Number must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${t.minimum}`:t.type==="date"?n=`Date must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(t.minimum))}`:n="Invalid input";break;case u.too_big:t.type==="array"?n=`Array must contain ${t.exact?"exactly":t.inclusive?"at most":"less than"} ${t.maximum} element(s)`:t.type==="string"?n=`String must contain ${t.exact?"exactly":t.inclusive?"at most":"under"} ${t.maximum} character(s)`:t.type==="number"?n=`Number must be ${t.exact?"exactly":t.inclusive?"less than or equal to":"less than"} ${t.maximum}`:t.type==="bigint"?n=`BigInt must be ${t.exact?"exactly":t.inclusive?"less than or equal to":"less than"} ${t.maximum}`:t.type==="date"?n=`Date must be ${t.exact?"exactly":t.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(t.maximum))}`:n="Invalid input";break;case u.custom:n="Invalid input";break;case u.invalid_intersection_types:n="Intersection results could not be merged";break;case u.not_multiple_of:n=`Number must be a multiple of ${t.multipleOf}`;break;case u.not_finite:n="Number must be finite";break;default:n=e.defaultError,b.assertNever(t)}return{message:n}};let Rn=fe;function On(){return Rn}const Pn=t=>{const{data:e,path:n,errorMaps:r,issueData:i}=t,s=[...n,...i.path||[]],a={...i,path:s};if(i.message!==void 0)return{...i,path:s,message:i.message};let o="";const c=r.filter(d=>!!d).slice().reverse();for(const d of c)o=d(a,{data:e,defaultError:o}).message;return{...i,path:s,message:o}};function l(t,e){const n=On(),r=Pn({issueData:e,data:t.data,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,n,n===fe?void 0:fe].filter(i=>!!i)});t.common.issues.push(r)}class A{constructor(){this.value="valid"}dirty(){this.value==="valid"&&(this.value="dirty")}abort(){this.value!=="aborted"&&(this.value="aborted")}static mergeArray(e,n){const r=[];for(const i of n){if(i.status==="aborted")return g;i.status==="dirty"&&e.dirty(),r.push(i.value)}return{status:e.value,value:r}}static async mergeObjectAsync(e,n){const r=[];for(const i of n){const s=await i.key,a=await i.value;r.push({key:s,value:a})}return A.mergeObjectSync(e,r)}static mergeObjectSync(e,n){const r={};for(const i of n){const{key:s,value:a}=i;if(s.status==="aborted"||a.status==="aborted")return g;s.status==="dirty"&&e.dirty(),a.status==="dirty"&&e.dirty(),s.value!=="__proto__"&&(typeof a.value<"u"||i.alwaysSet)&&(r[s.value]=a.value)}return{status:e.value,value:r}}}const g=Object.freeze({status:"aborted"}),K=t=>({status:"dirty",value:t}),I=t=>({status:"valid",value:t}),Be=t=>t.status==="aborted",Ge=t=>t.status==="dirty",F=t=>t.status==="valid",re=t=>typeof Promise<"u"&&t instanceof Promise;var h;(function(t){t.errToObj=e=>typeof e=="string"?{message:e}:e||{},t.toString=e=>typeof e=="string"?e:e?.message})(h||(h={}));class Z{constructor(e,n,r,i){this._cachedPath=[],this.parent=e,this.data=n,this._path=r,this._key=i}get path(){return this._cachedPath.length||(Array.isArray(this._key)?this._cachedPath.push(...this._path,...this._key):this._cachedPath.push(...this._path,this._key)),this._cachedPath}}const Fe=(t,e)=>{if(F(e))return{success:!0,data:e.value};if(!t.common.issues.length)throw new Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;const n=new R(t.common.issues);return this._error=n,this._error}}};function _(t){if(!t)return{};const{errorMap:e,invalid_type_error:n,required_error:r,description:i}=t;if(e&&(n||r))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return e?{errorMap:e,description:i}:{errorMap:(a,o)=>{const{message:c}=t;return a.code==="invalid_enum_value"?{message:c??o.defaultError}:typeof o.data>"u"?{message:c??r??o.defaultError}:a.code!=="invalid_type"?{message:o.defaultError}:{message:c??n??o.defaultError}},description:i}}class k{get description(){return this._def.description}_getType(e){return j(e.data)}_getOrReturnCtx(e,n){return n||{common:e.parent.common,data:e.data,parsedType:j(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}_processInputParams(e){return{status:new A,ctx:{common:e.parent.common,data:e.data,parsedType:j(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}}_parseSync(e){const n=this._parse(e);if(re(n))throw new Error("Synchronous parse encountered promise.");return n}_parseAsync(e){const n=this._parse(e);return Promise.resolve(n)}parse(e,n){const r=this.safeParse(e,n);if(r.success)return r.data;throw r.error}safeParse(e,n){const r={common:{issues:[],async:n?.async??!1,contextualErrorMap:n?.errorMap},path:n?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:j(e)},i=this._parseSync({data:e,path:r.path,parent:r});return Fe(r,i)}"~validate"(e){const n={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:j(e)};if(!this["~standard"].async)try{const r=this._parseSync({data:e,path:[],parent:n});return F(r)?{value:r.value}:{issues:n.common.issues}}catch(r){r?.message?.toLowerCase()?.includes("encountered")&&(this["~standard"].async=!0),n.common={issues:[],async:!0}}return this._parseAsync({data:e,path:[],parent:n}).then(r=>F(r)?{value:r.value}:{issues:n.common.issues})}async parseAsync(e,n){const r=await this.safeParseAsync(e,n);if(r.success)return r.data;throw r.error}async safeParseAsync(e,n){const r={common:{issues:[],contextualErrorMap:n?.errorMap,async:!0},path:n?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:j(e)},i=this._parse({data:e,path:r.path,parent:r}),s=await(re(i)?i:Promise.resolve(i));return Fe(r,s)}refine(e,n){const r=i=>typeof n=="string"||typeof n>"u"?{message:n}:typeof n=="function"?n(i):n;return this._refinement((i,s)=>{const a=e(i),o=()=>s.addIssue({code:u.custom,...r(i)});return typeof Promise<"u"&&a instanceof Promise?a.then(c=>c?!0:(o(),!1)):a?!0:(o(),!1)})}refinement(e,n){return this._refinement((r,i)=>e(r)?!0:(i.addIssue(typeof n=="function"?n(r,i):n),!1))}_refinement(e){return new Q({schema:this,typeName:y.ZodEffects,effect:{type:"refinement",refinement:e}})}superRefine(e){return this._refinement(e)}constructor(e){this.spa=this.safeParseAsync,this._def=e,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.readonly=this.readonly.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this),this["~standard"]={version:1,vendor:"zod",validate:n=>this["~validate"](n)}}optional(){return D.create(this,this._def)}nullable(){return Y.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return N.create(this)}promise(){return oe.create(this,this._def)}or(e){return se.create([this,e],this._def)}and(e){return ae.create(this,e,this._def)}transform(e){return new Q({..._(this._def),schema:this,typeName:y.ZodEffects,effect:{type:"transform",transform:e}})}default(e){const n=typeof e=="function"?e:()=>e;return new ge({..._(this._def),innerType:this,defaultValue:n,typeName:y.ZodDefault})}brand(){return new nr({typeName:y.ZodBranded,type:this,..._(this._def)})}catch(e){const n=typeof e=="function"?e:()=>e;return new ye({..._(this._def),innerType:this,catchValue:n,typeName:y.ZodCatch})}describe(e){const n=this.constructor;return new n({...this._def,description:e})}pipe(e){return _e.create(this,e)}readonly(){return ve.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const Ln=/^c[^\s-]{8,}$/i,jn=/^[0-9a-z]+$/,Zn=/^[0-9A-HJKMNP-TV-Z]{26}$/i,$n=/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i,Mn=/^[a-z0-9_-]{21}$/i,Dn=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,Un=/^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/,zn=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,Vn="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";let pe;const qn=/^(?:(?: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])$/,Bn=/^(?:(?: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])\/(3[0-2]|[12]?[0-9])$/,Gn=/^(([0-9a-fA-F]{1,4}:){7,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}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/,Fn=/^(([0-9a-fA-F]{1,4}:){7,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}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,Hn=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,Wn=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,He="((\\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])))",Jn=new RegExp(`^${He}$`);function We(t){let e="[0-5]\\d";t.precision?e=`${e}\\.\\d{${t.precision}}`:t.precision==null&&(e=`${e}(\\.\\d+)?`);const n=t.precision?"+":"?";return`([01]\\d|2[0-3]):[0-5]\\d(:${e})${n}`}function Qn(t){return new RegExp(`^${We(t)}$`)}function Yn(t){let e=`${He}T${We(t)}`;const n=[];return n.push(t.local?"Z?":"Z"),t.offset&&n.push("([+-]\\d{2}:?\\d{2})"),e=`${e}(${n.join("|")})`,new RegExp(`^${e}$`)}function Xn(t,e){return!!((e==="v4"||!e)&&qn.test(t)||(e==="v6"||!e)&&Gn.test(t))}function Kn(t,e){if(!Dn.test(t))return!1;try{const[n]=t.split(".");if(!n)return!1;const r=n.replace(/-/g,"+").replace(/_/g,"/").padEnd(n.length+(4-n.length%4)%4,"="),i=JSON.parse(atob(r));return!(typeof i!="object"||i===null||"typ"in i&&i?.typ!=="JWT"||!i.alg||e&&i.alg!==e)}catch{return!1}}function er(t,e){return!!((e==="v4"||!e)&&Bn.test(t)||(e==="v6"||!e)&&Fn.test(t))}class $ extends k{_parse(e){if(this._def.coerce&&(e.data=String(e.data)),this._getType(e)!==f.string){const s=this._getOrReturnCtx(e);return l(s,{code:u.invalid_type,expected:f.string,received:s.parsedType}),g}const r=new A;let i;for(const s of this._def.checks)if(s.kind==="min")e.data.length<s.value&&(i=this._getOrReturnCtx(e,i),l(i,{code:u.too_small,minimum:s.value,type:"string",inclusive:!0,exact:!1,message:s.message}),r.dirty());else if(s.kind==="max")e.data.length>s.value&&(i=this._getOrReturnCtx(e,i),l(i,{code:u.too_big,maximum:s.value,type:"string",inclusive:!0,exact:!1,message:s.message}),r.dirty());else if(s.kind==="length"){const a=e.data.length>s.value,o=e.data.length<s.value;(a||o)&&(i=this._getOrReturnCtx(e,i),a?l(i,{code:u.too_big,maximum:s.value,type:"string",inclusive:!0,exact:!0,message:s.message}):o&&l(i,{code:u.too_small,minimum:s.value,type:"string",inclusive:!0,exact:!0,message:s.message}),r.dirty())}else if(s.kind==="email")zn.test(e.data)||(i=this._getOrReturnCtx(e,i),l(i,{validation:"email",code:u.invalid_string,message:s.message}),r.dirty());else if(s.kind==="emoji")pe||(pe=new RegExp(Vn,"u")),pe.test(e.data)||(i=this._getOrReturnCtx(e,i),l(i,{validation:"emoji",code:u.invalid_string,message:s.message}),r.dirty());else if(s.kind==="uuid")$n.test(e.data)||(i=this._getOrReturnCtx(e,i),l(i,{validation:"uuid",code:u.invalid_string,message:s.message}),r.dirty());else if(s.kind==="nanoid")Mn.test(e.data)||(i=this._getOrReturnCtx(e,i),l(i,{validation:"nanoid",code:u.invalid_string,message:s.message}),r.dirty());else if(s.kind==="cuid")Ln.test(e.data)||(i=this._getOrReturnCtx(e,i),l(i,{validation:"cuid",code:u.invalid_string,message:s.message}),r.dirty());else if(s.kind==="cuid2")jn.test(e.data)||(i=this._getOrReturnCtx(e,i),l(i,{validation:"cuid2",code:u.invalid_string,message:s.message}),r.dirty());else if(s.kind==="ulid")Zn.test(e.data)||(i=this._getOrReturnCtx(e,i),l(i,{validation:"ulid",code:u.invalid_string,message:s.message}),r.dirty());else if(s.kind==="url")try{new URL(e.data)}catch{i=this._getOrReturnCtx(e,i),l(i,{validation:"url",code:u.invalid_string,message:s.message}),r.dirty()}else s.kind==="regex"?(s.regex.lastIndex=0,s.regex.test(e.data)||(i=this._getOrReturnCtx(e,i),l(i,{validation:"regex",code:u.invalid_string,message:s.message}),r.dirty())):s.kind==="trim"?e.data=e.data.trim():s.kind==="includes"?e.data.includes(s.value,s.position)||(i=this._getOrReturnCtx(e,i),l(i,{code:u.invalid_string,validation:{includes:s.value,position:s.position},message:s.message}),r.dirty()):s.kind==="toLowerCase"?e.data=e.data.toLowerCase():s.kind==="toUpperCase"?e.data=e.data.toUpperCase():s.kind==="startsWith"?e.data.startsWith(s.value)||(i=this._getOrReturnCtx(e,i),l(i,{code:u.invalid_string,validation:{startsWith:s.value},message:s.message}),r.dirty()):s.kind==="endsWith"?e.data.endsWith(s.value)||(i=this._getOrReturnCtx(e,i),l(i,{code:u.invalid_string,validation:{endsWith:s.value},message:s.message}),r.dirty()):s.kind==="datetime"?Yn(s).test(e.data)||(i=this._getOrReturnCtx(e,i),l(i,{code:u.invalid_string,validation:"datetime",message:s.message}),r.dirty()):s.kind==="date"?Jn.test(e.data)||(i=this._getOrReturnCtx(e,i),l(i,{code:u.invalid_string,validation:"date",message:s.message}),r.dirty()):s.kind==="time"?Qn(s).test(e.data)||(i=this._getOrReturnCtx(e,i),l(i,{code:u.invalid_string,validation:"time",message:s.message}),r.dirty()):s.kind==="duration"?Un.test(e.data)||(i=this._getOrReturnCtx(e,i),l(i,{validation:"duration",code:u.invalid_string,message:s.message}),r.dirty()):s.kind==="ip"?Xn(e.data,s.version)||(i=this._getOrReturnCtx(e,i),l(i,{validation:"ip",code:u.invalid_string,message:s.message}),r.dirty()):s.kind==="jwt"?Kn(e.data,s.alg)||(i=this._getOrReturnCtx(e,i),l(i,{validation:"jwt",code:u.invalid_string,message:s.message}),r.dirty()):s.kind==="cidr"?er(e.data,s.version)||(i=this._getOrReturnCtx(e,i),l(i,{validation:"cidr",code:u.invalid_string,message:s.message}),r.dirty()):s.kind==="base64"?Hn.test(e.data)||(i=this._getOrReturnCtx(e,i),l(i,{validation:"base64",code:u.invalid_string,message:s.message}),r.dirty()):s.kind==="base64url"?Wn.test(e.data)||(i=this._getOrReturnCtx(e,i),l(i,{validation:"base64url",code:u.invalid_string,message:s.message}),r.dirty()):b.assertNever(s);return{status:r.value,value:e.data}}_regex(e,n,r){return this.refinement(i=>e.test(i),{validation:n,code:u.invalid_string,...h.errToObj(r)})}_addCheck(e){return new $({...this._def,checks:[...this._def.checks,e]})}email(e){return this._addCheck({kind:"email",...h.errToObj(e)})}url(e){return this._addCheck({kind:"url",...h.errToObj(e)})}emoji(e){return this._addCheck({kind:"emoji",...h.errToObj(e)})}uuid(e){return this._addCheck({kind:"uuid",...h.errToObj(e)})}nanoid(e){return this._addCheck({kind:"nanoid",...h.errToObj(e)})}cuid(e){return this._addCheck({kind:"cuid",...h.errToObj(e)})}cuid2(e){return this._addCheck({kind:"cuid2",...h.errToObj(e)})}ulid(e){return this._addCheck({kind:"ulid",...h.errToObj(e)})}base64(e){return this._addCheck({kind:"base64",...h.errToObj(e)})}base64url(e){return this._addCheck({kind:"base64url",...h.errToObj(e)})}jwt(e){return this._addCheck({kind:"jwt",...h.errToObj(e)})}ip(e){return this._addCheck({kind:"ip",...h.errToObj(e)})}cidr(e){return this._addCheck({kind:"cidr",...h.errToObj(e)})}datetime(e){return typeof e=="string"?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:e}):this._addCheck({kind:"datetime",precision:typeof e?.precision>"u"?null:e?.precision,offset:e?.offset??!1,local:e?.local??!1,...h.errToObj(e?.message)})}date(e){return this._addCheck({kind:"date",message:e})}time(e){return typeof e=="string"?this._addCheck({kind:"time",precision:null,message:e}):this._addCheck({kind:"time",precision:typeof e?.precision>"u"?null:e?.precision,...h.errToObj(e?.message)})}duration(e){return this._addCheck({kind:"duration",...h.errToObj(e)})}regex(e,n){return this._addCheck({kind:"regex",regex:e,...h.errToObj(n)})}includes(e,n){return this._addCheck({kind:"includes",value:e,position:n?.position,...h.errToObj(n?.message)})}startsWith(e,n){return this._addCheck({kind:"startsWith",value:e,...h.errToObj(n)})}endsWith(e,n){return this._addCheck({kind:"endsWith",value:e,...h.errToObj(n)})}min(e,n){return this._addCheck({kind:"min",value:e,...h.errToObj(n)})}max(e,n){return this._addCheck({kind:"max",value:e,...h.errToObj(n)})}length(e,n){return this._addCheck({kind:"length",value:e,...h.errToObj(n)})}nonempty(e){return this.min(1,h.errToObj(e))}trim(){return new $({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new $({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new $({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(e=>e.kind==="datetime")}get isDate(){return!!this._def.checks.find(e=>e.kind==="date")}get isTime(){return!!this._def.checks.find(e=>e.kind==="time")}get isDuration(){return!!this._def.checks.find(e=>e.kind==="duration")}get isEmail(){return!!this._def.checks.find(e=>e.kind==="email")}get isURL(){return!!this._def.checks.find(e=>e.kind==="url")}get isEmoji(){return!!this._def.checks.find(e=>e.kind==="emoji")}get isUUID(){return!!this._def.checks.find(e=>e.kind==="uuid")}get isNANOID(){return!!this._def.checks.find(e=>e.kind==="nanoid")}get isCUID(){return!!this._def.checks.find(e=>e.kind==="cuid")}get isCUID2(){return!!this._def.checks.find(e=>e.kind==="cuid2")}get isULID(){return!!this._def.checks.find(e=>e.kind==="ulid")}get isIP(){return!!this._def.checks.find(e=>e.kind==="ip")}get isCIDR(){return!!this._def.checks.find(e=>e.kind==="cidr")}get isBase64(){return!!this._def.checks.find(e=>e.kind==="base64")}get isBase64url(){return!!this._def.checks.find(e=>e.kind==="base64url")}get minLength(){let e=null;for(const n of this._def.checks)n.kind==="min"&&(e===null||n.value>e)&&(e=n.value);return e}get maxLength(){let e=null;for(const n of this._def.checks)n.kind==="max"&&(e===null||n.value<e)&&(e=n.value);return e}}$.create=t=>new $({checks:[],typeName:y.ZodString,coerce:t?.coerce??!1,..._(t)});function tr(t,e){const n=(t.toString().split(".")[1]||"").length,r=(e.toString().split(".")[1]||"").length,i=n>r?n:r,s=Number.parseInt(t.toFixed(i).replace(".","")),a=Number.parseInt(e.toFixed(i).replace(".",""));return s%a/10**i}class H extends k{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(e){if(this._def.coerce&&(e.data=Number(e.data)),this._getType(e)!==f.number){const s=this._getOrReturnCtx(e);return l(s,{code:u.invalid_type,expected:f.number,received:s.parsedType}),g}let r;const i=new A;for(const s of this._def.checks)s.kind==="int"?b.isInteger(e.data)||(r=this._getOrReturnCtx(e,r),l(r,{code:u.invalid_type,expected:"integer",received:"float",message:s.message}),i.dirty()):s.kind==="min"?(s.inclusive?e.data<s.value:e.data<=s.value)&&(r=this._getOrReturnCtx(e,r),l(r,{code:u.too_small,minimum:s.value,type:"number",inclusive:s.inclusive,exact:!1,message:s.message}),i.dirty()):s.kind==="max"?(s.inclusive?e.data>s.value:e.data>=s.value)&&(r=this._getOrReturnCtx(e,r),l(r,{code:u.too_big,maximum:s.value,type:"number",inclusive:s.inclusive,exact:!1,message:s.message}),i.dirty()):s.kind==="multipleOf"?tr(e.data,s.value)!==0&&(r=this._getOrReturnCtx(e,r),l(r,{code:u.not_multiple_of,multipleOf:s.value,message:s.message}),i.dirty()):s.kind==="finite"?Number.isFinite(e.data)||(r=this._getOrReturnCtx(e,r),l(r,{code:u.not_finite,message:s.message}),i.dirty()):b.assertNever(s);return{status:i.value,value:e.data}}gte(e,n){return this.setLimit("min",e,!0,h.toString(n))}gt(e,n){return this.setLimit("min",e,!1,h.toString(n))}lte(e,n){return this.setLimit("max",e,!0,h.toString(n))}lt(e,n){return this.setLimit("max",e,!1,h.toString(n))}setLimit(e,n,r,i){return new H({...this._def,checks:[...this._def.checks,{kind:e,value:n,inclusive:r,message:h.toString(i)}]})}_addCheck(e){return new H({...this._def,checks:[...this._def.checks,e]})}int(e){return this._addCheck({kind:"int",message:h.toString(e)})}positive(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:h.toString(e)})}negative(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:h.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:h.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:h.toString(e)})}multipleOf(e,n){return this._addCheck({kind:"multipleOf",value:e,message:h.toString(n)})}finite(e){return this._addCheck({kind:"finite",message:h.toString(e)})}safe(e){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:h.toString(e)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:h.toString(e)})}get minValue(){let e=null;for(const n of this._def.checks)n.kind==="min"&&(e===null||n.value>e)&&(e=n.value);return e}get maxValue(){let e=null;for(const n of this._def.checks)n.kind==="max"&&(e===null||n.value<e)&&(e=n.value);return e}get isInt(){return!!this._def.checks.find(e=>e.kind==="int"||e.kind==="multipleOf"&&b.isInteger(e.value))}get isFinite(){let e=null,n=null;for(const r of this._def.checks){if(r.kind==="finite"||r.kind==="int"||r.kind==="multipleOf")return!0;r.kind==="min"?(n===null||r.value>n)&&(n=r.value):r.kind==="max"&&(e===null||r.value<e)&&(e=r.value)}return Number.isFinite(n)&&Number.isFinite(e)}}H.create=t=>new H({checks:[],typeName:y.ZodNumber,coerce:t?.coerce||!1,..._(t)});class ee extends k{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(e){if(this._def.coerce)try{e.data=BigInt(e.data)}catch{return this._getInvalidInput(e)}if(this._getType(e)!==f.bigint)return this._getInvalidInput(e);let r;const i=new A;for(const s of this._def.checks)s.kind==="min"?(s.inclusive?e.data<s.value:e.data<=s.value)&&(r=this._getOrReturnCtx(e,r),l(r,{code:u.too_small,type:"bigint",minimum:s.value,inclusive:s.inclusive,message:s.message}),i.dirty()):s.kind==="max"?(s.inclusive?e.data>s.value:e.data>=s.value)&&(r=this._getOrReturnCtx(e,r),l(r,{code:u.too_big,type:"bigint",maximum:s.value,inclusive:s.inclusive,message:s.message}),i.dirty()):s.kind==="multipleOf"?e.data%s.value!==BigInt(0)&&(r=this._getOrReturnCtx(e,r),l(r,{code:u.not_multiple_of,multipleOf:s.value,message:s.message}),i.dirty()):b.assertNever(s);return{status:i.value,value:e.data}}_getInvalidInput(e){const n=this._getOrReturnCtx(e);return l(n,{code:u.invalid_type,expected:f.bigint,received:n.parsedType}),g}gte(e,n){return this.setLimit("min",e,!0,h.toString(n))}gt(e,n){return this.setLimit("min",e,!1,h.toString(n))}lte(e,n){return this.setLimit("max",e,!0,h.toString(n))}lt(e,n){return this.setLimit("max",e,!1,h.toString(n))}setLimit(e,n,r,i){return new ee({...this._def,checks:[...this._def.checks,{kind:e,value:n,inclusive:r,message:h.toString(i)}]})}_addCheck(e){return new ee({...this._def,checks:[...this._def.checks,e]})}positive(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:h.toString(e)})}negative(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:h.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:h.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:h.toString(e)})}multipleOf(e,n){return this._addCheck({kind:"multipleOf",value:e,message:h.toString(n)})}get minValue(){let e=null;for(const n of this._def.checks)n.kind==="min"&&(e===null||n.value>e)&&(e=n.value);return e}get maxValue(){let e=null;for(const n of this._def.checks)n.kind==="max"&&(e===null||n.value<e)&&(e=n.value);return e}}ee.create=t=>new ee({checks:[],typeName:y.ZodBigInt,coerce:t?.coerce??!1,..._(t)});class Je extends k{_parse(e){if(this._def.coerce&&(e.data=!!e.data),this._getType(e)!==f.boolean){const r=this._getOrReturnCtx(e);return l(r,{code:u.invalid_type,expected:f.boolean,received:r.parsedType}),g}return I(e.data)}}Je.create=t=>new Je({typeName:y.ZodBoolean,coerce:t?.coerce||!1,..._(t)});class ie extends k{_parse(e){if(this._def.coerce&&(e.data=new Date(e.data)),this._getType(e)!==f.date){const s=this._getOrReturnCtx(e);return l(s,{code:u.invalid_type,expected:f.date,received:s.parsedType}),g}if(Number.isNaN(e.data.getTime())){const s=this._getOrReturnCtx(e);return l(s,{code:u.invalid_date}),g}const r=new A;let i;for(const s of this._def.checks)s.kind==="min"?e.data.getTime()<s.value&&(i=this._getOrReturnCtx(e,i),l(i,{code:u.too_small,message:s.message,inclusive:!0,exact:!1,minimum:s.value,type:"date"}),r.dirty()):s.kind==="max"?e.data.getTime()>s.value&&(i=this._getOrReturnCtx(e,i),l(i,{code:u.too_big,message:s.message,inclusive:!0,exact:!1,maximum:s.value,type:"date"}),r.dirty()):b.assertNever(s);return{status:r.value,value:new Date(e.data.getTime())}}_addCheck(e){return new ie({...this._def,checks:[...this._def.checks,e]})}min(e,n){return this._addCheck({kind:"min",value:e.getTime(),message:h.toString(n)})}max(e,n){return this._addCheck({kind:"max",value:e.getTime(),message:h.toString(n)})}get minDate(){let e=null;for(const n of this._def.checks)n.kind==="min"&&(e===null||n.value>e)&&(e=n.value);return e!=null?new Date(e):null}get maxDate(){let e=null;for(const n of this._def.checks)n.kind==="max"&&(e===null||n.value<e)&&(e=n.value);return e!=null?new Date(e):null}}ie.create=t=>new ie({checks:[],coerce:t?.coerce||!1,typeName:y.ZodDate,..._(t)});class Qe extends k{_parse(e){if(this._getType(e)!==f.symbol){const r=this._getOrReturnCtx(e);return l(r,{code:u.invalid_type,expected:f.symbol,received:r.parsedType}),g}return I(e.data)}}Qe.create=t=>new Qe({typeName:y.ZodSymbol,..._(t)});class Ye extends k{_parse(e){if(this._getType(e)!==f.undefined){const r=this._getOrReturnCtx(e);return l(r,{code:u.invalid_type,expected:f.undefined,received:r.parsedType}),g}return I(e.data)}}Ye.create=t=>new Ye({typeName:y.ZodUndefined,..._(t)});class Xe extends k{_parse(e){if(this._getType(e)!==f.null){const r=this._getOrReturnCtx(e);return l(r,{code:u.invalid_type,expected:f.null,received:r.parsedType}),g}return I(e.data)}}Xe.create=t=>new Xe({typeName:y.ZodNull,..._(t)});class Ke extends k{constructor(){super(...arguments),this._any=!0}_parse(e){return I(e.data)}}Ke.create=t=>new Ke({typeName:y.ZodAny,..._(t)});class he extends k{constructor(){super(...arguments),this._unknown=!0}_parse(e){return I(e.data)}}he.create=t=>new he({typeName:y.ZodUnknown,..._(t)});class M extends k{_parse(e){const n=this._getOrReturnCtx(e);return l(n,{code:u.invalid_type,expected:f.never,received:n.parsedType}),g}}M.create=t=>new M({typeName:y.ZodNever,..._(t)});class et extends k{_parse(e){if(this._getType(e)!==f.undefined){const r=this._getOrReturnCtx(e);return l(r,{code:u.invalid_type,expected:f.void,received:r.parsedType}),g}return I(e.data)}}et.create=t=>new et({typeName:y.ZodVoid,..._(t)});class N extends k{_parse(e){const{ctx:n,status:r}=this._processInputParams(e),i=this._def;if(n.parsedType!==f.array)return l(n,{code:u.invalid_type,expected:f.array,received:n.parsedType}),g;if(i.exactLength!==null){const a=n.data.length>i.exactLength.value,o=n.data.length<i.exactLength.value;(a||o)&&(l(n,{code:a?u.too_big:u.too_small,minimum:o?i.exactLength.value:void 0,maximum:a?i.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:i.exactLength.message}),r.dirty())}if(i.minLength!==null&&n.data.length<i.minLength.value&&(l(n,{code:u.too_small,minimum:i.minLength.value,type:"array",inclusive:!0,exact:!1,message:i.minLength.message}),r.dirty()),i.maxLength!==null&&n.data.length>i.maxLength.value&&(l(n,{code:u.too_big,maximum:i.maxLength.value,type:"array",inclusive:!0,exact:!1,message:i.maxLength.message}),r.dirty()),n.common.async)return Promise.all([...n.data].map((a,o)=>i.type._parseAsync(new Z(n,a,n.path,o)))).then(a=>A.mergeArray(r,a));const s=[...n.data].map((a,o)=>i.type._parseSync(new Z(n,a,n.path,o)));return A.mergeArray(r,s)}get element(){return this._def.type}min(e,n){return new N({...this._def,minLength:{value:e,message:h.toString(n)}})}max(e,n){return new N({...this._def,maxLength:{value:e,message:h.toString(n)}})}length(e,n){return new N({...this._def,exactLength:{value:e,message:h.toString(n)}})}nonempty(e){return this.min(1,e)}}N.create=(t,e)=>new N({type:t,minLength:null,maxLength:null,exactLength:null,typeName:y.ZodArray,..._(e)});function W(t){if(t instanceof x){const e={};for(const n in t.shape){const r=t.shape[n];e[n]=D.create(W(r))}return new x({...t._def,shape:()=>e})}else return t instanceof N?new N({...t._def,type:W(t.element)}):t instanceof D?D.create(W(t.unwrap())):t instanceof Y?Y.create(W(t.unwrap())):t instanceof B?B.create(t.items.map(e=>W(e))):t}class x extends k{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;const e=this._def.shape(),n=b.objectKeys(e);return this._cached={shape:e,keys:n},this._cached}_parse(e){if(this._getType(e)!==f.object){const d=this._getOrReturnCtx(e);return l(d,{code:u.invalid_type,expected:f.object,received:d.parsedType}),g}const{status:r,ctx:i}=this._processInputParams(e),{shape:s,keys:a}=this._getCached(),o=[];if(!(this._def.catchall instanceof M&&this._def.unknownKeys==="strip"))for(const d in i.data)a.includes(d)||o.push(d);const c=[];for(const d of a){const p=s[d],v=i.data[d];c.push({key:{status:"valid",value:d},value:p._parse(new Z(i,v,i.path,d)),alwaysSet:d in i.data})}if(this._def.catchall instanceof M){const d=this._def.unknownKeys;if(d==="passthrough")for(const p of o)c.push({key:{status:"valid",value:p},value:{status:"valid",value:i.data[p]}});else if(d==="strict")o.length>0&&(l(i,{code:u.unrecognized_keys,keys:o}),r.dirty());else if(d!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{const d=this._def.catchall;for(const p of o){const v=i.data[p];c.push({key:{status:"valid",value:p},value:d._parse(new Z(i,v,i.path,p)),alwaysSet:p in i.data})}}return i.common.async?Promise.resolve().then(async()=>{const d=[];for(const p of c){const v=await p.key,C=await p.value;d.push({key:v,value:C,alwaysSet:p.alwaysSet})}return d}).then(d=>A.mergeObjectSync(r,d)):A.mergeObjectSync(r,c)}get shape(){return this._def.shape()}strict(e){return h.errToObj,new x({...this._def,unknownKeys:"strict",...e!==void 0?{errorMap:(n,r)=>{const i=this._def.errorMap?.(n,r).message??r.defaultError;return n.code==="unrecognized_keys"?{message:h.errToObj(e).message??i}:{message:i}}}:{}})}strip(){return new x({...this._def,unknownKeys:"strip"})}passthrough(){return new x({...this._def,unknownKeys:"passthrough"})}extend(e){return new x({...this._def,shape:()=>({...this._def.shape(),...e})})}merge(e){return new x({unknownKeys:e._def.unknownKeys,catchall:e._def.catchall,shape:()=>({...this._def.shape(),...e._def.shape()}),typeName:y.ZodObject})}setKey(e,n){return this.augment({[e]:n})}catchall(e){return new x({...this._def,catchall:e})}pick(e){const n={};for(const r of b.objectKeys(e))e[r]&&this.shape[r]&&(n[r]=this.shape[r]);return new x({...this._def,shape:()=>n})}omit(e){const n={};for(const r of b.objectKeys(this.shape))e[r]||(n[r]=this.shape[r]);return new x({...this._def,shape:()=>n})}deepPartial(){return W(this)}partial(e){const n={};for(const r of b.objectKeys(this.shape)){const i=this.shape[r];e&&!e[r]?n[r]=i:n[r]=i.optional()}return new x({...this._def,shape:()=>n})}required(e){const n={};for(const r of b.objectKeys(this.shape))if(e&&!e[r])n[r]=this.shape[r];else{let s=this.shape[r];for(;s instanceof D;)s=s._def.innerType;n[r]=s}return new x({...this._def,shape:()=>n})}keyof(){return it(b.objectKeys(this.shape))}}x.create=(t,e)=>new x({shape:()=>t,unknownKeys:"strip",catchall:M.create(),typeName:y.ZodObject,..._(e)}),x.strictCreate=(t,e)=>new x({shape:()=>t,unknownKeys:"strict",catchall:M.create(),typeName:y.ZodObject,..._(e)}),x.lazycreate=(t,e)=>new x({shape:t,unknownKeys:"strip",catchall:M.create(),typeName:y.ZodObject,..._(e)});class se extends k{_parse(e){const{ctx:n}=this._processInputParams(e),r=this._def.options;function i(s){for(const o of s)if(o.result.status==="valid")return o.result;for(const o of s)if(o.result.status==="dirty")return n.common.issues.push(...o.ctx.common.issues),o.result;const a=s.map(o=>new R(o.ctx.common.issues));return l(n,{code:u.invalid_union,unionErrors:a}),g}if(n.common.async)return Promise.all(r.map(async s=>{const a={...n,common:{...n.common,issues:[]},parent:null};return{result:await s._parseAsync({data:n.data,path:n.path,parent:a}),ctx:a}})).then(i);{let s;const a=[];for(const c of r){const d={...n,common:{...n.common,issues:[]},parent:null},p=c._parseSync({data:n.data,path:n.path,parent:d});if(p.status==="valid")return p;p.status==="dirty"&&!s&&(s={result:p,ctx:d}),d.common.issues.length&&a.push(d.common.issues)}if(s)return n.common.issues.push(...s.ctx.common.issues),s.result;const o=a.map(c=>new R(c));return l(n,{code:u.invalid_union,unionErrors:o}),g}}get options(){return this._def.options}}se.create=(t,e)=>new se({options:t,typeName:y.ZodUnion,..._(e)});function me(t,e){const n=j(t),r=j(e);if(t===e)return{valid:!0,data:t};if(n===f.object&&r===f.object){const i=b.objectKeys(e),s=b.objectKeys(t).filter(o=>i.indexOf(o)!==-1),a={...t,...e};for(const o of s){const c=me(t[o],e[o]);if(!c.valid)return{valid:!1};a[o]=c.data}return{valid:!0,data:a}}else if(n===f.array&&r===f.array){if(t.length!==e.length)return{valid:!1};const i=[];for(let s=0;s<t.length;s++){const a=t[s],o=e[s],c=me(a,o);if(!c.valid)return{valid:!1};i.push(c.data)}return{valid:!0,data:i}}else return n===f.date&&r===f.date&&+t==+e?{valid:!0,data:t}:{valid:!1}}class ae extends k{_parse(e){const{status:n,ctx:r}=this._processInputParams(e),i=(s,a)=>{if(Be(s)||Be(a))return g;const o=me(s.value,a.value);return o.valid?((Ge(s)||Ge(a))&&n.dirty(),{status:n.value,value:o.data}):(l(r,{code:u.invalid_intersection_types}),g)};return r.common.async?Promise.all([this._def.left._parseAsync({data:r.data,path:r.path,parent:r}),this._def.right._parseAsync({data:r.data,path:r.path,parent:r})]).then(([s,a])=>i(s,a)):i(this._def.left._parseSync({data:r.data,path:r.path,parent:r}),this._def.right._parseSync({data:r.data,path:r.path,parent:r}))}}ae.create=(t,e,n)=>new ae({left:t,right:e,typeName:y.ZodIntersection,..._(n)});class B extends k{_parse(e){const{status:n,ctx:r}=this._processInputParams(e);if(r.parsedType!==f.array)return l(r,{code:u.invalid_type,expected:f.array,received:r.parsedType}),g;if(r.data.length<this._def.items.length)return l(r,{code:u.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),g;!this._def.rest&&r.data.length>this._def.items.length&&(l(r,{code:u.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),n.dirty());const s=[...r.data].map((a,o)=>{const c=this._def.items[o]||this._def.rest;return c?c._parse(new Z(r,a,r.path,o)):null}).filter(a=>!!a);return r.common.async?Promise.all(s).then(a=>A.mergeArray(n,a)):A.mergeArray(n,s)}get items(){return this._def.items}rest(e){return new B({...this._def,rest:e})}}B.create=(t,e)=>{if(!Array.isArray(t))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new B({items:t,typeName:y.ZodTuple,rest:null,..._(e)})};class tt extends k{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:n,ctx:r}=this._processInputParams(e);if(r.parsedType!==f.map)return l(r,{code:u.invalid_type,expected:f.map,received:r.parsedType}),g;const i=this._def.keyType,s=this._def.valueType,a=[...r.data.entries()].map(([o,c],d)=>({key:i._parse(new Z(r,o,r.path,[d,"key"])),value:s._parse(new Z(r,c,r.path,[d,"value"]))}));if(r.common.async){const o=new Map;return Promise.resolve().then(async()=>{for(const c of a){const d=await c.key,p=await c.value;if(d.status==="aborted"||p.status==="aborted")return g;(d.status==="dirty"||p.status==="dirty")&&n.dirty(),o.set(d.value,p.value)}return{status:n.value,value:o}})}else{const o=new Map;for(const c of a){const d=c.key,p=c.value;if(d.status==="aborted"||p.status==="aborted")return g;(d.status==="dirty"||p.status==="dirty")&&n.dirty(),o.set(d.value,p.value)}return{status:n.value,value:o}}}}tt.create=(t,e,n)=>new tt({valueType:e,keyType:t,typeName:y.ZodMap,..._(n)});class te extends k{_parse(e){const{status:n,ctx:r}=this._processInputParams(e);if(r.parsedType!==f.set)return l(r,{code:u.invalid_type,expected:f.set,received:r.parsedType}),g;const i=this._def;i.minSize!==null&&r.data.size<i.minSize.value&&(l(r,{code:u.too_small,minimum:i.minSize.value,type:"set",inclusive:!0,exact:!1,message:i.minSize.message}),n.dirty()),i.maxSize!==null&&r.data.size>i.maxSize.value&&(l(r,{code:u.too_big,maximum:i.maxSize.value,type:"set",inclusive:!0,exact:!1,message:i.maxSize.message}),n.dirty());const s=this._def.valueType;function a(c){const d=new Set;for(const p of c){if(p.status==="aborted")return g;p.status==="dirty"&&n.dirty(),d.add(p.value)}return{status:n.value,value:d}}const o=[...r.data.values()].map((c,d)=>s._parse(new Z(r,c,r.path,d)));return r.common.async?Promise.all(o).then(c=>a(c)):a(o)}min(e,n){return new te({...this._def,minSize:{value:e,message:h.toString(n)}})}max(e,n){return new te({...this._def,maxSize:{value:e,message:h.toString(n)}})}size(e,n){return this.min(e,n).max(e,n)}nonempty(e){return this.min(1,e)}}te.create=(t,e)=>new te({valueType:t,minSize:null,maxSize:null,typeName:y.ZodSet,..._(e)});class nt extends k{get schema(){return this._def.getter()}_parse(e){const{ctx:n}=this._processInputParams(e);return this._def.getter()._parse({data:n.data,path:n.path,parent:n})}}nt.create=(t,e)=>new nt({getter:t,typeName:y.ZodLazy,..._(e)});class rt extends k{_parse(e){if(e.data!==this._def.value){const n=this._getOrReturnCtx(e);return l(n,{received:n.data,code:u.invalid_literal,expected:this._def.value}),g}return{status:"valid",value:e.data}}get value(){return this._def.value}}rt.create=(t,e)=>new rt({value:t,typeName:y.ZodLiteral,..._(e)});function it(t,e){return new J({values:t,typeName:y.ZodEnum,..._(e)})}class J extends k{_parse(e){if(typeof e.data!="string"){const n=this._getOrReturnCtx(e),r=this._def.values;return l(n,{expected:b.joinValues(r),received:n.parsedType,code:u.invalid_type}),g}if(this._cache||(this._cache=new Set(this._def.values)),!this._cache.has(e.data)){const n=this._getOrReturnCtx(e),r=this._def.values;return l(n,{received:n.data,code:u.invalid_enum_value,options:r}),g}return I(e.data)}get options(){return this._def.values}get enum(){const e={};for(const n of this._def.values)e[n]=n;return e}get Values(){const e={};for(const n of this._def.values)e[n]=n;return e}get Enum(){const e={};for(const n of this._def.values)e[n]=n;return e}extract(e,n=this._def){return J.create(e,{...this._def,...n})}exclude(e,n=this._def){return J.create(this.options.filter(r=>!e.includes(r)),{...this._def,...n})}}J.create=it;class st extends k{_parse(e){const n=b.getValidEnumValues(this._def.values),r=this._getOrReturnCtx(e);if(r.parsedType!==f.string&&r.parsedType!==f.number){const i=b.objectValues(n);return l(r,{expected:b.joinValues(i),received:r.parsedType,code:u.invalid_type}),g}if(this._cache||(this._cache=new Set(b.getValidEnumValues(this._def.values))),!this._cache.has(e.data)){const i=b.objectValues(n);return l(r,{received:r.data,code:u.invalid_enum_value,options:i}),g}return I(e.data)}get enum(){return this._def.values}}st.create=(t,e)=>new st({values:t,typeName:y.ZodNativeEnum,..._(e)});class oe extends k{unwrap(){return this._def.type}_parse(e){const{ctx:n}=this._processInputParams(e);if(n.parsedType!==f.promise&&n.common.async===!1)return l(n,{code:u.invalid_type,expected:f.promise,received:n.parsedType}),g;const r=n.parsedType===f.promise?n.data:Promise.resolve(n.data);return I(r.then(i=>this._def.type.parseAsync(i,{path:n.path,errorMap:n.common.contextualErrorMap})))}}oe.create=(t,e)=>new oe({type:t,typeName:y.ZodPromise,..._(e)});class Q extends k{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===y.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(e){const{status:n,ctx:r}=this._processInputParams(e),i=this._def.effect||null,s={addIssue:a=>{l(r,a),a.fatal?n.abort():n.dirty()},get path(){return r.path}};if(s.addIssue=s.addIssue.bind(s),i.type==="preprocess"){const a=i.transform(r.data,s);if(r.common.async)return Promise.resolve(a).then(async o=>{if(n.value==="aborted")return g;const c=await this._def.schema._parseAsync({data:o,path:r.path,parent:r});return c.status==="aborted"?g:c.status==="dirty"||n.value==="dirty"?K(c.value):c});{if(n.value==="aborted")return g;const o=this._def.schema._parseSync({data:a,path:r.path,parent:r});return o.status==="aborted"?g:o.status==="dirty"||n.value==="dirty"?K(o.value):o}}if(i.type==="refinement"){const a=o=>{const c=i.refinement(o,s);if(r.common.async)return Promise.resolve(c);if(c instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return o};if(r.common.async===!1){const o=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});return o.status==="aborted"?g:(o.status==="dirty"&&n.dirty(),a(o.value),{status:n.value,value:o.value})}else return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(o=>o.status==="aborted"?g:(o.status==="dirty"&&n.dirty(),a(o.value).then(()=>({status:n.value,value:o.value}))))}if(i.type==="transform")if(r.common.async===!1){const a=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});if(!F(a))return g;const o=i.transform(a.value,s);if(o instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:n.value,value:o}}else return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(a=>F(a)?Promise.resolve(i.transform(a.value,s)).then(o=>({status:n.value,value:o})):g);b.assertNever(i)}}Q.create=(t,e,n)=>new Q({schema:t,typeName:y.ZodEffects,effect:e,..._(n)}),Q.createWithPreprocess=(t,e,n)=>new Q({schema:e,effect:{type:"preprocess",transform:t},typeName:y.ZodEffects,..._(n)});class D extends k{_parse(e){return this._getType(e)===f.undefined?I(void 0):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}D.create=(t,e)=>new D({innerType:t,typeName:y.ZodOptional,..._(e)});class Y extends k{_parse(e){return this._getType(e)===f.null?I(null):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}Y.create=(t,e)=>new Y({innerType:t,typeName:y.ZodNullable,..._(e)});class ge extends k{_parse(e){const{ctx:n}=this._processInputParams(e);let r=n.data;return n.parsedType===f.undefined&&(r=this._def.defaultValue()),this._def.innerType._parse({data:r,path:n.path,parent:n})}removeDefault(){return this._def.innerType}}ge.create=(t,e)=>new ge({innerType:t,typeName:y.ZodDefault,defaultValue:typeof e.default=="function"?e.default:()=>e.default,..._(e)});class ye extends k{_parse(e){const{ctx:n}=this._processInputParams(e),r={...n,common:{...n.common,issues:[]}},i=this._def.innerType._parse({data:r.data,path:r.path,parent:{...r}});return re(i)?i.then(s=>({status:"valid",value:s.status==="valid"?s.value:this._def.catchValue({get error(){return new R(r.common.issues)},input:r.data})})):{status:"valid",value:i.status==="valid"?i.value:this._def.catchValue({get error(){return new R(r.common.issues)},input:r.data})}}removeCatch(){return this._def.innerType}}ye.create=(t,e)=>new ye({innerType:t,typeName:y.ZodCatch,catchValue:typeof e.catch=="function"?e.catch:()=>e.catch,..._(e)});class at extends k{_parse(e){if(this._getType(e)!==f.nan){const r=this._getOrReturnCtx(e);return l(r,{code:u.invalid_type,expected:f.nan,received:r.parsedType}),g}return{status:"valid",value:e.data}}}at.create=t=>new at({typeName:y.ZodNaN,..._(t)});class nr extends k{_parse(e){const{ctx:n}=this._processInputParams(e),r=n.data;return this._def.type._parse({data:r,path:n.path,parent:n})}unwrap(){return this._def.type}}class _e extends k{_parse(e){const{status:n,ctx:r}=this._processInputParams(e);if(r.common.async)return(async()=>{const s=await this._def.in._parseAsync({data:r.data,path:r.path,parent:r});return s.status==="aborted"?g:s.status==="dirty"?(n.dirty(),K(s.value)):this._def.out._parseAsync({data:s.value,path:r.path,parent:r})})();{const i=this._def.in._parseSync({data:r.data,path:r.path,parent:r});return i.status==="aborted"?g:i.status==="dirty"?(n.dirty(),{status:"dirty",value:i.value}):this._def.out._parseSync({data:i.value,path:r.path,parent:r})}}static create(e,n){return new _e({in:e,out:n,typeName:y.ZodPipeline})}}class ve extends k{_parse(e){const n=this._def.innerType._parse(e),r=i=>(F(i)&&(i.value=Object.freeze(i.value)),i);return re(n)?n.then(i=>r(i)):r(n)}unwrap(){return this._def.innerType}}ve.create=(t,e)=>new ve({innerType:t,typeName:y.ZodReadonly,..._(e)});var y;(function(t){t.ZodString="ZodString",t.ZodNumber="ZodNumber",t.ZodNaN="ZodNaN",t.ZodBigInt="ZodBigInt",t.ZodBoolean="ZodBoolean",t.ZodDate="ZodDate",t.ZodSymbol="ZodSymbol",t.ZodUndefined="ZodUndefined",t.ZodNull="ZodNull",t.ZodAny="ZodAny",t.ZodUnknown="ZodUnknown",t.ZodNever="ZodNever",t.ZodVoid="ZodVoid",t.ZodArray="ZodArray",t.ZodObject="ZodObject",t.ZodUnion="ZodUnion",t.ZodDiscriminatedUnion="ZodDiscriminatedUnion",t.ZodIntersection="ZodIntersection",t.ZodTuple="ZodTuple",t.ZodRecord="ZodRecord",t.ZodMap="ZodMap",t.ZodSet="ZodSet",t.ZodFunction="ZodFunction",t.ZodLazy="ZodLazy",t.ZodLiteral="ZodLiteral",t.ZodEnum="ZodEnum",t.ZodEffects="ZodEffects",t.ZodNativeEnum="ZodNativeEnum",t.ZodOptional="ZodOptional",t.ZodNullable="ZodNullable",t.ZodDefault="ZodDefault",t.ZodCatch="ZodCatch",t.ZodPromise="ZodPromise",t.ZodBranded="ZodBranded",t.ZodPipeline="ZodPipeline",t.ZodReadonly="ZodReadonly"})(y||(y={}));const S=$.create,ne=H.create,rr=he.create;M.create;const ir=N.create,U=x.create;se.create,ae.create,B.create;const ot=J.create;oe.create,D.create,Y.create;const sr=U({sku:S(),name:S(),imageUrl:S().url().optional(),price:S().optional(),originalPrice:S().optional(),discountPercent:ne().optional(),url:S().url(),brand:S().optional(),rating:ne().min(0).max(5).optional(),reviewCount:ne().int().nonnegative().optional()}),ar=U({layout:ot(["grid","carousel"]).optional(),columns:ne().int().positive().optional()}),or=U({product:sr,index:ne().int().nonnegative(),discountType:ot(["strike-through","badge"]).optional()}),cr=U({sku:S(),label:S().optional(),cartCode:S()}),dr=U({actions:ir(U({label:S(),action:U({title:S(),type:S(),payload:rr().optional()})}))}),ur=U({message:S().optional()}),lr={components:{ProductGrid:{schema:ar,description:"Outer grid or carousel container for similar products."},ProductCard:{schema:or,description:"A single product card with image, title, price, and actions."},AddToCartButton:{schema:cr,description:"Add-to-cart CTA rendered inside or below a product card."},QuickActions:{schema:dr,description:"A row of quick-action buttons below product info."},EmptyState:{schema:ur,description:"Empty state shown when no similar products are available."}}};class ct extends Lt{constructor(){super(...arguments),this._abortController=null,this._contentEl=null,this._i18n=Ve}async onInit(e){this._i18n=this._resolveI18n(e),this._contentEl=document.createElement("div"),this._contentEl.className="gengage-simrel-container",this.root.appendChild(this._contentEl),this._lastSku=e.sku,await this._fetchAndRender(e.sku),this.isVisible=!0}onUpdate(e){const n=e.sku;!n||n===this._lastSku||(this._lastSku=n,this._fetchAndRender(n))}onShow(){this._contentEl&&(this._contentEl.style.opacity="0",this._contentEl.style.transition="opacity 0.3s ease-in",requestAnimationFrame(()=>{this._contentEl&&(this._contentEl.style.opacity="1")}))}onHide(){}onDestroy(){this._abort(),this._contentEl&&(this._contentEl.remove(),this._contentEl=null)}_handleProductClick(e){const n={sku:e.sku,name:e.name,url:e.url};if(e.imageUrl!==void 0&&(n.imageUrl=e.imageUrl),e.price!==void 0&&(n.price=e.price),e.originalPrice!==void 0&&(n.originalPrice=e.originalPrice),e.discountPercent!==void 0&&(n.discountPercent=e.discountPercent),e.brand!==void 0&&(n.brand=e.brand),e.rating!==void 0&&(n.rating=e.rating),e.reviewCount!==void 0&&(n.reviewCount=e.reviewCount),e.cartCode!==void 0&&(n.cartCode=e.cartCode),e.inStock!==void 0&&(n.inStock=e.inStock),this.config.onProductClick?.(n)===!1)return;const r=this.config.session?.sessionId??null;ce("gengage:similar:product-click",{sku:e.sku,url:e.url,sessionId:r}),this.config.onProductNavigate?.(e.url,e.sku,r)}_handleAddToCart(e){this.config.onAddToCart?.(e),ce("gengage:similar:add-to-cart",e),this.track(yt(this.analyticsContext(),{attribution_source:"simrel",attribution_action_id:crypto.randomUUID(),cart_value:0,currency:"TRY",line_items:e.quantity,sku:e.sku}))}_abort(){this._abortController?.abort(),this._abortController=null}async _fetchAndRender(e){if(this._abort(),this._abortController=new AbortController,!this._contentEl)return;this._contentEl.innerHTML="";const n=document.createElement("div");n.className="gengage-simrel-loading";const r=document.createElement("div");r.className="gengage-simrel-spinner",n.appendChild(r),this._contentEl.appendChild(n);const i={middlewareUrl:this.config.middlewareUrl},s=crypto.randomUUID(),a=Date.now();this.track(ft(this.analyticsContext(),{endpoint:"similar_products",request_id:s,widget:"simrel"}));try{const o={account_id:this.config.accountId,session_id:this.config.session?.sessionId??"",correlation_id:this.config.session?.sessionId??"",sku:e};this.config.domain!==void 0&&(o.domain=this.config.domain);const c=await xn(o,i,this._abortController.signal);if(!this._contentEl)return;if(this._contentEl.innerHTML="",c.length>0)try{const d=c.map(v=>v.sku),p=await Tn({account_id:this.config.accountId,session_id:this.config.session?.sessionId??"",correlation_id:this.config.session?.sessionId??"",skus:d},i,this._abortController.signal);if(p.length>0&&this._contentEl){const v=this._buildGroupsSpec(p),C=this._renderUISpec(v);this._contentEl.appendChild(C);return}}catch{}if(this._contentEl){const d=this._buildProductsSpec(c),p=this._renderUISpec(d);this._contentEl.appendChild(p)}this.track(pt(this.analyticsContext(),{request_id:s,latency_ms:Date.now()-a,chunk_count:c.length,widget:"simrel"})),this.track(gt(this.analyticsContext(),{message_count:c.length,history_ref:s,redaction_level:"none",widget:"simrel"}))}catch(o){if(o instanceof DOMException&&o.name==="AbortError")return;ce("gengage:global:error",{source:"simrel",code:"FETCH_ERROR",message:St(this.config.locale)}),this.track(ht(this.analyticsContext(),{request_id:s,error_code:"FETCH_ERROR",error_message:o instanceof Error?o.message:String(o),widget:"simrel"})),this._contentEl&&(this._contentEl.innerHTML="",this._contentEl.style.display="none")}}_resolveI18n(e){return{...Nn(e.locale),...e.i18n}}_resolveUISpecRegistry(){const e=Ue();return lt(e,this.config.renderer?.registry)}_buildRenderContext(){const e=this.config.renderCard,n={onClick:r=>this._handleProductClick(r),onAddToCart:r=>this._handleAddToCart(r),i18n:this._i18n};return this.config.discountType!==void 0&&(n.discountType=this.config.discountType),e!==void 0&&(n.renderCard=e),n}_renderUISpec(e){const n=this._resolveUISpecRegistry(),r=this._buildRenderContext(),i=this.config.renderer?.unknownRenderer??le,s=(c,d)=>ze(c,d,n,i),a=this.config.renderer?.renderUISpec;return a?a(e,r,{registry:n,unknownRenderer:i,defaultRender:s}):s(e,r)}_buildProductsSpec(e){const n={},r=[];for(let i=0;i<e.length;i++){const s=e[i],a=`product-${i}`;r.push(a),n[a]={type:"ProductCard",props:{product:s,index:i,discountType:this.config.discountType}}}return n.root={type:"ProductGrid",props:{layout:"grid"},children:r},{root:"root",elements:n}}_buildGroupsSpec(e){return{root:"root",elements:{root:{type:"GroupTabs",props:{groups:e}}}}}}function fr(){return new ct}z.GengageSimRel=ct,z.createDefaultSimRelUISpecRegistry=Ue,z.createSimRelWidget=fr,z.defaultSimRelUnknownUISpecRenderer=le,z.renderSimRelUISpec=ze,z.simRelCatalog=lr,Object.defineProperty(z,Symbol.toStringTag,{value:"Module"})})(this.Gengage=this.Gengage||{});
46
+ `,document.head.appendChild(e)}class $n{constructor(){this.isVisible=!1,this.isInitialised=!1,this._handlers=new Map,this._cleanups=[],this._ownsRoot=!1,this._destroying=!1}async init(t){if(this.isInitialised){console.warn("[gengage] Widget already initialised. Call update() instead.");return}const n=hn(t.theme);this.config={...t,theme:n,session:gn(t.session)},this.root=this._resolveMount(t.mountTarget),this._applyTheme(n),wn();const r=Ne("gengage:context:update",o=>this.update(o));this._cleanups.push(r);try{await this.onInit(this.config)}catch(o){throw this.destroy(),o}this.isInitialised=!0,this.emit("ready")}update(t){this.isInitialised&&(this.config.pageContext?this.config={...this.config,pageContext:{...this.config.pageContext,...t}}:t.pageType!==void 0&&(this.config={...this.config,pageContext:t}),this.onUpdate(t),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(t=>t()),this._cleanups.length=0,this._handlers.clear(),this.onDestroy(),this.config.analyticsClient?.destroy(),this._ownsRoot?this.root.remove():this.root.innerHTML="",this.isInitialised=!1)}on(t,n){return this._handlers.has(t)||this._handlers.set(t,new Set),this._handlers.get(t).add(n),()=>this._handlers.get(t)?.delete(n)}trackCheckout(t,n){const r=t==="start"?pn:fn;this.track(r(this.analyticsContext(),n))}flushMeteringSummary(t){this.track(dn(this.analyticsContext(),t))}emit(t,...n){this._handlers.get(t)?.forEach(r=>r(...n))}addCleanup(t){this._cleanups.push(t)}track(t){this.config.analyticsClient?.track(t)}analyticsContext(){const t={account_id:this.config.accountId,session_id:this.config.session?.sessionId??"",correlation_id:this.config.session?.sessionId??""};return this.config.session?.viewId!==void 0&&(t.view_id=this.config.session.viewId),this.config.session?.userId!==void 0&&(t.user_id=this.config.session.userId),this.config.pageContext?.pageType!==void 0&&(t.page_type=this.config.pageContext.pageType),this.config.pageContext?.sku!==void 0&&(t.sku=this.config.pageContext.sku),this.config.session?.abTestVariant!==void 0&&(t.ab_test_variant=this.config.session.abTestVariant),this.config.session?.abTestExperimentId!==void 0&&(t.ab_test_experiment_id=this.config.session.abTestExperimentId),t}_resolveMount(t){if(t instanceof HTMLElement)return t;if(typeof t=="string"){const r=document.querySelector(t);if(!r)throw new Error(`[gengage] Mount target not found: "${t}"`);return r}const n=document.createElement("div");return n.dataset.gengageWidget=this.constructor.name.toLowerCase(),document.body.appendChild(n),this._ownsRoot=!0,n}_applyTheme(t){if(t){for(const[n,r]of Object.entries(t))if(r!==void 0){const o=n.startsWith("--")?n:`--gengage-${In(n)}`;this.root.style.setProperty(o,r)}}}}function In(e){return e.replace(/([A-Z])/g,"-$1").toLowerCase()}const An={process_action:"/process_action",launcher_action:"/launcher_action",similar_products:"/similar_products",product_groupings:"/product_groupings",proactive_action:"/proactive_action"},Pn={process_action:"/message",launcher_action:"/message"};function On(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 xe(e,t){const n=On(t?.middlewareUrl);if(t.backendType==="acap"){const r=t.accountId??"",o=Pn[e];if(o)return`${n}/api/chat/${r}${o}`}return`${n}/chat${An[e]}`}function Le(e){return typeof e=="object"&&e!==null&&typeof e.type=="string"}function Zn(e){const t=[];let n=0,r=!1,o=!1,s=0;for(let i=0;i<e.length;i++){const a=e[i];if(o){o=!1;continue}if(a==="\\"&&r){o=!0;continue}if(a==='"'){r=!r;continue}r||(a==="{"&&n++,a==="}"&&(n--,n===0&&(t.push(e.slice(s,i+1)),s=i+1)))}return t.length>0?t:[e]}function Ue(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!0;try{const o=JSON.parse(r);return Le(o)?(t.onEvent(o),o.type==="done"?(t.onDone?.(),!0):!1):!1}catch{const o=Zn(r);if(o.length>1){for(const s of o)try{const i=JSON.parse(s);if(!Le(i))continue;if(t.onEvent(i),i.type==="done")return t.onDone?.(),!0}catch{}return!1}return!1}}async function Me(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 s=t.idleTimeoutMs??6e4,i=Symbol("idle-timeout");let a=!1;try{for(;;){const c=n.read();let u;const d=await(s>0?Promise.race([c.then(p=>(clearTimeout(u),p)),new Promise(p=>{u=setTimeout(()=>p(i),s)})]):c);if(d===i){a=!0,await n.cancel();break}const{done:f,value:g}=d;if(f)break;o+=r.decode(g,{stream:!0});const m=o.split(`
47
+ `);o=m.pop()??"";for(const p of m)if(Ue(p,t))return}if(o.trim()&&Ue(o,t))return}catch(c){if(c instanceof DOMException&&c.name==="AbortError")return;t.onError?.(c instanceof Error?c:new Error(String(c)))}finally{a||n.releaseLock()}t.onDone?.()}function Fe(e){if(typeof e.type!="string")return null;if(Nn(e))return e;const n=e;switch(n.type){case"outputText":return Rn(n);case"suggestedActions":return Dn(n);case"productList":return jn(n);case"productDetails":return xn(n);case"productDetailsSimilars":return Ln(n);case"comparisonTable":return Un(n);case"context":return Mn(n);case"chatStreamEnd":return Fn();case"loading":return Jn(n);case"panelLoading":return qn(n);case"similarLoading":return Gn(n);case"redirect":return Bn(n);case"error":return Vn(n);case"dummy":return Wn();case"launcherAction":return Hn(n);case"text":return me(n);case"productItem":return Kn(n);case"text_image":return Je(n);case"quick_qna":return qe(n);case"reviewHighlights":return Yn(n);case"aiProductSuggestions":return er(n);case"aiProductGroupings":return tr(n);case"aiSuggestedSearches":return nr(n);case"prosAndCons":return Qn(n);case"getGroundingReview":return rr(n);case"voice":return ir(n);case"visitorDataResponse":return Xn(n);case"productListPreview":return or();case"groupList":return sr(n);case"formGetInfo":case"formTestDrive":case"formServiceRequest":case"launchFormPage":return ar(n);case"launcherContent":return ur(n);case"handoff":return cr(n);default:return null}}function Nn(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=F(e.spec);return r?typeof r.root=="string"&&F(r.elements)!==null:!1}case"action":{const n=F(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 Rn(e){const t=v(e.payload.text,e.payload.plain_text)??"",n=v(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(a=>typeof a=="object"&&a!==null&&typeof a.sku=="string"&&typeof a.short_name=="string"));const s=e.payload.sku_to_product_item;s&&typeof s=="object"&&!Array.isArray(s)&&(r.skuToProductItem=s);const i=e.payload.conversation_mode;return typeof i=="string"&&i&&(r.conversationMode=i),r}function Dn(e){const t=(e.payload.actions??[]).map(n=>{const r=v(n.title)??"",o=R(n.requestDetails,r),s=o?{label:r,action:o}:null;return s?(typeof n.icon=="string"&&(s.icon=n.icon),typeof n.image=="string"&&(s.image=n.image),s):null});return Ge(t.filter(Ve),"chat")}function jn(e){const t=Be(e.payload.product_list??[],"chat");t.panelHint="panel";const n=t.spec.elements[t.spec.root];return n&&(typeof e.payload.offset=="number"&&(n.props={...n.props,offset:e.payload.offset}),typeof e.payload.end_of_list=="boolean"&&(n.props={...n.props,endOfList:e.payload.end_of_list})),t}function xn(e){const t=e.payload.productDetails;return t?{type:"ui_spec",widget:"chat",spec:{root:"root",elements:{root:{type:"ProductDetailsPanel",props:{product:D(t)}}}},panelHint:"panel"}:lr("chat")}function Ln(e){const t=Be(e.payload.similarProducts??[],"chat"),n=t.spec.elements[t.spec.root];return n&&(n.props={...n.props,similarsAppend:!0}),{...t,panelHint:"panel"}}function Un(e){const t=e.payload.multiple_product_details??[],n=e.payload.product_comparison_framework,r=e.payload.table,o=[];for(const p of t){const h=D(p);o.push(h)}const s=[];if(r){const p=n?.criteria_view??n?.criteria_view_short??{},h=n?.compared_field_names??Object.keys(r);for(const z of h){const P=r[z];if(!P||!Array.isArray(P))continue;const Pe=p[z]??z;s.push({label:Pe,values:P.map(I=>typeof I=="string"?I:String(I??""))})}}let i;n?.recommended_choice_sku?i=n.recommended_choice_sku:n?.winner_product&&n.winner_product.length>0&&(i=n.winner_product[0]?.product_detail?.sku??n.winner_product[0]?.sku);const a=i?o.find(p=>p.sku===i)??o[0]:o[0],c=[];if(Array.isArray(n?.key_differences))for(const p of n.key_differences)typeof p=="string"&&c.push(p);const u=[];if(n?.special_considerations)for(const p of n.special_considerations)typeof p=="string"&&u.push(p);const d=n?.recommended_choice,f=n?.winner_hits,g={};for(const p of o){const h=p.sku;h&&(g[h]={title:p.name??h,type:"launchSingleProduct",payload:{sku:h}})}const m={products:o,attributes:s,highlights:c,productActions:g};return a&&(m.recommended=a),u.length>0&&(m.specialCases=u),d&&(m.recommendedText=d),f&&(m.winnerHits=f),typeof n?.key_differences=="string"&&(m.keyDifferencesHtml=n.key_differences),n?.special_considerations&&(m.specialConsiderations=n.special_considerations),{type:"ui_spec",widget:"chat",spec:{root:"root",elements:{root:{type:"ComparisonTable",props:m}}},panelHint:"panel"}}function Mn(e){return{type:"metadata",sessionId:"",model:"",meta:{panel:e.payload.panel,messages:e.payload.messages,message_id:e.payload.message_id}}}function Fn(){return{type:"done"}}function Jn(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 qn(e){return{type:"metadata",sessionId:"",model:"",meta:{loading:!0,panelLoading:!0,panelPendingType:e.payload?.pending_type,loadingText:e.payload?.text}}}function Gn(e){return{type:"metadata",sessionId:"",model:"",meta:{loading:!0,similarPanelLoading:!0,panelPendingType:e.payload?.pending_type,loadingText:e.payload?.text}}}function Bn(e){const t=v(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:v(e.payload.to)}}}function Vn(e){return{type:"error",code:"BACKEND_ERROR",message:v(e.payload?.text,e.payload?.message,e.payload?.error)??"Backend returned an error"}}function Wn(e){return{type:"metadata",sessionId:"",model:"",meta:{noop:!0}}}function Hn(e){const t=e.payload??{};if(Array.isArray(t.action_list)){const s={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&&(s.type=i),a!==void 0&&(s.theme=a),qe({payload:s})}const r=F(t.action);if(r){const s={action:r},i=typeof t.text=="string"?t.text:void 0,a=typeof t.image_url=="string"?t.image_url:void 0,c=typeof t.theme=="string"?t.theme:void 0;return i!==void 0&&(s.text=i),a!==void 0&&(s.image_url=a),c!==void 0&&(s.theme=c),Je({payload:s})}const o=typeof t.text=="string"?t.text:"";if(o){const s={text:o},i=typeof t.type=="string"?t.type:void 0,a=typeof t.theme=="string"?t.theme:void 0,c=F(t.payload)??void 0;return i!==void 0&&(s.type=i),c!==void 0&&(s.payload=c),a!==void 0&&(s.theme=a),me({payload:s})}return{type:"metadata",sessionId:"",model:"",meta:{launcherAction:t}}}function me(e){const t={text:v(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 Kn(e){return dr(e.payload,"qna")}function Je(e){const t=v(e.payload.text)??"",n=R(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),me({payload:r})}function qe(e){const t=(e.payload.action_list??[]).map(n=>{const r=v(n.title)??"",o=R(n.requestDetails,r),s=o?{label:r,action:o}:null;return s?(typeof n.icon=="string"&&(s.icon=n.icon),typeof n.image=="string"&&(s.image=n.image),s):null});return Ge(t.filter(Ve),"qna")}function Yn(e){const n={reviews:(e.payload.reviews??[]).map(r=>{const o={};return typeof r.review_class=="string"&&(o.review_class=r.review_class),typeof r.review_text=="string"&&(o.review_text=r.review_text),(typeof r.review_rating=="string"||typeof r.review_rating=="number")&&(o.review_rating=r.review_rating),typeof r.review_tag=="string"&&(o.review_tag=r.review_tag),o})};return typeof e.payload.sku=="string"&&(n.sku=e.payload.sku),{type:"ui_spec",widget:"chat",spec:{root:"root",elements:{root:{type:"ReviewHighlights",props:n}}}}}function Qn(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 Xn(e){return{type:"metadata",sessionId:"",model:"",meta:{visitorDataResponse:e.payload}}}function er(e){const t=e.payload.product_suggestions??[],n=[];for(let r=0;r<t.length;r++){const o=t[r];if(!o)continue;const s=pr(o);if(!s)continue;const i={product:s},a=R(o.requestDetails,s.name);a&&(i.action=a),typeof o.role=="string"&&(i.role=o.role),typeof o.reason=="string"&&(i.reason=o.reason),typeof o.review_highlight=="string"&&(i.reviewHighlight=o.review_highlight),Array.isArray(o.labels)&&(i.labels=o.labels),typeof o.expert_quality_score=="number"&&(i.expertQualityScore=o.expert_quality_score),n.push(i)}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 tr(e){const t=e.payload.product_groupings??[],n=[];for(let r=0;r<t.length;r++){const o=t[r];if(!o)continue;const s=v(o.name)??"",i=o.sku&&o.sku.length>0?{type:"findSimilar",payload:{sku:o.sku}}:void 0,a=R(o.requestDetails??i,s);if(!a)continue;const c={name:s,action:a};if(Array.isArray(o.labels)){const u=o.labels.filter(d=>typeof d=="string");u.length>0&&(c.labels=u)}typeof o.image=="string"&&(c.image=o.image),n.push(c)}return n.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:n}}}}}}function nr(e){const t=e.payload.suggested_searches??[],n=[];for(let r=0;r<t.length;r++){const o=t[r];if(!o)continue;const s=v(o.short_name,o.chosen_attribute,o.detailed_user_message)??`Arama ${r+1}`,i={},a=v(o.detailed_user_message);a&&(i.text=a),o.group_skus&&Array.isArray(o.group_skus)&&(i.group_skus=o.group_skus);const c=v(o.sku,o.representative_product_sku);c&&(i.sku=c),i.is_suggested_text=1;const u={type:"inputText",payload:i},d=R(o.requestDetails??u,s);if(!d)continue;const f={shortName:s,action:d},g=v(o.detailed_user_message);g&&g!==s&&(f.detailedMessage=g);const m=v(o.why_different);m&&(f.whyDifferent=m),typeof o.image=="string"&&(f.image=o.image),n.push(f)}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 rr(e){const t=R(e.payload.requestDetails,v(e.payload.review_count,e.payload.text,e.payload.title)??"Urun yorumlarini goster");if(!t)return{type:"metadata",sessionId:"",model:"",meta:{groundingReview:e.payload}};const n={action:t};return e.payload.title&&(n.title=e.payload.title),e.payload.text&&(n.text=e.payload.text),e.payload.review_count&&(n.reviewCount=e.payload.review_count),{type:"ui_spec",widget:"chat",spec:{root:"root",elements:{root:{type:"GroundingReviewCard",props:n}}}}}function or(){return{type:"metadata",sessionId:"",model:"",meta:{analyzeAnimation:!0}}}function ir(e){return{type:"metadata",sessionId:"",model:"",meta:{voice:e.payload}}}function sr(e){const t=e.payload.group_list??[],n=[];for(const o of t){const s=o.group_name??"",i=(o.product_list??[]).map(D);n.push({groupName:s,products:i})}const r=[];for(const o of e.payload.filter_tags??[]){const s=o.title??"";if(!s)continue;const i=R(o.requestDetails,s),a={title:s};i&&(a.action=i),r.push(a)}return{type:"ui_spec",widget:"chat",spec:{root:"root",elements:{root:{type:"CategoriesContainer",props:{groups:n,filterTags:r}}}},panelHint:"panel"}}function ar(e){return{type:"metadata",sessionId:"",model:"",meta:{formType:e.type,formPayload:e.payload??{}}}}function cr(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 ur(e){return{type:"metadata",sessionId:"",model:"",meta:{launcherContent:e.payload??{}}}}function Ge(e,t){const n={},r=[];for(let o=0;o<e.length;o++){const s=e[o];if(!s)continue;const i=`action-${o}`;r.push(i);const a={label:s.label,action:s.action};s.icon!==void 0&&(a.icon=s.icon),s.image!==void 0&&(a.image=s.image),s.description!==void 0&&(a.description=s.description),n[i]={type:"ActionButton",props:a}}return n.root={type:"ActionButtons",props:{buttons:e.map(o=>{const s={label:o.label,action:o.action};return o.image!==void 0&&(s.image=o.image),o.description!==void 0&&(s.description=o.description),o.icon!==void 0&&(s.icon=o.icon),s})},children:r},{type:"ui_spec",widget:t,spec:{root:"root",elements:n}}}function Be(e,t){const n={},r=[];for(let o=0;o<e.length;o++){const s=e[o];if(!s)continue;const i=`product-${o}`;r.push(i),n[i]={type:"ProductCard",props:{product:D(s),index:o}}}return n.root={type:"ProductGrid",props:{layout:"grid"},children:r},{type:"ui_spec",widget:t,spec:{root:"root",elements:n}}}function dr(e,t){return{type:"ui_spec",widget:t,spec:{root:"root",elements:{root:{type:"ProductCard",props:{product:D(e),index:0}}}}}}function lr(e){return{type:"ui_spec",widget:e,spec:{root:"root",elements:{root:{type:"ActionButtons",props:{buttons:[]},children:[]}}}}}function pr(e){const t=v(e.sku),n=v(e.short_name),r=F(e.product_item)??e;return fr(r,t,n)}function fr(e,t,n){const r=v(e.sku,t),o=v(e.name,n);if(!r||!o)return null;const s={sku:r,name:o},i=v(e.brand);i&&(s.brand=i);const a=v(e.url);a&&(s.url=a);const c=mr(e.images);if(c.length>0)s.images=c;else{const p=v(e.image,e.image_url,e.imageUrl);p&&(s.images=[p])}const u=H(e.price_discounted);u!==void 0&&(s.price_discounted=u);const d=H(e.price);d!==void 0&&(s.price=d);const f=H(e.rating);f!==void 0&&(s.rating=f);const g=H(e.review_count)??H(e.reviewCount);g!==void 0&&(s.review_count=g);const m=v(e.cart_code,e.cartCode);return m&&(s.cart_code=m),typeof e.in_stock=="boolean"&&(s.in_stock=e.in_stock),typeof e.inStock=="boolean"&&(s.in_stock=e.inStock),D(s)}function R(e,t){const n=F(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 F(e){return!e||typeof e!="object"||Array.isArray(e)?null:e}function v(...e){for(const t of e)if(typeof t=="string"){const n=t.trim();if(n.length>0)return n}}function mr(e){return Array.isArray(e)?e.filter(t=>typeof t=="string"&&t.length>0):[]}function H(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 Ve(e){return e!=null}function D(e){const t=e.price_discounted!=null&&e.price_discounted>0?e.price_discounted:e.price,n=e.price_discounted!=null&&e.price_discounted>0&&e.price!=null?e.price:void 0;let r;n!=null&&t!=null&&n>0&&(r=Math.round((n-t)/n*100));const o=v(e.brand),s=v(e.name)??e.sku,i=o&&!s.toLowerCase().startsWith(o.toLowerCase())?`${o} ${s}`:s,a={sku:e.sku,name:i,url:v(e.url)??""},c=e.images?.[0];return c&&(a.imageUrl=c),e.images&&e.images.length>1&&(a.images=e.images),t!=null&&(a.price=String(t)),n!=null&&(a.originalPrice=String(n)),r!==void 0&&(a.discountPercent=r),o!==void 0&&(a.brand=o),e.rating!==void 0&&(a.rating=e.rating),e.review_count!==void 0&&(a.reviewCount=e.review_count),e.cart_code!==void 0&&(a.cartCode=e.cart_code),e.in_stock!==void 0&&(a.inStock=e.in_stock),e.variants&&e.variants.length>0&&(a.variants=e.variants),e.discount_reason!==void 0&&(a.discountReason=e.discount_reason),e.promotions&&e.promotions.length>0&&(a.promotions=e.promotions),a}function gr(e){return e.results.map(D)}function hr(e){return e.product_groupings.map(t=>{const n={name:t.name,products:(t.group_products??[]).map(D)};return t.highlight!==void 0&&(n.highlight=t.highlight),n})}function We(e){const t=e.headers.get("Content-Type")??"";return t.includes("application/x-ndjson")||t.includes("text/event-stream")}async function _r(e,t){const n=[],r={onEvent:o=>{const s=Fe(o);if(!(!s||s.type!=="ui_spec")){for(const i of Object.values(s.spec.elements))if(i.type==="ProductCard"&&i.props){const a=i.props.product??i.props;typeof a.sku=="string"&&typeof a.name=="string"&&n.push(a)}}}};return t!==void 0&&(r.signal=t),await Me(e,r),n}async function yr(e,t,n){const r=xe("similar_products",t),o={method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)};n!==void 0&&(o.signal=n);const s=await fetch(r,o);if(!s.ok)throw new Error(`HTTP ${s.status}: ${s.statusText}`);if(We(s))return _r(s,n);const i=await s.text();if(!i)return[];try{return gr(JSON.parse(i))}catch{throw new Error("Invalid JSON from similar_products endpoint")}}async function vr(e,t){const n=[];let r=null;const o={onEvent:s=>{const i=Fe(s);if(i){if(i.type==="metadata"&&i.meta){const a=i.meta.group_name;if(typeof a=="string"){r={name:a,products:[]};const c=i.meta.highlight;typeof c=="string"&&(r.highlight=c),n.push(r)}}if(i.type==="ui_spec"&&r){for(const a of Object.values(i.spec.elements))if(a.type==="ProductCard"&&a.props){const c=a.props.product??a.props;typeof c.sku=="string"&&typeof c.name=="string"&&r.products.push(c)}}}}};return t!==void 0&&(o.signal=t),await Me(e,o),n}async function br(e,t,n){const r=xe("product_groupings",t),o={method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)};n!==void 0&&(o.signal=n);const s=await fetch(r,o);if(!s.ok)throw new Error(`HTTP ${s.status}: ${s.statusText}`);if(We(s))return vr(s,n);const i=await s.text();if(!i)return[];try{return hr(JSON.parse(i))}catch{throw new Error("Invalid JSON from product_groupings endpoint")}}const wr={currencySymbol:"TL",currencyPosition:"suffix",thousandsSeparator:".",decimalSeparator:",",alwaysShowDecimals:!1};function He(e,t){const n=Number(e);if(!Number.isFinite(n)||n<0)return e;const r={...wr,...t},s=n%1!==0||r.alwaysShowDecimals?n.toFixed(2):n.toFixed(0),i=s.indexOf("."),a=i===-1?s:s.slice(0,i),c=i===-1?void 0:s.slice(i+1),u=a.replace(/\B(?=(\d{3})+(?!\d))/g,r.thousandsSeparator);let d;return c!==void 0?d=`${u}${r.decimalSeparator}${c}`:d=u,r.currencySymbol?r.currencyPosition==="prefix"?`${r.currencySymbol}${d}`:`${d} ${r.currencySymbol}`:d}const kr=new Set(["p","br","a","strong","b","em","i","u","ul","ol","li","h1","h2","h3","h4","h5","h6","span","div","table","thead","tbody","tr","th","td","hr","code","pre","blockquote","img","sup","sub"]),Sr=new Set(["script","iframe","object","embed","form","input","textarea","select","button","style","link","meta"]),Ke={"*":new Set(["class"]),a:new Set(["href","target","rel"]),img:new Set(["src","alt","width","height"]),div:new Set(["style"]),span:new Set(["style"]),p:new Set(["style"])};function zr(e){return/^\s*javascript\s*:/i.test(e)}function ge(e,t){if(e.nodeType===Node.TEXT_NODE)return;if(e.nodeType!==Node.ELEMENT_NODE){e.parentNode?.removeChild(e);return}const n=e,r=n.tagName.toLowerCase();if(Sr.has(r)){n.parentNode?.removeChild(n);return}if(!kr.has(r)){const c=Array.from(n.childNodes);for(const u of c)t.insertBefore(u,n);t.removeChild(n);for(const u of c)ge(u,t);return}const o=Ke["*"]??new Set,s=Ke[r]??new Set,i=Array.from(n.attributes);for(const c of i){const u=c.name.toLowerCase();if(!o.has(u)&&!s.has(u)){n.removeAttribute(c.name);continue}if(zr(c.value)){n.removeAttribute(c.name);continue}}if(r==="a"){const c=n.getAttribute("href");if(c!==null){const u=c.trim().toLowerCase();!u.startsWith("http://")&&!u.startsWith("https://")&&!u.startsWith("mailto:")&&n.removeAttribute("href")}n.setAttribute("target","_blank"),n.setAttribute("rel","noopener noreferrer")}if(r==="img"){const c=n.getAttribute("src");c!==null&&(c.trim().toLowerCase().startsWith("https://")||n.removeAttribute("src"))}const a=Array.from(n.childNodes);for(const c of a)ge(c,n)}const Er=["http:","https:"];function Cr(e){try{return Er.includes(new URL(e).protocol)}catch{return!1}}function Tr(e){if(!e)return"";const n=new DOMParser().parseFromString(e,"text/html").body,r=Array.from(n.childNodes);for(const o of r)ge(o,n);return n.innerHTML}function $r(e){const t=e.min??1,n=e.max??99,r=Math.min(t,n),o=Math.max(t,n);let i=Math.max(r,Math.min(o,e.initial??r));const a=document.createElement("div");a.className="gengage-qty-stepper";const c=document.createElement("button");c.className="gengage-qty-btn",c.type="button",c.textContent=e.decreaseSymbol??"−",c.setAttribute("aria-label",e.decreaseLabel??"Azalt");const u=document.createElement("span");u.className="gengage-qty-value",u.textContent=String(i),u.setAttribute("aria-live","polite"),u.setAttribute("aria-atomic","true");const d=document.createElement("button");d.className="gengage-qty-btn",d.type="button",d.textContent=e.increaseSymbol??"+",d.setAttribute("aria-label",e.increaseLabel??"Artır");const f=document.createElement("button");f.className="gengage-qty-submit",f.type="button",f.textContent=e.label??"Sepete Ekle";function g(){c.disabled=i<=r,d.disabled=i>=o}return c.addEventListener("click",m=>{m.stopPropagation(),i>r&&(i--,u.textContent=String(i),g())}),d.addEventListener("click",m=>{m.stopPropagation(),i<o&&(i++,u.textContent=String(i),g())}),f.addEventListener("click",m=>{m.stopPropagation(),e.onSubmit(i)}),a.addEventListener("click",m=>{m.stopPropagation()}),g(),a.appendChild(c),a.appendChild(u),a.appendChild(d),a.appendChild(f),a}function Ir(e){return Number.isFinite(e)?Math.max(0,Math.min(5,e)):0}function Ar(e){return Number.isFinite(e)?Math.max(0,Math.min(100,Math.round(e))):0}function Pr(e,t=!0){const n=Ir(e);if(t){const o=Math.floor(n),s=n-o>=.5?1:0,i=5-o-s;return"★".repeat(o)+(s?"½":"")+"☆".repeat(i)}const r=Math.round(n);return"★".repeat(r)+"☆".repeat(5-r)}function Or(e){e.addEventListener("error",()=>{e.style.display="none"},{once:!0})}function Ye(e){const{product:t,index:n,discountType:r,onClick:o,onAddToCart:s,renderCard:i}=e,a=e.i18n,c=e.pricing;if(i){const p=document.createElement("div");return p.className="gengage-simrel-card gengage-simrel-card--custom",p.innerHTML=Tr(i(t,n)),p.addEventListener("click",h=>{h.target.closest(".gengage-simrel-atc")||o(t)}),p}const u=document.createElement("article");u.className="gengage-simrel-card",u.setAttribute("role","listitem"),u.dataset.sku=t.sku;const d=document.createElement("div");if(d.className="gengage-simrel-card-image",t.imageUrl&&Cr(t.imageUrl)){const p=document.createElement("img");p.src=t.imageUrl,p.alt=t.name,p.loading="lazy",Or(p),d.appendChild(p)}if(r==="badge"&&t.discountPercent&&t.discountPercent>0){const p=document.createElement("span");p.className="gengage-simrel-badge",p.textContent=`%${Ar(t.discountPercent)}`,d.appendChild(p)}u.appendChild(d);const f=document.createElement("div");if(f.className="gengage-simrel-card-info",t.brand){const p=document.createElement("div");p.className="gengage-simrel-card-brand",p.textContent=t.brand,f.appendChild(p)}const g=document.createElement("div");if(g.className="gengage-simrel-card-name",g.textContent=t.name,f.appendChild(g),t.rating!=null&&t.rating>0){const p=document.createElement("div");if(p.className="gengage-simrel-card-rating",p.textContent=Pr(t.rating),t.reviewCount!=null){const h=document.createElement("span");h.className="gengage-simrel-card-review-count",h.textContent=` (${t.reviewCount})`,p.appendChild(h)}f.appendChild(p)}const m=document.createElement("div");if(m.className="gengage-simrel-card-price",t.originalPrice&&t.originalPrice!==t.price&&(r==="strike-through"||!r)){const p=document.createElement("span");p.className="gengage-simrel-card-price-original",p.textContent=He(t.originalPrice,c),m.appendChild(p)}if(t.price){const p=document.createElement("span");p.className="gengage-simrel-card-price-current",p.textContent=He(t.price,c),m.appendChild(p)}if(f.appendChild(m),u.appendChild(f),t.cartCode){const p=t.cartCode,h=$r({compact:!1,label:a?.addToCartButton??"Sepete Ekle",onSubmit:z=>{s({sku:t.sku,quantity:z,cartCode:p})}});h.classList.add("gengage-simrel-atc"),u.appendChild(h)}return u.addEventListener("click",p=>{p.target.closest(".gengage-simrel-atc")||o(t)}),u}function Qe(e){const t=document.createElement("div");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));for(let n=0;n<e.products.length;n++){const o={product:e.products[n],index:n,onClick:e.onClick,onAddToCart:e.onAddToCart};e.i18n!==void 0&&(o.i18n=e.i18n),e.discountType!==void 0&&(o.discountType=e.discountType),e.renderCard!==void 0&&(o.renderCard=e.renderCard);const s=Ye(o);t.appendChild(s)}if(e.products.length===0){const n=document.createElement("div");n.className="gengage-simrel-empty",n.textContent=e.i18n?.emptyStateMessage??"Benzer ürün bulunamadı.",t.appendChild(n)}return t}let Zr=0;function Nr(e){const t=Zr++,n=document.createElement("div");if(n.className="gengage-simrel-groups",e.groups.length===0){const d=document.createElement("div");return d.className="gengage-simrel-empty",d.textContent=e.i18n?.emptyStateMessage??"Benzer ürün bulunamadı.",n.appendChild(d),n}const r=document.createElement("div");r.className="gengage-simrel-tabs",r.setAttribute("role","tablist");const o=[],s=[],i=d=>{const f={products:d.products,onClick:e.onClick,onAddToCart:e.onAddToCart};return e.i18n!==void 0&&(f.i18n=e.i18n),e.discountType!==void 0&&(f.discountType=e.discountType),e.renderCard!==void 0&&(f.renderCard=e.renderCard),f},a=d=>{for(let p=0;p<o.length;p++){const h=p===d;o[p].classList.toggle("gengage-simrel-tab--active",h),o[p].setAttribute("aria-selected",String(h)),o[p].tabIndex=h?0:-1}const f=e.groups[d],g=s[d];g.innerHTML="";const m=Qe(i(f));g.appendChild(m);for(let p=0;p<s.length;p++){const h=p===d;s[p].style.display=h?"":"none",s[p].tabIndex=h?0:-1}};for(let d=0;d<e.groups.length;d++){const f=e.groups[d],g=`gengage-simrel-tab-${t}-${d}`,m=`gengage-simrel-panel-${t}-${d}`,p=document.createElement("button");p.className="gengage-simrel-tab",p.type="button",p.id=g,p.textContent=f.name,p.setAttribute("role","tab"),p.setAttribute("aria-controls",m),p.setAttribute("aria-selected",String(d===0)),p.tabIndex=d===0?0:-1,d===0&&p.classList.add("gengage-simrel-tab--active"),p.addEventListener("click",()=>a(d)),p.addEventListener("keydown",z=>{let P=-1;z.key==="ArrowRight"||z.key==="ArrowDown"?P=(d+1)%e.groups.length:z.key==="ArrowLeft"||z.key==="ArrowUp"?P=(d-1+e.groups.length)%e.groups.length:z.key==="Home"?P=0:z.key==="End"&&(P=e.groups.length-1),P>=0&&(z.preventDefault(),a(P),o[P].focus())}),o.push(p),r.appendChild(p);const h=document.createElement("div");h.className="gengage-simrel-tab-panel",h.id=m,h.setAttribute("role","tabpanel"),h.setAttribute("aria-labelledby",g),h.tabIndex=d===0?0:-1,d!==0&&(h.style.display="none"),s.push(h)}n.appendChild(r);const c=s[0],u=Qe(i(e.groups[0]));c.appendChild(u);for(const d of s)n.appendChild(d);return n}function Xe(e){if(!e||typeof e!="object")return null;const t=e;if(typeof t.sku!="string"||typeof t.name!="string"||typeof t.url!="string")return null;const n={sku:t.sku,name:t.name,url:t.url},r=t.imageUrl;typeof r=="string"&&(n.imageUrl=r);const o=t.price;typeof o=="string"&&(n.price=o);const s=t.originalPrice;typeof s=="string"&&(n.originalPrice=s);const i=t.discountPercent;typeof i=="number"&&(n.discountPercent=i);const a=t.brand;typeof a=="string"&&(n.brand=a);const c=t.rating;typeof c=="number"&&(n.rating=c);const u=t.reviewCount;typeof u=="number"&&(n.reviewCount=u);const d=t.cartCode;typeof d=="string"&&(n.cartCode=d);const f=t.inStock;return typeof f=="boolean"&&(n.inStock=f),n}function Rr(e){if(!e||typeof e!="object")return null;const t=e,n=t.title,r=t.type;if(typeof n!="string"||typeof r!="string")return null;const o={title:n,type:r};return t.payload!==void 0&&(o.payload=t.payload),o}const et={ProductGrid:({element:e,renderElement:t,context:n})=>{const r=document.createElement("div");r.className="gengage-simrel-grid",r.setAttribute("role","list");const o=e.props?.columns;typeof o=="number"&&Number.isFinite(o)&&o>0&&r.style.setProperty("--gengage-simrel-columns",String(o));for(const s of e.children??[]){const i=t(s);i&&r.appendChild(i)}if(r.children.length===0){const s=document.createElement("div");s.className="gengage-simrel-empty",s.textContent=n.i18n.emptyStateMessage,r.appendChild(s)}return r},ProductCard:({element:e,context:t})=>{const n=e.props?.product??e.props,r=Xe(n);if(!r)return null;const o=e.props?.index,s=typeof o=="number"&&Number.isFinite(o)?o:0,i=e.props?.discountType,a=i==="strike-through"||i==="badge"?i:t.discountType,c={product:r,index:s,onClick:t.onClick,onAddToCart:t.onAddToCart,i18n:t.i18n};return a!==void 0&&(c.discountType=a),t.renderCard!==void 0&&(c.renderCard=t.renderCard),t.pricing!==void 0&&(c.pricing=t.pricing),Ye(c)},GroupTabs:({element:e,context:t})=>{const n=e.props?.groups;if(!Array.isArray(n))return null;const r=[];for(const s of n){if(!s||typeof s!="object")continue;const i=s;if(typeof i.name!="string")continue;const a=[];if(Array.isArray(i.products))for(const u of i.products){const d=Xe(u);d&&a.push(d)}const c={name:i.name,products:a};typeof i.highlight=="string"&&(c.highlight=i.highlight),r.push(c)}const o={groups:r,onClick:t.onClick,onAddToCart:t.onAddToCart,i18n:t.i18n};return t.discountType!==void 0&&(o.discountType=t.discountType),t.renderCard!==void 0&&(o.renderCard=t.renderCard),Nr(o)},EmptyState:({element:e,context:t})=>{const n=document.createElement("div");n.className="gengage-simrel-empty";const r=e.props?.message;return n.textContent=typeof r=="string"?r:t.i18n.emptyStateMessage,n},AddToCartButton:({element:e,context:t})=>{const n=e.props?.sku,r=e.props?.cartCode;if(typeof n!="string"||typeof r!="string")return null;const o=document.createElement("button");o.className="gengage-simrel-atc",o.type="button";const s=e.props?.label;return o.textContent=typeof s=="string"?s:t.i18n.addToCartButton,o.addEventListener("click",i=>{i.preventDefault(),i.stopPropagation(),t.onAddToCart({sku:n,quantity:1,cartCode:r})}),o},QuickActions:({element:e,context:t})=>{const n=document.createElement("div");n.className="gengage-simrel-quick-actions";const r=e.props?.actions;if(!Array.isArray(r)||!t.onAction)return n;for(const o of r){if(!o||typeof o!="object")continue;const s=o,i=s.label,a=Rr(s.action);if(typeof i!="string"||!a)continue;const c=document.createElement("button");c.className="gengage-simrel-quick-action",c.type="button",c.textContent=i,c.addEventListener("click",u=>{u.preventDefault(),u.stopPropagation(),t.onAction?.(a)}),n.appendChild(c)}return n}},he=({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 tt(){return{...et}}function nt(e,t,n=et,r=he){return sn({spec:e,context:t,registry:n,containerClassName:"gengage-simrel-uispec",unknownRenderer:r})}const rt={similarProductsAriaLabel:"Benzer ürünler",emptyStateMessage:"Benzer ürün bulunamadı.",addToCartButton:"Sepete Ekle",priceSuffix:" TL"},Dr={similarProductsAriaLabel:"Similar products",emptyStateMessage:"No similar products found.",addToCartButton:"Add to cart",priceSuffix:""};function jr(e){return e?e.toLowerCase().split("-")[0]??"tr":"tr"}function xr(e){return jr(e)==="en"?Dr:rt}function Lr(){return typeof window<"u"&&Array.isArray(window.dataLayer)}function ee(e,t){const n={event:e,...t};Lr()&&window.dataLayer.push(n)}function Ur(e){ee("gengage-on-init",{gengage_widget:e})}function ot(e){ee("gengage-show",{gengage_widget:e})}function Mr(e,t){ee("gengage-product-detail",{gengage_sku:e,gengage_product_name:t})}function Fr(e,t){ee("gengage-cart-add",{gengage_sku:e,gengage_quantity:t})}function l(e,t,n){function r(a,c){if(a._zod||Object.defineProperty(a,"_zod",{value:{def:c,constr:i,traits:new Set},enumerable:!1}),a._zod.traits.has(e))return;a._zod.traits.add(e),t(a,c);const u=i.prototype,d=Object.keys(u);for(let f=0;f<d.length;f++){const g=d[f];g in a||(a[g]=u[g].bind(a))}}const o=n?.Parent??Object;class s extends o{}Object.defineProperty(s,"name",{value:e});function i(a){var c;const u=n?.Parent?new s:this;r(u,a),(c=u._zod).deferred??(c.deferred=[]);for(const d of u._zod.deferred)d();return u}return Object.defineProperty(i,"init",{value:r}),Object.defineProperty(i,Symbol.hasInstance,{value:a=>n?.Parent&&a instanceof n.Parent?!0:a?._zod?.traits?.has(e)}),Object.defineProperty(i,"name",{value:e}),i}class B extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class it extends Error{constructor(t){super(`Encountered unidirectional transform during encode: ${t}`),this.name="ZodEncodeError"}}const st={};function J(e){return st}function at(e){const t=Object.values(e).filter(r=>typeof r=="number");return Object.entries(e).filter(([r,o])=>t.indexOf(+r)===-1).map(([r,o])=>o)}function _e(e,t){return typeof t=="bigint"?t.toString():t}function ye(e){return{get value(){{const t=e();return Object.defineProperty(this,"value",{value:t}),t}}}}function ve(e){return e==null}function be(e){const t=e.startsWith("^")?1:0,n=e.endsWith("$")?e.length-1:e.length;return e.slice(t,n)}function Jr(e,t){const n=(e.toString().split(".")[1]||"").length,r=t.toString();let o=(r.split(".")[1]||"").length;if(o===0&&/\d?e-\d?/.test(r)){const c=r.match(/\d?e-(\d?)/);c?.[1]&&(o=Number.parseInt(c[1]))}const s=n>o?n:o,i=Number.parseInt(e.toFixed(s).replace(".","")),a=Number.parseInt(t.toFixed(s).replace(".",""));return i%a/10**s}const ct=Symbol("evaluating");function y(e,t,n){let r;Object.defineProperty(e,t,{get(){if(r!==ct)return r===void 0&&(r=ct,r=n()),r},set(o){Object.defineProperty(e,t,{value:o})},configurable:!0})}function q(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){const r=Object.getOwnPropertyDescriptors(n);Object.assign(t,r)}return Object.defineProperties({},t)}function ut(e){return JSON.stringify(e)}function qr(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")}const dt="captureStackTrace"in Error?Error.captureStackTrace:(...e)=>{};function te(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}const Gr=ye(()=>{if(typeof navigator<"u"&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{const e=Function;return new e(""),!0}catch{return!1}});function K(e){if(te(e)===!1)return!1;const t=e.constructor;if(t===void 0||typeof t!="function")return!0;const n=t.prototype;return!(te(n)===!1||Object.prototype.hasOwnProperty.call(n,"isPrototypeOf")===!1)}function lt(e){return K(e)?{...e}:Array.isArray(e)?[...e]:e}const Br=new Set(["string","number","symbol"]);function ne(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function x(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 Vr(e){return Object.keys(e).filter(t=>e[t]._zod.optin==="optional"&&e[t]._zod.optout==="optional")}const Wr={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 Hr(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");const s=j(e._zod.def,{get shape(){const i={};for(const a in t){if(!(a in n.shape))throw new Error(`Unrecognized key: "${a}"`);t[a]&&(i[a]=n.shape[a])}return q(this,"shape",i),i},checks:[]});return x(e,s)}function Kr(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");const s=j(e._zod.def,{get shape(){const i={...e._zod.def.shape};for(const a in t){if(!(a in n.shape))throw new Error(`Unrecognized key: "${a}"`);t[a]&&delete i[a]}return q(this,"shape",i),i},checks:[]});return x(e,s)}function Yr(e,t){if(!K(t))throw new Error("Invalid input to extend: expected a plain object");const n=e._zod.def.checks;if(n&&n.length>0){const s=e._zod.def.shape;for(const i in t)if(Object.getOwnPropertyDescriptor(s,i)!==void 0)throw new Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.")}const o=j(e._zod.def,{get shape(){const s={...e._zod.def.shape,...t};return q(this,"shape",s),s}});return x(e,o)}function Qr(e,t){if(!K(t))throw new Error("Invalid input to safeExtend: expected a plain object");const n=j(e._zod.def,{get shape(){const r={...e._zod.def.shape,...t};return q(this,"shape",r),r}});return x(e,n)}function Xr(e,t){const n=j(e._zod.def,{get shape(){const r={...e._zod.def.shape,...t._zod.def.shape};return q(this,"shape",r),r},get catchall(){return t._zod.def.catchall},checks:[]});return x(e,n)}function eo(e,t,n){const o=t._zod.def.checks;if(o&&o.length>0)throw new Error(".partial() cannot be used on object schemas containing refinements");const i=j(t._zod.def,{get shape(){const a=t._zod.def.shape,c={...a};if(n)for(const u in n){if(!(u in a))throw new Error(`Unrecognized key: "${u}"`);n[u]&&(c[u]=e?new e({type:"optional",innerType:a[u]}):a[u])}else for(const u in a)c[u]=e?new e({type:"optional",innerType:a[u]}):a[u];return q(this,"shape",c),c},checks:[]});return x(t,i)}function to(e,t,n){const r=j(t._zod.def,{get shape(){const o=t._zod.def.shape,s={...o};if(n)for(const i in n){if(!(i in s))throw new Error(`Unrecognized key: "${i}"`);n[i]&&(s[i]=new e({type:"nonoptional",innerType:o[i]}))}else for(const i in o)s[i]=new e({type:"nonoptional",innerType:o[i]});return q(this,"shape",s),s}});return x(t,r)}function V(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 pt(e,t){return t.map(n=>{var r;return(r=n).path??(r.path=[]),n.path.unshift(e),n})}function re(e){return typeof e=="string"?e:e?.message}function G(e,t,n){const r={...e,path:e.path??[]};if(!e.message){const o=re(e.inst?._zod.def?.error?.(e))??re(t?.error?.(e))??re(n.customError?.(e))??re(n.localeError?.(e))??"Invalid input";r.message=o}return delete r.inst,delete r.continue,t?.reportInput||delete r.input,r}function we(e){return Array.isArray(e)?"array":typeof e=="string"?"string":"unknown"}function Y(...e){const[t,n,r]=e;return typeof t=="string"?{message:t,code:"custom",input:n,inst:r}:{...t}}const ft=(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,_e,2),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},mt=l("$ZodError",ft),gt=l("$ZodError",ft,{Parent:Error});function no(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 ro(e,t=n=>n.message){const n={_errors:[]},r=o=>{for(const s of o.issues)if(s.code==="invalid_union"&&s.errors.length)s.errors.map(i=>r({issues:i}));else if(s.code==="invalid_key")r({issues:s.issues});else if(s.code==="invalid_element")r({issues:s.issues});else if(s.path.length===0)n._errors.push(t(s));else{let i=n,a=0;for(;a<s.path.length;){const c=s.path[a];a===s.path.length-1?(i[c]=i[c]||{_errors:[]},i[c]._errors.push(t(s))):i[c]=i[c]||{_errors:[]},i=i[c],a++}}};return r(e),n}const ke=e=>(t,n,r,o)=>{const s=r?Object.assign(r,{async:!1}):{async:!1},i=t._zod.run({value:n,issues:[]},s);if(i instanceof Promise)throw new B;if(i.issues.length){const a=new(o?.Err??e)(i.issues.map(c=>G(c,s,J())));throw dt(a,o?.callee),a}return i.value},Se=e=>async(t,n,r,o)=>{const s=r?Object.assign(r,{async:!0}):{async:!0};let i=t._zod.run({value:n,issues:[]},s);if(i instanceof Promise&&(i=await i),i.issues.length){const a=new(o?.Err??e)(i.issues.map(c=>G(c,s,J())));throw dt(a,o?.callee),a}return i.value},oe=e=>(t,n,r)=>{const o=r?{...r,async:!1}:{async:!1},s=t._zod.run({value:n,issues:[]},o);if(s instanceof Promise)throw new B;return s.issues.length?{success:!1,error:new(e??mt)(s.issues.map(i=>G(i,o,J())))}:{success:!0,data:s.value}},oo=oe(gt),ie=e=>async(t,n,r)=>{const o=r?Object.assign(r,{async:!0}):{async:!0};let s=t._zod.run({value:n,issues:[]},o);return s instanceof Promise&&(s=await s),s.issues.length?{success:!1,error:new e(s.issues.map(i=>G(i,o,J())))}:{success:!0,data:s.value}},io=ie(gt),so=e=>(t,n,r)=>{const o=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return ke(e)(t,n,o)},ao=e=>(t,n,r)=>ke(e)(t,n,r),co=e=>async(t,n,r)=>{const o=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return Se(e)(t,n,o)},uo=e=>async(t,n,r)=>Se(e)(t,n,r),lo=e=>(t,n,r)=>{const o=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return oe(e)(t,n,o)},po=e=>(t,n,r)=>oe(e)(t,n,r),fo=e=>async(t,n,r)=>{const o=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return ie(e)(t,n,o)},mo=e=>async(t,n,r)=>ie(e)(t,n,r),go=/^[cC][^\s-]{8,}$/,ho=/^[0-9a-z]+$/,_o=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,yo=/^[0-9a-vA-V]{20}$/,vo=/^[A-Za-z0-9]{27}$/,bo=/^[a-zA-Z0-9_-]{21}$/,wo=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,ko=/^([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})$/,ht=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)$/,So=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,zo="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";function Eo(){return new RegExp(zo,"u")}const Co=/^(?:(?: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])$/,To=/^(([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}|:))$/,$o=/^((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])$/,Io=/^(([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])$/,Ao=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,_t=/^[A-Za-z0-9_-]*$/,Po=/^\+[1-9]\d{6,14}$/,yt="(?:(?:\\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])))",Oo=new RegExp(`^${yt}$`);function vt(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 Zo(e){return new RegExp(`^${vt(e)}$`)}function No(e){const t=vt({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(`^${yt}T(?:${r})$`)}const Ro=e=>{const t=e?`[\\s\\S]{${e?.minimum??0},${e?.maximum??""}}`:"[\\s\\S]*";return new RegExp(`^${t}$`)},Do=/^-?\d+$/,jo=/^-?\d+(?:\.\d+)?$/,xo=/^[^A-Z]*$/,Lo=/^[^a-z]*$/,T=l("$ZodCheck",(e,t)=>{var n;e._zod??(e._zod={}),e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),bt={number:"number",bigint:"bigint",object:"date"},wt=l("$ZodCheckLessThan",(e,t)=>{T.init(e,t);const n=bt[typeof t.value];e._zod.onattach.push(r=>{const o=r._zod.bag,s=(t.inclusive?o.maximum:o.exclusiveMaximum)??Number.POSITIVE_INFINITY;t.value<s&&(t.inclusive?o.maximum=t.value:o.exclusiveMaximum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value<=t.value:r.value<t.value)||r.issues.push({origin:n,code:"too_big",maximum:typeof t.value=="object"?t.value.getTime():t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),kt=l("$ZodCheckGreaterThan",(e,t)=>{T.init(e,t);const n=bt[typeof t.value];e._zod.onattach.push(r=>{const o=r._zod.bag,s=(t.inclusive?o.minimum:o.exclusiveMinimum)??Number.NEGATIVE_INFINITY;t.value>s&&(t.inclusive?o.minimum=t.value:o.exclusiveMinimum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value>=t.value:r.value>t.value)||r.issues.push({origin:n,code:"too_small",minimum:typeof t.value=="object"?t.value.getTime():t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),Uo=l("$ZodCheckMultipleOf",(e,t)=>{T.init(e,t),e._zod.onattach.push(n=>{var r;(r=n._zod.bag).multipleOf??(r.multipleOf=t.value)}),e._zod.check=n=>{if(typeof n.value!=typeof t.value)throw new Error("Cannot mix number and bigint in multiple_of check.");(typeof n.value=="bigint"?n.value%t.value===BigInt(0):Jr(n.value,t.value)===0)||n.issues.push({origin:typeof n.value,code:"not_multiple_of",divisor:t.value,input:n.value,inst:e,continue:!t.abort})}}),Mo=l("$ZodCheckNumberFormat",(e,t)=>{T.init(e,t),t.format=t.format||"float64";const n=t.format?.includes("int"),r=n?"int":"number",[o,s]=Wr[t.format];e._zod.onattach.push(i=>{const a=i._zod.bag;a.format=t.format,a.minimum=o,a.maximum=s,n&&(a.pattern=Do)}),e._zod.check=i=>{const a=i.value;if(n){if(!Number.isInteger(a)){i.issues.push({expected:r,format:t.format,code:"invalid_type",continue:!1,input:a,inst:e});return}if(!Number.isSafeInteger(a)){a>0?i.issues.push({input:a,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:r,inclusive:!0,continue:!t.abort}):i.issues.push({input:a,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:r,inclusive:!0,continue:!t.abort});return}}a<o&&i.issues.push({origin:"number",input:a,code:"too_small",minimum:o,inclusive:!0,inst:e,continue:!t.abort}),a>s&&i.issues.push({origin:"number",input:a,code:"too_big",maximum:s,inclusive:!0,inst:e,continue:!t.abort})}}),Fo=l("$ZodCheckMaxLength",(e,t)=>{var n;T.init(e,t),(n=e._zod.def).when??(n.when=r=>{const o=r.value;return!ve(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=we(o);r.issues.push({origin:i,code:"too_big",maximum:t.maximum,inclusive:!0,input:o,inst:e,continue:!t.abort})}}),Jo=l("$ZodCheckMinLength",(e,t)=>{var n;T.init(e,t),(n=e._zod.def).when??(n.when=r=>{const o=r.value;return!ve(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=we(o);r.issues.push({origin:i,code:"too_small",minimum:t.minimum,inclusive:!0,input:o,inst:e,continue:!t.abort})}}),qo=l("$ZodCheckLengthEquals",(e,t)=>{var n;T.init(e,t),(n=e._zod.def).when??(n.when=r=>{const o=r.value;return!ve(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,s=o.length;if(s===t.length)return;const i=we(o),a=s>t.length;r.issues.push({origin:i,...a?{code:"too_big",maximum:t.length}:{code:"too_small",minimum:t.length},inclusive:!0,exact:!0,input:r.value,inst:e,continue:!t.abort})}}),se=l("$ZodCheckStringFormat",(e,t)=>{var n,r;T.init(e,t),e._zod.onattach.push(o=>{const s=o._zod.bag;s.format=t.format,t.pattern&&(s.patterns??(s.patterns=new Set),s.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=()=>{})}),Go=l("$ZodCheckRegex",(e,t)=>{se.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})}}),Bo=l("$ZodCheckLowerCase",(e,t)=>{t.pattern??(t.pattern=xo),se.init(e,t)}),Vo=l("$ZodCheckUpperCase",(e,t)=>{t.pattern??(t.pattern=Lo),se.init(e,t)}),Wo=l("$ZodCheckIncludes",(e,t)=>{T.init(e,t);const n=ne(t.includes),r=new RegExp(typeof t.position=="number"?`^.{${t.position}}${n}`:n);t.pattern=r,e._zod.onattach.push(o=>{const s=o._zod.bag;s.patterns??(s.patterns=new Set),s.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})}}),Ho=l("$ZodCheckStartsWith",(e,t)=>{T.init(e,t);const n=new RegExp(`^${ne(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})}}),Ko=l("$ZodCheckEndsWith",(e,t)=>{T.init(e,t);const n=new RegExp(`.*${ne(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})}}),Yo=l("$ZodCheckOverwrite",(e,t)=>{T.init(e,t),e._zod.check=n=>{n.value=t.tx(n.value)}});class Qo{constructor(t=[]){this.content=[],this.indent=0,this&&(this.args=t)}indented(t){this.indent+=1,t(this),this.indent-=1}write(t){if(typeof t=="function"){t(this,{execution:"sync"}),t(this,{execution:"async"});return}const r=t.split(`
48
+ `).filter(i=>i),o=Math.min(...r.map(i=>i.length-i.trimStart().length)),s=r.map(i=>i.slice(o)).map(i=>" ".repeat(this.indent*2)+i);for(const i of s)this.content.push(i)}compile(){const t=Function,n=this?.args,o=[...(this?.content??[""]).map(s=>` ${s}`)];return new t(...n,o.join(`
49
+ `))}}const Xo={major:4,minor:3,patch:6},k=l("$ZodType",(e,t)=>{var n;e??(e={}),e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=Xo;const r=[...e._zod.def.checks??[]];e._zod.traits.has("$ZodCheck")&&r.unshift(e);for(const o of r)for(const s of o._zod.onattach)s(e);if(r.length===0)(n=e._zod).deferred??(n.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{const o=(i,a,c)=>{let u=V(i),d;for(const f of a){if(f._zod.def.when){if(!f._zod.def.when(i))continue}else if(u)continue;const g=i.issues.length,m=f._zod.check(i);if(m instanceof Promise&&c?.async===!1)throw new B;if(d||m instanceof Promise)d=(d??Promise.resolve()).then(async()=>{await m,i.issues.length!==g&&(u||(u=V(i,g)))});else{if(i.issues.length===g)continue;u||(u=V(i,g))}}return d?d.then(()=>i):i},s=(i,a,c)=>{if(V(i))return i.aborted=!0,i;const u=o(a,r,c);if(u instanceof Promise){if(c.async===!1)throw new B;return u.then(d=>e._zod.parse(d,c))}return e._zod.parse(u,c)};e._zod.run=(i,a)=>{if(a.skipChecks)return e._zod.parse(i,a);if(a.direction==="backward"){const u=e._zod.parse({value:i.value,issues:[]},{...a,skipChecks:!0});return u instanceof Promise?u.then(d=>s(d,i,a)):s(u,i,a)}const c=e._zod.parse(i,a);if(c instanceof Promise){if(a.async===!1)throw new B;return c.then(u=>o(u,r,a))}return o(c,r,a)}}y(e,"~standard",()=>({validate:o=>{try{const s=oo(e,o);return s.success?{value:s.data}:{issues:s.error?.issues}}catch{return io(e,o).then(i=>i.success?{value:i.data}:{issues:i.error?.issues})}},vendor:"zod",version:1}))}),ze=l("$ZodString",(e,t)=>{k.init(e,t),e._zod.pattern=[...e?._zod.bag?.patterns??[]].pop()??Ro(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}}),b=l("$ZodStringFormat",(e,t)=>{se.init(e,t),ze.init(e,t)}),ei=l("$ZodGUID",(e,t)=>{t.pattern??(t.pattern=ko),b.init(e,t)}),ti=l("$ZodUUID",(e,t)=>{if(t.version){const r={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[t.version];if(r===void 0)throw new Error(`Invalid UUID version: "${t.version}"`);t.pattern??(t.pattern=ht(r))}else t.pattern??(t.pattern=ht());b.init(e,t)}),ni=l("$ZodEmail",(e,t)=>{t.pattern??(t.pattern=So),b.init(e,t)}),ri=l("$ZodURL",(e,t)=>{b.init(e,t),e._zod.check=n=>{try{const r=n.value.trim(),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})}}}),oi=l("$ZodEmoji",(e,t)=>{t.pattern??(t.pattern=Eo()),b.init(e,t)}),ii=l("$ZodNanoID",(e,t)=>{t.pattern??(t.pattern=bo),b.init(e,t)}),si=l("$ZodCUID",(e,t)=>{t.pattern??(t.pattern=go),b.init(e,t)}),ai=l("$ZodCUID2",(e,t)=>{t.pattern??(t.pattern=ho),b.init(e,t)}),ci=l("$ZodULID",(e,t)=>{t.pattern??(t.pattern=_o),b.init(e,t)}),ui=l("$ZodXID",(e,t)=>{t.pattern??(t.pattern=yo),b.init(e,t)}),di=l("$ZodKSUID",(e,t)=>{t.pattern??(t.pattern=vo),b.init(e,t)}),li=l("$ZodISODateTime",(e,t)=>{t.pattern??(t.pattern=No(t)),b.init(e,t)}),pi=l("$ZodISODate",(e,t)=>{t.pattern??(t.pattern=Oo),b.init(e,t)}),fi=l("$ZodISOTime",(e,t)=>{t.pattern??(t.pattern=Zo(t)),b.init(e,t)}),mi=l("$ZodISODuration",(e,t)=>{t.pattern??(t.pattern=wo),b.init(e,t)}),gi=l("$ZodIPv4",(e,t)=>{t.pattern??(t.pattern=Co),b.init(e,t),e._zod.bag.format="ipv4"}),hi=l("$ZodIPv6",(e,t)=>{t.pattern??(t.pattern=To),b.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})}}}),_i=l("$ZodCIDRv4",(e,t)=>{t.pattern??(t.pattern=$o),b.init(e,t)}),yi=l("$ZodCIDRv6",(e,t)=>{t.pattern??(t.pattern=Io),b.init(e,t),e._zod.check=n=>{const r=n.value.split("/");try{if(r.length!==2)throw new Error;const[o,s]=r;if(!s)throw new Error;const i=Number(s);if(`${i}`!==s)throw new Error;if(i<0||i>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 St(e){if(e==="")return!0;if(e.length%4!==0)return!1;try{return atob(e),!0}catch{return!1}}const vi=l("$ZodBase64",(e,t)=>{t.pattern??(t.pattern=Ao),b.init(e,t),e._zod.bag.contentEncoding="base64",e._zod.check=n=>{St(n.value)||n.issues.push({code:"invalid_format",format:"base64",input:n.value,inst:e,continue:!t.abort})}});function bi(e){if(!_t.test(e))return!1;const t=e.replace(/[-_]/g,r=>r==="-"?"+":"/"),n=t.padEnd(Math.ceil(t.length/4)*4,"=");return St(n)}const wi=l("$ZodBase64URL",(e,t)=>{t.pattern??(t.pattern=_t),b.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})}}),ki=l("$ZodE164",(e,t)=>{t.pattern??(t.pattern=Po),b.init(e,t)});function Si(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}}const zi=l("$ZodJWT",(e,t)=>{b.init(e,t),e._zod.check=n=>{Si(n.value,t.alg)||n.issues.push({code:"invalid_format",format:"jwt",input:n.value,inst:e,continue:!t.abort})}}),zt=l("$ZodNumber",(e,t)=>{k.init(e,t),e._zod.pattern=e._zod.bag.pattern??jo,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=Number(n.value)}catch{}const o=n.value;if(typeof o=="number"&&!Number.isNaN(o)&&Number.isFinite(o))return n;const s=typeof o=="number"?Number.isNaN(o)?"NaN":Number.isFinite(o)?void 0:"Infinity":void 0;return n.issues.push({expected:"number",code:"invalid_type",input:o,inst:e,...s?{received:s}:{}}),n}}),Ei=l("$ZodNumberFormat",(e,t)=>{Mo.init(e,t),zt.init(e,t)}),Ci=l("$ZodUnknown",(e,t)=>{k.init(e,t),e._zod.parse=n=>n}),Ti=l("$ZodNever",(e,t)=>{k.init(e,t),e._zod.parse=(n,r)=>(n.issues.push({expected:"never",code:"invalid_type",input:n.value,inst:e}),n)});function Et(e,t,n){e.issues.length&&t.issues.push(...pt(n,e.issues)),t.value[n]=e.value}const $i=l("$ZodArray",(e,t)=>{k.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 s=[];for(let i=0;i<o.length;i++){const a=o[i],c=t.element._zod.run({value:a,issues:[]},r);c instanceof Promise?s.push(c.then(u=>Et(u,n,i))):Et(c,n,i)}return s.length?Promise.all(s).then(()=>n):n}});function ae(e,t,n,r,o){if(e.issues.length){if(o&&!(n in r))return;t.issues.push(...pt(n,e.issues))}e.value===void 0?n in r&&(t.value[n]=void 0):t.value[n]=e.value}function Ct(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=Vr(e.shape);return{...e,keys:t,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(n)}}function Tt(e,t,n,r,o,s){const i=[],a=o.keySet,c=o.catchall._zod,u=c.def.type,d=c.optout==="optional";for(const f in t){if(a.has(f))continue;if(u==="never"){i.push(f);continue}const g=c.run({value:t[f],issues:[]},r);g instanceof Promise?e.push(g.then(m=>ae(m,n,f,t,d))):ae(g,n,f,t,d)}return i.length&&n.issues.push({code:"unrecognized_keys",keys:i,input:t,inst:s}),e.length?Promise.all(e).then(()=>n):n}const Ii=l("$ZodObject",(e,t)=>{if(k.init(e,t),!Object.getOwnPropertyDescriptor(t,"shape")?.get){const a=t.shape;Object.defineProperty(t,"shape",{get:()=>{const c={...a};return Object.defineProperty(t,"shape",{value:c}),c}})}const r=ye(()=>Ct(t));y(e._zod,"propValues",()=>{const a=t.shape,c={};for(const u in a){const d=a[u]._zod;if(d.values){c[u]??(c[u]=new Set);for(const f of d.values)c[u].add(f)}}return c});const o=te,s=t.catchall;let i;e._zod.parse=(a,c)=>{i??(i=r.value);const u=a.value;if(!o(u))return a.issues.push({expected:"object",code:"invalid_type",input:u,inst:e}),a;a.value={};const d=[],f=i.shape;for(const g of i.keys){const m=f[g],p=m._zod.optout==="optional",h=m._zod.run({value:u[g],issues:[]},c);h instanceof Promise?d.push(h.then(z=>ae(z,a,g,u,p))):ae(h,a,g,u,p)}return s?Tt(d,u,a,c,r.value,e):d.length?Promise.all(d).then(()=>a):a}}),Ai=l("$ZodObjectJIT",(e,t)=>{Ii.init(e,t);const n=e._zod.parse,r=ye(()=>Ct(t)),o=g=>{const m=new Qo(["shape","payload","ctx"]),p=r.value,h=I=>{const A=ut(I);return`shape[${A}]._zod.run({ value: input[${A}], issues: [] }, ctx)`};m.write("const input = payload.value;");const z=Object.create(null);let P=0;for(const I of p.keys)z[I]=`key_${P++}`;m.write("const newResult = {};");for(const I of p.keys){const A=z[I],Z=ut(I),Sc=g[I]?._zod?.optout==="optional";m.write(`const ${A} = ${h(I)};`),Sc?m.write(`
50
+ if (${A}.issues.length) {
51
+ if (${Z} in input) {
52
+ payload.issues = payload.issues.concat(${A}.issues.map(iss => ({
53
+ ...iss,
54
+ path: iss.path ? [${Z}, ...iss.path] : [${Z}]
55
+ })));
56
+ }
57
+ }
58
+
59
+ if (${A}.value === undefined) {
60
+ if (${Z} in input) {
61
+ newResult[${Z}] = undefined;
62
+ }
63
+ } else {
64
+ newResult[${Z}] = ${A}.value;
65
+ }
66
+
67
+ `):m.write(`
68
+ if (${A}.issues.length) {
69
+ payload.issues = payload.issues.concat(${A}.issues.map(iss => ({
70
+ ...iss,
71
+ path: iss.path ? [${Z}, ...iss.path] : [${Z}]
72
+ })));
73
+ }
74
+
75
+ if (${A}.value === undefined) {
76
+ if (${Z} in input) {
77
+ newResult[${Z}] = undefined;
78
+ }
79
+ } else {
80
+ newResult[${Z}] = ${A}.value;
81
+ }
82
+
83
+ `)}m.write("payload.value = newResult;"),m.write("return payload;");const Pe=m.compile();return(I,A)=>Pe(g,I,A)};let s;const i=te,a=!st.jitless,u=a&&Gr.value,d=t.catchall;let f;e._zod.parse=(g,m)=>{f??(f=r.value);const p=g.value;return i(p)?a&&u&&m?.async===!1&&m.jitless!==!0?(s||(s=o(t.shape)),g=s(g,m),d?Tt([],p,g,m,f,e):g):n(g,m):(g.issues.push({expected:"object",code:"invalid_type",input:p,inst:e}),g)}});function $t(e,t,n,r){for(const s of e)if(s.issues.length===0)return t.value=s.value,t;const o=e.filter(s=>!V(s));return o.length===1?(t.value=o[0].value,o[0]):(t.issues.push({code:"invalid_union",input:t.value,inst:n,errors:e.map(s=>s.issues.map(i=>G(i,r,J())))}),t)}const Pi=l("$ZodUnion",(e,t)=>{k.init(e,t),y(e._zod,"optin",()=>t.options.some(o=>o._zod.optin==="optional")?"optional":void 0),y(e._zod,"optout",()=>t.options.some(o=>o._zod.optout==="optional")?"optional":void 0),y(e._zod,"values",()=>{if(t.options.every(o=>o._zod.values))return new Set(t.options.flatMap(o=>Array.from(o._zod.values)))}),y(e._zod,"pattern",()=>{if(t.options.every(o=>o._zod.pattern)){const o=t.options.map(s=>s._zod.pattern);return new RegExp(`^(${o.map(s=>be(s.source)).join("|")})$`)}});const n=t.options.length===1,r=t.options[0]._zod.run;e._zod.parse=(o,s)=>{if(n)return r(o,s);let i=!1;const a=[];for(const c of t.options){const u=c._zod.run({value:o.value,issues:[]},s);if(u instanceof Promise)a.push(u),i=!0;else{if(u.issues.length===0)return u;a.push(u)}}return i?Promise.all(a).then(c=>$t(c,o,e,s)):$t(a,o,e,s)}}),Oi=l("$ZodIntersection",(e,t)=>{k.init(e,t),e._zod.parse=(n,r)=>{const o=n.value,s=t.left._zod.run({value:o,issues:[]},r),i=t.right._zod.run({value:o,issues:[]},r);return s instanceof Promise||i instanceof Promise?Promise.all([s,i]).then(([c,u])=>It(n,c,u)):It(n,s,i)}});function Ee(e,t){if(e===t)return{valid:!0,data:e};if(e instanceof Date&&t instanceof Date&&+e==+t)return{valid:!0,data:e};if(K(e)&&K(t)){const n=Object.keys(t),r=Object.keys(e).filter(s=>n.indexOf(s)!==-1),o={...e,...t};for(const s of r){const i=Ee(e[s],t[s]);if(!i.valid)return{valid:!1,mergeErrorPath:[s,...i.mergeErrorPath]};o[s]=i.data}return{valid:!0,data:o}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};const n=[];for(let r=0;r<e.length;r++){const o=e[r],s=t[r],i=Ee(o,s);if(!i.valid)return{valid:!1,mergeErrorPath:[r,...i.mergeErrorPath]};n.push(i.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function It(e,t,n){const r=new Map;let o;for(const a of t.issues)if(a.code==="unrecognized_keys"){o??(o=a);for(const c of a.keys)r.has(c)||r.set(c,{}),r.get(c).l=!0}else e.issues.push(a);for(const a of n.issues)if(a.code==="unrecognized_keys")for(const c of a.keys)r.has(c)||r.set(c,{}),r.get(c).r=!0;else e.issues.push(a);const s=[...r].filter(([,a])=>a.l&&a.r).map(([a])=>a);if(s.length&&o&&e.issues.push({...o,keys:s}),V(e))return e;const i=Ee(t.value,n.value);if(!i.valid)throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(i.mergeErrorPath)}`);return e.value=i.data,e}const Zi=l("$ZodEnum",(e,t)=>{k.init(e,t);const n=at(t.entries),r=new Set(n);e._zod.values=r,e._zod.pattern=new RegExp(`^(${n.filter(o=>Br.has(typeof o)).map(o=>typeof o=="string"?ne(o):o.toString()).join("|")})$`),e._zod.parse=(o,s)=>{const i=o.value;return r.has(i)||o.issues.push({code:"invalid_value",values:n,input:i,inst:e}),o}}),Ni=l("$ZodTransform",(e,t)=>{k.init(e,t),e._zod.parse=(n,r)=>{if(r.direction==="backward")throw new it(e.constructor.name);const o=t.transform(n.value,n);if(r.async)return(o instanceof Promise?o:Promise.resolve(o)).then(i=>(n.value=i,n));if(o instanceof Promise)throw new B;return n.value=o,n}});function At(e,t){return e.issues.length&&t===void 0?{issues:[],value:void 0}:e}const Pt=l("$ZodOptional",(e,t)=>{k.init(e,t),e._zod.optin="optional",e._zod.optout="optional",y(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),y(e._zod,"pattern",()=>{const n=t.innerType._zod.pattern;return n?new RegExp(`^(${be(n.source)})?$`):void 0}),e._zod.parse=(n,r)=>{if(t.innerType._zod.optin==="optional"){const o=t.innerType._zod.run(n,r);return o instanceof Promise?o.then(s=>At(s,n.value)):At(o,n.value)}return n.value===void 0?n:t.innerType._zod.run(n,r)}}),Ri=l("$ZodExactOptional",(e,t)=>{Pt.init(e,t),y(e._zod,"values",()=>t.innerType._zod.values),y(e._zod,"pattern",()=>t.innerType._zod.pattern),e._zod.parse=(n,r)=>t.innerType._zod.run(n,r)}),Di=l("$ZodNullable",(e,t)=>{k.init(e,t),y(e._zod,"optin",()=>t.innerType._zod.optin),y(e._zod,"optout",()=>t.innerType._zod.optout),y(e._zod,"pattern",()=>{const n=t.innerType._zod.pattern;return n?new RegExp(`^(${be(n.source)}|null)$`):void 0}),y(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,null]):void 0),e._zod.parse=(n,r)=>n.value===null?n:t.innerType._zod.run(n,r)}),ji=l("$ZodDefault",(e,t)=>{k.init(e,t),e._zod.optin="optional",y(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(n,r)=>{if(r.direction==="backward")return t.innerType._zod.run(n,r);if(n.value===void 0)return n.value=t.defaultValue,n;const o=t.innerType._zod.run(n,r);return o instanceof Promise?o.then(s=>Ot(s,t)):Ot(o,t)}});function Ot(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}const xi=l("$ZodPrefault",(e,t)=>{k.init(e,t),e._zod.optin="optional",y(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(n,r)=>(r.direction==="backward"||n.value===void 0&&(n.value=t.defaultValue),t.innerType._zod.run(n,r))}),Li=l("$ZodNonOptional",(e,t)=>{k.init(e,t),y(e._zod,"values",()=>{const n=t.innerType._zod.values;return n?new Set([...n].filter(r=>r!==void 0)):void 0}),e._zod.parse=(n,r)=>{const o=t.innerType._zod.run(n,r);return o instanceof Promise?o.then(s=>Zt(s,e)):Zt(o,e)}});function Zt(e,t){return!e.issues.length&&e.value===void 0&&e.issues.push({code:"invalid_type",expected:"nonoptional",input:e.value,inst:t}),e}const Ui=l("$ZodCatch",(e,t)=>{k.init(e,t),y(e._zod,"optin",()=>t.innerType._zod.optin),y(e._zod,"optout",()=>t.innerType._zod.optout),y(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(n,r)=>{if(r.direction==="backward")return t.innerType._zod.run(n,r);const o=t.innerType._zod.run(n,r);return o instanceof Promise?o.then(s=>(n.value=s.value,s.issues.length&&(n.value=t.catchValue({...n,error:{issues:s.issues.map(i=>G(i,r,J()))},input:n.value}),n.issues=[]),n)):(n.value=o.value,o.issues.length&&(n.value=t.catchValue({...n,error:{issues:o.issues.map(s=>G(s,r,J()))},input:n.value}),n.issues=[]),n)}}),Mi=l("$ZodPipe",(e,t)=>{k.init(e,t),y(e._zod,"values",()=>t.in._zod.values),y(e._zod,"optin",()=>t.in._zod.optin),y(e._zod,"optout",()=>t.out._zod.optout),y(e._zod,"propValues",()=>t.in._zod.propValues),e._zod.parse=(n,r)=>{if(r.direction==="backward"){const s=t.out._zod.run(n,r);return s instanceof Promise?s.then(i=>ce(i,t.in,r)):ce(s,t.in,r)}const o=t.in._zod.run(n,r);return o instanceof Promise?o.then(s=>ce(s,t.out,r)):ce(o,t.out,r)}});function ce(e,t,n){return e.issues.length?(e.aborted=!0,e):t._zod.run({value:e.value,issues:e.issues},n)}const Fi=l("$ZodReadonly",(e,t)=>{k.init(e,t),y(e._zod,"propValues",()=>t.innerType._zod.propValues),y(e._zod,"values",()=>t.innerType._zod.values),y(e._zod,"optin",()=>t.innerType?._zod?.optin),y(e._zod,"optout",()=>t.innerType?._zod?.optout),e._zod.parse=(n,r)=>{if(r.direction==="backward")return t.innerType._zod.run(n,r);const o=t.innerType._zod.run(n,r);return o instanceof Promise?o.then(Nt):Nt(o)}});function Nt(e){return e.value=Object.freeze(e.value),e}const Ji=l("$ZodCustom",(e,t)=>{T.init(e,t),k.init(e,t),e._zod.parse=(n,r)=>n,e._zod.check=n=>{const r=n.value,o=t.fn(r);if(o instanceof Promise)return o.then(s=>Rt(s,n,r,e));Rt(o,n,r,e)}});function Rt(e,t,n,r){if(!e){const o={code:"custom",input:n,inst:r,path:[...r._zod.def.path??[]],continue:!r._zod.def.abort};r._zod.def.params&&(o.params=r._zod.def.params),t.issues.push(Y(o))}}var Dt;class qi{constructor(){this._map=new WeakMap,this._idmap=new Map}add(t,...n){const r=n[0];return this._map.set(t,r),r&&typeof r=="object"&&"id"in r&&this._idmap.set(r.id,t),this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(t){const n=this._map.get(t);return n&&typeof n=="object"&&"id"in n&&this._idmap.delete(n.id),this._map.delete(t),this}get(t){const n=t._zod.parent;if(n){const r={...this.get(n)??{}};delete r.id;const o={...r,...this._map.get(t)};return Object.keys(o).length?o:void 0}return this._map.get(t)}has(t){return this._map.has(t)}}function Gi(){return new qi}(Dt=globalThis).__zod_globalRegistry??(Dt.__zod_globalRegistry=Gi());const Q=globalThis.__zod_globalRegistry;function Bi(e,t){return new e({type:"string",..._(t)})}function Vi(e,t){return new e({type:"string",format:"email",check:"string_format",abort:!1,..._(t)})}function jt(e,t){return new e({type:"string",format:"guid",check:"string_format",abort:!1,..._(t)})}function Wi(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,..._(t)})}function Hi(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",..._(t)})}function Ki(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",..._(t)})}function Yi(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",..._(t)})}function Qi(e,t){return new e({type:"string",format:"url",check:"string_format",abort:!1,..._(t)})}function Xi(e,t){return new e({type:"string",format:"emoji",check:"string_format",abort:!1,..._(t)})}function es(e,t){return new e({type:"string",format:"nanoid",check:"string_format",abort:!1,..._(t)})}function ts(e,t){return new e({type:"string",format:"cuid",check:"string_format",abort:!1,..._(t)})}function ns(e,t){return new e({type:"string",format:"cuid2",check:"string_format",abort:!1,..._(t)})}function rs(e,t){return new e({type:"string",format:"ulid",check:"string_format",abort:!1,..._(t)})}function os(e,t){return new e({type:"string",format:"xid",check:"string_format",abort:!1,..._(t)})}function is(e,t){return new e({type:"string",format:"ksuid",check:"string_format",abort:!1,..._(t)})}function ss(e,t){return new e({type:"string",format:"ipv4",check:"string_format",abort:!1,..._(t)})}function as(e,t){return new e({type:"string",format:"ipv6",check:"string_format",abort:!1,..._(t)})}function cs(e,t){return new e({type:"string",format:"cidrv4",check:"string_format",abort:!1,..._(t)})}function us(e,t){return new e({type:"string",format:"cidrv6",check:"string_format",abort:!1,..._(t)})}function ds(e,t){return new e({type:"string",format:"base64",check:"string_format",abort:!1,..._(t)})}function ls(e,t){return new e({type:"string",format:"base64url",check:"string_format",abort:!1,..._(t)})}function ps(e,t){return new e({type:"string",format:"e164",check:"string_format",abort:!1,..._(t)})}function fs(e,t){return new e({type:"string",format:"jwt",check:"string_format",abort:!1,..._(t)})}function ms(e,t){return new e({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,..._(t)})}function gs(e,t){return new e({type:"string",format:"date",check:"string_format",..._(t)})}function hs(e,t){return new e({type:"string",format:"time",check:"string_format",precision:null,..._(t)})}function _s(e,t){return new e({type:"string",format:"duration",check:"string_format",..._(t)})}function ys(e,t){return new e({type:"number",checks:[],..._(t)})}function vs(e,t){return new e({type:"number",check:"number_format",abort:!1,format:"safeint",..._(t)})}function bs(e){return new e({type:"unknown"})}function ws(e,t){return new e({type:"never",..._(t)})}function xt(e,t){return new wt({check:"less_than",..._(t),value:e,inclusive:!1})}function Ce(e,t){return new wt({check:"less_than",..._(t),value:e,inclusive:!0})}function Lt(e,t){return new kt({check:"greater_than",..._(t),value:e,inclusive:!1})}function Te(e,t){return new kt({check:"greater_than",..._(t),value:e,inclusive:!0})}function Ut(e,t){return new Uo({check:"multiple_of",..._(t),value:e})}function Mt(e,t){return new Fo({check:"max_length",..._(t),maximum:e})}function ue(e,t){return new Jo({check:"min_length",..._(t),minimum:e})}function Ft(e,t){return new qo({check:"length_equals",..._(t),length:e})}function ks(e,t){return new Go({check:"string_format",format:"regex",..._(t),pattern:e})}function Ss(e){return new Bo({check:"string_format",format:"lowercase",..._(e)})}function zs(e){return new Vo({check:"string_format",format:"uppercase",..._(e)})}function Es(e,t){return new Wo({check:"string_format",format:"includes",..._(t),includes:e})}function Cs(e,t){return new Ho({check:"string_format",format:"starts_with",..._(t),prefix:e})}function Ts(e,t){return new Ko({check:"string_format",format:"ends_with",..._(t),suffix:e})}function W(e){return new Yo({check:"overwrite",tx:e})}function $s(e){return W(t=>t.normalize(e))}function Is(){return W(e=>e.trim())}function As(){return W(e=>e.toLowerCase())}function Ps(){return W(e=>e.toUpperCase())}function Os(){return W(e=>qr(e))}function Zs(e,t,n){return new e({type:"array",element:t,..._(n)})}function Ns(e,t,n){return new e({type:"custom",check:"custom",fn:t,..._(n)})}function Rs(e){const t=Ds(n=>(n.addIssue=r=>{if(typeof r=="string")n.issues.push(Y(r,n.value,t._zod.def));else{const o=r;o.fatal&&(o.continue=!1),o.code??(o.code="custom"),o.input??(o.input=n.value),o.inst??(o.inst=t),o.continue??(o.continue=!t._zod.def.abort),n.issues.push(Y(o))}},e(n.value,n)));return t}function Ds(e,t){const n=new T({check:"custom",..._(t)});return n._zod.check=e,n}function Jt(e){let t=e?.target??"draft-2020-12";return t==="draft-4"&&(t="draft-04"),t==="draft-7"&&(t="draft-07"),{processors:e.processors??{},metadataRegistry:e?.metadata??Q,target:t,unrepresentable:e?.unrepresentable??"throw",override:e?.override??(()=>{}),io:e?.io??"output",counter:0,seen:new Map,cycles:e?.cycles??"ref",reused:e?.reused??"inline",external:e?.external??void 0}}function E(e,t,n={path:[],schemaPath:[]}){var r;const o=e._zod.def,s=t.seen.get(e);if(s)return s.count++,n.schemaPath.includes(e)&&(s.cycle=n.path),s.schema;const i={schema:{},count:1,cycle:void 0,path:n.path};t.seen.set(e,i);const a=e._zod.toJSONSchema?.();if(a)i.schema=a;else{const d={...n,schemaPath:[...n.schemaPath,e],path:n.path};if(e._zod.processJSONSchema)e._zod.processJSONSchema(t,i.schema,d);else{const g=i.schema,m=t.processors[o.type];if(!m)throw new Error(`[toJSONSchema]: Non-representable type encountered: ${o.type}`);m(e,t,g,d)}const f=e._zod.parent;f&&(i.ref||(i.ref=f),E(f,t,d),t.seen.get(f).isParent=!0)}const c=t.metadataRegistry.get(e);return c&&Object.assign(i.schema,c),t.io==="input"&&C(e)&&(delete i.schema.examples,delete i.schema.default),t.io==="input"&&i.schema._prefault&&((r=i.schema).default??(r.default=i.schema._prefault)),delete i.schema._prefault,t.seen.get(e).schema}function qt(e,t){const n=e.seen.get(t);if(!n)throw new Error("Unprocessed schema. This is a bug in Zod.");const r=new Map;for(const i of e.seen.entries()){const a=e.metadataRegistry.get(i[0])?.id;if(a){const c=r.get(a);if(c&&c!==i[0])throw new Error(`Duplicate schema id "${a}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);r.set(a,i[0])}}const o=i=>{const a=e.target==="draft-2020-12"?"$defs":"definitions";if(e.external){const f=e.external.registry.get(i[0])?.id,g=e.external.uri??(p=>p);if(f)return{ref:g(f)};const m=i[1].defId??i[1].schema.id??`schema${e.counter++}`;return i[1].defId=m,{defId:m,ref:`${g("__shared")}#/${a}/${m}`}}if(i[1]===n)return{ref:"#"};const u=`#/${a}/`,d=i[1].schema.id??`__schema${e.counter++}`;return{defId:d,ref:u+d}},s=i=>{if(i[1].schema.$ref)return;const a=i[1],{ref:c,defId:u}=o(i);a.def={...a.schema},u&&(a.defId=u);const d=a.schema;for(const f in d)delete d[f];d.$ref=c};if(e.cycles==="throw")for(const i of e.seen.entries()){const a=i[1];if(a.cycle)throw new Error(`Cycle detected: #/${a.cycle?.join("/")}/<root>
84
+
85
+ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(const i of e.seen.entries()){const a=i[1];if(t===i[0]){s(i);continue}if(e.external){const u=e.external.registry.get(i[0])?.id;if(t!==i[0]&&u){s(i);continue}}if(e.metadataRegistry.get(i[0])?.id){s(i);continue}if(a.cycle){s(i);continue}if(a.count>1&&e.reused==="ref"){s(i);continue}}}function Gt(e,t){const n=e.seen.get(t);if(!n)throw new Error("Unprocessed schema. This is a bug in Zod.");const r=i=>{const a=e.seen.get(i);if(a.ref===null)return;const c=a.def??a.schema,u={...c},d=a.ref;if(a.ref=null,d){r(d);const g=e.seen.get(d),m=g.schema;if(m.$ref&&(e.target==="draft-07"||e.target==="draft-04"||e.target==="openapi-3.0")?(c.allOf=c.allOf??[],c.allOf.push(m)):Object.assign(c,m),Object.assign(c,u),i._zod.parent===d)for(const h in c)h==="$ref"||h==="allOf"||h in u||delete c[h];if(m.$ref&&g.def)for(const h in c)h==="$ref"||h==="allOf"||h in g.def&&JSON.stringify(c[h])===JSON.stringify(g.def[h])&&delete c[h]}const f=i._zod.parent;if(f&&f!==d){r(f);const g=e.seen.get(f);if(g?.schema.$ref&&(c.$ref=g.schema.$ref,g.def))for(const m in c)m==="$ref"||m==="allOf"||m in g.def&&JSON.stringify(c[m])===JSON.stringify(g.def[m])&&delete c[m]}e.override({zodSchema:i,jsonSchema:c,path:a.path??[]})};for(const i of[...e.seen.entries()].reverse())r(i[0]);const o={};if(e.target==="draft-2020-12"?o.$schema="https://json-schema.org/draft/2020-12/schema":e.target==="draft-07"?o.$schema="http://json-schema.org/draft-07/schema#":e.target==="draft-04"?o.$schema="http://json-schema.org/draft-04/schema#":e.target,e.external?.uri){const i=e.external.registry.get(t)?.id;if(!i)throw new Error("Schema is missing an `id` property");o.$id=e.external.uri(i)}Object.assign(o,n.def??n.schema);const s=e.external?.defs??{};for(const i of e.seen.entries()){const a=i[1];a.def&&a.defId&&(s[a.defId]=a.def)}e.external||Object.keys(s).length>0&&(e.target==="draft-2020-12"?o.$defs=s:o.definitions=s);try{const i=JSON.parse(JSON.stringify(o));return Object.defineProperty(i,"~standard",{value:{...t["~standard"],jsonSchema:{input:de(t,"input",e.processors),output:de(t,"output",e.processors)}},enumerable:!1,writable:!1}),i}catch{throw new Error("Error converting schema to JSON.")}}function C(e,t){const n=t??{seen:new Set};if(n.seen.has(e))return!1;n.seen.add(e);const r=e._zod.def;if(r.type==="transform")return!0;if(r.type==="array")return C(r.element,n);if(r.type==="set")return C(r.valueType,n);if(r.type==="lazy")return C(r.getter(),n);if(r.type==="promise"||r.type==="optional"||r.type==="nonoptional"||r.type==="nullable"||r.type==="readonly"||r.type==="default"||r.type==="prefault")return C(r.innerType,n);if(r.type==="intersection")return C(r.left,n)||C(r.right,n);if(r.type==="record"||r.type==="map")return C(r.keyType,n)||C(r.valueType,n);if(r.type==="pipe")return C(r.in,n)||C(r.out,n);if(r.type==="object"){for(const o in r.shape)if(C(r.shape[o],n))return!0;return!1}if(r.type==="union"){for(const o of r.options)if(C(o,n))return!0;return!1}if(r.type==="tuple"){for(const o of r.items)if(C(o,n))return!0;return!!(r.rest&&C(r.rest,n))}return!1}const js=(e,t={})=>n=>{const r=Jt({...n,processors:t});return E(e,r),qt(r,e),Gt(r,e)},de=(e,t,n={})=>r=>{const{libraryOptions:o,target:s}=r??{},i=Jt({...o??{},target:s,io:t,processors:n});return E(e,i),qt(i,e),Gt(i,e)},xs={guid:"uuid",url:"uri",datetime:"date-time",json_string:"json-string",regex:""},Ls=(e,t,n,r)=>{const o=n;o.type="string";const{minimum:s,maximum:i,format:a,patterns:c,contentEncoding:u}=e._zod.bag;if(typeof s=="number"&&(o.minLength=s),typeof i=="number"&&(o.maxLength=i),a&&(o.format=xs[a]??a,o.format===""&&delete o.format,a==="time"&&delete o.format),u&&(o.contentEncoding=u),c&&c.size>0){const d=[...c];d.length===1?o.pattern=d[0].source:d.length>1&&(o.allOf=[...d.map(f=>({...t.target==="draft-07"||t.target==="draft-04"||t.target==="openapi-3.0"?{type:"string"}:{},pattern:f.source}))])}},Us=(e,t,n,r)=>{const o=n,{minimum:s,maximum:i,format:a,multipleOf:c,exclusiveMaximum:u,exclusiveMinimum:d}=e._zod.bag;typeof a=="string"&&a.includes("int")?o.type="integer":o.type="number",typeof d=="number"&&(t.target==="draft-04"||t.target==="openapi-3.0"?(o.minimum=d,o.exclusiveMinimum=!0):o.exclusiveMinimum=d),typeof s=="number"&&(o.minimum=s,typeof d=="number"&&t.target!=="draft-04"&&(d>=s?delete o.minimum:delete o.exclusiveMinimum)),typeof u=="number"&&(t.target==="draft-04"||t.target==="openapi-3.0"?(o.maximum=u,o.exclusiveMaximum=!0):o.exclusiveMaximum=u),typeof i=="number"&&(o.maximum=i,typeof u=="number"&&t.target!=="draft-04"&&(u<=i?delete o.maximum:delete o.exclusiveMaximum)),typeof c=="number"&&(o.multipleOf=c)},Ms=(e,t,n,r)=>{n.not={}},Fs=(e,t,n,r)=>{},Js=(e,t,n,r)=>{const o=e._zod.def,s=at(o.entries);s.every(i=>typeof i=="number")&&(n.type="number"),s.every(i=>typeof i=="string")&&(n.type="string"),n.enum=s},qs=(e,t,n,r)=>{if(t.unrepresentable==="throw")throw new Error("Custom types cannot be represented in JSON Schema")},Gs=(e,t,n,r)=>{if(t.unrepresentable==="throw")throw new Error("Transforms cannot be represented in JSON Schema")},Bs=(e,t,n,r)=>{const o=n,s=e._zod.def,{minimum:i,maximum:a}=e._zod.bag;typeof i=="number"&&(o.minItems=i),typeof a=="number"&&(o.maxItems=a),o.type="array",o.items=E(s.element,t,{...r,path:[...r.path,"items"]})},Vs=(e,t,n,r)=>{const o=n,s=e._zod.def;o.type="object",o.properties={};const i=s.shape;for(const u in i)o.properties[u]=E(i[u],t,{...r,path:[...r.path,"properties",u]});const a=new Set(Object.keys(i)),c=new Set([...a].filter(u=>{const d=s.shape[u]._zod;return t.io==="input"?d.optin===void 0:d.optout===void 0}));c.size>0&&(o.required=Array.from(c)),s.catchall?._zod.def.type==="never"?o.additionalProperties=!1:s.catchall?s.catchall&&(o.additionalProperties=E(s.catchall,t,{...r,path:[...r.path,"additionalProperties"]})):t.io==="output"&&(o.additionalProperties=!1)},Ws=(e,t,n,r)=>{const o=e._zod.def,s=o.inclusive===!1,i=o.options.map((a,c)=>E(a,t,{...r,path:[...r.path,s?"oneOf":"anyOf",c]}));s?n.oneOf=i:n.anyOf=i},Hs=(e,t,n,r)=>{const o=e._zod.def,s=E(o.left,t,{...r,path:[...r.path,"allOf",0]}),i=E(o.right,t,{...r,path:[...r.path,"allOf",1]}),a=u=>"allOf"in u&&Object.keys(u).length===1,c=[...a(s)?s.allOf:[s],...a(i)?i.allOf:[i]];n.allOf=c},Ks=(e,t,n,r)=>{const o=e._zod.def,s=E(o.innerType,t,r),i=t.seen.get(e);t.target==="openapi-3.0"?(i.ref=o.innerType,n.nullable=!0):n.anyOf=[s,{type:"null"}]},Ys=(e,t,n,r)=>{const o=e._zod.def;E(o.innerType,t,r);const s=t.seen.get(e);s.ref=o.innerType},Qs=(e,t,n,r)=>{const o=e._zod.def;E(o.innerType,t,r);const s=t.seen.get(e);s.ref=o.innerType,n.default=JSON.parse(JSON.stringify(o.defaultValue))},Xs=(e,t,n,r)=>{const o=e._zod.def;E(o.innerType,t,r);const s=t.seen.get(e);s.ref=o.innerType,t.io==="input"&&(n._prefault=JSON.parse(JSON.stringify(o.defaultValue)))},ea=(e,t,n,r)=>{const o=e._zod.def;E(o.innerType,t,r);const s=t.seen.get(e);s.ref=o.innerType;let i;try{i=o.catchValue(void 0)}catch{throw new Error("Dynamic catch values are not supported in JSON Schema")}n.default=i},ta=(e,t,n,r)=>{const o=e._zod.def,s=t.io==="input"?o.in._zod.def.type==="transform"?o.out:o.in:o.out;E(s,t,r);const i=t.seen.get(e);i.ref=s},na=(e,t,n,r)=>{const o=e._zod.def;E(o.innerType,t,r);const s=t.seen.get(e);s.ref=o.innerType,n.readOnly=!0},Bt=(e,t,n,r)=>{const o=e._zod.def;E(o.innerType,t,r);const s=t.seen.get(e);s.ref=o.innerType},ra=l("ZodISODateTime",(e,t)=>{li.init(e,t),w.init(e,t)});function oa(e){return ms(ra,e)}const ia=l("ZodISODate",(e,t)=>{pi.init(e,t),w.init(e,t)});function sa(e){return gs(ia,e)}const aa=l("ZodISOTime",(e,t)=>{fi.init(e,t),w.init(e,t)});function ca(e){return hs(aa,e)}const ua=l("ZodISODuration",(e,t)=>{mi.init(e,t),w.init(e,t)});function da(e){return _s(ua,e)}const O=l("ZodError",(e,t)=>{mt.init(e,t),e.name="ZodError",Object.defineProperties(e,{format:{value:n=>ro(e,n)},flatten:{value:n=>no(e,n)},addIssue:{value:n=>{e.issues.push(n),e.message=JSON.stringify(e.issues,_e,2)}},addIssues:{value:n=>{e.issues.push(...n),e.message=JSON.stringify(e.issues,_e,2)}},isEmpty:{get(){return e.issues.length===0}}})},{Parent:Error}),la=ke(O),pa=Se(O),fa=oe(O),ma=ie(O),ga=so(O),ha=ao(O),_a=co(O),ya=uo(O),va=lo(O),ba=po(O),wa=fo(O),ka=mo(O),S=l("ZodType",(e,t)=>(k.init(e,t),Object.assign(e["~standard"],{jsonSchema:{input:de(e,"input"),output:de(e,"output")}}),e.toJSONSchema=js(e,{}),e.def=t,e.type=t.type,Object.defineProperty(e,"_def",{value:t}),e.check=(...n)=>e.clone(j(t,{checks:[...t.checks??[],...n.map(r=>typeof r=="function"?{_zod:{check:r,def:{check:"custom"},onattach:[]}}:r)]}),{parent:!0}),e.with=e.check,e.clone=(n,r)=>x(e,n,r),e.brand=()=>e,e.register=((n,r)=>(n.add(e,r),e)),e.parse=(n,r)=>la(e,n,r,{callee:e.parse}),e.safeParse=(n,r)=>fa(e,n,r),e.parseAsync=async(n,r)=>pa(e,n,r,{callee:e.parseAsync}),e.safeParseAsync=async(n,r)=>ma(e,n,r),e.spa=e.safeParseAsync,e.encode=(n,r)=>ga(e,n,r),e.decode=(n,r)=>ha(e,n,r),e.encodeAsync=async(n,r)=>_a(e,n,r),e.decodeAsync=async(n,r)=>ya(e,n,r),e.safeEncode=(n,r)=>va(e,n,r),e.safeDecode=(n,r)=>ba(e,n,r),e.safeEncodeAsync=async(n,r)=>wa(e,n,r),e.safeDecodeAsync=async(n,r)=>ka(e,n,r),e.refine=(n,r)=>e.check(fc(n,r)),e.superRefine=n=>e.check(mc(n)),e.overwrite=n=>e.check(W(n)),e.optional=()=>Xt(e),e.exactOptional=()=>ec(e),e.nullable=()=>en(e),e.nullish=()=>Xt(en(e)),e.nonoptional=n=>sc(e,n),e.array=()=>Yt(e),e.or=n=>Wa([e,n]),e.and=n=>Ka(e,n),e.transform=n=>nn(e,Qa(n)),e.default=n=>rc(e,n),e.prefault=n=>ic(e,n),e.catch=n=>cc(e,n),e.pipe=n=>nn(e,n),e.readonly=()=>lc(e),e.describe=n=>{const r=e.clone();return Q.add(r,{description:n}),r},Object.defineProperty(e,"description",{get(){return Q.get(e)?.description},configurable:!0}),e.meta=(...n)=>{if(n.length===0)return Q.get(e);const r=e.clone();return Q.add(r,n[0]),r},e.isOptional=()=>e.safeParse(void 0).success,e.isNullable=()=>e.safeParse(null).success,e.apply=n=>n(e),e)),Vt=l("_ZodString",(e,t)=>{ze.init(e,t),S.init(e,t),e._zod.processJSONSchema=(r,o,s)=>Ls(e,r,o);const n=e._zod.bag;e.format=n.format??null,e.minLength=n.minimum??null,e.maxLength=n.maximum??null,e.regex=(...r)=>e.check(ks(...r)),e.includes=(...r)=>e.check(Es(...r)),e.startsWith=(...r)=>e.check(Cs(...r)),e.endsWith=(...r)=>e.check(Ts(...r)),e.min=(...r)=>e.check(ue(...r)),e.max=(...r)=>e.check(Mt(...r)),e.length=(...r)=>e.check(Ft(...r)),e.nonempty=(...r)=>e.check(ue(1,...r)),e.lowercase=r=>e.check(Ss(r)),e.uppercase=r=>e.check(zs(r)),e.trim=()=>e.check(Is()),e.normalize=(...r)=>e.check($s(...r)),e.toLowerCase=()=>e.check(As()),e.toUpperCase=()=>e.check(Ps()),e.slugify=()=>e.check(Os())}),Sa=l("ZodString",(e,t)=>{ze.init(e,t),Vt.init(e,t),e.email=n=>e.check(Vi(za,n)),e.url=n=>e.check(Qi(Ea,n)),e.jwt=n=>e.check(fs(Ua,n)),e.emoji=n=>e.check(Xi(Ca,n)),e.guid=n=>e.check(jt(Wt,n)),e.uuid=n=>e.check(Wi(le,n)),e.uuidv4=n=>e.check(Hi(le,n)),e.uuidv6=n=>e.check(Ki(le,n)),e.uuidv7=n=>e.check(Yi(le,n)),e.nanoid=n=>e.check(es(Ta,n)),e.guid=n=>e.check(jt(Wt,n)),e.cuid=n=>e.check(ts($a,n)),e.cuid2=n=>e.check(ns(Ia,n)),e.ulid=n=>e.check(rs(Aa,n)),e.base64=n=>e.check(ds(ja,n)),e.base64url=n=>e.check(ls(xa,n)),e.xid=n=>e.check(os(Pa,n)),e.ksuid=n=>e.check(is(Oa,n)),e.ipv4=n=>e.check(ss(Za,n)),e.ipv6=n=>e.check(as(Na,n)),e.cidrv4=n=>e.check(cs(Ra,n)),e.cidrv6=n=>e.check(us(Da,n)),e.e164=n=>e.check(ps(La,n)),e.datetime=n=>e.check(oa(n)),e.date=n=>e.check(sa(n)),e.time=n=>e.check(ca(n)),e.duration=n=>e.check(da(n))});function $(e){return Bi(Sa,e)}const w=l("ZodStringFormat",(e,t)=>{b.init(e,t),Vt.init(e,t)}),za=l("ZodEmail",(e,t)=>{ni.init(e,t),w.init(e,t)}),Wt=l("ZodGUID",(e,t)=>{ei.init(e,t),w.init(e,t)}),le=l("ZodUUID",(e,t)=>{ti.init(e,t),w.init(e,t)}),Ea=l("ZodURL",(e,t)=>{ri.init(e,t),w.init(e,t)}),Ca=l("ZodEmoji",(e,t)=>{oi.init(e,t),w.init(e,t)}),Ta=l("ZodNanoID",(e,t)=>{ii.init(e,t),w.init(e,t)}),$a=l("ZodCUID",(e,t)=>{si.init(e,t),w.init(e,t)}),Ia=l("ZodCUID2",(e,t)=>{ai.init(e,t),w.init(e,t)}),Aa=l("ZodULID",(e,t)=>{ci.init(e,t),w.init(e,t)}),Pa=l("ZodXID",(e,t)=>{ui.init(e,t),w.init(e,t)}),Oa=l("ZodKSUID",(e,t)=>{di.init(e,t),w.init(e,t)}),Za=l("ZodIPv4",(e,t)=>{gi.init(e,t),w.init(e,t)}),Na=l("ZodIPv6",(e,t)=>{hi.init(e,t),w.init(e,t)}),Ra=l("ZodCIDRv4",(e,t)=>{_i.init(e,t),w.init(e,t)}),Da=l("ZodCIDRv6",(e,t)=>{yi.init(e,t),w.init(e,t)}),ja=l("ZodBase64",(e,t)=>{vi.init(e,t),w.init(e,t)}),xa=l("ZodBase64URL",(e,t)=>{wi.init(e,t),w.init(e,t)}),La=l("ZodE164",(e,t)=>{ki.init(e,t),w.init(e,t)}),Ua=l("ZodJWT",(e,t)=>{zi.init(e,t),w.init(e,t)}),Ht=l("ZodNumber",(e,t)=>{zt.init(e,t),S.init(e,t),e._zod.processJSONSchema=(r,o,s)=>Us(e,r,o),e.gt=(r,o)=>e.check(Lt(r,o)),e.gte=(r,o)=>e.check(Te(r,o)),e.min=(r,o)=>e.check(Te(r,o)),e.lt=(r,o)=>e.check(xt(r,o)),e.lte=(r,o)=>e.check(Ce(r,o)),e.max=(r,o)=>e.check(Ce(r,o)),e.int=r=>e.check(Kt(r)),e.safe=r=>e.check(Kt(r)),e.positive=r=>e.check(Lt(0,r)),e.nonnegative=r=>e.check(Te(0,r)),e.negative=r=>e.check(xt(0,r)),e.nonpositive=r=>e.check(Ce(0,r)),e.multipleOf=(r,o)=>e.check(Ut(r,o)),e.step=(r,o)=>e.check(Ut(r,o)),e.finite=()=>e;const n=e._zod.bag;e.minValue=Math.max(n.minimum??Number.NEGATIVE_INFINITY,n.exclusiveMinimum??Number.NEGATIVE_INFINITY)??null,e.maxValue=Math.min(n.maximum??Number.POSITIVE_INFINITY,n.exclusiveMaximum??Number.POSITIVE_INFINITY)??null,e.isInt=(n.format??"").includes("int")||Number.isSafeInteger(n.multipleOf??.5),e.isFinite=!0,e.format=n.format??null});function X(e){return ys(Ht,e)}const Ma=l("ZodNumberFormat",(e,t)=>{Ei.init(e,t),Ht.init(e,t)});function Kt(e){return vs(Ma,e)}const Fa=l("ZodUnknown",(e,t)=>{Ci.init(e,t),S.init(e,t),e._zod.processJSONSchema=(n,r,o)=>Fs()});function $e(){return bs(Fa)}const Ja=l("ZodNever",(e,t)=>{Ti.init(e,t),S.init(e,t),e._zod.processJSONSchema=(n,r,o)=>Ms(e,n,r)});function qa(e){return ws(Ja,e)}const Ga=l("ZodArray",(e,t)=>{$i.init(e,t),S.init(e,t),e._zod.processJSONSchema=(n,r,o)=>Bs(e,n,r,o),e.element=t.element,e.min=(n,r)=>e.check(ue(n,r)),e.nonempty=n=>e.check(ue(1,n)),e.max=(n,r)=>e.check(Mt(n,r)),e.length=(n,r)=>e.check(Ft(n,r)),e.unwrap=()=>e.element});function Yt(e,t){return Zs(Ga,e,t)}const Ba=l("ZodObject",(e,t)=>{Ai.init(e,t),S.init(e,t),e._zod.processJSONSchema=(n,r,o)=>Vs(e,n,r,o),y(e,"shape",()=>t.shape),e.keyof=()=>Ae(Object.keys(e._zod.def.shape)),e.catchall=n=>e.clone({...e._zod.def,catchall:n}),e.passthrough=()=>e.clone({...e._zod.def,catchall:$e()}),e.loose=()=>e.clone({...e._zod.def,catchall:$e()}),e.strict=()=>e.clone({...e._zod.def,catchall:qa()}),e.strip=()=>e.clone({...e._zod.def,catchall:void 0}),e.extend=n=>Yr(e,n),e.safeExtend=n=>Qr(e,n),e.merge=n=>Xr(e,n),e.pick=n=>Hr(e,n),e.omit=n=>Kr(e,n),e.partial=(...n)=>eo(Qt,e,n[0]),e.required=(...n)=>to(tn,e,n[0])});function L(e,t){const n={type:"object",shape:e??{},..._(t)};return new Ba(n)}const Va=l("ZodUnion",(e,t)=>{Pi.init(e,t),S.init(e,t),e._zod.processJSONSchema=(n,r,o)=>Ws(e,n,r,o),e.options=t.options});function Wa(e,t){return new Va({type:"union",options:e,..._(t)})}const Ha=l("ZodIntersection",(e,t)=>{Oi.init(e,t),S.init(e,t),e._zod.processJSONSchema=(n,r,o)=>Hs(e,n,r,o)});function Ka(e,t){return new Ha({type:"intersection",left:e,right:t})}const Ie=l("ZodEnum",(e,t)=>{Zi.init(e,t),S.init(e,t),e._zod.processJSONSchema=(r,o,s)=>Js(e,r,o),e.enum=t.entries,e.options=Object.values(t.entries);const n=new Set(Object.keys(t.entries));e.extract=(r,o)=>{const s={};for(const i of r)if(n.has(i))s[i]=t.entries[i];else throw new Error(`Key ${i} not found in enum`);return new Ie({...t,checks:[],..._(o),entries:s})},e.exclude=(r,o)=>{const s={...t.entries};for(const i of r)if(n.has(i))delete s[i];else throw new Error(`Key ${i} not found in enum`);return new Ie({...t,checks:[],..._(o),entries:s})}});function Ae(e,t){const n=Array.isArray(e)?Object.fromEntries(e.map(r=>[r,r])):e;return new Ie({type:"enum",entries:n,..._(t)})}const Ya=l("ZodTransform",(e,t)=>{Ni.init(e,t),S.init(e,t),e._zod.processJSONSchema=(n,r,o)=>Gs(e,n),e._zod.parse=(n,r)=>{if(r.direction==="backward")throw new it(e.constructor.name);n.addIssue=s=>{if(typeof s=="string")n.issues.push(Y(s,n.value,t));else{const i=s;i.fatal&&(i.continue=!1),i.code??(i.code="custom"),i.input??(i.input=n.value),i.inst??(i.inst=e),n.issues.push(Y(i))}};const o=t.transform(n.value,n);return o instanceof Promise?o.then(s=>(n.value=s,n)):(n.value=o,n)}});function Qa(e){return new Ya({type:"transform",transform:e})}const Qt=l("ZodOptional",(e,t)=>{Pt.init(e,t),S.init(e,t),e._zod.processJSONSchema=(n,r,o)=>Bt(e,n,r,o),e.unwrap=()=>e._zod.def.innerType});function Xt(e){return new Qt({type:"optional",innerType:e})}const Xa=l("ZodExactOptional",(e,t)=>{Ri.init(e,t),S.init(e,t),e._zod.processJSONSchema=(n,r,o)=>Bt(e,n,r,o),e.unwrap=()=>e._zod.def.innerType});function ec(e){return new Xa({type:"optional",innerType:e})}const tc=l("ZodNullable",(e,t)=>{Di.init(e,t),S.init(e,t),e._zod.processJSONSchema=(n,r,o)=>Ks(e,n,r,o),e.unwrap=()=>e._zod.def.innerType});function en(e){return new tc({type:"nullable",innerType:e})}const nc=l("ZodDefault",(e,t)=>{ji.init(e,t),S.init(e,t),e._zod.processJSONSchema=(n,r,o)=>Qs(e,n,r,o),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function rc(e,t){return new nc({type:"default",innerType:e,get defaultValue(){return typeof t=="function"?t():lt(t)}})}const oc=l("ZodPrefault",(e,t)=>{xi.init(e,t),S.init(e,t),e._zod.processJSONSchema=(n,r,o)=>Xs(e,n,r,o),e.unwrap=()=>e._zod.def.innerType});function ic(e,t){return new oc({type:"prefault",innerType:e,get defaultValue(){return typeof t=="function"?t():lt(t)}})}const tn=l("ZodNonOptional",(e,t)=>{Li.init(e,t),S.init(e,t),e._zod.processJSONSchema=(n,r,o)=>Ys(e,n,r,o),e.unwrap=()=>e._zod.def.innerType});function sc(e,t){return new tn({type:"nonoptional",innerType:e,..._(t)})}const ac=l("ZodCatch",(e,t)=>{Ui.init(e,t),S.init(e,t),e._zod.processJSONSchema=(n,r,o)=>ea(e,n,r,o),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function cc(e,t){return new ac({type:"catch",innerType:e,catchValue:typeof t=="function"?t:()=>t})}const uc=l("ZodPipe",(e,t)=>{Mi.init(e,t),S.init(e,t),e._zod.processJSONSchema=(n,r,o)=>ta(e,n,r,o),e.in=t.in,e.out=t.out});function nn(e,t){return new uc({type:"pipe",in:e,out:t})}const dc=l("ZodReadonly",(e,t)=>{Fi.init(e,t),S.init(e,t),e._zod.processJSONSchema=(n,r,o)=>na(e,n,r,o),e.unwrap=()=>e._zod.def.innerType});function lc(e){return new dc({type:"readonly",innerType:e})}const pc=l("ZodCustom",(e,t)=>{Ji.init(e,t),S.init(e,t),e._zod.processJSONSchema=(n,r,o)=>qs(e,n)});function fc(e,t={}){return Ns(pc,e,t)}function mc(e){return Rs(e)}const gc=L({sku:$(),name:$(),imageUrl:$().url().optional(),price:$().optional(),originalPrice:$().optional(),discountPercent:X().optional(),url:$().url(),brand:$().optional(),rating:X().min(0).max(5).optional(),reviewCount:X().int().nonnegative().optional()}),hc=L({layout:Ae(["grid","carousel"]).optional(),columns:X().int().positive().optional()}),_c=L({product:gc,index:X().int().nonnegative(),discountType:Ae(["strike-through","badge"]).optional()}),yc=L({sku:$(),label:$().optional(),cartCode:$()}),vc=L({actions:Yt(L({label:$(),action:L({title:$(),type:$(),payload:$e().optional()})}))}),bc=L({message:$().optional()}),wc={components:{ProductGrid:{schema:hc,description:"Outer grid or carousel container for similar products."},ProductCard:{schema:_c,description:"A single product card with image, title, price, and actions."},AddToCartButton:{schema:yc,description:"Add-to-cart CTA rendered inside or below a product card."},QuickActions:{schema:vc,description:"A row of quick-action buttons below product info."},EmptyState:{schema:bc,description:"Empty state shown when no similar products are available."}}};class rn extends $n{constructor(){super(...arguments),this._abortController=null,this._contentEl=null,this._i18n=rt}async onInit(t){this._i18n=this._resolveI18n(t),this._contentEl=document.createElement("div"),this._contentEl.className="gengage-simrel-container",this.root.appendChild(this._contentEl),this._lastSku=t.sku,await this._fetchAndRender(t.sku),this.isVisible=!0,Ur("simrel")}onUpdate(t){const n=t.sku;!n||n===this._lastSku||(this._lastSku=n,this._fetchAndRender(n))}onShow(){this._contentEl&&(this._contentEl.style.opacity="0",this._contentEl.style.transition="opacity 0.3s ease-in",requestAnimationFrame(()=>{this._contentEl&&(this._contentEl.style.opacity="1")}))}onHide(){}onDestroy(){this._abort(),this._contentEl&&(this._contentEl.remove(),this._contentEl=null)}_handleProductClick(t){const n={sku:t.sku,name:t.name,url:t.url};if(t.imageUrl!==void 0&&(n.imageUrl=t.imageUrl),t.price!==void 0&&(n.price=t.price),t.originalPrice!==void 0&&(n.originalPrice=t.originalPrice),t.discountPercent!==void 0&&(n.discountPercent=t.discountPercent),t.brand!==void 0&&(n.brand=t.brand),t.rating!==void 0&&(n.rating=t.rating),t.reviewCount!==void 0&&(n.reviewCount=t.reviewCount),t.cartCode!==void 0&&(n.cartCode=t.cartCode),t.inStock!==void 0&&(n.inStock=t.inStock),this.config.onProductClick?.(n)===!1)return;Mr(t.sku,t.name);const r=this.config.session?.sessionId??null;pe("gengage:similar:product-click",{sku:t.sku,url:t.url,sessionId:r}),this.config.onProductNavigate?.(t.url,t.sku,r)}_handleAddToCart(t){Fr(t.sku,t.quantity),this.config.onAddToCart?.(t),pe("gengage:similar:add-to-cart",t),this.track(ln(this.analyticsContext(),{attribution_source:"simrel",attribution_action_id:crypto.randomUUID(),cart_value:0,currency:"TRY",line_items:t.quantity,sku:t.sku}))}_abort(){this._abortController?.abort(),this._abortController=null}async _fetchAndRender(t){this._abort(),this._abortController=new AbortController;const n=this._abortController.signal;if(!this._contentEl)return;this._contentEl.innerHTML="",this._contentEl.style.display="";const r=document.createElement("div");r.className="gengage-simrel-loading";const o=document.createElement("div");o.className="gengage-simrel-spinner",r.appendChild(o),this._contentEl.appendChild(r);const s={middlewareUrl:this.config.middlewareUrl},i=crypto.randomUUID(),a=Date.now();this.track(cn(this.analyticsContext(),{endpoint:"similar_products",request_id:i,widget:"simrel"}));try{const c={account_id:this.config.accountId,session_id:this.config.session?.sessionId??"",correlation_id:this.config.session?.sessionId??"",sku:t};this.config.domain!==void 0&&(c.domain=this.config.domain);const u=await yr(c,s,n);if(!this._contentEl)return;if(this._contentEl.innerHTML="",u.length>0)try{const d=u.map(g=>g.sku),f=await br({account_id:this.config.accountId,session_id:this.config.session?.sessionId??"",correlation_id:this.config.session?.sessionId??"",skus:d},s,n);if(f.length>0&&this._contentEl){const g=this._buildGroupsSpec(f),m=this._renderUISpec(g);this._contentEl.appendChild(m),ot("simrel"),this.track(Oe(this.analyticsContext(),{request_id:i,latency_ms:Date.now()-a,chunk_count:f.reduce((p,h)=>p+h.products.length,0),widget:"simrel"})),this.track(Ze(this.analyticsContext(),{message_count:f.reduce((p,h)=>p+h.products.length,0),history_ref:i,redaction_level:"none",widget:"simrel"}));return}}catch{}if(this._contentEl){const d=this._buildProductsSpec(u),f=this._renderUISpec(d);this._contentEl.appendChild(f)}u.length>0&&ot("simrel"),this.track(Oe(this.analyticsContext(),{request_id:i,latency_ms:Date.now()-a,chunk_count:u.length,widget:"simrel"})),this.track(Ze(this.analyticsContext(),{message_count:u.length,history_ref:i,redaction_level:"none",widget:"simrel"}))}catch(c){if(c instanceof DOMException&&c.name==="AbortError")return;pe("gengage:global:error",{source:"simrel",code:"FETCH_ERROR",message:bn(this.config.locale)}),this.track(un(this.analyticsContext(),{request_id:i,error_code:"FETCH_ERROR",error_message:c instanceof Error?c.message:String(c),widget:"simrel"})),this._contentEl&&(this._contentEl.innerHTML="",this._contentEl.style.display="none")}}_resolveI18n(t){return{...xr(t.locale),...t.i18n}}_resolveUISpecRegistry(){const t=tt();return an(t,this.config.renderer?.registry)}_buildRenderContext(){const t=this.config.renderCard,n={onClick:r=>this._handleProductClick(r),onAddToCart:r=>this._handleAddToCart(r),i18n:this._i18n};return this.config.discountType!==void 0&&(n.discountType=this.config.discountType),t!==void 0&&(n.renderCard=t),this.config.pricing!==void 0&&(n.pricing=this.config.pricing),n}_renderUISpec(t){const n=this._resolveUISpecRegistry(),r=this._buildRenderContext(),o=this.config.renderer?.unknownRenderer??he,s=(c,u)=>nt(c,u,n,o),i=this.config.renderer?.renderUISpec;return i?i(t,r,{registry:n,unknownRenderer:o,defaultRender:s}):s(t,r)}_buildProductsSpec(t){const n={},r=[];for(let o=0;o<t.length;o++){const s=t[o],i=`product-${o}`;r.push(i),n[i]={type:"ProductCard",props:{product:s,index:o,discountType:this.config.discountType}}}return n.root={type:"ProductGrid",props:{layout:"grid"},children:r},{root:"root",elements:n}}_buildGroupsSpec(t){return{root:"root",elements:{root:{type:"GroupTabs",props:{groups:t}}}}}}function kc(){return new rn}U.GengageSimRel=rn,U.createDefaultSimRelUISpecRegistry=tt,U.createSimRelWidget=kc,U.defaultSimRelUnknownUISpecRenderer=he,U.renderSimRelUISpec=nt,U.simRelCatalog=wc,Object.defineProperty(U,Symbol.toStringTag,{value:"Module"})})(this.Gengage=this.Gengage||{});
48
86
  //# sourceMappingURL=simrel.iife.js.map