import type { Renderable } from '@tempots/dom';
import type { Controller } from '../../form';
import type { SchemaContext, JSONSchema } from '../schema-context';
import { type ResolvedWidget } from './utils';
/**
 * Widget factory function signature
 */
export type WidgetFactory<T = unknown> = (props: {
    controller: Controller<T>;
    ctx: SchemaContext;
    options?: Record<string, unknown>;
}) => Renderable;
/**
 * Widget registration entry
 */
export interface WidgetRegistration<T = unknown> {
    /** Widget factory function */
    factory: WidgetFactory<T>;
    /** Widget display name */
    displayName: string;
    /** Widget description */
    description?: string;
    /** Supported JSON Schema types */
    supportedTypes?: string[];
    /** Default configuration */
    defaultConfig?: Record<string, unknown>;
    /** Configuration schema for the widget */
    configSchema?: JSONSchema;
    /** Widget priority (higher = preferred when multiple widgets match) */
    priority?: number;
    /** Whether this widget can be used as a fallback */
    canFallback?: boolean;
}
/**
 * Widget customization configuration from x:ui
 */
export interface WidgetCustomization {
    /** Custom widget type override */
    widget?: string;
    /** Widget-specific configuration */
    config?: Record<string, unknown>;
    /** Custom CSS classes */
    className?: string;
    /** Custom styles */
    style?: Record<string, string>;
    /** Custom attributes */
    attributes?: Record<string, string>;
    /** Widget wrapper configuration */
    wrapper?: {
        tag?: string;
        className?: string;
        style?: Record<string, string>;
        attributes?: Record<string, string>;
    };
    /** Conditional widget selection */
    conditional?: {
        condition: string | ((value: unknown, formData: unknown) => boolean);
        then?: WidgetCustomization;
        else?: WidgetCustomization;
    };
}
/**
 * Widget registry for managing custom widgets
 */
export declare class WidgetRegistry {
    private widgets;
    private typeMapping;
    /**
     * Register a custom widget
     */
    register<T = unknown>(name: string, registration: WidgetRegistration<T>): void;
    /**
     * Unregister a widget
     */
    unregister(name: string): void;
    /**
     * Get a registered widget
     */
    get(name: string): WidgetRegistration<unknown> | undefined;
    /**
     * Get all registered widgets
     */
    getAll(): Map<string, WidgetRegistration<unknown>>;
    /**
     * Get widgets that support a specific JSON Schema type
     */
    getForType(type: string): WidgetRegistration<unknown>[];
    /**
     * Find the best widget for a schema context
     */
    findBestWidget(ctx: SchemaContext): {
        name: string;
        registration: WidgetRegistration<unknown>;
        resolved: ResolvedWidget;
    } | null;
}
/**
 * Global widget registry instance
 */
export declare const globalWidgetRegistry: WidgetRegistry;
/**
 * Extract widget customization from schema x:ui
 */
export declare function getWidgetCustomization(schema: JSONSchema): WidgetCustomization | undefined;
/**
 * Apply widget customization to a rendered widget
 */
export declare function applyWidgetCustomization(widget: Renderable, customization: WidgetCustomization, value?: unknown, formData?: unknown): Renderable;
/**
 * Create a customized widget factory
 */
export declare function createCustomizedWidget<T = unknown>(baseFactory: WidgetFactory<T>, customization: WidgetCustomization): WidgetFactory<T>;
/**
 * Register built-in enhanced widgets
 */
export declare function registerEnhancedWidgets(registry?: WidgetRegistry): void;
/**
 * Helper to register a simple widget
 */
export declare function registerWidget<T = unknown>(name: string, factory: WidgetFactory<T>, options?: Partial<WidgetRegistration<T>>, registry?: WidgetRegistry): void;
