/**
 * Creates a new hooks system for a Lix instance.
 *
 * Uses the native EventTarget API under the hood for efficient
 * event handling and automatic memory management.
 *
 * @returns LixHooks instance with event subscription methods
 */
function ensureCustomEventPolyfill() {
    if (typeof globalThis.CustomEvent === "function") {
        return;
    }
    class NodeCustomEvent extends Event {
        detail;
        constructor(type, params) {
            super(type, params);
            this.detail = (params?.detail ?? null);
        }
    }
    globalThis.CustomEvent =
        NodeCustomEvent;
}
export function createHooks() {
    ensureCustomEventPolyfill();
    const eventTarget = new EventTarget();
    return {
        onStateCommit(handler) {
            const wrappedHandler = (event) => {
                const customEvent = event;
                handler(customEvent.detail);
            };
            eventTarget.addEventListener("state_commit", wrappedHandler);
            return () => eventTarget.removeEventListener("state_commit", wrappedHandler);
        },
        _emit(eventType, data) {
            eventTarget.dispatchEvent(new CustomEvent(eventType, { detail: data }));
        },
    };
}
//# sourceMappingURL=create-hooks.js.map