import { AiConfig } from '../../../types/src/index.ts';
import { BlockDefaults } from '../../types/src/index.ts';
import { BlockDefaults as BlockDefaults_2 } from '../../../types/src/index.ts';
import { CollaborationConfig } from '../../../types/src/index.ts';
import { CommentEvent } from '../../../types/src/index.ts';
import { ComputedRef } from 'vue';
import { CustomBlock } from '../../types/src/index.ts';
import { CustomBlockDefinition } from '../../types/src/index.ts';
import { CustomBlockDefinition as CustomBlockDefinition_2 } from '../../../types/src/index.ts';
import { CustomFont } from '../../types/src/index.ts';
import { CustomFont as CustomFont_2 } from '../../../types/src/index.ts';
import { DisplayConditionsConfig } from '../../types/src/index.ts';
import { DisplayConditionsConfig as DisplayConditionsConfig_2 } from '../../../types/src/index.ts';
import { FontsConfig } from '../../types/src/index.ts';
import { FontsConfig as FontsConfig_2 } from '../../../types/src/index.ts';
import { McpConfig } from '../../../types/src/index.ts';
import { MediaItem } from '../../../media-library/src/index.ts';
import { MediaRequestContext } from '../../media-library/src/index.ts';
import { MediaRequestContext as MediaRequestContext_2 } from '../../../media-library/src/index.ts';
import { MediaResult } from '../../types/src/index.ts';
import { MergeTagsConfig } from '../../types/src/index.ts';
import { MergeTagsConfig as MergeTagsConfig_2 } from '../../../types/src/index.ts';
import { Ref } from 'vue';
import { SaveResult } from '../../types/src/index.ts';
import { SaveResult as SaveResult_2 } from '../../../types/src/index.ts';
import { Template } from '../../types/src/index.ts';
import { Template as Template_2 } from '../../../types/src/index.ts';
import { TemplateContent } from '../../types/src/index.ts';
import { TemplateContent as TemplateContent_2 } from '../../../types/src/index.ts';
import { TemplateDefaults } from '../../types/src/index.ts';
import { TemplateDefaults as TemplateDefaults_2 } from '../../../types/src/index.ts';
import { ThemeOverrides } from '../../types/src/index.ts';
import { ThemeOverrides as ThemeOverrides_2 } from '../../../types/src/index.ts';
import { UiTheme } from '../../types/src/index.ts';
import { UiTheme as UiTheme_2 } from '../../../types/src/index.ts';
import { ViewportSize } from '../../types/src/index.ts';

export { BlockDefaults }

export { CustomBlockDefinition }

export { CustomFont }

export { DisplayConditionsConfig }

export declare interface EditorCapabilities {
    plan?: {
        hasFeature(feature: string): boolean;
    };
    ai?: {
        isFeatureEnabled(feature: string): boolean;
    };
    comments?: {
        getBlockCount(blockId: string): number;
        openForBlock(blockId: string): void;
    };
    savedModules?: {
        openSaveDialog(blockId: string): void;
        openBrowser(): void;
        moduleCount: ComputedRef<number>;
    };
}

export declare interface FontOption {
    value: string;
    label: string;
    isCustom?: boolean;
}

export { FontsConfig }

export declare function init(config: TemplaticalEditorConfig): Promise<TemplaticalEditor>;

export declare function initCloud(config: TemplaticalCloudEditorConfig): Promise<TemplaticalCloudEditor>;

export { MergeTagsConfig }

/** Function type for media browser requests, used by both OSS and Cloud editors. */
export declare type OnRequestMedia = (context?: MediaRequestContext) => Promise<MediaResult | null>;

export { SaveResult }

export { Template }

export { TemplateContent }

export { TemplateDefaults }

/**
 * Cloud editor does not expose `toMjml` or `renderCustomBlock`: the cloud
 * backend performs MJML conversion server-side with additional processing
 * (e.g., signed image URLs, attachment handling) that isn't available client
 * side. Use the cloud `save()` flow to persist content; the backend handles
 * MJML/HTML export from there.
 */
export declare interface TemplaticalCloudEditor extends TemplaticalEditorBase {
    create(content?: TemplateContent): Promise<Template>;
    load(templateId: string): Promise<Template>;
    save(): Promise<SaveResult>;
}

