import { RefObject } from 'react';
import { Props, Model, Actions, Filter, ActionId, HandlerPayload, ChanneledAction, HandlerContext } from '../types/index.js';
import { default as EventEmitter } from 'eventemitter3';
import { Dispatchers, LifecycleConfig, Scope } from './types.js';
import { isChanneledAction, getActionSymbol } from '../action/index.js';
import * as React from "react";
/**
* Creates a new object with getters for each property of the input object.
* The getters retrieve the current value from a ref, ensuring that the latest value is always accessed.
*/
export declare function withGetters
(a: P, b: RefObject
): P;
/**
* Checks if the given result is a generator or async generator object.
* Uses `Object.prototype.toString` which reliably returns
* `"[object Generator]"` or `"[object AsyncGenerator]"` regardless of
* the generator function's name.
*/
export declare function isGenerator(result: unknown): result is Generator | AsyncGenerator;
/**
* Invokes all listeners for an event and returns a promise that resolves
* when every handler has settled. For {@link BroadcastEmitter} instances the
* payload is cached — sharded by channel — before listeners
* fire so late-mounting components see every cached entry.
*
* @internal
*/
export declare function emitAsync(emitter: EventEmitter, event: string | symbol, ...args: unknown[]): Promise;
/**
* Emits lifecycle events across a component's mount cycle and tracks the
* `phase` ref.
*
* The Mount effect (layout) fires `Mount`, replays cached broadcast /
* multicast values, and — on first mount — the initial `Update`
* with the starting data (`{}` when there is no data). All of these run while
* `phase` is `Mounting`. It skips when `phase` is already `Mounted` (catching
* Strict Mode's dev-only double-invocation) and accepts both `Mounting`
* (first mount) and `Unmounted` (re-mount after `` show) as entry
* states.
*
* The Paint effect (passive `useEffect`) fires after the first frame commits
* and is where `phase` becomes `Mounted` — so every layout-phase
* emission, including each `useAction`'s reactive mount fire, observes
* `Mounting`. It ref-guards itself to fire once per mount cycle (re-firing
* after `` show).
*
* The Update effect (layout) fires `Update` with the changed data keys on
* every render after the first; the first render's Update is owned by the
* Mount effect so `context.phase` reads `Mounting` there.
*
* Phase transitions:
* - First mount: Mounting → (paint) Mounted
* - Activity hide / show: Mounted → Unmounting → Unmounted → Mounting → (paint) Mounted
*/
export declare function useLifecycles({ unicast, broadcast, dispatchers, scope, phase, data, handlers, }: LifecycleConfig): void;
/**
* Creates a data proxy for a given object, returning a memoized version.
* The proxy provides stable access to the object's properties,
* even as the original object changes across renders.
*
* The ref is updated synchronously during render so the proxy is current
* both during the render itself (for JSX reading the third tuple element
* returned by {@link useActions}) and afterwards (for handler reads via
* `context.data` across `await` boundaries).
*
* @template P The type of the object.
* @param props The object to create a data proxy for.
* @returns A memoized data proxy of the object.
*/
export declare function useData(props: P): P;
/**
* Scans a handler registry for a lifecycle action of the given type.
*
* When lifecycle actions become per-class instances (via `Lifecycle.Mount()`),
* each Actions class has its own unique symbol. Emission sites can no longer
* emit to a shared singleton — they must discover the component's lifecycle
* action by scanning the registry keys for matching lifecycle prefixes.
*
* Handler maps typically contain 5–15 entries, so the O(n) scan is trivial.
*
* @param handlers The handler map from a component's scope.
* @param type The lifecycle type to find (e.g. `"Mount"`, `"Unmount"`, `"Error"`).
* @returns The matching ActionId, or `null` if no lifecycle action of that type is registered.
*
* @internal
*/
export declare function findLifecycleAction(handlers: Map>, type: string): ActionId | null;
export { isChanneledAction, getActionSymbol };
/**
* Manages sets of broadcast and multicast action IDs.
*
* This hook creates stable refs for tracking which actions have been registered
* as broadcast or multicast within a component. These sets are used to:
* - Replay cached broadcast values on mount
* - Track multicast subscriptions for scope-based dispatch
*
* @returns Object with `broadcast` and `multicast` Sets for action tracking
*
* @example
* ```ts
* const actions = useDispatchers();
*
* // Register a broadcast action
* actions.broadcast.add(getActionSymbol(MyBroadcastAction));
*
* // Check if an action is registered as multicast
* if (actions.multicast.has(actionId)) {
* // Handle multicast dispatch
* }
* ```
*
* @internal
*/
export declare function useDispatchers(): Dispatchers;
/**
* Registers an action handler within a component's scope.
*
* This hook binds a handler function to an action, supporting both regular and channeled
* actions. The handler is wrapped with `useEffectEvent` to ensure it always has access
* to the latest closure values while maintaining a stable reference.
*
* For generator handlers (sync or async), the hook automatically iterates through
* all yielded values to completion.
*
* @template M - The model type representing the component's state
* @template AC - The actions class containing action definitions
* @template D - The data type for reactive external values
*
* @param scope - Ref to the component's handler scope containing registered handlers
* @param action - The action to register (ActionId, HandlerPayload, ChanneledAction, or ReactiveBinding)
* @param handler - The handler function to invoke when the action is dispatched
* @param site - Per-call-site symbol; registered as the channel for reactive
* bindings so each binding's emission reaches only its own handler
*
* @example
* ```ts
* useRegisterHandler(scope, Actions.Increment, async (context, payload) => {
* context.actions.produce((draft) => {
* draft.model.count += payload;
* });
* }, site);
*
* // With channeled action
* useRegisterHandler(scope, Actions.UserUpdated({ UserId: 5 }), (context, user) => {
* // Only called when UserId matches 5
* }, site);
* ```
*
* @internal
*/
export declare function useRegisterHandler(scope: React.RefObject>, action: ActionId | HandlerPayload | ChanneledAction, handler: (context: HandlerContext, payload: unknown) => void | Promise | AsyncGenerator | Generator, site: symbol): void;
/**
* Emits a reactive binding's value through the component's unicast
* emitter whenever it changes between renders. No-ops for every other
* registration kind — it is called unconditionally per `useAction`
* call site so the hook order stays stable.
*
* The comparison is `Object.is` against the last-dispatched value, seeded
* with the shared {@link unset} sentinel so the mount emission always fires once
* — whether the initial value is defined (a hydrated React Query
* cache) or `undefined`. Every later render fires only on a change, so the
* `Object.is` guard makes unchanged renders free.
*
* The effect runs after every commit (no dependency array) because the
* binding is a fresh wrapper each render. It also runs after the
* subscription effect in `useActions` (declared earlier in the hook
* order), so the mount emission is never lost.
*
* The emission carries the registration's site symbol as its channel so
* that two bindings of the same static within one component stay
* isolated — each site's dispatch reaches only its own handler,
* while uncalled subscriptions on the static hear every site.
*
* @internal
*/
export declare function useReactiveEmit(action: ActionId | HandlerPayload | ChanneledAction, unicast: EventEmitter, site: symbol): void;
/**
* Checks whether a dispatch channel satisfies a registered handler's
* channel filter. The handler's channel is the filter: every key the
* subscriber supplied must be present and equal on the dispatch channel.
* Extra keys on the dispatch channel are ignored — the dispatcher
* is free to be more specific than any single subscriber needs.
*
* Mental model: "the subscriber declares everything it wants matched
* against; the dispatcher matches what it can." A subscriber that
* registers no channel keys (`{}` or no channel at all) matches every
* dispatch on the action.
*
* @param dispatchChannel - The channel from the dispatch call (from ChanneledAction)
* @param registeredChannel - The channel registered with useAction
* @returns `true` if every key on the registered channel is satisfied by the dispatch channel
*
* @example
* ```ts
* matchesChannel({ UserId: 1 }, { UserId: 1 }); // true (exact)
* matchesChannel({ UserId: 1, Role: "admin" }, { UserId: 1 }); // true (subscriber narrower)
* matchesChannel({ UserId: 1 }, { UserId: 1, Role: "admin" }); // false (subscriber asked for Role, dispatch did not supply it)
* matchesChannel({ UserId: 1 }, { UserId: 2 }); // false (value mismatch)
* matchesChannel({ UserId: 1, Role: "admin" }, {}); // true (subscriber filters nothing)
* matchesChannel({}, { UserId: 1 }); // false (subscriber asked for UserId, dispatch did not supply it)
* ```
*/
export declare function matchesChannel(dispatchChannel: Filter, registeredChannel: Filter): boolean;