(function(n,s){typeof exports=="object"&&typeof module<"u"?s(exports):typeof define=="function"&&define.amd?define(["exports"],s):(n=typeof globalThis<"u"?globalThis:n||self,s(n["entando-mfecommunication"]={}))})(this,function(n){var f,a;"use strict";var c=Object.defineProperty;var h=(n,s,r)=>s in n?c(n,s,{enumerable:!0,configurable:!0,writable:!0,value:r}):n[s]=r;var l=(n,s,r)=>(h(n,typeof s!="symbol"?s+"":s,r),r);console.log("Debug: Mediator.ts file loaded");class s{constructor(){l(this,"events");this.events={}}verifyString(e,t){if(typeof t!="string")throw new Error(`${e} must be a string`)}verifyArrayOfStrings(e,t){if(!Array.isArray(t))throw new Error(`${e} must be an array`);t.forEach(i=>{if(typeof i!="string")throw new Error(`${e} must be an array of strings`)})}verifyCallback(e,t){if(typeof t!="function"||!t)throw new Error(`${e} must be a function`)}verifyEventCallback(e){if(typeof e!="object"||!e)throw new Error("eventCallback must be an object with callerId and callback properties");this.verifyString("eventCallback.callerId",e.callerId),this.verifyCallback("eventCallback.callback",e.callback)}subscribe(e,t){this.verifyString("eventType",e),this.verifyEventCallback(t),this.events[e]||(this.events[e]=[]),this.events[e].push(t)}unsubscribe(e,t){this.verifyString("eventType",e),this.verifyString("callerId",t),this.events[e]&&(this.events[e]=this.events[e].filter(i=>i.callerId!==t))}unsubscribeAllEventsOfSubscriber(e){this.verifyString("callerId",e);for(const t in this.events)this.events[t]=this.events[t].filter(i=>i.callerId!==e)}unsubscribeAllSubscribersOfEvent(e){this.verifyString("eventType",e),this.events[e]&&(this.events[e]=[])}unsubscribeAll(){for(const e in this.events)this.events[e]=[]}publish(e,t){this.verifyString("eventType",e),this.events[e]&&this.events[e].forEach(i=>i.callback(t))}publishToSubscribers(e,t,i){this.verifyString("eventType",e),this.verifyArrayOfStrings("callerIds",t),this.events[e]&&this.events[e].forEach(o=>{t.includes(o.callerId)&&o.callback(i)})}publishExceptToSubscribers(e,t,i){this.verifyString("eventType",e),this.verifyArrayOfStrings("callerIds",t),this.events[e]&&this.events[e].forEach(o=>{t.includes(o.callerId)||o.callback(i)})}listSubscribers(){const e=[];for(const t in this.events)this.events[t].forEach(i=>e.push({eventType:t,subscriber:i.callerId}));return e}listSubscribersForEvent(e){const t=[];return this.events[e]&&this.events[e].forEach(i=>t.push(i.callerId)),t}listEvents(){const e=[];for(const t in this.events)e.push(t);return e}listEventsForSubscriber(e){const t=[];for(const i in this.events)this.events[i].forEach(o=>{o.callerId===e&&t.push(i)});return t}}typeof window<"u"&&(window.entando=window.entando||{},window.entando.globals=window.entando.globals||{},window.entando.globals.mediator||(window.entando.globals.mediator=new s));const r=typeof window<"u"&&((a=(f=window==null?void 0:window.entando)==null?void 0:f.globals)!=null&&a.mediator)?window.entando.globals.mediator:new s;console.log("entando-mfecommunication: src/index.tsx: No default export"),n.Mediator=s,n.mediatorInstance=r,Object.defineProperty(n,Symbol.toStringTag,{value:"Module"})});