export declare interface TemplaticalCloudEditorConfig {
    container: string | HTMLElement;
    content?: TemplateContent_2;
    auth: {
        url: string;
        baseUrl?: string;
        requestOptions?: {
            method?: "GET" | "POST";
            headers?: Record<string, string>;
            body?: Record<string, unknown>;
            credentials?: RequestCredentials;
        };
    };
    theme?: ThemeOverrides_2;
    uiTheme?: UiTheme_2;
    locale?: string;
    /**
     * Show the "Powered by Templatical" footer. Defaults to `true`.
     * Set to `false` to hide the footer (no attribution required by the license).
     * Cloud white-label plans hide the footer regardless of this setting.
     */
    branding?: boolean;
    ai?: AiConfig | false;
    commenting?: boolean;
    collaboration?: CollaborationConfig;
    mcp?: McpConfig;
    blockDefaults?: BlockDefaults_2;
    templateDefaults?: TemplateDefaults_2;
    modules?: boolean;
    autoSave?: boolean;
    autoSaveDebounce?: number;
    mergeTags?: MergeTagsConfig_2;
    displayConditions?: DisplayConditionsConfig_2;
    customBlocks?: CustomBlockDefinition_2[];
    fonts?: FontsConfig_2;
    onChange?: (content: TemplateContent_2) => void;
    onSave?: (result: SaveResult_2) => void;
    onCreate?: (template: Template_2) => void;
    onLoad?: (template: Template_2) => void;
    onError?: (error: Error) => void;
    onComment?: (event: CommentEvent) => void;
    onUnmount?: () => void;
    onRequestMedia?: (context: MediaRequestContext_2) => Promise<MediaItem | null>;
    onBeforeTestEmail?: (html: string) => string | Promise<string>;
}

export declare interface TemplaticalEditor extends TemplaticalEditorBase {
    /**
     * Render the current template to an MJML string. Resolves custom blocks
     * via the editor's internal block registry. Throws if the optional
     * `@templatical/renderer` package is not installed.
     */
    toMjml(): Promise<string>;
    /**
     * Render a single custom block to its HTML representation, using the
     * registered custom block definition's template and the block's current
     * field values. Exposed for headless callers that want to reuse the
     * editor's renderer (e.g., to drive `@templatical/renderer`'s
     * `renderCustomBlock` option from outside the editor instance).
     */
    renderCustomBlock(block: CustomBlock): Promise<string>;
}

declare interface TemplaticalEditorBase {
    getContent(): TemplateContent;
    setContent(content: TemplateContent): void;
    setTheme(theme: UiTheme): void;
    unmount(): void;
}

export declare interface TemplaticalEditorConfig {
    container: string | HTMLElement;
    content?: TemplateContent;
    onChange?: (content: TemplateContent) => void;
    onSave?: (content: TemplateContent) => void;
    onError?: (error: Error) => void;
    onRequestMedia?: OnRequestMedia;
    mergeTags?: MergeTagsConfig;
    displayConditions?: DisplayConditionsConfig;
    customBlocks?: CustomBlockDefinition[];
    fonts?: FontsConfig;
    blockDefaults?: BlockDefaults;
    templateDefaults?: TemplateDefaults;
    theme?: ThemeOverrides;
    uiTheme?: UiTheme;
    locale?: string;
    /**
     * Show the "Powered by Templatical" footer. Defaults to `true`.
     * Set to `false` to hide the footer (no attribution required by the license).
     */
    branding?: boolean;
}

export { ThemeOverrides }

export { UiTheme }

export declare function unmount(): void;

export declare function useFonts(config?: FontsConfig_2): UseFontsReturn;

export declare interface UseFontsReturn {
    fonts: ComputedRef<FontOption[]>;
    defaultFont: ComputedRef<string>;
    defaultFallback: ComputedRef<string>;
    customFonts: Ref<CustomFont_2[]>;
    customFontsEnabled: Ref<boolean>;
    isLoaded: Ref<boolean>;
    setCustomFontsEnabled: (enabled: boolean) => void;
    loadCustomFonts: () => Promise<void>;
    cleanupFontLinks: () => void;
    getFontWithFallback: (fontName: string) => string;
    getDefaultFont: () => string;
}

export { ViewportSize }

export { }


declare module "@tiptap/core" {
    interface Commands<ReturnType> {
        letterSpacing: {
            setLetterSpacing: (spacing: string) => ReturnType;
            unsetLetterSpacing: () => ReturnType;
        };
    }
}


declare module "@tiptap/core" {
    interface Commands<ReturnType> {
        lineHeight: {
            setLineHeight: (lineHeight: string) => ReturnType;
            unsetLineHeight: () => ReturnType;
        };
    }
}


declare module "@tiptap/core" {
    interface Commands<ReturnType> {
        mergeTagNode: {
            insertMergeTag: (attrs: MergeTag) => ReturnType;
        };
    }
}


declare module "@tiptap/core" {
    interface Commands<ReturnType> {
        fontSize: {
            setFontSize: (size: string) => ReturnType;
            unsetFontSize: () => ReturnType;
        };
    }
}
