import type { ComponentType } from 'react';
import type { AspectMain } from '@teambit/aspect';
import type { AspectDefinition } from '@teambit/aspect-loader';
import type { CacheMain } from '@teambit/cache';
import type { CLIMain } from '@teambit/cli';
import type { ComponentMain } from '@teambit/component';
import type { ExpressMain } from '@teambit/express';
import type { GraphqlMain } from '@teambit/graphql';
import type { SlotRegistry, Harmony } from '@teambit/harmony';
import type { Logger, LoggerMain } from '@teambit/logger';
import type { PubsubMain } from '@teambit/pubsub';
import webpack from 'webpack';
import type { UIRoot } from './ui-root';
import { UIServer } from './ui-server';
import type { StartPlugin } from './start-plugin';
export type UIDeps = [PubsubMain, CLIMain, GraphqlMain, ExpressMain, ComponentMain, CacheMain, LoggerMain, AspectMain];
export type UIRootRegistry = SlotRegistry<UIRoot>;
export type PreStart = (preStartOpts: PreStartOpts) => Promise<void>;
export type PreStartOpts = {
    skipCompilation?: boolean;
};
export type OnStart = () => Promise<undefined | ComponentType<{}>>;
export type StartPluginSlot = SlotRegistry<StartPlugin>;
export type PublicDirOverwrite = (uiRoot: UIRoot) => Promise<string | undefined>;
export type BuildMethodOverwrite = (name: string, uiRoot: UIRoot, rebuild?: boolean) => Promise<string>;
export type PreStartSlot = SlotRegistry<PreStart>;
export type OnStartSlot = SlotRegistry<OnStart>;
export type PublicDirOverwriteSlot = SlotRegistry<PublicDirOverwrite>;
export type BuildMethodOverwriteSlot = SlotRegistry<BuildMethodOverwrite>;
export type UIConfig = {
    /**
     * port for the UI root to use.
     */
    port?: number;
    /**
     * port range for the UI root to use.
     */
    portRange: [number, number];
    /**
     * host for the UI root
     */
    host: string;
    /**
     * directory in workspace to use for public assets.
     * always relative to the workspace root directory.
     */
    publicDir: string;
    /** the url to display when server is listening. Note that bit does not provide proxying to this url */
    publicUrl?: string;
};
export type RuntimeOptions = {
    /**
     * determine whether to initiate on verbose mode.
     */
    verbose?: boolean;
    /**
     * name of the UI root to load.
     */
    uiRootName?: string;
    uiRootAspectIdOrName?: string;
    /**
     * component selector pattern to load.
     */
    pattern?: string;
    /**
     * determine whether to start a dev server (defaults to false).
     */
    dev?: boolean;
    /**
     * port of the config.
     */
    port?: number;
    /**
     * determine whether to rebuild the UI before start.
     */
    rebuild?: boolean;
    /**
     * skip build the UI before start
     */
    skipUiBuild?: boolean;
    /**
     * Show the internal urls of the dev servers
     */
    showInternalUrls?: boolean;
};
export declare class UiMain {
    /**
     * Pubsub extension.
     */
    private pubsub;
    private config;
    /**
     * graphql extension.
     */
    private graphql;
    /**
     * slot registry of ui roots.
     */
    private uiRootSlot;
    /**
     * express extension.
     */
    private express;
    /**
     * pre-start slot
     */
    private preStartSlot;
    /**
     * on start slot
     */
    private onStartSlot;
    /**
     * Overwrite the public dir Slot
     */
    private publicDirOverwriteSlot;
    /**
     * Overwrite the build ui method
     */
    private buildMethodOverwriteSlot;
    /**
     * component extension.
     */
    private componentExtension;
    /**
     * ui logger instance.
     */
    private cache;
    /**
     * ui logger instance.
     */
    private logger;
    private harmony;
    private startPluginSlot;
    private _isBundleUiServed;
    private currentUIServer;
    constructor(
    /**
     * Pubsub extension.
     */
    pubsub: PubsubMain, config: UIConfig, 
    /**
     * graphql extension.
     */
    graphql: GraphqlMain, 
    /**
     * slot registry of ui roots.
     */
    uiRootSlot: UIRootRegistry, 
    /**
     * express extension.
     */
    express: ExpressMain, 
    /**
     * pre-start slot
     */
    preStartSlot: PreStartSlot, 
    /**
     * on start slot
     */
    onStartSlot: OnStartSlot, 
    /**
     * Overwrite the public dir Slot
     */
    publicDirOverwriteSlot: PublicDirOverwriteSlot, 
    /**
     * Overwrite the build ui method
     */
    buildMethodOverwriteSlot: BuildMethodOverwriteSlot, 
    /**
     * component extension.
     */
    componentExtension: ComponentMain, 
    /**
     * ui logger instance.
     */
    cache: CacheMain, 
    /**
     * ui logger instance.
     */
    logger: Logger, harmony: Harmony, startPluginSlot: StartPluginSlot);
    publicDir(uiRoot: UIRoot): Promise<string>;
    private getUiByName;
    /**
     * create a build of the given UI root.
     */
    build(uiRootAspectIdOrName?: string, customOutputPath?: string): Promise<webpack.MultiStats | undefined>;
    registerStartPlugin(startPlugin: StartPlugin): this;
    private runWebpackPromise;
    private initiatePlugins;
    runtimeOptions: RuntimeOptions;
    getUIServer(): UIServer | undefined;
    /**
     * create a Bit UI runtime.
     */
    createRuntime(runtimeOptions: RuntimeOptions): Promise<UIServer>;
    private addSignalListener;
    getPort(port?: number): Promise<number>;
    /**
     * Events
     */
    private createUiServerStartedEvent;
    /**
     * pre-start events are triggered and *completed* before the webserver started.
     * (the promise is awaited)
     */
    registerPreStart(preStartFn: PreStart): void;
    /**
     * bind to ui server start event.
     */
    registerOnStart(onStartFn: OnStart): this;
    /**
     * overwrite the build ui function
     */
    registerBuildUIOverwrite(fn: BuildMethodOverwrite): this;
    /**
     * overwrite the build ui function
     */
    registerPublicDirOverwrite(fn: PublicDirOverwrite): this;
    private getOverwriteBuildFn;
    private getOverwritePublic;
    invokePreStart(preStartOpts: PreStartOpts): Promise<void>;
    invokeOnStart(): Promise<ComponentType[]>;
    /**
     * register a UI slot.
     */
    registerUiRoot(uiRoot: UIRoot): void;
    /**
     * get a UI runtime instance.
     */
    getUi(uiRootAspectIdOrName?: string): [string, UIRoot] | undefined;
    isHostAvailable(): boolean;
    getUiName(uiRootAspectIdOrName?: string): string | undefined;
    private possibleUis;
    createLink(aspectDefs: AspectDefinition[], rootExtensionName: string): Promise<string>;
    /**
     * generate the root file of the UI runtime.
     */
    generateRoot(aspectDefs: AspectDefinition[], rootExtensionName: string, runtimeName?: string, rootAspect?: string, config?: object, path?: string, ignoreVersion?: boolean, addRuntimes?: boolean, harmonyPackage?: string, shouldRun?: boolean): Promise<string>;
    private selectPort;
    private buildUI;
    private shouldServeBundleUi;
    buildIfChanged(uiRootAspectId: string, uiRoot: UIRoot, force: boolean | undefined): Promise<boolean>;
    private createBuildUiHash;
    /**
     * Generate hash for a given root
     * This API is public and used by external users, do not rename this function
     */
    buildUiHash(uiRoot: UIRoot, runtime?: string): Promise<string>;
    createBundleUiHash(uiRoot: UIRoot, runtime?: string): Promise<string>;
    private readBundleUiHash;
    private getBundleUiPath;
    private buildIfNoBundle;
    clearConsole(): void;
    get publicUrl(): string | undefined;
    static defaultConfig: UIConfig;
    static runtime: import("@teambit/harmony").RuntimeDefinition;
    static dependencies: import("@teambit/harmony").Aspect[];
    static slots: (((registerFn: () => string) => SlotRegistry<UIRoot>) | ((registerFn: () => string) => SlotRegistry<PreStart>) | ((registerFn: () => string) => SlotRegistry<OnStart>) | ((registerFn: () => string) => SlotRegistry<PublicDirOverwriteSlot>) | ((registerFn: () => string) => SlotRegistry<BuildMethodOverwriteSlot>) | ((registerFn: () => string) => SlotRegistry<StartPlugin>))[];
    static provider([pubsub, cli, graphql, express, componentExtension, cache, loggerMain]: UIDeps, config: any, [uiRootSlot, preStartSlot, onStartSlot, publicDirOverwriteSlot, buildMethodOverwriteSlot, proxyGetterSlot]: [
        UIRootRegistry,
        PreStartSlot,
        OnStartSlot,
        PublicDirOverwriteSlot,
        BuildMethodOverwriteSlot,
        StartPluginSlot
    ], harmony: Harmony): Promise<UiMain>;
}
