/**
 * This file is part of the NocoBase (R) project.
 * Copyright (c) 2020-2024 NocoBase Co., Ltd.
 * Authors: NocoBase Team.
 *
 * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
 * For more information, please refer to: https://www.nocobase.com/agreement.
 */
import { FlowEngine, FlowEngineContext, FlowModel } from '@nocobase/flow-engine';
import { APIClient } from '@nocobase/sdk';
import type { i18n as i18next } from 'i18next';
import React, { ReactElement, ReactNode } from 'react';
import type { AppListProps } from '@ant-design/pro-layout/es/components/AppsLogoComponents/types';
import { AIManager } from './ai';
import { SystemSettingsSource } from './flow/system-settings';
import { LayoutManager } from './layout-manager/LayoutManager';
import type { PluginClass, PluginManager, PluginType } from './PluginManager';
import { RouteRepository } from './RouteRepository';
import type { ComponentTypeAndString, RenderableComponentType, RouterComponentType, RouterManager, RouterOptions } from './RouterManager';
import { WebSocketClient, type WebSocketClientOptions } from './WebSocketClient';
import type { RequireJS } from './utils/requirejs';
declare global {
    interface Window {
        requirejs?: RequireJS;
        define: RequireJS['define'];
    }
}
type AnyComponent = RenderableComponentType<any>;
type AppListLoader = (app: BaseApplication<any>) => Promise<AppListProps> | AppListProps;
type AuthTokenPayload = {
    token: string;
    authenticator: string | null;
};
export type JsonLogic = {
    apply: (logic: any, data?: any) => any;
    addOperation: (name: string, fn?: any) => void;
    rmOperation: (name: string) => void;
};
export type DevDynamicImport = (packageName: string) => Promise<{
    default: PluginClass;
}>;
export type ComponentAndProps<T = any> = [AnyComponent, T];
export interface BaseApplicationOptions<TPluginType> {
    name?: string;
    publicPath?: string;
    apiClient?: any;
    ws?: WebSocketClientOptions | boolean;
    i18n?: i18next;
    providers?: (AnyComponent | ComponentAndProps)[];
    plugins?: TPluginType[];
    components?: Record<string, AnyComponent>;
    scopes?: Record<string, any>;
    router?: RouterOptions;
    designable?: boolean;
    loadRemotePlugins?: boolean;
    devDynamicImport?: DevDynamicImport;
    disableAcl?: boolean;
}
/**
 * 共享的应用运行时基类。
 *
 * 该类只负责承接 client 与 client-v2 共用的 Application 骨架，
 * 具体产品行为通过子类钩子补齐。
 */
