import * as Provider from 'ox/Provider';
import * as RpcResponse from 'ox/RpcResponse';
import type { StoreApi } from 'zustand/vanilla';
import type * as Messenger from '../core/Messenger.js';
import type * as CoreProvider from '../core/Provider.js';
import * as Schema from '../core/Schema.js';
import type * as Store from '../core/Store.js';
/** State managed by the remote (dialog) side. */
export type State = {
    /** Whether the dialog is rendered in an iframe or popup. */
    mode: 'iframe' | 'popup' | undefined;
    /** Trusted host origin from MessageEvent. */
    origin: string | undefined;
    /** Whether the dialog is ready to display content. */
    ready: boolean;
    /** Queued RPC requests received from the host. */
    requests: readonly Store.QueuedRequest[];
};
/** Remote context — bundles messenger, provider, and remote store. */
export type Remote = {
    /**
     * Messenger for remote communication.
     */
    messenger: Messenger.Bridge;
    /**
     * Provider instance for executing RPC methods.
     */
    provider: CoreProvider.Provider;
    /**
     * Remote context store.
     */
    store: StoreApi<State>;
    /**
     * Hostnames trusted to render the embed in an iframe.
     */
    trustedHosts: readonly string[];
    /**
     * Subscribes to user-facing RPC requests from the parent context.
     *
     * Syncs the host's active chain, updates the remote store, and invokes
     * the callback with the first pending request (or `null` when the queue
     * is cleared, signalling the UI should close).
     *
     * @param cb - Callback receiving the request payload.
     * @returns Unsubscribe function.
     */
    onUserRequest: (cb: (payload: onUserRequest.Payload) => void | Promise<void>) => () => void;
    /**
     * Subscribes to incoming RPC requests from the parent context.
     * Updates the remote store with the received requests and syncs the
     * host's active chain to the remote provider.
     *
     * @param cb - Callback receiving the full queued request list.
     * @returns Unsubscribe function.
     */
    onRequests: (cb: (requests: readonly Store.QueuedRequest[], event: MessageEvent, extra: {
        account: {
            address: string;
        } | undefined;
    }) => void) => () => void;
    /**
     * Signals readiness to the host and begins accepting requests.
     * Call this after the remote context is fully initialized.
     */
    ready: (options?: ready.Options | undefined) => void;
    /**
     * Reject an RPC request.
     */
    reject: (request: Store.QueuedRequest['request'], error?: Provider.ProviderRpcError | RpcResponse.BaseError | undefined) => void;
    /** Reject all pending RPC requests. */
    rejectAll: (error?: Provider.ProviderRpcError | RpcResponse.BaseError | undefined) => void;
    /**
     * Respond to an RPC request.
     *
     * When `options.result` is provided, sends it directly.
     * When `options.error` is provided, sends an error response.
     * Otherwise, executes `provider.request(request)` and sends the result.
     */
    respond: (request: Store.QueuedRequest['request'], options?: respond.Options) => Promise<unknown>;
};
export declare namespace onUserRequest {
    type Payload = {
        /** Active account on the host side. */
        account: {
            address: string;
        } | undefined;
        /** Origin of the host that opened this dialog. */
        origin: string;
        /** The pending request to display, or `null` when the dialog should close. */
        request: Store.QueuedRequest['request'] | null;
    };
}
export declare namespace ready {
    type Options = Messenger.ReadyOptions & {
        /** Authenticated account addresses. When provided, the wallet responds to SDK sync requests. */
        accounts?: readonly string[] | undefined;
    };
}
export declare namespace respond {
    type Options = {
        /** Error to respond with (takes precedence over result). */
        error?: {
            code: number;
            message: string;
        } | undefined;
        /**
         * Called when `provider.request()` throws. Return `true` to suppress the
         * error response to the parent — the dialog stays open and can show a
         * recovery UI. The error is still re-thrown to the caller.
         */
        onError?: ((error: Error) => boolean | void) | undefined;
        /** Explicit result — if omitted, calls `provider.request(request)`. */
        result?: unknown | undefined;
        /** Transform the result before sending. */
        selector?: ((result: any) => unknown) | undefined;
    };
}
/** Creates a remote context for the dialog app. */
export declare function create(options: create.Options): Remote;
export declare namespace create {
    type Options = {
        /** Bridge messenger for cross-frame communication. */
        messenger: Messenger.Bridge;
        /** Provider to execute RPC requests against. */
        provider: CoreProvider.Provider;
        /** Hostnames trusted to render the embed in an iframe. */
        trustedHosts?: readonly string[] | undefined;
    };
}
/** Returns an inert remote context for SSR environments. */
export declare function noop(): Remote;
/**
 * Validates an RPC request from search params.
 *
 * Parses against the `Schema.Request` discriminated union, checks the
 * method matches, and enforces strict parameter schemas (e.g. required
 * `limits`). On failure, rejects all pending requests via the messenger
 * and re-throws so the router can handle the error boundary.
 */
export declare function validateSearch<const method extends Schema.Request['method']>(remote: Remote, search: Record<string, unknown>, parameters: {
    method: method;
}): validateSearch.ReturnType<method>;
export declare namespace validateSearch {
    type ReturnType<method extends Schema.Request['method']> = Extract<Schema.Request, {
        method: method;
    }> & {
        id: number;
        jsonrpc: '2.0';
        _decoded: Extract<Schema.Request, {
            method: method;
        }>;
        _returnType: unknown;
    };
}
//# sourceMappingURL=Remote.d.ts.map