@botuyo/chat-widget-standalone 1.0.6 → 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@botuyo/chat-widget-standalone",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "type": "module",
5
5
  "description": "BotUyo Chat Widget - Standalone CDN version with React/TypeScript support",
6
6
  "main": "dist/botuyo-chat.umd.js",
@@ -1,33 +0,0 @@
1
- import{r as e,j as t}from"./vendor-react-CtfcjTlq.js";import{u as n,g as r,f as o,h as s,D as i,c as a,X as c,M as u,l as d,m as l,t as p,i as f,j as m,k as h,n as g}from"./chunk-chat-ui-DmqgsaBa.js";import{l as y}from"./vendor-socket-DMqyM-90.js";function v({isOpen:l,onClick:p,unreadCount:f=0,primaryColor:m,logoUrl:h,starterPrompt:g,position:y="bottom-right",emotion:v="default",avatars:b={},styles:_,promptPersistence:w="session",avatarScale:k=1}){const{t:z}=n("extracted"),x=r({primaryColor:m}),E=_?.launcher?.bg,S=o(),{triggerHaptic:O,getGlowClass:I}=s(),$=S.launcherPulse&&!1!==_?.launcher?.pulse,[N,C]=e.useState(!1),[T,A]=e.useState(!1),[j,Z]=e.useState(!1),[M,P]=e.useState(!1),D="bottom-right"===y,F="chat_launcher_prompt_state",R=e.useMemo(()=>b[v]||b.default||h||i,[v,b,h]);e.useEffect(()=>{P(!1)},[R]),e.useEffect(()=>{const e=Object.values(b).filter(e=>!!e);h&&e.push(h),e.forEach(e=>{(new Image).src=e})},[b,h]),e.useEffect(()=>{"forever"===w&&"dismissed"===localStorage.getItem(F)&&Z(!0)},[w]);const L=e.useCallback(()=>{A(!0),setTimeout(()=>C(!1),500),"always"!==w&&(Z(!0),"forever"===w&&localStorage.setItem(F,"dismissed"))},[w]);return e.useEffect(()=>{if("always"!==w&&j||!g||l)return void C(!1);const e=setTimeout(()=>{C(!0),A(!1)},2e3),t=setTimeout(()=>L(),12e3);return()=>{clearTimeout(e),clearTimeout(t)}},[g,l,j,w,L]),/* @__PURE__ */t.jsxs("div",{className:a("flex items-center w-fit transition-all duration-500",D?"flex-row ml-auto":"flex-row-reverse mr-auto"),children:[
2
- /* @__PURE__ */t.jsx("div",{className:a("transition-all duration-700 ease-in-out flex items-center",N?a("opacity-100 translate-x-0 w-auto max-w-[350px]",D?"mr-4":"ml-4"):"opacity-0 translate-x-8 w-0 max-w-0 overflow-hidden"),children:/* @__PURE__ */t.jsxs("div",{className:a("relative px-5 py-3.5 shadow-soft-xl border flex items-center gap-3",_?.radius?.card||"rounded-[20px]",T&&"opacity-0 scale-95 transition-all duration-300",!N&&"hidden"),style:{width:"max-content",maxWidth:"280px",backgroundColor:"hsl(var(--background))",color:"hsl(var(--foreground))",borderColor:"hsl(var(--border))"},children:[
3
- /* @__PURE__ */t.jsx("span",{className:"text-sm font-semibold leading-tight tracking-tight whitespace-nowrap",children:g}),
4
- /* @__PURE__ */t.jsx("button",{onClick:e=>{e.stopPropagation(),L()},className:"text-muted-foreground hover:text-foreground transition-colors p-1 rounded-full hover:bg-muted shrink-0",children:/* @__PURE__ */t.jsx(c,{className:"h-3.5 w-3.5 stroke-[2.5]"})}),
5
- /* @__PURE__ */t.jsx("div",{className:a("absolute top-1/2 -translate-y-1/2 w-0 h-0 border-[7px] border-transparent",D?"right-[-14px] border-l-background":"left-[-14px] border-r-background")}),
6
- /* @__PURE__ */t.jsx("div",{className:a("absolute top-1/2 -translate-y-1/2 w-0 h-0 border-[7px] border-transparent -z-10",D?"right-[-15px] border-l-border":"left-[-15px] border-r-border")})]})}),
7
- /* @__PURE__ */t.jsxs("div",{className:"relative flex items-center justify-center shrink-0",children:[!l&&$&&/* @__PURE__ */t.jsx("span",{className:"absolute inset-0 flex items-center justify-center",children:/* @__PURE__ */t.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full opacity-20",style:{backgroundColor:x}})}),
8
- /* @__PURE__ */t.jsxs("button",{type:"button",onClick:()=>{d.debug("Launcher handleMainAction called, isOpen:",l),O(),Z(!0),"forever"===w&&localStorage.setItem(F,"dismissed"),p()},className:a("relative z-10 h-14 w-14 sm:h-16 sm:w-16","flex items-center justify-center text-white transition-all duration-500","hover:scale-110 active:scale-95 shadow-soft-xl cursor-pointer",!l&&"hover:rotate-6",!l&&S.enabled&&"animate-glow-pulse",_?.radius?.button||"rounded-full",E,I()),style:{backgroundColor:x||"hsl(160, 84%, 39%)","--primary-glow":`${x}66`},"aria-label":l?"Cerrar chat":"Abrir chat",children:[
9
- /* @__PURE__ */t.jsxs("div",{className:"relative h-full w-full flex items-center justify-center overflow-hidden rounded-inherit",children:[
10
- /* @__PURE__ */t.jsx("div",{className:a("absolute inset-0 transition-all duration-500 flex items-center justify-center",l?"opacity-0 scale-50 rotate-90":"opacity-100 scale-100 rotate-0"),children:R&&!M?/* @__PURE__ */t.jsx("img",{src:R,alt:z("assistant"),className:"w-full h-full object-cover",style:{transform:`scale(${k})`},onError:()=>P(!0)},R):/* @__PURE__ */t.jsx(u,{className:"h-7 w-7 sm:h-8 sm:w-8 fill-current"})}),
11
- /* @__PURE__ */t.jsx("div",{className:a("absolute inset-0 transition-all duration-500 flex items-center justify-center bg-black/5 dark:bg-white/10",l?"opacity-100 scale-100 rotate-0":"opacity-0 scale-50 -rotate-90"),children:/* @__PURE__ */t.jsx(c,{className:"h-7 w-7 sm:h-8 sm:w-8 stroke-[2.5]"})})]}),!l&&f>0&&/* @__PURE__ */t.jsx("div",{className:"absolute -top-1 -right-1 z-20 flex h-6 w-6 items-center justify-center bg-destructive text-destructive-foreground rounded-full border-2 border-background text-[10px] font-black shadow-soft-md tabular-nums",children:f>9?"9+":f})]})]})]})}class b extends e.Component{constructor(e){super(e),this.state={hasError:!1,error:null}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,t){d.error("ErrorBoundary caught error:",e,t),this.props.onError?.(e,t)}handleReset=()=>{this.setState({hasError:!1,error:null})};render(){return this.state.hasError?this.props.fallback?this.props.fallback:/* @__PURE__ */t.jsxs("div",{className:"flex flex-col items-center justify-center p-8 bg-background text-center",children:[
12
- /* @__PURE__ */t.jsx("div",{className:"text-6xl mb-4",children:"⚠️"}),
13
- /* @__PURE__ */t.jsx("h2",{className:"text-xl font-bold text-foreground mb-2",children:"Algo salió mal"}),
14
- /* @__PURE__ */t.jsx("p",{className:"text-sm text-muted-foreground mb-6 max-w-md",children:this.state.error?.message||"Ocurrió un error inesperado"}),
15
- /* @__PURE__ */t.jsx("button",{onClick:this.handleReset,className:"px-4 py-2 bg-primary text-primary-foreground rounded-lg font-medium hover:opacity-90 transition-opacity",children:"Intentar de nuevo"})]}):this.props.children}}const _={bubble:"rounded-2xl",image:"rounded-xl",button:"rounded-xl",card:"rounded-2xl"},w={bg:"bg-muted/50 dark:bg-muted/20",text:"text-foreground",border:"border-border/50"},k={text:"text-primary-foreground"};const z=(e,t)=>t.some(t=>e instanceof t);let x,E;const S=/* @__PURE__ */new WeakMap,O=/* @__PURE__ */new WeakMap,I=/* @__PURE__ */new WeakMap;let $={get(e,t,n){if(e instanceof IDBTransaction){if("done"===t)return S.get(e);if("store"===t)return n.objectStoreNames[1]?void 0:n.objectStore(n.objectStoreNames[0])}return T(e[t])},set:(e,t,n)=>(e[t]=n,!0),has:(e,t)=>e instanceof IDBTransaction&&("done"===t||"store"===t)||t in e};function N(e){$=e($)}function C(e){return"function"==typeof e?(t=e,(E||(E=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])).includes(t)?function(...e){return t.apply(A(this),e),T(this.request)}:function(...e){return T(t.apply(A(this),e))}):(e instanceof IDBTransaction&&function(e){if(S.has(e))return;const t=new Promise((t,n)=>{const r=()=>{e.removeEventListener("complete",o),e.removeEventListener("error",s),e.removeEventListener("abort",s)},o=()=>{t(),r()},s=()=>{n(e.error||new DOMException("AbortError","AbortError")),r()};e.addEventListener("complete",o),e.addEventListener("error",s),e.addEventListener("abort",s)});S.set(e,t)}(e),z(e,x||(x=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction]))?new Proxy(e,$):e);var t}function T(e){if(e instanceof IDBRequest)return function(e){const t=new Promise((t,n)=>{const r=()=>{e.removeEventListener("success",o),e.removeEventListener("error",s)},o=()=>{t(T(e.result)),r()},s=()=>{n(e.error),r()};e.addEventListener("success",o),e.addEventListener("error",s)});return I.set(t,e),t}(e);if(O.has(e))return O.get(e);const t=C(e);return t!==e&&(O.set(e,t),I.set(t,e)),t}const A=e=>I.get(e),j=["get","getKey","getAll","getAllKeys","count"],Z=["put","add","delete","clear"],M=/* @__PURE__ */new Map;function P(e,t){if(!(e instanceof IDBDatabase)||t in e||"string"!=typeof t)return;if(M.get(t))return M.get(t);const n=t.replace(/FromIndex$/,""),r=t!==n,o=Z.includes(n);if(!(n in(r?IDBIndex:IDBObjectStore).prototype)||!o&&!j.includes(n))return;const s=async function(e,...t){const s=this.transaction(e,o?"readwrite":"readonly");let i=s.store;return r&&(i=i.index(t.shift())),(await Promise.all([i[n](...t),o&&s.done]))[0]};return M.set(t,s),s}N(e=>({...e,get:(t,n,r)=>P(t,n)||e.get(t,n,r),has:(t,n)=>!!P(t,n)||e.has(t,n)}));const D=["continue","continuePrimaryKey","advance"],F={},R=/* @__PURE__ */new WeakMap,L=/* @__PURE__ */new WeakMap,U={get(e,t){if(!D.includes(t))return e[t];let n=F[t];return n||(n=F[t]=function(...e){R.set(this,L.get(this)[t](...e))}),n}};async function*J(...e){let t=this;if(t instanceof IDBCursor||(t=await t.openCursor(...e)),!t)return;const n=new Proxy(t,U);for(L.set(n,t),I.set(n,A(t));t;)yield n,t=await(R.get(n)||t.continue()),R.delete(n)}function B(e,t){return t===Symbol.asyncIterator&&z(e,[IDBIndex,IDBObjectStore,IDBCursor])||"iterate"===t&&z(e,[IDBIndex,IDBObjectStore])}N(e=>({...e,get:(t,n,r)=>B(t,n)?J:e.get(t,n,r),has:(t,n)=>B(t,n)||e.has(t,n)}));const W=new class{db=null;DB_NAME="botuyo-chat";DB_VERSION=1;async init(){try{this.db=await function(e,t,{blocked:n,upgrade:r,blocking:o,terminated:s}={}){const i=indexedDB.open(e,t),a=T(i);return r&&i.addEventListener("upgradeneeded",e=>{r(T(i.result),e.oldVersion,e.newVersion,T(i.transaction),e)}),n&&i.addEventListener("blocked",e=>n(e.oldVersion,e.newVersion,e)),a.then(e=>{s&&e.addEventListener("close",()=>s()),o&&e.addEventListener("versionchange",e=>o(e.oldVersion,e.newVersion,e))}).catch(()=>{}),a}(this.DB_NAME,this.DB_VERSION,{upgrade(e){e.objectStoreNames.contains("messages")||e.createObjectStore("messages",{keyPath:"id"}).createIndex("by-timestamp","timestamp"),e.objectStoreNames.contains("metadata")||e.createObjectStore("metadata")}}),d.info("IndexedDB initialized")}catch(e){throw d.error("Failed to initialize IndexedDB:",e),e}}async saveMessage(e){this.db||await this.init();try{await this.db.put("messages",e)}catch(t){d.error("Failed to save message:",t)}}async saveMessages(e){this.db||await this.init();try{const t=this.db.transaction("messages","readwrite");await Promise.all([...e.map(e=>t.store.put(e)),t.done])}catch(t){d.error("Failed to save messages:",t)}}async getMessages(e=100){this.db||await this.init();try{return(await this.db.getAllFromIndex("messages","by-timestamp")).slice(-e)}catch(t){return d.error("Failed to get messages:",t),[]}}async getMessage(e){this.db||await this.init();try{return await this.db.get("messages",e)}catch(t){return void d.error("Failed to get message:",t)}}async deleteMessage(e){this.db||await this.init();try{await this.db.delete("messages",e)}catch(t){d.error("Failed to delete message:",t)}}async clearMessages(){this.db||await this.init();try{await this.db.clear("messages"),d.info("Messages cleared from IndexedDB")}catch(e){d.error("Failed to clear messages:",e)}}async setMetadata(e){this.db||await this.init();try{await this.db.put("metadata",e,"chat-metadata")}catch(t){d.error("Failed to set metadata:",t)}}async getMetadata(){this.db||await this.init();try{return await this.db.get("metadata","chat-metadata")}catch(e){return d.error("Failed to get metadata:",e),null}}async clearAll(){this.db||await this.init();try{await Promise.all([this.db.clear("messages"),this.db.clear("metadata")]),d.info("All data cleared from IndexedDB")}catch(e){d.error("Failed to clear all data:",e)}}async migrateFromLocalStorage(){try{const e="botuyo_chat_v1",t=localStorage.getItem(e);if(!t)return;const n=JSON.parse(t);if(n.messages&&Array.isArray(n.messages)){const e=n.messages.map(e=>({...e,timestamp:new Date(e.timestamp)}));await this.saveMessages(e),d.info(`Migrated ${e.length} messages from localStorage`)}n.sessionId&&await this.setMetadata({sessionId:n.sessionId}),localStorage.removeItem(e),d.info("Migration from localStorage completed")}catch(e){d.error("Failed to migrate from localStorage:",e)}}},V="botuyo_chat_v1",q={isOpen:!1,isConnected:!1,isTyping:!1,messages:[],error:null,sessionId:null};function G(e,t){switch(t.type){case"TOGGLE_WINDOW":return{...e,isOpen:!e.isOpen};case"OPEN_WINDOW":return{...e,isOpen:!0};case"CLOSE_WINDOW":return{...e,isOpen:!1};case"SET_CONNECTED":return{...e,isConnected:t.payload};case"SET_TYPING":return{...e,isTyping:t.payload};case"ADD_MESSAGE":{if(e.messages.some(e=>e.id===t.payload.id))return e;const n=[...e.messages,t.payload],r="bot"===t.payload.sender;return{...e,messages:n,isTyping:!r&&e.isTyping}}case"SET_MESSAGES":return{...e,messages:[...t.payload]};case"SET_ERROR":return{...e,error:t.payload};case"SET_SESSION_ID":return{...e,sessionId:t.payload};case"CLEAR_CHAT":return{...q,isOpen:e.isOpen};case"RESTORE_SESSION":return{...e,...t.payload,isConnected:!1,isTyping:!1,error:null};default:return e}}function K(e,t,n){function r(n,r){if(n._zod||Object.defineProperty(n,"_zod",{value:{def:r,constr:i,traits:/* @__PURE__ */new Set},enumerable:!1}),n._zod.traits.has(e))return;n._zod.traits.add(e),t(n,r);const o=i.prototype,s=Object.keys(o);for(let e=0;e<s.length;e++){const t=s[e];t in n||(n[t]=o[t].bind(n))}}const o=n?.Parent??Object;class s extends o{}function i(e){var t;const o=n?.Parent?new s:this;r(o,e),(t=o._zod).deferred??(t.deferred=[]);for(const n of o._zod.deferred)n();return o}return Object.defineProperty(s,"name",{value:e}),Object.defineProperty(i,"init",{value:r}),Object.defineProperty(i,Symbol.hasInstance,{value:t=>!!(n?.Parent&&t instanceof n.Parent)||t?._zod?.traits?.has(e)}),Object.defineProperty(i,"name",{value:e}),i}class H extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class Y extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`),this.name="ZodEncodeError"}}const X={};function Q(e){return X}function ee(e){const t=Object.values(e).filter(e=>"number"==typeof e);return Object.entries(e).filter(([e,n])=>-1===t.indexOf(+e)).map(([e,t])=>t)}function te(e,t){return"bigint"==typeof t?t.toString():t}function ne(e){return{get value(){{const t=e();return Object.defineProperty(this,"value",{value:t}),t}}}}function re(e){return null==e}function oe(e){const t=e.startsWith("^")?1:0,n=e.endsWith("$")?e.length-1:e.length;return e.slice(t,n)}const se=/* @__PURE__ */Symbol("evaluating");function ie(e,t,n){let r;Object.defineProperty(e,t,{get(){if(r!==se)return void 0===r&&(r=se,r=n()),r},set(n){Object.defineProperty(e,t,{value:n})},configurable:!0})}function ae(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function ce(...e){const t={};for(const n of e){const e=Object.getOwnPropertyDescriptors(n);Object.assign(t,e)}return Object.defineProperties({},t)}function ue(e){return JSON.stringify(e)}const de="captureStackTrace"in Error?Error.captureStackTrace:(...e)=>{};function le(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}const pe=ne(()=>{if("undefined"!=typeof navigator&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{return new Function(""),!0}catch(e){return!1}});function fe(e){if(!1===le(e))return!1;const t=e.constructor;if(void 0===t)return!0;if("function"!=typeof t)return!0;const n=t.prototype;return!1!==le(n)&&!1!==Object.prototype.hasOwnProperty.call(n,"isPrototypeOf")}function me(e){return fe(e)?{...e}:Array.isArray(e)?[...e]:e}const he=/* @__PURE__ */new Set(["string","number","symbol"]);function ge(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function ye(e,t,n){const r=new e._zod.constr(t??e._zod.def);return t&&!n?.parent||(r._zod.parent=e),r}function ve(e){const t=e;if(!t)return{};if("string"==typeof t)return{error:()=>t};if(void 0!==t?.message){if(void 0!==t?.error)throw new Error("Cannot specify both `message` and `error` params");t.error=t.message}return delete t.message,"string"==typeof t.error?{...t,error:()=>t.error}:t}const be={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 _e(e,t=0){if(!0===e.aborted)return!0;for(let n=t;n<e.issues.length;n++)if(!0!==e.issues[n]?.continue)return!0;return!1}function we(e,t){return t.map(t=>{var n;return(n=t).path??(n.path=[]),t.path.unshift(e),t})}function ke(e){return"string"==typeof e?e:e?.message}function ze(e,t,n){const r={...e,path:e.path??[]};if(!e.message){const o=ke(e.inst?._zod.def?.error?.(e))??ke(t?.error?.(e))??ke(n.customError?.(e))??ke(n.localeError?.(e))??"Invalid input";r.message=o}return delete r.inst,delete r.continue,t?.reportInput||delete r.input,r}function xe(e){return Array.isArray(e)?"array":"string"==typeof e?"string":"unknown"}function Ee(...e){const[t,n,r]=e;return"string"==typeof t?{message:t,code:"custom",input:n,inst:r}:{...t}}const Se=(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,te,2),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},Oe=K("$ZodError",Se),Ie=K("$ZodError",Se,{Parent:Error}),$e=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 H;if(i.issues.length){const t=new(o?.Err??e)(i.issues.map(e=>ze(e,s,Q())));throw de(t,o?.callee),t}return i.value},Ne=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 t=new(o?.Err??e)(i.issues.map(e=>ze(e,s,Q())));throw de(t,o?.callee),t}return i.value},Ce=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 H;return s.issues.length?{success:!1,error:new(e??Oe)(s.issues.map(e=>ze(e,o,Q())))}:{success:!0,data:s.value}},Te=/* @__PURE__ */Ce(Ie),Ae=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(e=>ze(e,o,Q())))}:{success:!0,data:s.value}},je=/* @__PURE__ */Ae(Ie),Ze=e=>(t,n,r)=>{const o=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return $e(e)(t,n,o)},Me=e=>(t,n,r)=>$e(e)(t,n,r),Pe=e=>async(t,n,r)=>{const o=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return Ne(e)(t,n,o)},De=e=>async(t,n,r)=>Ne(e)(t,n,r),Fe=e=>(t,n,r)=>{const o=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return Ce(e)(t,n,o)},Re=e=>(t,n,r)=>Ce(e)(t,n,r),Le=e=>async(t,n,r)=>{const o=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return Ae(e)(t,n,o)},Ue=e=>async(t,n,r)=>Ae(e)(t,n,r),Je=/^[cC][^\s-]{8,}$/,Be=/^[0-9a-z]+$/,We=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,Ve=/^[0-9a-vA-V]{20}$/,qe=/^[A-Za-z0-9]{27}$/,Ge=/^[a-zA-Z0-9_-]{21}$/,Ke=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,He=/^([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})$/,Ye=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)$/,Xe=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,Qe=/^(?:(?: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])$/,et=/^(([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}|:))$/,tt=/^((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])$/,nt=/^(([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])$/,rt=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,ot=/^[A-Za-z0-9_-]*$/,st=/^\+[1-9]\d{6,14}$/,it="(?:(?:\\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])))",at=/* @__PURE__ */new RegExp(`^${it}$`);function ct(e){const t="(?:[01]\\d|2[0-3]):[0-5]\\d";return"number"==typeof e.precision?-1===e.precision?`${t}`:0===e.precision?`${t}:[0-5]\\d`:`${t}:[0-5]\\d\\.\\d{${e.precision}}`:`${t}(?::[0-5]\\d(?:\\.\\d+)?)?`}const ut=/^-?\d+$/,dt=/^-?\d+(?:\.\d+)?$/,lt=/^[^A-Z]*$/,pt=/^[^a-z]*$/,ft=/* @__PURE__ */K("$ZodCheck",(e,t)=>{var n;e._zod??(e._zod={}),e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),mt={number:"number",bigint:"bigint",object:"date"},ht=/* @__PURE__ */K("$ZodCheckLessThan",(e,t)=>{ft.init(e,t);const n=mt[typeof t.value];e._zod.onattach.push(e=>{const n=e._zod.bag,r=(t.inclusive?n.maximum:n.exclusiveMaximum)??Number.POSITIVE_INFINITY;t.value<r&&(t.inclusive?n.maximum=t.value:n.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:"object"==typeof t.value?t.value.getTime():t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),gt=/* @__PURE__ */K("$ZodCheckGreaterThan",(e,t)=>{ft.init(e,t);const n=mt[typeof t.value];e._zod.onattach.push(e=>{const n=e._zod.bag,r=(t.inclusive?n.minimum:n.exclusiveMinimum)??Number.NEGATIVE_INFINITY;t.value>r&&(t.inclusive?n.minimum=t.value:n.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:"object"==typeof t.value?t.value.getTime():t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),yt=/* @__PURE__ */K("$ZodCheckMultipleOf",(e,t)=>{ft.init(e,t),e._zod.onattach.push(e=>{var n;(n=e._zod.bag).multipleOf??(n.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.");("bigint"==typeof n.value?n.value%t.value===BigInt(0):0===function(e,t){const n=(e.toString().split(".")[1]||"").length,r=t.toString();let o=(r.split(".")[1]||"").length;if(0===o&&/\d?e-\d?/.test(r)){const e=r.match(/\d?e-(\d?)/);e?.[1]&&(o=Number.parseInt(e[1]))}const s=n>o?n:o;return Number.parseInt(e.toFixed(s).replace(".",""))%Number.parseInt(t.toFixed(s).replace(".",""))/10**s}(n.value,t.value))||n.issues.push({origin:typeof n.value,code:"not_multiple_of",divisor:t.value,input:n.value,inst:e,continue:!t.abort})}}),vt=/* @__PURE__ */K("$ZodCheckNumberFormat",(e,t)=>{ft.init(e,t),t.format=t.format||"float64";const n=t.format?.includes("int"),r=n?"int":"number",[o,s]=be[t.format];e._zod.onattach.push(e=>{const r=e._zod.bag;r.format=t.format,r.minimum=o,r.maximum=s,n&&(r.pattern=ut)}),e._zod.check=i=>{const a=i.value;if(n){if(!Number.isInteger(a))return void i.issues.push({expected:r,format:t.format,code:"invalid_type",continue:!1,input:a,inst:e});if(!Number.isSafeInteger(a))return void(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}))}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})}}),bt=/* @__PURE__ */K("$ZodCheckMaxLength",(e,t)=>{var n;ft.init(e,t),(n=e._zod.def).when??(n.when=e=>{const t=e.value;return!re(t)&&void 0!==t.length}),e._zod.onattach.push(e=>{const n=e._zod.bag.maximum??Number.POSITIVE_INFINITY;t.maximum<n&&(e._zod.bag.maximum=t.maximum)}),e._zod.check=n=>{const r=n.value;if(r.length<=t.maximum)return;const o=xe(r);n.issues.push({origin:o,code:"too_big",maximum:t.maximum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),_t=/* @__PURE__ */K("$ZodCheckMinLength",(e,t)=>{var n;ft.init(e,t),(n=e._zod.def).when??(n.when=e=>{const t=e.value;return!re(t)&&void 0!==t.length}),e._zod.onattach.push(e=>{const n=e._zod.bag.minimum??Number.NEGATIVE_INFINITY;t.minimum>n&&(e._zod.bag.minimum=t.minimum)}),e._zod.check=n=>{const r=n.value;if(r.length>=t.minimum)return;const o=xe(r);n.issues.push({origin:o,code:"too_small",minimum:t.minimum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),wt=/* @__PURE__ */K("$ZodCheckLengthEquals",(e,t)=>{var n;ft.init(e,t),(n=e._zod.def).when??(n.when=e=>{const t=e.value;return!re(t)&&void 0!==t.length}),e._zod.onattach.push(e=>{const n=e._zod.bag;n.minimum=t.length,n.maximum=t.length,n.length=t.length}),e._zod.check=n=>{const r=n.value,o=r.length;if(o===t.length)return;const s=xe(r),i=o>t.length;n.issues.push({origin:s,...i?{code:"too_big",maximum:t.length}:{code:"too_small",minimum:t.length},inclusive:!0,exact:!0,input:n.value,inst:e,continue:!t.abort})}}),kt=/* @__PURE__ */K("$ZodCheckStringFormat",(e,t)=>{var n,r;ft.init(e,t),e._zod.onattach.push(e=>{const n=e._zod.bag;n.format=t.format,t.pattern&&(n.patterns??(n.patterns=/* @__PURE__ */new Set),n.patterns.add(t.pattern))}),t.pattern?(n=e._zod).check??(n.check=n=>{t.pattern.lastIndex=0,t.pattern.test(n.value)||n.issues.push({origin:"string",code:"invalid_format",format:t.format,input:n.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})}):(r=e._zod).check??(r.check=()=>{})}),zt=/* @__PURE__ */K("$ZodCheckRegex",(e,t)=>{kt.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})}}),xt=/* @__PURE__ */K("$ZodCheckLowerCase",(e,t)=>{t.pattern??(t.pattern=lt),kt.init(e,t)}),Et=/* @__PURE__ */K("$ZodCheckUpperCase",(e,t)=>{t.pattern??(t.pattern=pt),kt.init(e,t)}),St=/* @__PURE__ */K("$ZodCheckIncludes",(e,t)=>{ft.init(e,t);const n=ge(t.includes),r=new RegExp("number"==typeof t.position?`^.{${t.position}}${n}`:n);t.pattern=r,e._zod.onattach.push(e=>{const t=e._zod.bag;t.patterns??(t.patterns=/* @__PURE__ */new Set),t.patterns.add(r)}),e._zod.check=n=>{n.value.includes(t.includes,t.position)||n.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:t.includes,input:n.value,inst:e,continue:!t.abort})}}),Ot=/* @__PURE__ */K("$ZodCheckStartsWith",(e,t)=>{ft.init(e,t);const n=new RegExp(`^${ge(t.prefix)}.*`);t.pattern??(t.pattern=n),e._zod.onattach.push(e=>{const t=e._zod.bag;t.patterns??(t.patterns=/* @__PURE__ */new Set),t.patterns.add(n)}),e._zod.check=n=>{n.value.startsWith(t.prefix)||n.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:t.prefix,input:n.value,inst:e,continue:!t.abort})}}),It=/* @__PURE__ */K("$ZodCheckEndsWith",(e,t)=>{ft.init(e,t);const n=new RegExp(`.*${ge(t.suffix)}$`);t.pattern??(t.pattern=n),e._zod.onattach.push(e=>{const t=e._zod.bag;t.patterns??(t.patterns=/* @__PURE__ */new Set),t.patterns.add(n)}),e._zod.check=n=>{n.value.endsWith(t.suffix)||n.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:t.suffix,input:n.value,inst:e,continue:!t.abort})}}),$t=/* @__PURE__ */K("$ZodCheckOverwrite",(e,t)=>{ft.init(e,t),e._zod.check=e=>{e.value=t.tx(e.value)}});class Nt{constructor(e=[]){this.content=[],this.indent=0,this&&(this.args=e)}indented(e){this.indent+=1,e(this),this.indent-=1}write(e){if("function"==typeof e)return e(this,{execution:"sync"}),void e(this,{execution:"async"});const t=e.split("\n").filter(e=>e),n=Math.min(...t.map(e=>e.length-e.trimStart().length)),r=t.map(e=>e.slice(n)).map(e=>" ".repeat(2*this.indent)+e);for(const o of r)this.content.push(o)}compile(){const e=Function,t=this?.args;return new e(...t,[...(this?.content??[""]).map(e=>` ${e}`)].join("\n"))}}const Ct={major:4,minor:3,patch:6},Tt=/* @__PURE__ */K("$ZodType",(e,t)=>{var n;e??(e={}),e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=Ct;const r=[...e._zod.def.checks??[]];e._zod.traits.has("$ZodCheck")&&r.unshift(e);for(const o of r)for(const t of o._zod.onattach)t(e);if(0===r.length)(n=e._zod).deferred??(n.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{const t=(e,t,n)=>{let r,o=_e(e);for(const s of t){if(s._zod.def.when){if(!s._zod.def.when(e))continue}else if(o)continue;const t=e.issues.length,i=s._zod.check(e);if(i instanceof Promise&&!1===n?.async)throw new H;if(r||i instanceof Promise)r=(r??Promise.resolve()).then(async()=>{await i,e.issues.length!==t&&(o||(o=_e(e,t)))});else{if(e.issues.length===t)continue;o||(o=_e(e,t))}}return r?r.then(()=>e):e},n=(n,o,s)=>{if(_e(n))return n.aborted=!0,n;const i=t(o,r,s);if(i instanceof Promise){if(!1===s.async)throw new H;return i.then(t=>e._zod.parse(t,s))}return e._zod.parse(i,s)};e._zod.run=(o,s)=>{if(s.skipChecks)return e._zod.parse(o,s);if("backward"===s.direction){const t=e._zod.parse({value:o.value,issues:[]},{...s,skipChecks:!0});return t instanceof Promise?t.then(e=>n(e,o,s)):n(t,o,s)}const i=e._zod.parse(o,s);if(i instanceof Promise){if(!1===s.async)throw new H;return i.then(e=>t(e,r,s))}return t(i,r,s)}}ie(e,"~standard",()=>({validate:t=>{try{const n=Te(e,t);return n.success?{value:n.data}:{issues:n.error?.issues}}catch(n){return je(e,t).then(e=>e.success?{value:e.data}:{issues:e.error?.issues})}},vendor:"zod",version:1}))}),At=/* @__PURE__ */K("$ZodString",(e,t)=>{var n;Tt.init(e,t),e._zod.pattern=[...e?._zod.bag?.patterns??[]].pop()??(n=e._zod.bag,new RegExp(`^${n?`[\\s\\S]{${n?.minimum??0},${n?.maximum??""}}`:"[\\s\\S]*"}$`)),e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=String(n.value)}catch(o){}return"string"==typeof n.value||n.issues.push({expected:"string",code:"invalid_type",input:n.value,inst:e}),n}}),jt=/* @__PURE__ */K("$ZodStringFormat",(e,t)=>{kt.init(e,t),At.init(e,t)}),Zt=/* @__PURE__ */K("$ZodGUID",(e,t)=>{t.pattern??(t.pattern=He),jt.init(e,t)}),Mt=/* @__PURE__ */K("$ZodUUID",(e,t)=>{if(t.version){const e={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[t.version];if(void 0===e)throw new Error(`Invalid UUID version: "${t.version}"`);t.pattern??(t.pattern=Ye(e))}else t.pattern??(t.pattern=Ye());jt.init(e,t)}),Pt=/* @__PURE__ */K("$ZodEmail",(e,t)=>{t.pattern??(t.pattern=Xe),jt.init(e,t)}),Dt=/* @__PURE__ */K("$ZodURL",(e,t)=>{jt.init(e,t),e._zod.check=n=>{try{const r=n.value.trim(),o=new URL(r);return 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})),void(t.normalize?n.value=o.href:n.value=r)}catch(r){n.issues.push({code:"invalid_format",format:"url",input:n.value,inst:e,continue:!t.abort})}}}),Ft=/* @__PURE__ */K("$ZodEmoji",(e,t)=>{t.pattern??(t.pattern=new RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$","u")),jt.init(e,t)}),Rt=/* @__PURE__ */K("$ZodNanoID",(e,t)=>{t.pattern??(t.pattern=Ge),jt.init(e,t)}),Lt=/* @__PURE__ */K("$ZodCUID",(e,t)=>{t.pattern??(t.pattern=Je),jt.init(e,t)}),Ut=/* @__PURE__ */K("$ZodCUID2",(e,t)=>{t.pattern??(t.pattern=Be),jt.init(e,t)}),Jt=/* @__PURE__ */K("$ZodULID",(e,t)=>{t.pattern??(t.pattern=We),jt.init(e,t)}),Bt=/* @__PURE__ */K("$ZodXID",(e,t)=>{t.pattern??(t.pattern=Ve),jt.init(e,t)}),Wt=/* @__PURE__ */K("$ZodKSUID",(e,t)=>{t.pattern??(t.pattern=qe),jt.init(e,t)}),Vt=/* @__PURE__ */K("$ZodISODateTime",(e,t)=>{t.pattern??(t.pattern=function(e){const t=ct({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(`^${it}T(?:${r})$`)}(t)),jt.init(e,t)}),qt=/* @__PURE__ */K("$ZodISODate",(e,t)=>{t.pattern??(t.pattern=at),jt.init(e,t)}),Gt=/* @__PURE__ */K("$ZodISOTime",(e,t)=>{t.pattern??(t.pattern=new RegExp(`^${ct(t)}$`)),jt.init(e,t)}),Kt=/* @__PURE__ */K("$ZodISODuration",(e,t)=>{t.pattern??(t.pattern=Ke),jt.init(e,t)}),Ht=/* @__PURE__ */K("$ZodIPv4",(e,t)=>{t.pattern??(t.pattern=Qe),jt.init(e,t),e._zod.bag.format="ipv4"}),Yt=/* @__PURE__ */K("$ZodIPv6",(e,t)=>{t.pattern??(t.pattern=et),jt.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})}}}),Xt=/* @__PURE__ */K("$ZodCIDRv4",(e,t)=>{t.pattern??(t.pattern=tt),jt.init(e,t)}),Qt=/* @__PURE__ */K("$ZodCIDRv6",(e,t)=>{t.pattern??(t.pattern=nt),jt.init(e,t),e._zod.check=n=>{const r=n.value.split("/");try{if(2!==r.length)throw new Error;const[e,t]=r;if(!t)throw new Error;const n=Number(t);if(`${n}`!==t)throw new Error;if(n<0||n>128)throw new Error;new URL(`http://[${e}]`)}catch{n.issues.push({code:"invalid_format",format:"cidrv6",input:n.value,inst:e,continue:!t.abort})}}});function en(e){if(""===e)return!0;if(e.length%4!=0)return!1;try{return atob(e),!0}catch{return!1}}const tn=/* @__PURE__ */K("$ZodBase64",(e,t)=>{t.pattern??(t.pattern=rt),jt.init(e,t),e._zod.bag.contentEncoding="base64",e._zod.check=n=>{en(n.value)||n.issues.push({code:"invalid_format",format:"base64",input:n.value,inst:e,continue:!t.abort})}}),nn=/* @__PURE__ */K("$ZodBase64URL",(e,t)=>{t.pattern??(t.pattern=ot),jt.init(e,t),e._zod.bag.contentEncoding="base64url",e._zod.check=n=>{(function(e){if(!ot.test(e))return!1;const t=e.replace(/[-_]/g,e=>"-"===e?"+":"/");return en(t.padEnd(4*Math.ceil(t.length/4),"="))})(n.value)||n.issues.push({code:"invalid_format",format:"base64url",input:n.value,inst:e,continue:!t.abort})}}),rn=/* @__PURE__ */K("$ZodE164",(e,t)=>{t.pattern??(t.pattern=st),jt.init(e,t)}),on=/* @__PURE__ */K("$ZodJWT",(e,t)=>{jt.init(e,t),e._zod.check=n=>{(function(e,t=null){try{const n=e.split(".");if(3!==n.length)return!1;const[r]=n;if(!r)return!1;const o=JSON.parse(atob(r));return!("typ"in o&&"JWT"!==o?.typ||!o.alg||t&&(!("alg"in o)||o.alg!==t))}catch{return!1}})(n.value,t.alg)||n.issues.push({code:"invalid_format",format:"jwt",input:n.value,inst:e,continue:!t.abort})}}),sn=/* @__PURE__ */K("$ZodNumber",(e,t)=>{Tt.init(e,t),e._zod.pattern=e._zod.bag.pattern??dt,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=Number(n.value)}catch(i){}const o=n.value;if("number"==typeof o&&!Number.isNaN(o)&&Number.isFinite(o))return n;const s="number"==typeof o?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}}),an=/* @__PURE__ */K("$ZodNumberFormat",(e,t)=>{vt.init(e,t),sn.init(e,t)}),cn=/* @__PURE__ */K("$ZodAny",(e,t)=>{Tt.init(e,t),e._zod.parse=e=>e}),un=/* @__PURE__ */K("$ZodUnknown",(e,t)=>{Tt.init(e,t),e._zod.parse=e=>e}),dn=/* @__PURE__ */K("$ZodNever",(e,t)=>{Tt.init(e,t),e._zod.parse=(t,n)=>(t.issues.push({expected:"never",code:"invalid_type",input:t.value,inst:e}),t)});function ln(e,t,n){e.issues.length&&t.issues.push(...we(n,e.issues)),t.value[n]=e.value}const pn=/* @__PURE__ */K("$ZodArray",(e,t)=>{Tt.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 e=0;e<o.length;e++){const i=o[e],a=t.element._zod.run({value:i,issues:[]},r);a instanceof Promise?s.push(a.then(t=>ln(t,n,e))):ln(a,n,e)}return s.length?Promise.all(s).then(()=>n):n}});function fn(e,t,n,r,o){if(e.issues.length){if(o&&!(n in r))return;t.issues.push(...we(n,e.issues))}void 0===e.value?n in r&&(t.value[n]=void 0):t.value[n]=e.value}function mn(e){const t=Object.keys(e.shape);for(const o of t)if(!e.shape?.[o]?._zod?.traits?.has("$ZodType"))throw new Error(`Invalid element at key "${o}": expected a Zod schema`);const n=(r=e.shape,Object.keys(r).filter(e=>"optional"===r[e]._zod.optin&&"optional"===r[e]._zod.optout));var r;return{...e,keys:t,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(n)}}function hn(e,t,n,r,o,s){const i=[],a=o.keySet,c=o.catchall._zod,u=c.def.type,d="optional"===c.optout;for(const l in t){if(a.has(l))continue;if("never"===u){i.push(l);continue}const o=c.run({value:t[l],issues:[]},r);o instanceof Promise?e.push(o.then(e=>fn(e,n,l,t,d))):fn(o,n,l,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 gn=/* @__PURE__ */K("$ZodObject",(e,t)=>{Tt.init(e,t);const n=Object.getOwnPropertyDescriptor(t,"shape");if(!n?.get){const e=t.shape;Object.defineProperty(t,"shape",{get:()=>{const n={...e};return Object.defineProperty(t,"shape",{value:n}),n}})}const r=ne(()=>mn(t));ie(e._zod,"propValues",()=>{const e=t.shape,n={};for(const t in e){const r=e[t]._zod;if(r.values){n[t]??(n[t]=/* @__PURE__ */new Set);for(const e of r.values)n[t].add(e)}}return n});const o=le,s=t.catchall;let i;e._zod.parse=(t,n)=>{i??(i=r.value);const a=t.value;if(!o(a))return t.issues.push({expected:"object",code:"invalid_type",input:a,inst:e}),t;t.value={};const c=[],u=i.shape;for(const e of i.keys){const r=u[e],o="optional"===r._zod.optout,s=r._zod.run({value:a[e],issues:[]},n);s instanceof Promise?c.push(s.then(n=>fn(n,t,e,a,o))):fn(s,t,e,a,o)}return s?hn(c,a,t,n,r.value,e):c.length?Promise.all(c).then(()=>t):t}}),yn=/* @__PURE__ */K("$ZodObjectJIT",(e,t)=>{gn.init(e,t);const n=e._zod.parse,r=ne(()=>mn(t));let o;const s=le,i=!X.jitless,a=i&&pe.value,c=t.catchall;let u;e._zod.parse=(d,l)=>{u??(u=r.value);const p=d.value;return s(p)?i&&a&&!1===l?.async&&!0!==l.jitless?(o||(o=(e=>{const t=new Nt(["shape","payload","ctx"]),n=r.value,o=e=>{const t=ue(e);return`shape[${t}]._zod.run({ value: input[${t}], issues: [] }, ctx)`};t.write("const input = payload.value;");const s=/* @__PURE__ */Object.create(null);let i=0;for(const r of n.keys)s[r]="key_"+i++;t.write("const newResult = {};");for(const r of n.keys){const n=s[r],i=ue(r),a=e[r],c="optional"===a?._zod?.optout;t.write(`const ${n} = ${o(r)};`),c?t.write(`\n if (${n}.issues.length) {\n if (${i} in input) {\n payload.issues = payload.issues.concat(${n}.issues.map(iss => ({\n ...iss,\n path: iss.path ? [${i}, ...iss.path] : [${i}]\n })));\n }\n }\n \n if (${n}.value === undefined) {\n if (${i} in input) {\n newResult[${i}] = undefined;\n }\n } else {\n newResult[${i}] = ${n}.value;\n }\n \n `):t.write(`\n if (${n}.issues.length) {\n payload.issues = payload.issues.concat(${n}.issues.map(iss => ({\n ...iss,\n path: iss.path ? [${i}, ...iss.path] : [${i}]\n })));\n }\n \n if (${n}.value === undefined) {\n if (${i} in input) {\n newResult[${i}] = undefined;\n }\n } else {\n newResult[${i}] = ${n}.value;\n }\n \n `)}t.write("payload.value = newResult;"),t.write("return payload;");const a=t.compile();return(t,n)=>a(e,t,n)})(t.shape)),d=o(d,l),c?hn([],p,d,l,u,e):d):n(d,l):(d.issues.push({expected:"object",code:"invalid_type",input:p,inst:e}),d)}});function vn(e,t,n,r){for(const s of e)if(0===s.issues.length)return t.value=s.value,t;const o=e.filter(e=>!_e(e));return 1===o.length?(t.value=o[0].value,o[0]):(t.issues.push({code:"invalid_union",input:t.value,inst:n,errors:e.map(e=>e.issues.map(e=>ze(e,r,Q())))}),t)}const bn=/* @__PURE__ */K("$ZodUnion",(e,t)=>{Tt.init(e,t),ie(e._zod,"optin",()=>t.options.some(e=>"optional"===e._zod.optin)?"optional":void 0),ie(e._zod,"optout",()=>t.options.some(e=>"optional"===e._zod.optout)?"optional":void 0),ie(e._zod,"values",()=>{if(t.options.every(e=>e._zod.values))return new Set(t.options.flatMap(e=>Array.from(e._zod.values)))}),ie(e._zod,"pattern",()=>{if(t.options.every(e=>e._zod.pattern)){const e=t.options.map(e=>e._zod.pattern);return new RegExp(`^(${e.map(e=>oe(e.source)).join("|")})$`)}});const n=1===t.options.length,r=t.options[0]._zod.run;e._zod.parse=(o,s)=>{if(n)return r(o,s);let i=!1;const a=[];for(const e of t.options){const t=e._zod.run({value:o.value,issues:[]},s);if(t instanceof Promise)a.push(t),i=!0;else{if(0===t.issues.length)return t;a.push(t)}}return i?Promise.all(a).then(t=>vn(t,o,e,s)):vn(a,o,e,s)}}),_n=/* @__PURE__ */K("$ZodIntersection",(e,t)=>{Tt.init(e,t),e._zod.parse=(e,n)=>{const r=e.value,o=t.left._zod.run({value:r,issues:[]},n),s=t.right._zod.run({value:r,issues:[]},n);return o instanceof Promise||s instanceof Promise?Promise.all([o,s]).then(([t,n])=>kn(e,t,n)):kn(e,o,s)}});function wn(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(fe(e)&&fe(t)){const n=Object.keys(t),r=Object.keys(e).filter(e=>-1!==n.indexOf(e)),o={...e,...t};for(const s of r){const n=wn(e[s],t[s]);if(!n.valid)return{valid:!1,mergeErrorPath:[s,...n.mergeErrorPath]};o[s]=n.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=wn(e[r],t[r]);if(!o.valid)return{valid:!1,mergeErrorPath:[r,...o.mergeErrorPath]};n.push(o.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function kn(e,t,n){const r=/* @__PURE__ */new Map;let o;for(const a of t.issues)if("unrecognized_keys"===a.code){o??(o=a);for(const e of a.keys)r.has(e)||r.set(e,{}),r.get(e).l=!0}else e.issues.push(a);for(const a of n.issues)if("unrecognized_keys"===a.code)for(const e of a.keys)r.has(e)||r.set(e,{}),r.get(e).r=!0;else e.issues.push(a);const s=[...r].filter(([,e])=>e.l&&e.r).map(([e])=>e);if(s.length&&o&&e.issues.push({...o,keys:s}),_e(e))return e;const i=wn(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 zn=/* @__PURE__ */K("$ZodEnum",(e,t)=>{Tt.init(e,t);const n=ee(t.entries),r=new Set(n);e._zod.values=r,e._zod.pattern=new RegExp(`^(${n.filter(e=>he.has(typeof e)).map(e=>"string"==typeof e?ge(e):e.toString()).join("|")})$`),e._zod.parse=(t,o)=>{const s=t.value;return r.has(s)||t.issues.push({code:"invalid_value",values:n,input:s,inst:e}),t}}),xn=/* @__PURE__ */K("$ZodTransform",(e,t)=>{Tt.init(e,t),e._zod.parse=(n,r)=>{if("backward"===r.direction)throw new Y(e.constructor.name);const o=t.transform(n.value,n);if(r.async)return(o instanceof Promise?o:Promise.resolve(o)).then(e=>(n.value=e,n));if(o instanceof Promise)throw new H;return n.value=o,n}});function En(e,t){return e.issues.length&&void 0===t?{issues:[],value:void 0}:e}const Sn=/* @__PURE__ */K("$ZodOptional",(e,t)=>{Tt.init(e,t),e._zod.optin="optional",e._zod.optout="optional",ie(e._zod,"values",()=>t.innerType._zod.values?/* @__PURE__ */new Set([...t.innerType._zod.values,void 0]):void 0),ie(e._zod,"pattern",()=>{const e=t.innerType._zod.pattern;return e?new RegExp(`^(${oe(e.source)})?$`):void 0}),e._zod.parse=(e,n)=>{if("optional"===t.innerType._zod.optin){const r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(t=>En(t,e.value)):En(r,e.value)}return void 0===e.value?e:t.innerType._zod.run(e,n)}}),On=/* @__PURE__ */K("$ZodExactOptional",(e,t)=>{Sn.init(e,t),ie(e._zod,"values",()=>t.innerType._zod.values),ie(e._zod,"pattern",()=>t.innerType._zod.pattern),e._zod.parse=(e,n)=>t.innerType._zod.run(e,n)}),In=/* @__PURE__ */K("$ZodNullable",(e,t)=>{Tt.init(e,t),ie(e._zod,"optin",()=>t.innerType._zod.optin),ie(e._zod,"optout",()=>t.innerType._zod.optout),ie(e._zod,"pattern",()=>{const e=t.innerType._zod.pattern;return e?new RegExp(`^(${oe(e.source)}|null)$`):void 0}),ie(e._zod,"values",()=>t.innerType._zod.values?/* @__PURE__ */new Set([...t.innerType._zod.values,null]):void 0),e._zod.parse=(e,n)=>null===e.value?e:t.innerType._zod.run(e,n)}),$n=/* @__PURE__ */K("$ZodDefault",(e,t)=>{Tt.init(e,t),e._zod.optin="optional",ie(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{if("backward"===n.direction)return t.innerType._zod.run(e,n);if(void 0===e.value)return e.value=t.defaultValue,e;const r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(e=>Nn(e,t)):Nn(r,t)}});function Nn(e,t){return void 0===e.value&&(e.value=t.defaultValue),e}const Cn=/* @__PURE__ */K("$ZodPrefault",(e,t)=>{Tt.init(e,t),e._zod.optin="optional",ie(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(e,n)=>("backward"===n.direction||void 0===e.value&&(e.value=t.defaultValue),t.innerType._zod.run(e,n))}),Tn=/* @__PURE__ */K("$ZodNonOptional",(e,t)=>{Tt.init(e,t),ie(e._zod,"values",()=>{const e=t.innerType._zod.values;return e?new Set([...e].filter(e=>void 0!==e)):void 0}),e._zod.parse=(n,r)=>{const o=t.innerType._zod.run(n,r);return o instanceof Promise?o.then(t=>An(t,e)):An(o,e)}});function An(e,t){return e.issues.length||void 0!==e.value||e.issues.push({code:"invalid_type",expected:"nonoptional",input:e.value,inst:t}),e}const jn=/* @__PURE__ */K("$ZodCatch",(e,t)=>{Tt.init(e,t),ie(e._zod,"optin",()=>t.innerType._zod.optin),ie(e._zod,"optout",()=>t.innerType._zod.optout),ie(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{if("backward"===n.direction)return t.innerType._zod.run(e,n);const r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(r=>(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>ze(e,n,Q()))},input:e.value}),e.issues=[]),e)):(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>ze(e,n,Q()))},input:e.value}),e.issues=[]),e)}}),Zn=/* @__PURE__ */K("$ZodPipe",(e,t)=>{Tt.init(e,t),ie(e._zod,"values",()=>t.in._zod.values),ie(e._zod,"optin",()=>t.in._zod.optin),ie(e._zod,"optout",()=>t.out._zod.optout),ie(e._zod,"propValues",()=>t.in._zod.propValues),e._zod.parse=(e,n)=>{if("backward"===n.direction){const r=t.out._zod.run(e,n);return r instanceof Promise?r.then(e=>Mn(e,t.in,n)):Mn(r,t.in,n)}const r=t.in._zod.run(e,n);return r instanceof Promise?r.then(e=>Mn(e,t.out,n)):Mn(r,t.out,n)}});function Mn(e,t,n){return e.issues.length?(e.aborted=!0,e):t._zod.run({value:e.value,issues:e.issues},n)}const Pn=/* @__PURE__ */K("$ZodReadonly",(e,t)=>{Tt.init(e,t),ie(e._zod,"propValues",()=>t.innerType._zod.propValues),ie(e._zod,"values",()=>t.innerType._zod.values),ie(e._zod,"optin",()=>t.innerType?._zod?.optin),ie(e._zod,"optout",()=>t.innerType?._zod?.optout),e._zod.parse=(e,n)=>{if("backward"===n.direction)return t.innerType._zod.run(e,n);const r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(Dn):Dn(r)}});function Dn(e){return e.value=Object.freeze(e.value),e}const Fn=/* @__PURE__ */K("$ZodCustom",(e,t)=>{ft.init(e,t),Tt.init(e,t),e._zod.parse=(e,t)=>e,e._zod.check=n=>{const r=n.value,o=t.fn(r);if(o instanceof Promise)return o.then(t=>Rn(t,n,r,e));Rn(o,n,r,e)}});function Rn(e,t,n,r){if(!e){const e={code:"custom",input:n,inst:r,path:[...r._zod.def.path??[]],continue:!r._zod.def.abort};r._zod.def.params&&(e.params=r._zod.def.params),t.issues.push(Ee(e))}}var Ln;(Ln=globalThis).__zod_globalRegistry??(Ln.__zod_globalRegistry=new class{constructor(){this._map=/* @__PURE__ */new WeakMap,this._idmap=/* @__PURE__ */new Map}add(e,...t){const n=t[0];return this._map.set(e,n),n&&"object"==typeof n&&"id"in n&&this._idmap.set(n.id,e),this}clear(){return this._map=/* @__PURE__ */new WeakMap,this._idmap=/* @__PURE__ */new Map,this}remove(e){const t=this._map.get(e);return t&&"object"==typeof t&&"id"in t&&this._idmap.delete(t.id),this._map.delete(e),this}get(e){const t=e._zod.parent;if(t){const n={...this.get(t)??{}};delete n.id;const r={...n,...this._map.get(e)};return Object.keys(r).length?r:void 0}return this._map.get(e)}has(e){return this._map.has(e)}});const Un=globalThis.__zod_globalRegistry;function Jn(e,t){return new e({type:"string",...ve(t)})}function Bn(e,t){return new e({type:"string",format:"email",check:"string_format",abort:!1,...ve(t)})}function Wn(e,t){return new e({type:"string",format:"guid",check:"string_format",abort:!1,...ve(t)})}function Vn(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,...ve(t)})}function qn(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...ve(t)})}function Gn(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...ve(t)})}function Kn(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...ve(t)})}function Hn(e,t){return new e({type:"string",format:"url",check:"string_format",abort:!1,...ve(t)})}function Yn(e,t){return new e({type:"string",format:"emoji",check:"string_format",abort:!1,...ve(t)})}function Xn(e,t){return new e({type:"string",format:"nanoid",check:"string_format",abort:!1,...ve(t)})}function Qn(e,t){return new e({type:"string",format:"cuid",check:"string_format",abort:!1,...ve(t)})}function er(e,t){return new e({type:"string",format:"cuid2",check:"string_format",abort:!1,...ve(t)})}function tr(e,t){return new e({type:"string",format:"ulid",check:"string_format",abort:!1,...ve(t)})}function nr(e,t){return new e({type:"string",format:"xid",check:"string_format",abort:!1,...ve(t)})}function rr(e,t){return new e({type:"string",format:"ksuid",check:"string_format",abort:!1,...ve(t)})}function or(e,t){return new e({type:"string",format:"ipv4",check:"string_format",abort:!1,...ve(t)})}function sr(e,t){return new e({type:"string",format:"ipv6",check:"string_format",abort:!1,...ve(t)})}function ir(e,t){return new e({type:"string",format:"cidrv4",check:"string_format",abort:!1,...ve(t)})}function ar(e,t){return new e({type:"string",format:"cidrv6",check:"string_format",abort:!1,...ve(t)})}function cr(e,t){return new e({type:"string",format:"base64",check:"string_format",abort:!1,...ve(t)})}function ur(e,t){return new e({type:"string",format:"base64url",check:"string_format",abort:!1,...ve(t)})}function dr(e,t){return new e({type:"string",format:"e164",check:"string_format",abort:!1,...ve(t)})}function lr(e,t){return new e({type:"string",format:"jwt",check:"string_format",abort:!1,...ve(t)})}function pr(e,t){return new e({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...ve(t)})}function fr(e,t){return new e({type:"string",format:"date",check:"string_format",...ve(t)})}function mr(e,t){return new e({type:"string",format:"time",check:"string_format",precision:null,...ve(t)})}function hr(e,t){return new e({type:"string",format:"duration",check:"string_format",...ve(t)})}function gr(e,t){return new e({type:"number",checks:[],...ve(t)})}function yr(e,t){return new e({type:"number",check:"number_format",abort:!1,format:"safeint",...ve(t)})}function vr(e){return new e({type:"any"})}function br(e){return new e({type:"unknown"})}function _r(e,t){return new e({type:"never",...ve(t)})}function wr(e,t){return new ht({check:"less_than",...ve(t),value:e,inclusive:!1})}function kr(e,t){return new ht({check:"less_than",...ve(t),value:e,inclusive:!0})}function zr(e,t){return new gt({check:"greater_than",...ve(t),value:e,inclusive:!1})}function xr(e,t){return new gt({check:"greater_than",...ve(t),value:e,inclusive:!0})}function Er(e,t){return new yt({check:"multiple_of",...ve(t),value:e})}function Sr(e,t){return new bt({check:"max_length",...ve(t),maximum:e})}function Or(e,t){return new _t({check:"min_length",...ve(t),minimum:e})}function Ir(e,t){return new wt({check:"length_equals",...ve(t),length:e})}function $r(e,t){return new zt({check:"string_format",format:"regex",...ve(t),pattern:e})}function Nr(e){return new xt({check:"string_format",format:"lowercase",...ve(e)})}function Cr(e){return new Et({check:"string_format",format:"uppercase",...ve(e)})}function Tr(e,t){return new St({check:"string_format",format:"includes",...ve(t),includes:e})}function Ar(e,t){return new Ot({check:"string_format",format:"starts_with",...ve(t),prefix:e})}function jr(e,t){return new It({check:"string_format",format:"ends_with",...ve(t),suffix:e})}function Zr(e){return new $t({check:"overwrite",tx:e})}function Mr(e){/* @__PURE__ */
16
- return Zr(t=>t.normalize(e))}function Pr(){/* @__PURE__ */
17
- return Zr(e=>e.trim())}function Dr(){/* @__PURE__ */
18
- return Zr(e=>e.toLowerCase())}function Fr(){/* @__PURE__ */
19
- return Zr(e=>e.toUpperCase())}function Rr(){/* @__PURE__ */
20
- return Zr(e=>function(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")}(e))}function Lr(e,t,n){return new e({type:"array",element:t,...ve(n)})}function Ur(e,t,n){return new e({type:"custom",check:"custom",fn:t,...ve(n)})}function Jr(e){const t=/* @__PURE__ */Br(n=>(n.addIssue=e=>{if("string"==typeof e)n.issues.push(Ee(e,n.value,t._zod.def));else{const r=e;r.fatal&&(r.continue=!1),r.code??(r.code="custom"),r.input??(r.input=n.value),r.inst??(r.inst=t),r.continue??(r.continue=!t._zod.def.abort),n.issues.push(Ee(r))}},e(n.value,n)));return t}function Br(e,t){const n=new ft({check:"custom",...ve(t)});return n._zod.check=e,n}function Wr(e){let t=e?.target??"draft-2020-12";return"draft-4"===t&&(t="draft-04"),"draft-7"===t&&(t="draft-07"),{processors:e.processors??{},metadataRegistry:e?.metadata??Un,target:t,unrepresentable:e?.unrepresentable??"throw",override:e?.override??(()=>{}),io:e?.io??"output",counter:0,seen:/* @__PURE__ */new Map,cycles:e?.cycles??"ref",reused:e?.reused??"inline",external:e?.external??void 0}}function Vr(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 r={...n,schemaPath:[...n.schemaPath,e],path:n.path};if(e._zod.processJSONSchema)e._zod.processJSONSchema(t,i.schema,r);else{const n=i.schema,s=t.processors[o.type];if(!s)throw new Error(`[toJSONSchema]: Non-representable type encountered: ${o.type}`);s(e,t,n,r)}const s=e._zod.parent;s&&(i.ref||(i.ref=s),Vr(s,t,r),t.seen.get(s).isParent=!0)}const c=t.metadataRegistry.get(e);return c&&Object.assign(i.schema,c),"input"===t.io&&Kr(e)&&(delete i.schema.examples,delete i.schema.default),"input"===t.io&&i.schema._prefault&&((r=i.schema).default??(r.default=i.schema._prefault)),delete i.schema._prefault,t.seen.get(e).schema}function qr(e,t){const n=e.seen.get(t);if(!n)throw new Error("Unprocessed schema. This is a bug in Zod.");const r=/* @__PURE__ */new Map;for(const s of e.seen.entries()){const t=e.metadataRegistry.get(s[0])?.id;if(t){const e=r.get(t);if(e&&e!==s[0])throw new Error(`Duplicate schema id "${t}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);r.set(t,s[0])}}const o=t=>{if(t[1].schema.$ref)return;const r=t[1],{ref:o,defId:s}=(t=>{const r="draft-2020-12"===e.target?"$defs":"definitions";if(e.external){const n=e.external.registry.get(t[0])?.id,o=e.external.uri??(e=>e);if(n)return{ref:o(n)};const s=t[1].defId??t[1].schema.id??"schema"+e.counter++;return t[1].defId=s,{defId:s,ref:`${o("__shared")}#/${r}/${s}`}}if(t[1]===n)return{ref:"#"};const o=`#/${r}/`,s=t[1].schema.id??"__schema"+e.counter++;return{defId:s,ref:o+s}})(t);r.def={...r.schema},s&&(r.defId=s);const i=r.schema;for(const e in i)delete i[e];i.$ref=o};if("throw"===e.cycles)for(const s of e.seen.entries()){const e=s[1];if(e.cycle)throw new Error(`Cycle detected: #/${e.cycle?.join("/")}/<root>\n\nSet the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(const s of e.seen.entries()){const n=s[1];if(t===s[0]){o(s);continue}if(e.external){const n=e.external.registry.get(s[0])?.id;if(t!==s[0]&&n){o(s);continue}}const r=e.metadataRegistry.get(s[0])?.id;(r||n.cycle||n.count>1&&"ref"===e.reused)&&o(s)}}function Gr(e,t){const n=e.seen.get(t);if(!n)throw new Error("Unprocessed schema. This is a bug in Zod.");const r=t=>{const n=e.seen.get(t);if(null===n.ref)return;const o=n.def??n.schema,s={...o},i=n.ref;if(n.ref=null,i){r(i);const n=e.seen.get(i),a=n.schema;if(!a.$ref||"draft-07"!==e.target&&"draft-04"!==e.target&&"openapi-3.0"!==e.target?Object.assign(o,a):(o.allOf=o.allOf??[],o.allOf.push(a)),Object.assign(o,s),t._zod.parent===i)for(const e in o)"$ref"!==e&&"allOf"!==e&&(e in s||delete o[e]);if(a.$ref&&n.def)for(const e in o)"$ref"!==e&&"allOf"!==e&&e in n.def&&JSON.stringify(o[e])===JSON.stringify(n.def[e])&&delete o[e]}const a=t._zod.parent;if(a&&a!==i){r(a);const t=e.seen.get(a);if(t?.schema.$ref&&(o.$ref=t.schema.$ref,t.def))for(const e in o)"$ref"!==e&&"allOf"!==e&&e in t.def&&JSON.stringify(o[e])===JSON.stringify(t.def[e])&&delete o[e]}e.override({zodSchema:t,jsonSchema:o,path:n.path??[]})};for(const a of[...e.seen.entries()].reverse())r(a[0]);const o={};if("draft-2020-12"===e.target?o.$schema="https://json-schema.org/draft/2020-12/schema":"draft-07"===e.target?o.$schema="http://json-schema.org/draft-07/schema#":"draft-04"===e.target?o.$schema="http://json-schema.org/draft-04/schema#":e.target,e.external?.uri){const n=e.external.registry.get(t)?.id;if(!n)throw new Error("Schema is missing an `id` property");o.$id=e.external.uri(n)}Object.assign(o,n.def??n.schema);const s=e.external?.defs??{};for(const a of e.seen.entries()){const e=a[1];e.def&&e.defId&&(s[e.defId]=e.def)}e.external||Object.keys(s).length>0&&("draft-2020-12"===e.target?o.$defs=s:o.definitions=s);try{const n=JSON.parse(JSON.stringify(o));return Object.defineProperty(n,"~standard",{value:{...t["~standard"],jsonSchema:{input:Hr(t,"input",e.processors),output:Hr(t,"output",e.processors)}},enumerable:!1,writable:!1}),n}catch(i){throw new Error("Error converting schema to JSON.")}}function Kr(e,t){const n=t??{seen:/* @__PURE__ */new Set};if(n.seen.has(e))return!1;n.seen.add(e);const r=e._zod.def;if("transform"===r.type)return!0;if("array"===r.type)return Kr(r.element,n);if("set"===r.type)return Kr(r.valueType,n);if("lazy"===r.type)return Kr(r.getter(),n);if("promise"===r.type||"optional"===r.type||"nonoptional"===r.type||"nullable"===r.type||"readonly"===r.type||"default"===r.type||"prefault"===r.type)return Kr(r.innerType,n);if("intersection"===r.type)return Kr(r.left,n)||Kr(r.right,n);if("record"===r.type||"map"===r.type)return Kr(r.keyType,n)||Kr(r.valueType,n);if("pipe"===r.type)return Kr(r.in,n)||Kr(r.out,n);if("object"===r.type){for(const e in r.shape)if(Kr(r.shape[e],n))return!0;return!1}if("union"===r.type){for(const e of r.options)if(Kr(e,n))return!0;return!1}if("tuple"===r.type){for(const e of r.items)if(Kr(e,n))return!0;return!(!r.rest||!Kr(r.rest,n))}return!1}const Hr=(e,t,n={})=>r=>{const{libraryOptions:o,target:s}=r??{},i=Wr({...o??{},target:s,io:t,processors:n});return Vr(e,i),qr(i,e),Gr(i,e)},Yr={guid:"uuid",url:"uri",datetime:"date-time",json_string:"json-string",regex:""},Xr=(e,t,n,r)=>{const o=e._zod.def;Vr(o.innerType,t,r),t.seen.get(e).ref=o.innerType},Qr=/* @__PURE__ */K("ZodISODateTime",(e,t)=>{Vt.init(e,t),wo.init(e,t)}),eo=/* @__PURE__ */K("ZodISODate",(e,t)=>{qt.init(e,t),wo.init(e,t)}),to=/* @__PURE__ */K("ZodISOTime",(e,t)=>{Gt.init(e,t),wo.init(e,t)}),no=/* @__PURE__ */K("ZodISODuration",(e,t)=>{Kt.init(e,t),wo.init(e,t)}),ro=K("ZodError",(e,t)=>{Oe.init(e,t),e.name="ZodError",Object.defineProperties(e,{format:{value:t=>function(e,t=e=>e.message){const n={_errors:[]},r=e=>{for(const o of e.issues)if("invalid_union"===o.code&&o.errors.length)o.errors.map(e=>r({issues:e}));else if("invalid_key"===o.code)r({issues:o.issues});else if("invalid_element"===o.code)r({issues:o.issues});else if(0===o.path.length)n._errors.push(t(o));else{let e=n,r=0;for(;r<o.path.length;){const n=o.path[r];r===o.path.length-1?(e[n]=e[n]||{_errors:[]},e[n]._errors.push(t(o))):e[n]=e[n]||{_errors:[]},e=e[n],r++}}};return r(e),n}(e,t)},flatten:{value:t=>function(e,t=e=>e.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}}(e,t)},addIssue:{value:t=>{e.issues.push(t),e.message=JSON.stringify(e.issues,te,2)}},addIssues:{value:t=>{e.issues.push(...t),e.message=JSON.stringify(e.issues,te,2)}},isEmpty:{get:()=>0===e.issues.length}})},{Parent:Error}),oo=/* @__PURE__ */$e(ro),so=/* @__PURE__ */Ne(ro),io=/* @__PURE__ */Ce(ro),ao=/* @__PURE__ */Ae(ro),co=/* @__PURE__ */Ze(ro),uo=/* @__PURE__ */Me(ro),lo=/* @__PURE__ */Pe(ro),po=/* @__PURE__ */De(ro),fo=/* @__PURE__ */Fe(ro),mo=/* @__PURE__ */Re(ro),ho=/* @__PURE__ */Le(ro),go=/* @__PURE__ */Ue(ro),yo=/* @__PURE__ */K("ZodType",(e,t)=>(Tt.init(e,t),Object.assign(e["~standard"],{jsonSchema:{input:Hr(e,"input"),output:Hr(e,"output")}}),e.toJSONSchema=((e,t={})=>n=>{const r=Wr({...n,processors:t});return Vr(e,r),qr(r,e),Gr(r,e)})(e,{}),e.def=t,e.type=t.type,Object.defineProperty(e,"_def",{value:t}),e.check=(...n)=>e.clone(ce(t,{checks:[...t.checks??[],...n.map(e=>"function"==typeof e?{_zod:{check:e,def:{check:"custom"},onattach:[]}}:e)]}),{parent:!0}),e.with=e.check,e.clone=(t,n)=>ye(e,t,n),e.brand=()=>e,e.register=(t,n)=>(t.add(e,n),e),e.parse=(t,n)=>oo(e,t,n,{callee:e.parse}),e.safeParse=(t,n)=>io(e,t,n),e.parseAsync=async(t,n)=>so(e,t,n,{callee:e.parseAsync}),e.safeParseAsync=async(t,n)=>ao(e,t,n),e.spa=e.safeParseAsync,e.encode=(t,n)=>co(e,t,n),e.decode=(t,n)=>uo(e,t,n),e.encodeAsync=async(t,n)=>lo(e,t,n),e.decodeAsync=async(t,n)=>po(e,t,n),e.safeEncode=(t,n)=>fo(e,t,n),e.safeDecode=(t,n)=>mo(e,t,n),e.safeEncodeAsync=async(t,n)=>ho(e,t,n),e.safeDecodeAsync=async(t,n)=>go(e,t,n),e.refine=(t,n)=>e.check(function(e,t={}){/* @__PURE__ */
21
- return Ur(ms,e,t)}(t,n)),e.superRefine=t=>e.check(/* @__PURE__ */Jr(t)),e.overwrite=t=>e.check(/* @__PURE__ */Zr(t)),e.optional=()=>rs(e),e.exactOptional=()=>new os({type:"optional",innerType:e}),e.nullable=()=>is(e),e.nullish=()=>rs(is(e)),e.nonoptional=t=>function(e,t){return new us({type:"nonoptional",innerType:e,...ve(t)})}(e,t),e.array=()=>/* @__PURE__ */Lr(Ko,e,void 0),e.or=t=>new Yo({type:"union",options:[e,t],...ve(void 0)}),e.and=t=>new Xo({type:"intersection",left:e,right:t}),e.transform=t=>ps(e,new ts({type:"transform",transform:t})),e.default=t=>{return n=t,new as({type:"default",innerType:e,get defaultValue(){return"function"==typeof n?n():me(n)}});var n},e.prefault=t=>{return n=t,new cs({type:"prefault",innerType:e,get defaultValue(){return"function"==typeof n?n():me(n)}});var n},e.catch=t=>{return new ds({type:"catch",innerType:e,catchValue:"function"==typeof(n=t)?n:()=>n});var n},e.pipe=t=>ps(e,t),e.readonly=()=>new fs({type:"readonly",innerType:e}),e.describe=t=>{const n=e.clone();return Un.add(n,{description:t}),n},Object.defineProperty(e,"description",{get:()=>Un.get(e)?.description,configurable:!0}),e.meta=(...t)=>{if(0===t.length)return Un.get(e);const n=e.clone();return Un.add(n,t[0]),n},e.isOptional=()=>e.safeParse(void 0).success,e.isNullable=()=>e.safeParse(null).success,e.apply=t=>t(e),e)),vo=/* @__PURE__ */K("_ZodString",(e,t)=>{At.init(e,t),yo.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n)=>{const r=n;r.type="string";const{minimum:o,maximum:s,format:i,patterns:a,contentEncoding:c}=e._zod.bag;if("number"==typeof o&&(r.minLength=o),"number"==typeof s&&(r.maxLength=s),i&&(r.format=Yr[i]??i,""===r.format&&delete r.format,"time"===i&&delete r.format),c&&(r.contentEncoding=c),a&&a.size>0){const e=[...a];1===e.length?r.pattern=e[0].source:e.length>1&&(r.allOf=[...e.map(e=>({..."draft-07"===t.target||"draft-04"===t.target||"openapi-3.0"===t.target?{type:"string"}:{},pattern:e.source}))])}})(e,t,n);const n=e._zod.bag;e.format=n.format??null,e.minLength=n.minimum??null,e.maxLength=n.maximum??null,e.regex=(...t)=>e.check(/* @__PURE__ */$r(...t)),e.includes=(...t)=>e.check(/* @__PURE__ */Tr(...t)),e.startsWith=(...t)=>e.check(/* @__PURE__ */Ar(...t)),e.endsWith=(...t)=>e.check(/* @__PURE__ */jr(...t)),e.min=(...t)=>e.check(/* @__PURE__ */Or(...t)),e.max=(...t)=>e.check(/* @__PURE__ */Sr(...t)),e.length=(...t)=>e.check(/* @__PURE__ */Ir(...t)),e.nonempty=(...t)=>e.check(/* @__PURE__ */Or(1,...t)),e.lowercase=t=>e.check(/* @__PURE__ */Nr(t)),e.uppercase=t=>e.check(/* @__PURE__ */Cr(t)),e.trim=()=>e.check(/* @__PURE__ */Pr()),e.normalize=(...t)=>e.check(/* @__PURE__ */Mr(...t)),e.toLowerCase=()=>e.check(/* @__PURE__ */Dr()),e.toUpperCase=()=>e.check(/* @__PURE__ */Fr()),e.slugify=()=>e.check(/* @__PURE__ */Rr())}),bo=/* @__PURE__ */K("ZodString",(e,t)=>{At.init(e,t),vo.init(e,t),e.email=t=>e.check(/* @__PURE__ */Bn(ko,t)),e.url=t=>e.check(/* @__PURE__ */Hn(Eo,t)),e.jwt=t=>e.check(/* @__PURE__ */lr(Ro,t)),e.emoji=t=>e.check(/* @__PURE__ */Yn(So,t)),e.guid=t=>e.check(/* @__PURE__ */Wn(zo,t)),e.uuid=t=>e.check(/* @__PURE__ */Vn(xo,t)),e.uuidv4=t=>e.check(/* @__PURE__ */qn(xo,t)),e.uuidv6=t=>e.check(/* @__PURE__ */Gn(xo,t)),e.uuidv7=t=>e.check(/* @__PURE__ */Kn(xo,t)),e.nanoid=t=>e.check(/* @__PURE__ */Xn(Oo,t)),e.guid=t=>e.check(/* @__PURE__ */Wn(zo,t)),e.cuid=t=>e.check(/* @__PURE__ */Qn(Io,t)),e.cuid2=t=>e.check(/* @__PURE__ */er($o,t)),e.ulid=t=>e.check(/* @__PURE__ */tr(No,t)),e.base64=t=>e.check(/* @__PURE__ */cr(Po,t)),e.base64url=t=>e.check(/* @__PURE__ */ur(Do,t)),e.xid=t=>e.check(/* @__PURE__ */nr(Co,t)),e.ksuid=t=>e.check(/* @__PURE__ */rr(To,t)),e.ipv4=t=>e.check(/* @__PURE__ */or(Ao,t)),e.ipv6=t=>e.check(/* @__PURE__ */sr(jo,t)),e.cidrv4=t=>e.check(/* @__PURE__ */ir(Zo,t)),e.cidrv6=t=>e.check(/* @__PURE__ */ar(Mo,t)),e.e164=t=>e.check(/* @__PURE__ */dr(Fo,t)),e.datetime=t=>e.check(function(e){/* @__PURE__ */
22
- return pr(Qr,e)}(t)),e.date=t=>e.check(function(e){/* @__PURE__ */
23
- return fr(eo,e)}(t)),e.time=t=>e.check(function(e){/* @__PURE__ */
24
- return mr(to,e)}(t)),e.duration=t=>e.check(function(e){/* @__PURE__ */
25
- return hr(no,e)}(t))});function _o(e){/* @__PURE__ */
26
- return Jn(bo,e)}const wo=/* @__PURE__ */K("ZodStringFormat",(e,t)=>{jt.init(e,t),vo.init(e,t)}),ko=/* @__PURE__ */K("ZodEmail",(e,t)=>{Pt.init(e,t),wo.init(e,t)}),zo=/* @__PURE__ */K("ZodGUID",(e,t)=>{Zt.init(e,t),wo.init(e,t)}),xo=/* @__PURE__ */K("ZodUUID",(e,t)=>{Mt.init(e,t),wo.init(e,t)}),Eo=/* @__PURE__ */K("ZodURL",(e,t)=>{Dt.init(e,t),wo.init(e,t)}),So=/* @__PURE__ */K("ZodEmoji",(e,t)=>{Ft.init(e,t),wo.init(e,t)}),Oo=/* @__PURE__ */K("ZodNanoID",(e,t)=>{Rt.init(e,t),wo.init(e,t)}),Io=/* @__PURE__ */K("ZodCUID",(e,t)=>{Lt.init(e,t),wo.init(e,t)}),$o=/* @__PURE__ */K("ZodCUID2",(e,t)=>{Ut.init(e,t),wo.init(e,t)}),No=/* @__PURE__ */K("ZodULID",(e,t)=>{Jt.init(e,t),wo.init(e,t)}),Co=/* @__PURE__ */K("ZodXID",(e,t)=>{Bt.init(e,t),wo.init(e,t)}),To=/* @__PURE__ */K("ZodKSUID",(e,t)=>{Wt.init(e,t),wo.init(e,t)}),Ao=/* @__PURE__ */K("ZodIPv4",(e,t)=>{Ht.init(e,t),wo.init(e,t)}),jo=/* @__PURE__ */K("ZodIPv6",(e,t)=>{Yt.init(e,t),wo.init(e,t)}),Zo=/* @__PURE__ */K("ZodCIDRv4",(e,t)=>{Xt.init(e,t),wo.init(e,t)}),Mo=/* @__PURE__ */K("ZodCIDRv6",(e,t)=>{Qt.init(e,t),wo.init(e,t)}),Po=/* @__PURE__ */K("ZodBase64",(e,t)=>{tn.init(e,t),wo.init(e,t)}),Do=/* @__PURE__ */K("ZodBase64URL",(e,t)=>{nn.init(e,t),wo.init(e,t)}),Fo=/* @__PURE__ */K("ZodE164",(e,t)=>{rn.init(e,t),wo.init(e,t)}),Ro=/* @__PURE__ */K("ZodJWT",(e,t)=>{on.init(e,t),wo.init(e,t)}),Lo=/* @__PURE__ */K("ZodNumber",(e,t)=>{sn.init(e,t),yo.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n)=>{const r=n,{minimum:o,maximum:s,format:i,multipleOf:a,exclusiveMaximum:c,exclusiveMinimum:u}=e._zod.bag;"string"==typeof i&&i.includes("int")?r.type="integer":r.type="number","number"==typeof u&&("draft-04"===t.target||"openapi-3.0"===t.target?(r.minimum=u,r.exclusiveMinimum=!0):r.exclusiveMinimum=u),"number"==typeof o&&(r.minimum=o,"number"==typeof u&&"draft-04"!==t.target&&(u>=o?delete r.minimum:delete r.exclusiveMinimum)),"number"==typeof c&&("draft-04"===t.target||"openapi-3.0"===t.target?(r.maximum=c,r.exclusiveMaximum=!0):r.exclusiveMaximum=c),"number"==typeof s&&(r.maximum=s,"number"==typeof c&&"draft-04"!==t.target&&(c<=s?delete r.maximum:delete r.exclusiveMaximum)),"number"==typeof a&&(r.multipleOf=a)})(e,t,n),e.gt=(t,n)=>e.check(/* @__PURE__ */zr(t,n)),e.gte=(t,n)=>e.check(/* @__PURE__ */xr(t,n)),e.min=(t,n)=>e.check(/* @__PURE__ */xr(t,n)),e.lt=(t,n)=>e.check(/* @__PURE__ */wr(t,n)),e.lte=(t,n)=>e.check(/* @__PURE__ */kr(t,n)),e.max=(t,n)=>e.check(/* @__PURE__ */kr(t,n)),e.int=t=>e.check(Bo(t)),e.safe=t=>e.check(Bo(t)),e.positive=t=>e.check(/* @__PURE__ */zr(0,t)),e.nonnegative=t=>e.check(/* @__PURE__ */xr(0,t)),e.negative=t=>e.check(/* @__PURE__ */wr(0,t)),e.nonpositive=t=>e.check(/* @__PURE__ */kr(0,t)),e.multipleOf=(t,n)=>e.check(/* @__PURE__ */Er(t,n)),e.step=(t,n)=>e.check(/* @__PURE__ */Er(t,n)),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 Uo(e){/* @__PURE__ */
27
- return gr(Lo,e)}const Jo=/* @__PURE__ */K("ZodNumberFormat",(e,t)=>{an.init(e,t),Lo.init(e,t)});function Bo(e){/* @__PURE__ */
28
- return yr(Jo,e)}const Wo=/* @__PURE__ */K("ZodAny",(e,t)=>{cn.init(e,t),yo.init(e,t),e._zod.processJSONSchema=(e,t,n)=>{}}),Vo=/* @__PURE__ */K("ZodUnknown",(e,t)=>{un.init(e,t),yo.init(e,t),e._zod.processJSONSchema=(e,t,n)=>{}});function qo(){/* @__PURE__ */
29
- return br(Vo)}const Go=/* @__PURE__ */K("ZodNever",(e,t)=>{dn.init(e,t),yo.init(e,t),e._zod.processJSONSchema=(e,t,n)=>((e,t,n)=>{n.not={}})(0,0,t)}),Ko=/* @__PURE__ */K("ZodArray",(e,t)=>{pn.init(e,t),yo.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const o=n,s=e._zod.def,{minimum:i,maximum:a}=e._zod.bag;"number"==typeof i&&(o.minItems=i),"number"==typeof a&&(o.maxItems=a),o.type="array",o.items=Vr(s.element,t,{...r,path:[...r.path,"items"]})})(e,t,n,r),e.element=t.element,e.min=(t,n)=>e.check(/* @__PURE__ */Or(t,n)),e.nonempty=t=>e.check(/* @__PURE__ */Or(1,t)),e.max=(t,n)=>e.check(/* @__PURE__ */Sr(t,n)),e.length=(t,n)=>e.check(/* @__PURE__ */Ir(t,n)),e.unwrap=()=>e.element}),Ho=/* @__PURE__ */K("ZodObject",(e,t)=>{yn.init(e,t),yo.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((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]=Vr(i[u],t,{...r,path:[...r.path,"properties",u]});const a=new Set(Object.keys(i)),c=new Set([...a].filter(e=>{const n=s.shape[e]._zod;return"input"===t.io?void 0===n.optin:void 0===n.optout}));c.size>0&&(o.required=Array.from(c)),"never"===s.catchall?._zod.def.type?o.additionalProperties=!1:s.catchall?s.catchall&&(o.additionalProperties=Vr(s.catchall,t,{...r,path:[...r.path,"additionalProperties"]})):"output"===t.io&&(o.additionalProperties=!1)})(e,t,n,r),ie(e,"shape",()=>t.shape),e.keyof=()=>es(Object.keys(e._zod.def.shape)),e.catchall=t=>e.clone({...e._zod.def,catchall:t}),e.passthrough=()=>e.clone({...e._zod.def,catchall:qo()}),e.loose=()=>e.clone({...e._zod.def,catchall:qo()}),e.strict=()=>e.clone({...e._zod.def,catchall:/* @__PURE__ */_r(Go,void 0)}),e.strip=()=>e.clone({...e._zod.def,catchall:void 0}),e.extend=t=>function(e,t){if(!fe(t))throw new Error("Invalid input to extend: expected a plain object");const n=e._zod.def.checks;if(n&&n.length>0){const n=e._zod.def.shape;for(const e in t)if(void 0!==Object.getOwnPropertyDescriptor(n,e))throw new Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.")}const r=ce(e._zod.def,{get shape(){const n={...e._zod.def.shape,...t};return ae(this,"shape",n),n}});return ye(e,r)}(e,t),e.safeExtend=t=>function(e,t){if(!fe(t))throw new Error("Invalid input to safeExtend: expected a plain object");const n=ce(e._zod.def,{get shape(){const n={...e._zod.def.shape,...t};return ae(this,"shape",n),n}});return ye(e,n)}(e,t),e.merge=t=>function(e,t){const n=ce(e._zod.def,{get shape(){const n={...e._zod.def.shape,...t._zod.def.shape};return ae(this,"shape",n),n},get catchall(){return t._zod.def.catchall},checks:[]});return ye(e,n)}(e,t),e.pick=t=>function(e,t){const n=e._zod.def,r=n.checks;if(r&&r.length>0)throw new Error(".pick() cannot be used on object schemas containing refinements");return ye(e,ce(e._zod.def,{get shape(){const e={};for(const r in t){if(!(r in n.shape))throw new Error(`Unrecognized key: "${r}"`);t[r]&&(e[r]=n.shape[r])}return ae(this,"shape",e),e},checks:[]}))}(e,t),e.omit=t=>function(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 o=ce(e._zod.def,{get shape(){const r={...e._zod.def.shape};for(const e in t){if(!(e in n.shape))throw new Error(`Unrecognized key: "${e}"`);t[e]&&delete r[e]}return ae(this,"shape",r),r},checks:[]});return ye(e,o)}(e,t),e.partial=(...t)=>function(e,t,n){const r=t._zod.def.checks;if(r&&r.length>0)throw new Error(".partial() cannot be used on object schemas containing refinements");const o=ce(t._zod.def,{get shape(){const r=t._zod.def.shape,o={...r};if(n)for(const t in n){if(!(t in r))throw new Error(`Unrecognized key: "${t}"`);n[t]&&(o[t]=e?new e({type:"optional",innerType:r[t]}):r[t])}else for(const t in r)o[t]=e?new e({type:"optional",innerType:r[t]}):r[t];return ae(this,"shape",o),o},checks:[]});return ye(t,o)}(ns,e,t[0]),e.required=(...t)=>function(e,t,n){const r=ce(t._zod.def,{get shape(){const r=t._zod.def.shape,o={...r};if(n)for(const t in n){if(!(t in o))throw new Error(`Unrecognized key: "${t}"`);n[t]&&(o[t]=new e({type:"nonoptional",innerType:r[t]}))}else for(const t in r)o[t]=new e({type:"nonoptional",innerType:r[t]});return ae(this,"shape",o),o}});return ye(t,r)}(us,e,t[0])}),Yo=/* @__PURE__ */K("ZodUnion",(e,t)=>{bn.init(e,t),yo.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const o=e._zod.def,s=!1===o.inclusive,i=o.options.map((e,n)=>Vr(e,t,{...r,path:[...r.path,s?"oneOf":"anyOf",n]}));s?n.oneOf=i:n.anyOf=i})(e,t,n,r),e.options=t.options}),Xo=/* @__PURE__ */K("ZodIntersection",(e,t)=>{_n.init(e,t),yo.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const o=e._zod.def,s=Vr(o.left,t,{...r,path:[...r.path,"allOf",0]}),i=Vr(o.right,t,{...r,path:[...r.path,"allOf",1]}),a=e=>"allOf"in e&&1===Object.keys(e).length,c=[...a(s)?s.allOf:[s],...a(i)?i.allOf:[i]];n.allOf=c})(e,t,n,r)}),Qo=/* @__PURE__ */K("ZodEnum",(e,t)=>{zn.init(e,t),yo.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n)=>{const r=ee(e._zod.def.entries);r.every(e=>"number"==typeof e)&&(n.type="number"),r.every(e=>"string"==typeof e)&&(n.type="string"),n.enum=r})(e,0,n),e.enum=t.entries,e.options=Object.values(t.entries);const n=new Set(Object.keys(t.entries));e.extract=(e,r)=>{const o={};for(const s of e){if(!n.has(s))throw new Error(`Key ${s} not found in enum`);o[s]=t.entries[s]}return new Qo({...t,checks:[],...ve(r),entries:o})},e.exclude=(e,r)=>{const o={...t.entries};for(const t of e){if(!n.has(t))throw new Error(`Key ${t} not found in enum`);delete o[t]}return new Qo({...t,checks:[],...ve(r),entries:o})}});function es(e,t){const n=Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e;return new Qo({type:"enum",entries:n,...ve(t)})}const ts=/* @__PURE__ */K("ZodTransform",(e,t)=>{xn.init(e,t),yo.init(e,t),e._zod.processJSONSchema=(e,t,n)=>((e,t)=>{if("throw"===t.unrepresentable)throw new Error("Transforms cannot be represented in JSON Schema")})(0,e),e._zod.parse=(n,r)=>{if("backward"===r.direction)throw new Y(e.constructor.name);n.addIssue=r=>{if("string"==typeof r)n.issues.push(Ee(r,n.value,t));else{const t=r;t.fatal&&(t.continue=!1),t.code??(t.code="custom"),t.input??(t.input=n.value),t.inst??(t.inst=e),n.issues.push(Ee(t))}};const o=t.transform(n.value,n);return o instanceof Promise?o.then(e=>(n.value=e,n)):(n.value=o,n)}}),ns=/* @__PURE__ */K("ZodOptional",(e,t)=>{Sn.init(e,t),yo.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Xr(e,t,0,r),e.unwrap=()=>e._zod.def.innerType});function rs(e){return new ns({type:"optional",innerType:e})}const os=/* @__PURE__ */K("ZodExactOptional",(e,t)=>{On.init(e,t),yo.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Xr(e,t,0,r),e.unwrap=()=>e._zod.def.innerType}),ss=/* @__PURE__ */K("ZodNullable",(e,t)=>{In.init(e,t),yo.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const o=e._zod.def,s=Vr(o.innerType,t,r),i=t.seen.get(e);"openapi-3.0"===t.target?(i.ref=o.innerType,n.nullable=!0):n.anyOf=[s,{type:"null"}]})(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function is(e){return new ss({type:"nullable",innerType:e})}const as=/* @__PURE__ */K("ZodDefault",(e,t)=>{$n.init(e,t),yo.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const o=e._zod.def;Vr(o.innerType,t,r),t.seen.get(e).ref=o.innerType,n.default=JSON.parse(JSON.stringify(o.defaultValue))})(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap}),cs=/* @__PURE__ */K("ZodPrefault",(e,t)=>{Cn.init(e,t),yo.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const o=e._zod.def;Vr(o.innerType,t,r),t.seen.get(e).ref=o.innerType,"input"===t.io&&(n._prefault=JSON.parse(JSON.stringify(o.defaultValue)))})(e,t,n,r),e.unwrap=()=>e._zod.def.innerType}),us=/* @__PURE__ */K("ZodNonOptional",(e,t)=>{Tn.init(e,t),yo.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const o=e._zod.def;Vr(o.innerType,t,r),t.seen.get(e).ref=o.innerType})(e,t,0,r),e.unwrap=()=>e._zod.def.innerType}),ds=/* @__PURE__ */K("ZodCatch",(e,t)=>{jn.init(e,t),yo.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const o=e._zod.def;let s;Vr(o.innerType,t,r),t.seen.get(e).ref=o.innerType;try{s=o.catchValue(void 0)}catch{throw new Error("Dynamic catch values are not supported in JSON Schema")}n.default=s})(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap}),ls=/* @__PURE__ */K("ZodPipe",(e,t)=>{Zn.init(e,t),yo.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const o=e._zod.def,s="input"===t.io?"transform"===o.in._zod.def.type?o.out:o.in:o.out;Vr(s,t,r),t.seen.get(e).ref=s})(e,t,0,r),e.in=t.in,e.out=t.out});function ps(e,t){return new ls({type:"pipe",in:e,out:t})}const fs=/* @__PURE__ */K("ZodReadonly",(e,t)=>{Pn.init(e,t),yo.init(e,t),e._zod.processJSONSchema=(t,n,r)=>((e,t,n,r)=>{const o=e._zod.def;Vr(o.innerType,t,r),t.seen.get(e).ref=o.innerType,n.readOnly=!0})(e,t,n,r),e.unwrap=()=>e._zod.def.innerType}),ms=/* @__PURE__ */K("ZodCustom",(e,t)=>{Fn.init(e,t),yo.init(e,t),e._zod.processJSONSchema=(e,t,n)=>((e,t)=>{if("throw"===t.unrepresentable)throw new Error("Custom types cannot be represented in JSON Schema")})(0,e)}),hs="chat_device_id";function gs(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{const t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)})}const ys=function(){const e={type:"object",shape:{id:_o().optional(),type:es(["text","image","audio","location","system"]).default("text"),content:_o().optional(),imageUrl:_o().url().optional(),audioUrl:_o().url().optional(),latitude:Uo().optional(),longitude:Uo().optional(),timestamp:_o().optional(),sender:es(["bot","user","system"]).optional(),emotion:/* @__PURE__ */vr(Wo).optional()}??{},...ve(void 0)};return new Ho(e)}();class vs{queue=[];endpoint;apiKey;flushInterval=null;isFlushing=!1;isDisabled=!1;MAX_QUEUE_SIZE=100;FLUSH_INTERVAL_MS=3e4;BATCH_SIZE=10;constructor(e,t){this.endpoint=e,this.apiKey=t,this.startAutoFlush()}startAutoFlush(){this.flushInterval=setInterval(()=>{!this.isDisabled&&this.queue.length>0&&this.flush()},this.FLUSH_INTERVAL_MS)}trackOpen(){this.track("chat_opened")}trackClose(){this.track("chat_closed")}trackMessageSent(e){this.track("message_sent",{type:e})}trackMessageReceived(e,t){this.track("message_received",{type:e,latency:t})}trackError(e,t){this.track("error",{error:e,context:t})}trackConnectionStatus(e){this.track("connection_status",{isConnected:e})}trackFeatureUsed(e){this.track("feature_used",{feature:e})}trackTypingStarted(){this.track("typing_started")}trackAttachmentSent(e,t){this.track("attachment_sent",{type:e,size:t})}track(e,t){this.isDisabled||(this.queue.push({event:e,properties:{...t,userAgent:"undefined"!=typeof navigator?navigator.userAgent:void 0,url:"undefined"!=typeof window?window.location.href:void 0},timestamp:Date.now()}),this.queue.length>=this.BATCH_SIZE&&this.flush(),this.queue.length>this.MAX_QUEUE_SIZE&&(this.queue=this.queue.slice(-this.MAX_QUEUE_SIZE),d.warn("Analytics queue overflow, dropping old events")))}async flush(){if(this.isDisabled||0===this.queue.length||this.isFlushing)return;this.isFlushing=!0;const e=[...this.queue];this.queue=[];try{const t=await fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.apiKey}`},body:JSON.stringify({events:e}),keepalive:!0});t.ok?d.debug(`Analytics: Flushed ${e.length} events`):(this.isDisabled=!0,this.queue=[],d.debug(`Analytics disabled: endpoint returned ${t.status}`))}catch(t){this.isDisabled=!0,this.queue=[],d.debug("Analytics disabled due to network error")}finally{this.isFlushing=!1}}destroy(){this.flushInterval&&clearInterval(this.flushInterval),this.flush()}}function bs(t){const{apiKey:r,apiBaseUrl:o,pageContext:s,includeSEOMetadata:a=!1,theme:c,userContext:u,onLogin:l,onNavigate:m,onEvent:h,onStateChange:g,onThemeUpdate:v}=t,[b,_]=e.useState(0),w=e.useRef(0),{t:k}=n(),z=function(t,n,r=!0){const o=e.useRef(null);return e.useEffect(()=>{if(!r||!t||!n)return;const e=`${t}/analytics`;o.current=new vs(e,n);const s=()=>o.current?.flush(),i=()=>{"hidden"===document.visibilityState&&o.current?.flush()};return window.addEventListener("beforeunload",s),window.addEventListener("visibilitychange",i),()=>{window.removeEventListener("beforeunload",s),window.removeEventListener("visibilitychange",i),o.current?.destroy()}},[t,n,r]),{trackOpen:e.useCallback(()=>{o.current?.trackOpen()},[]),trackClose:e.useCallback(()=>{o.current?.trackClose()},[]),trackMessageSent:e.useCallback(e=>{o.current?.trackMessageSent(e)},[]),trackMessageReceived:e.useCallback((e,t)=>{o.current?.trackMessageReceived(e,t)},[]),trackError:e.useCallback((e,t)=>{o.current?.trackError(e,t)},[]),trackConnectionStatus:e.useCallback(e=>{o.current?.trackConnectionStatus(e)},[]),trackFeatureUsed:e.useCallback(e=>{o.current?.trackFeatureUsed(e)},[])}}(o,r,!0),x=function({enabled:t=!0,soundEnabled:n=!0,desktopEnabled:r=!0,botName:o="Asistente",logoUrl:s,notificationSoundUrl:a}={}){const[c,u]=e.useState("default"),l=e.useRef(null),p=s||i,m=a||f;e.useEffect(()=>{n&&"undefined"!=typeof window&&(l.current=new Audio(m),l.current.volume=.3)},[n,m]),e.useEffect(()=>{"undefined"!=typeof window&&"Notification"in window&&u(Notification.permission)},[]);const h=e.useCallback(async()=>{if("undefined"==typeof window||!("Notification"in window))return d.warn("Notifications API not available"),!1;try{const e=await Notification.requestPermission();return u(e),d.info("Notification permission:",e),"granted"===e}catch(e){return d.error("Error requesting notification permission:",e),!1}},[]),g=e.useCallback(e=>{if(t&&r&&"granted"===c&&("undefined"==typeof document||!document.hasFocus()))try{const t=`Nuevo mensaje de ${o}`;let n="Mensaje recibido";"text"===e.type&&"content"in e?n=e.content?.slice(0,100)||"Mensaje recibido":"image"===e.type?n="📷 Imagen":"audio"===e.type?n="🎵 Audio":"location"===e.type&&(n="📍 Ubicación");const r=new Notification(t,{body:n,icon:p,tag:"chat-message",requireInteraction:!1,silent:!1});r.onclick=()=>{window.focus(),r.close()},setTimeout(()=>r.close(),5e3)}catch(n){d.error("Error showing notification:",n)}},[t,r,c,o,p]),y=e.useCallback(()=>{if(t&&n&&("undefined"==typeof document||!document.hasFocus()))try{l.current?.play().catch(e=>{d.debug("Audio playback blocked:",e)})}catch(e){d.error("Error playing sound:",e)}},[t,n]),v=e.useCallback(e=>{g(e),y()},[g,y]);return{permission:c,requestPermission:h,notify:g,playSound:y,notifyWithSound:v}}({enabled:!0,soundEnabled:!0,desktopEnabled:!0,botName:c?.botName||"Asistente",logoUrl:c?.logoUrl}),E=function(t=10,n=6e4){const r=e.useRef([]);return{isAllowed:e.useCallback(()=>{const e=Date.now();return r.current=r.current.filter(t=>e-t<n),!(r.current.length>=t||(r.current.push(e),0))},[t,n]),getRemainingAttempts:e.useCallback(()=>{const e=Date.now();return r.current=r.current.filter(t=>e-t<n),Math.max(0,t-r.current.length)},[t,n]),getTimeUntilReset:e.useCallback(()=>{if(0===r.current.length)return 0;const e=Date.now(),t=r.current[0],o=n-(e-t);return Math.max(0,o)},[n]),reset:e.useCallback(()=>{r.current=[]},[])}}(10,6e4),{state:S,actions:O}=function(){const[t,n]=e.useReducer(G,q),[r,o]=e.useState(!1);e.useEffect(()=>{"undefined"==typeof window||r||(async()=>{try{await W.migrateFromLocalStorage();const e=await W.getMessages(100),t=await W.getMetadata();if(e.length>0||t){const r={messages:e.map(e=>({...e,timestamp:new Date(e.timestamp)})),sessionId:t?.sessionId||null,isOpen:t?.isOpen||!1};n({type:"RESTORE_SESSION",payload:r})}}catch(e){d.warn("Chat: Error rehydrating from IndexedDB",e);try{const e=localStorage.getItem(V);if(e){const t=JSON.parse(e);t.messages&&(t.messages=t.messages.map(e=>({...e,timestamp:new Date(e.timestamp)}))),n({type:"RESTORE_SESSION",payload:t})}}catch(t){d.error("Chat: Fallback rehydration failed",t)}}finally{o(!0)}})()},[r]),e.useEffect(()=>{if(!r)return;const e=setTimeout(async()=>{try{await W.saveMessages(t.messages),await W.setMetadata({isOpen:t.isOpen,sessionId:t.sessionId})}catch(e){d.error("Chat Persistence Error:",e);try{const e={isOpen:t.isOpen,messages:t.messages,sessionId:t.sessionId};localStorage.setItem(V,JSON.stringify(e))}catch(n){d.error("Chat: Fallback persistence failed",n)}}},500);return()=>clearTimeout(e)},[t.isOpen,t.messages,t.sessionId,r]);const s=e.useCallback(e=>{n({type:"ADD_MESSAGE",payload:e})},[]),i=e.useCallback(()=>n({type:"TOGGLE_WINDOW"}),[]),a=e.useCallback(()=>n({type:"OPEN_WINDOW"}),[]),c=e.useCallback(()=>n({type:"CLOSE_WINDOW"}),[]),u=e.useCallback(e=>n({type:"SET_CONNECTED",payload:e}),[]),l=e.useCallback(e=>n({type:"SET_TYPING",payload:e}),[]),p=e.useCallback(e=>n({type:"SET_MESSAGES",payload:e}),[]),f=e.useCallback(e=>n({type:"SET_ERROR",payload:e}),[]),m=e.useCallback(e=>n({type:"SET_SESSION_ID",payload:e}),[]),h=e.useCallback(()=>{localStorage.removeItem(V),n({type:"CLEAR_CHAT"})},[]),g=e.useCallback(()=>{n({type:"SET_MESSAGES",payload:[]})},[]);return{state:t,isHydrated:r,actions:{toggleWindow:i,openWindow:a,closeWindow:c,setConnected:u,setTyping:l,addMessage:s,setMessages:p,setError:f,setSessionId:m,clearChat:h,clearMessages:g}}}(),I=function(t=!1){const n="undefined"!=typeof window?window.location.pathname:"",r=e.useMemo(()=>n,[n]),[o,s]=e.useState({});return e.useEffect(()=>{if(!t)return void s({});const e=setTimeout(()=>{const e=function(){if("undefined"==typeof window)return{};const e={};e.title=document.title,document.querySelectorAll("meta").forEach(t=>{const n=t.getAttribute("name"),r=t.getAttribute("property"),o=t.getAttribute("content");if(o){if(n)switch(n){case"description":e.description=o;break;case"keywords":e.keywords=o.split(",").map(e=>e.trim());break;case"author":e.author=o}if(r){if(r.startsWith("og:")){const t=r.replace("og:","og_");e[t]=o}if(r.startsWith("twitter:")){const t=r.replace("twitter:","twitter_");e[t]=o}}}});try{const t=document.querySelectorAll('script[type="application/ld+json"]');if(t.length>0){const n=[];t.forEach(e=>{try{const t=JSON.parse(e.textContent||"");n.push(t)}catch{}}),n.length>0&&(e.structuredData=n)}}catch{}return e}();s(e)},100);return()=>clearTimeout(e)},[r,t]),t&&Object.keys(o).length>0?o:void 0}(a),$=function(t){const{apiKey:n,apiBaseUrl:r,pageContext:o,userContext:s}=t,i=e.useRef(t);e.useEffect(()=>{i.current=t},[t]);const a=e.useRef(null),[c,u]=e.useState(!1),[l,f]=e.useState(!1),m=e.useRef(function(){try{const e=localStorage.getItem(hs);if(e)return e;const t=gs();return localStorage.setItem(hs,t),t}catch{return d.warn("localStorage not available, using session-only device ID"),gs()}}()),h=e.useRef(o);e.useEffect(()=>{h.current=o},[o]);const g=e.useCallback(e=>{const t=ys.safeParse(e),n=t.success&&t.data.id?t.data.id:`msg-${Math.random().toString(36).slice(2,11)}`,r=t.success&&t.data.sender?t.data.sender:"bot",o=t.success&&t.data.timestamp?new Date(t.data.timestamp):/* @__PURE__ */new Date,s=t.success?t.data:{type:"text"};switch(s.type){case"image":return{id:n,type:"image",sender:r,timestamp:o,imageUrl:s.imageUrl||s.content||"",altText:"Imagen enviada"};case"audio":return{id:n,type:"audio",sender:r,timestamp:o,content:s.audioUrl||s.content||""};case"location":return{id:n,type:"location",sender:r,timestamp:o,latitude:Number(s.latitude||0),longitude:Number(s.longitude||0),name:s.content||"Ubicación compartida"};case"system":return{id:n,type:"system",sender:"system",timestamp:o,content:String(s.content||"")};default:return{id:n,type:"text",sender:r,timestamp:o,content:String(s.content||"Sin contenido"),emotion:s.emotion}}},[]),v=e.useCallback(()=>{if(!n||!r)return;if(a.current?.connected)return;u(!0);const e=y(`${r}/webchat`,{auth:{apiKey:n,deviceId:m.current,token:s?.token,metadata:s?.metadata},transports:["websocket","polling"],reconnection:!0,reconnectionAttempts:5,reconnectionDelay:1e3,extraHeaders:{"bypass-tunnel-reminder":"true","X-Tunnel-Skip-Anti-Phishing-Page":"true"}});e.on("connect",()=>{u(!1),f(!0),i.current.onConnected(`temp-${Date.now()}`,void 0)}),e.on("disconnect",e=>{u(!1),f(!1),i.current.onDisconnected()}),e.on("connect_error",e=>{u(!1),i.current.onError(`Error de conexión: ${e.message}`)}),e.on("connection_ack",e=>{i.current.onConnected(e.sessionId,e.config)}),e.on("bot_message",e=>{try{i.current.onMessage(g(e))}catch(t){d.error("ChatSocket Error processing bot_message:",t)}}),e.on("chat_history",e=>{e.messages&&Array.isArray(e.messages)&&e.messages.forEach(e=>{try{i.current.onMessage(g(e))}catch(t){d.debug("Error processing history message:",t)}}),i.current.onEvent&&i.current.onEvent("history_loaded",e)}),e.on("bot_typing",e=>i.current.onTyping(e)),e.on("auth_success",e=>{i.current.onLogin&&i.current.onLogin(e),e.theme&&i.current.onThemeUpdate&&i.current.onThemeUpdate(e.theme)}),a.current=e},[n,r]),b=e.useCallback(()=>{a.current&&(a.current.disconnect(),a.current=null,f(!1))},[]),_=e.useRef(v);_.current=v,e.useEffect(()=>(_.current(),()=>{a.current&&(a.current.disconnect(),a.current=null)}),[]);const w=e.useRef([]),k=e.useRef([]),z=e.useCallback(()=>`msg_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,[]),x=e.useCallback(()=>{if(a.current?.connected)for(;w.current.length>0;){const e=w.current.shift();a.current.emit("user_message",e)}},[]);e.useEffect(()=>{l&&x()},[l,x]),e.useEffect(()=>{if(!l)return;const e=setInterval(()=>{const e=Date.now();k.current=k.current.filter(t=>e<t.nextRetryAt||(t.attempts>=t.maxAttempts?(i.current.onEvent?.("message_failed",{id:t.id,payload:t.payload}),d.error("Message failed after max retries:",t.id),!1):!a.current?.connected||(a.current.emit("user_message",t.payload,e=>{e?.success&&i.current.onEvent?.("message_sent",{id:t.id})}),t.attempts++,t.nextRetryAt=e+1e3*Math.pow(2,t.attempts),t.attempts<t.maxAttempts)))},500);return()=>clearInterval(e)},[l]);const E=e.useCallback((e,t="text")=>{const n=z(),r={...h.current,currentUrl:"undefined"!=typeof window?window.location.href:void 0,sentAt:/* @__PURE__ */(new Date).toISOString(),deviceId:m.current},o={id:n,content:e.trim(),type:t,metadata:r};return a.current?.connected?(a.current.emit("user_message",o,e=>{!1!==e?.success&&e?i.current.onEvent?.("message_sent",{id:n}):(k.current.push({id:n,payload:o,attempts:0,maxAttempts:3,nextRetryAt:Date.now()+1e3}),i.current.onEvent?.("message_retry_queued",{id:n}))}),n):(w.current.push(o),i.current.onEvent?.("queued_message",{id:n,payload:o}),n)},[z]),S=e.useMemo(()=>p(e=>{a.current?.emit("typing",e)},250),[]);return{isConnected:l,isConnecting:c,sendMessage:E,sendTyping:S,requestHistory:e.useCallback(()=>{a.current?.emit("request_history")},[]),reconnect:v,disconnect:b}}({apiKey:r,apiBaseUrl:o,pageContext:e.useMemo(()=>I?{...s||{},seo:{...I||{}}}:s,[s,I]),userContext:u,onMessage:e.useCallback(e=>{const t=Date.now(),n=w.current>0?t-w.current:void 0;w.current=t,O.addMessage(e),z.trackMessageReceived(e.type,n),S.isOpen||"bot"!==e.sender||(_(e=>e+1),x.notifyWithSound(e))},[O,S.isOpen,z,x]),onConnected:e.useCallback((e,t)=>{O.setConnected(!0),O.setSessionId(e),z.trackConnectionStatus(!0),t&&h&&h("backend_config",t)},[O,h,z]),onDisconnected:e.useCallback(()=>{O.setConnected(!1),z.trackConnectionStatus(!1)},[O,z]),onTyping:e.useCallback(e=>O.setTyping(e),[O]),onError:e.useCallback(e=>{O.setError(e),z.trackError(e)},[O,z]),onLogin:l,onNavigate:m,onEvent:h,onThemeUpdate:v}),N=e.useCallback(()=>{d.debug("ChatWidget handleToggle called, current isOpen:",S.isOpen),S.isOpen?(O.closeWindow(),z.trackClose(),g?.(!1),d.debug("ChatWidget Closing window")):(O.openWindow(),_(0),z.trackOpen(),g?.(!0),d.debug("ChatWidget Opening window"))},[S.isOpen,O,g,z]),C=e.useCallback(e=>{if(!E.isAllowed()){const e=E.getTimeUntilReset(),t=Math.ceil(e/1e3);return void O.setError(k("rate_limit_exceeded")+` Espera ${t}s.`)}const t={id:`temp-${Date.now()}-${Math.random()}`,type:"text",sender:"user",timestamp:/* @__PURE__ */new Date,content:e};O.addMessage(t),z.trackMessageSent("text"),$.sendMessage(e,"text")},[O,$,E,z,k]),T=e.useCallback(async(e,t)=>{let n;n="audio"===t?{id:`temp-${Date.now()}-${Math.random()}`,type:"audio",sender:"user",timestamp:/* @__PURE__ */new Date,content:URL.createObjectURL(e)}:"image"===t?{id:`temp-${Date.now()}-${Math.random()}`,type:"image",sender:"user",timestamp:/* @__PURE__ */new Date,imageUrl:URL.createObjectURL(e)}:{id:`temp-${Date.now()}-${Math.random()}`,type:"text",sender:"user",timestamp:/* @__PURE__ */new Date,content:`📎 ${e.name}`},O.addMessage(n);const r=await(e=>new Promise((t,n)=>{const r=new FileReader;r.readAsDataURL(e),r.onload=()=>t(r.result),r.onerror=e=>n(e)}))(e);$.sendMessage(r,t)},[O,$]),A=e.useCallback(e=>{const t={id:`temp-${Date.now()}-${Math.random()}`,type:"location",sender:"user",timestamp:/* @__PURE__ */new Date,latitude:e.latitude,longitude:e.longitude,name:"Mi ubicación"};O.addMessage(t),$.sendMessage(JSON.stringify(e),"location")},[O,$]);e.useEffect(()=>{const e=()=>{S.isOpen||O.openWindow()},t=()=>{S.isOpen&&O.closeWindow()},n=()=>{S.isOpen?O.closeWindow():O.openWindow()},r=e=>{e.detail?.message&&C(e.detail.message)};return window.addEventListener("botuyo-chat:open",e),window.addEventListener("botuyo-chat:close",t),window.addEventListener("botuyo-chat:toggle",n),window.addEventListener("botuyo-chat:send-message",r),()=>{window.removeEventListener("botuyo-chat:open",e),window.removeEventListener("botuyo-chat:close",t),window.removeEventListener("botuyo-chat:toggle",n),window.removeEventListener("botuyo-chat:send-message",r)}},[S.isOpen,O,C]),e.useEffect(()=>()=>{},[C]);const j=e.useCallback(()=>{O.clearMessages(),d.info("Chat history cleared")},[O]);e.useEffect(()=>()=>{},[j]);const Z=e.useMemo(()=>{if(S.isTyping)return"thinking";const e=[...S.messages].reverse().find(e=>"bot"===e.sender&&"text"===e.type);return"text"===e?.type&&e.emotion?e.emotion:"default"},[S.isTyping,S.messages]);return{state:S,actions:O,unreadCount:b,currentBotEmotion:Z,isConnected:$.isConnected,handleToggle:N,handleSendText:C,handleSendAttachment:T,handleSendLocation:A}}function _s(n){const{apiKey:r,apiBaseUrl:o,pageContext:s,includeSEOMetadata:i=!1,theme:c,mediaConfig:u,userContext:d,onLogin:p,onNavigate:f,onEvent:y,onStateChange:z,onVoiceCall:x}=n,E=e.useRef(null),S=m();!function(t){const[n,r]=e.useState(!1);e.useEffect(()=>{let e=null;const n=()=>{if(!t.current)return;const e=!!t.current.parentElement?.closest(".dark"),n=!!document.getElementById("botuyo-chat-widget-root")?.classList.contains("dark"),o=document.getElementById("botuyo-chat-widget-root"),s=!!o?.parentElement?.closest(".dark"),i=document.documentElement.classList.contains("dark"),a=document.body.classList.contains("dark"),c=window.matchMedia("(prefers-color-scheme: dark)").matches,u=e||n||s||i||a||c;t.current&&(u?t.current.classList.add("dark"):t.current.classList.remove("dark")),r(u)};n();const o=window.matchMedia("(prefers-color-scheme: dark)"),s=()=>n();o.addEventListener("change",s);const i=new MutationObserver(()=>{n()}),a=document.getElementById("botuyo-chat-widget-root");a&&(i.observe(a,{attributes:!0,attributeFilter:["class"]}),a.parentElement&&(i.observe(a.parentElement,{attributes:!0,attributeFilter:["class"],childList:!0}),e=a.parentElement)),i.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}),i.observe(document.body,{attributes:!0,attributeFilter:["class"]});let c=t.current?.parentElement;for(;c;)i.observe(c,{attributes:!0,attributeFilter:["class"]}),c=c.parentElement;const u=setInterval(()=>{const t=document.getElementById("botuyo-chat-widget-root");t&&t.parentElement!==e&&(e&&t.parentElement&&(i.observe(t.parentElement,{attributes:!0,attributeFilter:["class"],childList:!0}),e=t.parentElement),n())},100);return()=>{i.disconnect(),o.removeEventListener("change",s),clearInterval(u)}},[t])}(E);const[O,I]=e.useState(),{mergedTheme:$,mergedStyles:N,getContainerStyle:C}=function(t,n){const r=function(){const[t,n]=e.useState(()=>"undefined"!=typeof window&&(window.matchMedia("(prefers-contrast: high)").matches||window.matchMedia("(prefers-contrast: more)").matches));return e.useEffect(()=>{const e=window.matchMedia("(prefers-contrast: high)"),t=window.matchMedia("(prefers-contrast: more)"),r=e=>{n(e.matches)};return e.addEventListener("change",r),t.addEventListener("change",r),()=>{e.removeEventListener("change",r),t.removeEventListener("change",r)}},[]),t}(),o=e.useMemo(()=>{const e=l(t,n);return r?{...e,primaryColor:"#000000",cssVariables:{...e.cssVariables,background:"#FFFFFF",foreground:"#000000",card:"#FFFFFF",cardForeground:"#000000",primary:"#000000",primaryForeground:"#FFFFFF",muted:"#F5F5F5",mutedForeground:"#000000",border:"#000000"}}:e},[t,n,r]),s=e.useMemo(()=>({radius:{..._,...t?.bubbleStyles?.radius},bot:{...w,...t?.bubbleStyles?.bot},user:{...k,...t?.bubbleStyles?.user},launcher:{...t?.bubbleStyles?.launcher},mapCard:{...t?.bubbleStyles?.mapCard}}),[t?.bubbleStyles]);return{mergedTheme:o,mergedStyles:s,getContainerStyle:(e,t,n)=>({"--chat-primary":o.primaryColor,zIndex:e?2147483647:9999,position:"fixed",top:t&&e?0:"auto",left:t&&e?0:"bottom-left"===n?"24px":"auto",right:t&&e?0:"bottom-right"!==n&&n?"auto":"24px",bottom:t&&e?0:"100px",width:t&&e?"100%":"auto",height:t&&e?"100%":"auto"})}}(c,O),{state:T,actions:A,unreadCount:j,currentBotEmotion:Z,isConnected:M,handleToggle:P,handleSendText:D,handleSendAttachment:F,handleSendLocation:R}=bs({apiKey:r,apiBaseUrl:o,pageContext:s,includeSEOMetadata:i,theme:c,userContext:d,onLogin:p,onNavigate:f,onEvent:y,onStateChange:z,onThemeUpdate:I}),L=e.useCallback(e=>{e.stopPropagation()},[]),U=C(T.isOpen,S,c?.position),J=e.useMemo(()=>{if(!$.cssVariables)return{};const e={},t=$.cssVariables;return t.background&&(e["--background"]=t.background),t.foreground&&(e["--foreground"]=t.foreground),t.card&&(e["--card"]=t.card),t.cardForeground&&(e["--card-foreground"]=t.cardForeground),t.primary&&(e["--primary"]=t.primary),t.primaryForeground&&(e["--primary-foreground"]=t.primaryForeground),t.muted&&(e["--muted"]=t.muted),t.mutedForeground&&(e["--muted-foreground"]=t.mutedForeground),t.border&&(e["--border"]=t.border),t.destructive&&(e["--destructive"]=t.destructive),t.radius&&(e["--radius"]=t.radius),t.spacing1&&(e["--spacing-1"]=t.spacing1),t.spacing2&&(e["--spacing-2"]=t.spacing2),t.spacing3&&(e["--spacing-3"]=t.spacing3),t.spacing4&&(e["--spacing-4"]=t.spacing4),t.spacing5&&(e["--spacing-5"]=t.spacing5),t.spacing6&&(e["--spacing-6"]=t.spacing6),t.spacing8&&(e["--spacing-8"]=t.spacing8),e},[$.cssVariables]);/* @__PURE__ */
30
- return t.jsx(h,{animations:c?.animations,effects:c?.effects,children:/* @__PURE__ */t.jsxs("div",{ref:E,id:"botuyo-chat-widget",className:a("botuyo-chat-widget flex flex-col",!S&&("bottom-left"===c?.position?"items-start":"items-end")),style:{...U,...J,pointerEvents:"auto",backgroundColor:"transparent"},"data-animations-disabled":!1===c?.animations?.enabled?"true":void 0,"data-effects-glassmorphism":!1===c?.effects?.glassmorphism?"false":void 0,"data-effects-shadows":!1===c?.effects?.softShadows?"false":void 0,children:[
31
- /* @__PURE__ */t.jsx("div",{className:a("transition-all duration-400 ease-[cubic-bezier(0.34,1.56,0.64,1)]",S?"bottom-left"===c?.position?"origin-bottom-left":"origin-bottom-right":"origin-bottom",T.isOpen?"opacity-100 scale-100 h-full w-full translate-y-0 pointer-events-auto":"opacity-0 scale-[0.85] pointer-events-none translate-y-8 h-0 w-0"),style:{pointerEvents:T.isOpen?"auto":"none"},onMouseDown:L,onTouchStart:L,children:/* @__PURE__ */t.jsx(b,{children:/* @__PURE__ */t.jsx(g,{isOpen:T.isOpen,isConnected:M,isTyping:T.isTyping,messages:T.messages,onClose:()=>A.closeWindow(),onSendMessage:D,onSendAttachment:F,onSendLocation:R,botName:c?.botName,logoUrl:c?.logoUrl,welcomeMessage:c?.welcomeMessage,inputPlaceholder:c?.inputPlaceholder,primaryColor:c?.primaryColor,position:c?.position,bubbleStyles:N,avatars:c?.avatars,mediaConfig:u,theme:$,onVoiceCall:x})})}),
32
- /* @__PURE__ */t.jsx("div",{className:a(T.isOpen?"hidden":"block",!S&&"mt-4"),style:{pointerEvents:"auto"},onMouseDown:L,onTouchStart:L,children:/* @__PURE__ */t.jsx(v,{isOpen:T.isOpen,onClick:P,unreadCount:j,position:c?.position||"bottom-right",primaryColor:c?.primaryColor,logoUrl:c?.logoUrl,starterPrompt:c?.starterPrompt,avatars:c?.avatars,emotion:Z,styles:N,promptPersistence:c?.promptPersistence,avatarScale:c?.avatarScale})})]})})}e.createContext(null);export{_s as ChatWidget};
33
- //# sourceMappingURL=ChatWidget-3m1RqH_c.js.map