/**
 * 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 { APIClientOptions } from '@nocobase/sdk';
import { i18n as i18next } from 'i18next';
import React, { ComponentType, ReactElement, ReactNode } from 'react';
import { APIClient } from '../api-client';
import { PluginManager, PluginType } from './PluginManager';
import { PluginSettingOptions, PluginSettingsManager } from './PluginSettingsManager';
import { ComponentTypeAndString, RouterManager, RouterOptions } from './RouterManager';
import { WebSocketClient, WebSocketClientOptions } from './WebSocketClient';
import { SchemaInitializer, SchemaInitializerManager } from './schema-initializer';
import { SchemaSettings, SchemaSettingsItemType, SchemaSettingsManager } from './schema-settings';
import { CollectionFieldInterfaceComponentOption } from '../data-source/collection-field-interface/CollectionFieldInterface';
import { DataSourceManager, type DataSourceManagerOptions } from '../data-source/data-source/DataSourceManager';
import { FlowEngine, FlowEngineContext } from '@nocobase/flow-engine';
import type { CollectionFieldInterfaceFactory } from '../data-source';
import type { Plugin } from './Plugin';
import type { RequireJS } from './utils/requirejs';
import { AIManager } from '../ai';
type JsonLogic = {
    addOperation: (name: string, fn?: any) => void;
    rmOperation: (name: string) => void;
};
declare global {
    interface Window {
        define: RequireJS['define'];
    }
}
export type DevDynamicImport = (packageName: string) => Promise<{
    default: typeof Plugin;
}>;
export type ComponentAndProps<T = any> = [ComponentType, T];
export interface ApplicationOptions {
    name?: string;
    publicPath?: string;
    apiClient?: APIClientOptions | APIClient;
    ws?: WebSocketClientOptions | boolean;
    i18n?: i18next;
    providers?: (ComponentType | ComponentAndProps)[];
    plugins?: PluginType[];
    components?: Record<string, ComponentType>;
    scopes?: Record<string, any>;
    router?: RouterOptions;
    pluginSettings?: Record<string, PluginSettingOptions>;
    schemaSettings?: SchemaSettings[];
    schemaInitializers?: SchemaInitializer[];
    designable?: boolean;
    loadRemotePlugins?: boolean;
    devDynamicImport?: DevDynamicImport;
    dataSourceManager?: DataSourceManagerOptions;
    disableAcl?: boolean;
}
/**
 * Reference: https://ant.design/components/cascader-cn#option
 */
interface VariableOption {
    /** Unique identifier of the variable */
    value: string | number;
    /** Variable name displayed in UI */
    label?: React.ReactNode;
    disabled?: boolean;
    children?: VariableOption[];
}
interface Variable {
    /** Unique identifier of the variable */
    name: string;
    /** Variable configuration options */
    useOption: () => {
        option: VariableOption;
        visible?: boolean;
    };
    /** Variable context */
    useCtx: () => any | ((param: {
        variableName: string;
    }) => Promise<any>);
}
export declare class Application {
    protected options: ApplicationOptions;
    eventBus: EventTarget;
    aiManager: AIManager;
    providers: ComponentAndProps[];
    router: RouterManager;
    scopes: Record<string, any>;
    i18n: i18next;
    ws: WebSocketClient;
    apiClient: APIClient;
    components: Record<string, ComponentType<any> | any>;
    pluginManager: PluginManager;
    pluginSettingsManager: PluginSettingsManager;
    devDynamicImport: DevDynamicImport;
    requirejs: RequireJS;
    notification: any;
    schemaInitializerManager: SchemaInitializerManager;
    schemaSettingsManager: SchemaSettingsManager;
    dataSourceManager: DataSourceManager;
    name: string;
    favicon: string;
    globalVars: Record<string, any>;
    globalVarCtxs: Record<string, any>;
    jsonLogic: JsonLogic;
    flowEngine: FlowEngine;
    context: FlowEngineContext & {
        pluginSettingsRouter: PluginSettingsManager;
        pluginManager: PluginManager;
    };
    loading: boolean;
    maintained: boolean;
    maintaining: boolean;
    error: any;
    hasLoadError: boolean;
    locales: any;
    private wsAuthorized;
    private readonly variables;
    apps: {
        Component?: ComponentType;
    };
    get pm(): PluginManager;
    get disableAcl(): boolean;
    get isWsAuthorized(): boolean;
    updateFavicon(favicon?: string): void;
    setWsAuthorized(authorized: boolean): void;
    constructor(options?: ApplicationOptions);
    private initListeners;
    protected setTokenInWebSocket(options: {
        token: string;
        authenticator: string;
    }): void;
    setMaintaining(maintaining: boolean): void;
    private initRequireJs;
    private addDefaultProviders;
    private addReactRouterComponents;
    private addRoutes;
    getOptions(): ApplicationOptions;
    getName(): string;
    getPublicPath(): string;
    getApiUrl(pathname?: string): string;
    getRouteUrl(pathname: string): string;
    getHref(pathname: string): string;
    getCollectionManager(dataSource?: string): import("../data-source").CollectionManager;
    /**
     * @internal
     */
    getComposeProviders(): React.FC;
    use<T = any>(component: ComponentType, props?: T): number;
    addProvider<T = any>(component: ComponentType, props?: T): number;
    addProviders(providers: (ComponentType | [ComponentType, any])[]): void;
    load(): Promise<void>;
    loadWebSocket(): Promise<void>;
    getComponent<T = any>(Component: ComponentTypeAndString<T>, isShowError?: boolean): ComponentType<T> | undefined;
    renderComponent<T extends {}>(Component: ComponentTypeAndString, props?: T, children?: ReactNode): ReactElement;
    /**
     * @internal use addComponents({ SomeComponent }) instead
     */
    protected addComponent(component: ComponentType, name?: string): void;
    addComponents(components: Record<string, ComponentType>): void;
    addScopes(scopes: Record<string, any>): void;
    getRootComponent(): React.FC<{
        children?: React.ReactNode;
    }>;
    mount(containerOrSelector: Element | ShadowRoot | string): import("react-dom/client").Root;
    addFieldInterfaces(fieldInterfaceClasses?: CollectionFieldInterfaceFactory[]): void;
    addFieldInterfaceComponentOption(fieldName: string, componentOption: CollectionFieldInterfaceComponentOption): void;
    /**
     * 为指定的字段接口添加操作符选项
     *
     * @param name 字段接口的名称
     * @param operatorOption 要添加的操作符选项
     *
     * @example
     * // 为"单行文本"类型字段添加"等于任意一个"操作符
     * app.addFieldInterfaceOperator('input', {
     *   label: '{{t("equals any of")}}',
     *   value: '$in',
     * });
     */
    addFieldInterfaceOperator(name: string, operatorOption: any): void;
    addGlobalVar(key: string, value: any, varCtx?: any): void;
    getGlobalVar(key: any): any;
    getGlobalVarCtx(key: any): any;
    addUserCenterSettingsItem(item: SchemaSettingsItemType & {
        aclSnippet?: string;
    }): void;
    /**
     * Register a variable for use in the frontend
     *
     * Note: It is not recommended to register variables in components as it may cause rendering errors
     * @param variable
     * @returns
     */
    registerVariable(variable: Variable): void;
    /**
     * Get all registered variables
     * @returns
     */
    getVariables(): Variable[];
    setAppsComponent({ Component }: {
        Component: ComponentType;
    }): void;
}
export {};
