import { AnyCircuitElement } from 'circuit-json';
import { RootCircuitEventName, RootCircuit } from '@tscircuit/core';
import { PlatformConfig } from '@tscircuit/props';

interface CircuitRunnerConfiguration {
    snippetsApiBaseUrl: string;
    cjsRegistryUrl: string;
    verbose?: boolean;
    platform?: PlatformConfig;
}
interface WebWorkerConfiguration extends CircuitRunnerConfiguration {
    evalVersion?: string;
    /**
     * @deprecated, renamed to webWorkerBlobUrl
     */
    webWorkerUrl?: URL | string;
    webWorkerBlobUrl?: URL | string;
}
/**
 * API for the CircuitRunner class, used for eval'ing circuits
 */
interface CircuitRunnerApi {
    execute: (code: string, opts?: {
        name?: string;
    }) => Promise<void>;
    executeWithFsMap(opts: {
        entrypoint?: string;
        fsMap: Record<string, string>;
        name?: string;
    }): Promise<void>;
    renderUntilSettled: () => Promise<void>;
    getCircuitJson: () => Promise<AnyCircuitElement[]>;
    setSnippetsApiBaseUrl: (baseUrl: string) => Promise<void>;
    setPlatformConfig: (platform: PlatformConfig) => Promise<void>;
    on: (event: RootCircuitEventName, callback: (...args: any[]) => void) => void;
    clearEventListeners: () => void;
    kill: () => Promise<void>;
}
type CircuitWebWorker = {
    execute: (code: string) => Promise<void>;
    executeWithFsMap: (opts: {
        entrypoint?: string;
        mainComponentPath?: string;
        fsMap: Record<string, string>;
    }) => Promise<void>;
    renderUntilSettled: () => Promise<void>;
    getCircuitJson: () => Promise<AnyCircuitElement[]>;
    on: (event: RootCircuitEventName, callback: (...args: any[]) => void) => void;
    clearEventListeners: () => void;
    kill: () => Promise<void>;
};

interface ExecutionContext extends WebWorkerConfiguration {
    fsMap: Record<string, string>;
    entrypoint: string;
    preSuppliedImports: Record<string, any>;
    circuit: RootCircuit;
}
declare function createExecutionContext(webWorkerConfiguration: WebWorkerConfiguration, opts?: {
    name?: string;
    platform?: PlatformConfig;
}): ExecutionContext;

declare class CircuitRunner implements CircuitRunnerApi {
    _executionContext: ReturnType<typeof createExecutionContext> | null;
    _circuitRunnerConfiguration: CircuitRunnerConfiguration;
    _eventListeners: Record<string, ((...args: any[]) => void)[]>;
    constructor(configuration?: Partial<CircuitRunnerConfiguration>);
    executeWithFsMap(ogOpts: {
        entrypoint?: string;
        mainComponentPath?: string;
        mainComponentName?: string;
        fsMap: Record<string, string>;
        name?: string;
        mainComponentProps?: Record<string, any>;
    }): Promise<void>;
    execute(code: string, opts?: {
        name?: string;
    }): Promise<void>;
    on(event: string, callback: (...args: any[]) => void): void;
    renderUntilSettled(): Promise<void>;
    getCircuitJson(): Promise<AnyCircuitElement[]>;
    clearEventListeners(): void;
    kill(): Promise<void>;
    setSnippetsApiBaseUrl(baseUrl: string): Promise<void>;
    setPlatformConfig(platform: PlatformConfig): Promise<void>;
    private _bindEventListeners;
}

declare function runTscircuitCode(filesystemOrCodeString: Record<string, string> | string, opts?: Omit<Parameters<CircuitRunner["executeWithFsMap"]>[0], "fsMap">): Promise<any[]>;

declare const runTscircuitModule: (module: string, opts?: {
    props?: Record<string, any>;
    exportName?: string;
}) => Promise<any[]>;

declare const getImportsFromCode: (code: string) => string[];

declare global {
    interface Window {
        TSCIRCUIT_GLOBAL_CIRCUIT_WORKER: CircuitWebWorker | undefined;
    }
    var TSCIRCUIT_GLOBAL_CIRCUIT_WORKER: CircuitWebWorker | undefined;
}
declare const createCircuitWebWorker: (configuration: Partial<WebWorkerConfiguration>) => Promise<CircuitWebWorker>;

declare const getPossibleEntrypointComponentPaths: (fsMap: Record<string, string>) => string[];

export { CircuitRunner, type CircuitWebWorker, type WebWorkerConfiguration, createCircuitWebWorker, getImportsFromCode, getPossibleEntrypointComponentPaths, runTscircuitCode, runTscircuitModule };