export declare abstract class BaseApplication<TOptions extends BaseApplicationOptions<any> = BaseApplicationOptions<PluginType>, TPluginManager extends PluginManager<any> = PluginManager<any>, TRouterManager extends RouterManager<any> = RouterManager<any>, TApiClient extends APIClient = APIClient, TPluginSettingsManager = any> {
    protected options: TOptions;
    eventBus: EventTarget;
    providers: ComponentAndProps[];
    router: TRouterManager;
    scopes: Record<string, any>;
    i18n: i18next;
    ws: WebSocketClient;
    apiClient: TApiClient;
    components: Record<string, AnyComponent>;
    pluginManager: TPluginManager;
    pluginSettingsManager: TPluginSettingsManager;
    layoutManager: LayoutManager<this>;
    aiManager: AIManager;
    devDynamicImport?: DevDynamicImport;
    requirejs: RequireJS;
    name: string;
    favicon: string;
    flowEngine: FlowEngine;
    dataSourceManager: any;
    jsonLogic: JsonLogic;
    context: FlowEngineContext & {
        routeRepository: RouteRepository;
        appInfo: Promise<Record<string, any>>;
        pageInfo: {
            version?: 'v1' | 'v2';
        };
        systemSettings: SystemSettingsSource;
        acl?: {
            data: Record<string, any>;
            meta: Record<string, any>;
            setData: (data: Record<string, any>) => void;
            setMeta: (meta: Record<string, any>) => void;
        };
        pluginManager: TPluginManager;
    };
    systemSettings: SystemSettingsSource;
    maintained: boolean;
    maintaining: boolean;
    error: any;
    model: ApplicationModel;
    private wsAuthorized;
    apps: {
        Component?: AnyComponent | null;
        loadAppList?: AppListLoader | null;
    };
    get pm(): TPluginManager;
    get disableAcl(): boolean;
    get isWsAuthorized(): boolean;
    setDocumentLanguage(language?: string | null): void;
    constructor(options?: TOptions);
    /**
     * 注册共享 observable 状态。
     */
    protected defineObservableState(): void;
    protected initializeExtendedState(): void;
    protected afterManagersInitialized(): void;
    protected configureContext(): void;
    protected configureRuntimeAdapters(): void;
    protected addCustomProviders(): void;
    protected initListeners(): void;
    protected setTokenInWebSocket(options: AuthTokenPayload): void;
    protected initRequireJs(): void;
    /**
     * 注入两边共享的基础 context。
     */
    protected configureBaseContext(): void;
    /**
     * 注册两边共享的默认 providers。
     */
    protected addBaseProviders(): void;
    protected addFinalProviders(): void;
    addReactRouterComponents(): void;
    addRoutes(): void;
    updateFavicon(favicon?: string | null): void;
    setWsAuthorized(authorized: boolean): void;
    setMaintaining(maintaining: boolean): void;
    getOptions(): TOptions;
    getName(): string;
    getCdnUrl(): string;
    getPublicPath(): string;
    getApiUrl(pathname?: string): string;
    getRouteUrl(pathname: string): string;
    getHref(pathname: string): string;
    getComposeProviders(): React.FC;
    use<T = any>(component: AnyComponent, props?: T): number;
    addProvider<T = any>(component: AnyComponent, props?: T): number;
    addProviders(providers: (AnyComponent | ComponentAndProps)[]): void;
    getComponent<T = any>(Component: ComponentTypeAndString<T>, isShowError?: boolean): AnyComponent | undefined;
    renderComponent<T extends {}>(Component: ComponentTypeAndString, props?: T, children?: ReactNode): ReactElement | null;
    /**
     * @internal
     */
    protected addComponent(component: AnyComponent, name?: string): void;
    addComponents(components: Record<string, AnyComponent>): void;
    setAppsComponent({ Component }: {
        Component: AnyComponent;
    }): void;
    setAppsProvider({ loadAppList }: {
        loadAppList: AppListLoader;
    }): void;
    protected getRootFallback(): React.ReactElement<any, string | React.JSXElementConstructor<any>>;
    getRootComponent(): React.FC<{
        children?: React.ReactNode;
    }>;
    mount(containerOrSelector: Element | ShadowRoot | string): import("react-dom/client").Root;
    protected abstract createApiClient(options: TOptions): TApiClient;
    protected abstract createI18n(options: TOptions): i18next;
    protected abstract createRouterManager(options: TOptions): TRouterManager;
    protected abstract createPluginManager(options: TOptions): TPluginManager;
    protected abstract createPluginSettingsManager(options: TOptions): TPluginSettingsManager;
    protected createLayoutManager(_options: TOptions): LayoutManager<this>;
    protected createWebSocketClient(options: TOptions): WebSocketClient;
    protected getDefaultComponents(): Record<string, AnyComponent>;
    abstract load(): Promise<void>;
    abstract loadWebSocket(): Promise<void>;
}
/**
 * Application 共享根模型。
 *
 * 该模型统一承接 app.load、错误态、维护态和主内容渲染。
 */
export declare class ApplicationModel extends FlowModel {
    #private;
    get app(): BaseApplication<BaseApplicationOptions<PluginType>, PluginManager<any>, RouterManager<any>, APIClient, any>;
    getProviders(): AnyComponent;
    getRouter(): RouterComponentType;
    render(): React.JSX.Element;
    renderMaintaining(): React.ReactElement<any, string | React.JSXElementConstructor<any>>;
    renderMaintainingDialog(): React.ReactElement<any, string | React.JSXElementConstructor<any>>;
    renderError(): React.ReactElement<any, string | React.JSXElementConstructor<any>>;
    renderContent(): React.JSX.Element;
}
export {};
