import * as i0 from '@angular/core';
import { InjectionToken, TemplateRef, ElementRef, EventEmitter, Signal, AfterViewInit, OnDestroy, DestroyRef, WritableSignal, ModuleWithProviders } from '@angular/core';
import { ValidationErrors, NgForm, FormGroupDirective, NgControl } from '@angular/forms';
import { PlatformFormFieldControl } from '@fundamental-ngx/platform/shared';
import { Subject } from 'rxjs';
import { FormStates } from '@fundamental-ngx/cdk/forms';
import { ObjectStatus } from '@fundamental-ngx/core/object-status';
import { Nullable, TabbableElementService } from '@fundamental-ngx/cdk/utils';
import { PopoverComponent } from '@fundamental-ngx/core/popover';

interface MessagePopoverErrorConfig {
    heading: string;
    description?: string;
    type: FormStates;
}
interface MessagePopoverConfig {
    /**
     * Errors object where key is error type and value is i18n string.
     */
    errors: Record<string, string | MessagePopoverErrorConfig>;
}
declare const FDP_MESSAGE_POPOVER_DEFAULT_CONFIG: MessagePopoverConfig;
declare const FDP_MESSAGE_POPOVER_CONFIG: InjectionToken<MessagePopoverConfig>;

interface MessagePopoverEntry {
    heading: MessagePopoverErrorText;
    type: FormStates;
    state: ObjectStatus;
    group?: string;
    description: MessagePopoverErrorText;
    name: string;
    fieldName: string;
    errors: ValidationErrors | null;
    element?: ElementRef;
    formField?: PlatformFormFieldControl;
}
interface MessagePopoverError {
    group: FormStates | 'all';
    state: ObjectStatus;
    count: number;
}
interface MessagePopoverErrorText {
    message?: TemplateRef<any> | string | null;
    type: 'templateRef' | 'directive' | 'string';
    error?: any;
}
interface MessagePopoverErrorGroup {
    group?: string;
    errors: MessagePopoverEntry[];
}

type MessagePopoverState = Omit<ObjectStatus, 'informative' | 'neutral' | 'positive'> | 'information' | 'success' | 'neutral';
interface MessagePopover {
    focusItem: EventEmitter<MessagePopoverEntry>;
}

interface MessagePopoverWrapper {
    formFields: PlatformFormFieldControl[];
    errors$: Signal<MessagePopoverErrorGroup[]>;
    setMessagePopover: (messagePopover: MessagePopover) => void;
}

type MessagePopoverForm = NgForm | FormGroupDirective;
declare class MessagePopoverFormWrapperComponent implements MessagePopoverWrapper, AfterViewInit, OnDestroy {
    private readonly _destroyRef;
    private readonly _config;
    /** @hidden */
    private readonly _projectedForm;
    /** @hidden */
    private readonly _projectedFormFieldControls;
    /** @hidden */
    private readonly _directiveItems;
    /** Message Popover instance. */
    messagePopover$: Subject<MessagePopover>;
    /**
     * User-passed forms.
     */
    set forms(forms: MessagePopoverForm | MessagePopoverForm[]);
    /** User-passed form fields. */
    set formFields(value: PlatformFormFieldControl[]);
    get formFields(): PlatformFormFieldControl[];
    /**
     * Error models Signal. Emitted when form submitted and contains invalid fields.
     */
    readonly errors$: i0.WritableSignal<MessagePopoverErrorGroup[]>;
    /** @hidden */
    private _formFields;
    /** @hidden */
    private _formErrorsSubscription;
    /** @hidden */
    private _ngForms;
    /** @hidden */
    private _formItemErrorsSubscription;
    /** @hidden */
    private _formSubmitted;
    /** @hidden */
    constructor(_destroyRef: DestroyRef, _config: MessagePopoverConfig);
    /** @hidden */
    ngAfterViewInit(): void;
    /**
     * Sets Message Popover component instance.
     */
    setMessagePopover(messagePopover: MessagePopover): void;
    /**
     * Programmatically add new form to array of forms.
     * @param forms
     */
    addForms(forms: MessagePopoverForm | MessagePopoverForm[]): void;
    /**
     * Programmatically add new form fields to array of listened form fields.
     * @param formFields
     */
    addFormFields(formFields: PlatformFormFieldControl[]): void;
    /** @hidden */
    ngOnDestroy(): void;
    /**
     * @hidden
     * Listens to the form submission and collects form control errors.
     */
    private _startListeningForErrors;
    /** @hidden */
    private _listenToFormFieldErrors;
    /** @hidden */
    private _collectPlainFormData;
    /** @hidden */
    private _collectAdvancedFormData;
    /**
     * @hidden
     * Creates error model
     */
    private _getErrorModel;
    /**
     * @hidden
     * Creates error text based on the type of the error.
     * @param field Form Field Control.
     * @param errorDirective Optional Error directive
     * @param section Section where text should be rendered.
     * @param errorKey
     * @param error
     */
    private _getErrorText;
    /** @hidden */
    private _getGroupName;
    /** @hidden */
    private _getConfigErrorModel;
    /** @hidden */
    private _isAdvancedError;
    static ɵfac: i0.ɵɵFactoryDeclaration<MessagePopoverFormWrapperComponent, never>;
    static ɵcmp: i0.ɵɵComponentDeclaration<MessagePopoverFormWrapperComponent, "fdp-message-popover-form-wrapper", ["messagePopoverWrapper"], { "forms": { "alias": "forms"; "required": false; }; "formFields": { "alias": "formFields"; "required": false; }; }, {}, ["_projectedForm", "_projectedFormFieldControls", "_directiveItems"], ["*"], true, never>;
}

declare class MessageViewComponent implements AfterViewInit {
    private readonly _destroyRef;
    private readonly _tabbableService;
    private readonly _document;
    /** Current Message Popover screen. Can be either `list` or `details`. */
    currentScreen: 'list' | 'details';
    /** Filtered errors to render. */
    filteredErrors: MessagePopoverErrorGroup[];
    /** Current error entry. Used for details view. */
    currentEntry: Nullable<MessagePopoverEntry>;
    /** Event emitted when user clicks on error entry containing additional description. */
    openDetails: EventEmitter<MessagePopoverEntry>;
    /** Event emitted when user clicks on error entry and item's element should be focused. */
    focusItem: EventEmitter<MessagePopoverEntry>;
    /** Event emitted when user clicks on the field link to focus on the field itself. */
    closePopover: EventEmitter<boolean>;
    /** @hidden */
    protected _listView: ElementRef;
    /** @hidden */
    protected _detailsView: ElementRef;
    /** @Hidden */
    protected readonly _initialClass = "fd-message-popover__view-container";
    /** @hidden */
    private _activeListElement;
    /** @hidden */
    constructor(_destroyRef: DestroyRef, _tabbableService: TabbableElementService, _document: Document);
    /** @hidden */
    ngAfterViewInit(): void;
    /** @hidden */
    _showDetails(entry: MessagePopoverEntry): void;
    /** @hidden */
    _focusElement(event?: MouseEvent, item?: MessagePopoverEntry): void;
    /** @hidden */
    _onListAnimationComplete(event: any): void;
    static ɵfac: i0.ɵɵFactoryDeclaration<MessageViewComponent, never>;
    static ɵcmp: i0.ɵɵComponentDeclaration<MessageViewComponent, "fdp-message-view", never, { "currentScreen": { "alias": "currentScreen"; "required": false; }; "filteredErrors": { "alias": "filteredErrors"; "required": false; }; "currentEntry": { "alias": "currentEntry"; "required": false; }; }, { "openDetails": "openDetails"; "focusItem": "focusItem"; "closePopover": "closePopover"; }, never, never, true, never>;
}

declare class MessagePopoverFormItemDirective {
    readonly elementRef: ElementRef;
    readonly control: NgControl;
    /** Form item name. */
    label: string;
    /** Error type definition. */
    errorTypes: MessagePopoverConfig['errors'];
    /** @hidden */
    constructor(elementRef: ElementRef, control: NgControl);
    static ɵfac: i0.ɵɵFactoryDeclaration<MessagePopoverFormItemDirective, [null, { optional: true; }]>;
    static ɵdir: i0.ɵɵDirectiveDeclaration<MessagePopoverFormItemDirective, "[fdpMessagePopoverFormItem]", never, { "label": { "alias": "fdpMessagePopoverFormItem"; "required": false; }; "errorTypes": { "alias": "errorTypes"; "required": false; }; }, {}, never, never, true, never>;
}

declare class MessagePopoverComponent implements MessagePopover {
    /** @hidden */
    readonly _popover: PopoverComponent;
    /** Message Popover Wrapper component. */
    set wrapper(value: Nullable<MessagePopoverWrapper>);
    get wrapper(): Nullable<MessagePopoverWrapper>;
    /** Event emits when user clicks on error entry and item's element needs to be focused. */
    focusItem: EventEmitter<MessagePopoverEntry>;
    /** Current message popover screen. Can be `list` or `details`. */
    currentScreen: 'list' | 'details';
    /** Current error entry. */
    currentEntry: Nullable<MessagePopoverEntry>;
    /** @hidden */
    _currentErrorType$: WritableSignal<MessagePopoverError['group']>;
    /** @hidden */
    _errorTypes$: i0.Signal<MessagePopoverError[]>;
    /** @hidden */
    _priorityStateItemsCount$: i0.Signal<number>;
    /** @hidden */
    _priorityFormState$: i0.Signal<"success" | "error" | "warning" | "default" | "information">;
    /** @hidden */
    _priorityState$: i0.Signal<Nullable<MessagePopoverState>>;
    /** @hidden */
    readonly _filteredErrors$: i0.Signal<MessagePopoverErrorGroup[]>;
    private readonly _groupedErrors$;
    private readonly _wrapper$;
    private readonly _countedErrors$;
    /** @hidden */
    _showList(): void;
    /** @hidden */
    _showDetails(entry: MessagePopoverEntry): void;
    /** @hidden */
    _closePopover(focusLast?: boolean): void;
    static ɵfac: i0.ɵɵFactoryDeclaration<MessagePopoverComponent, never>;
    static ɵcmp: i0.ɵɵComponentDeclaration<MessagePopoverComponent, "fdp-message-popover", never, { "wrapper": { "alias": "wrapper"; "required": false; }; }, { "focusItem": "focusItem"; }, never, never, true, never>;
}

/**
 * @deprecated
 * Use direct imports of components and directives.
 */
declare class PlatformMessagePopoverModule {
    /**
     * Method allows users to apply custom configuration.
     * @param config Object containing error definitions.
     */
    static withConfig(config: MessagePopoverConfig): ModuleWithProviders<PlatformMessagePopoverModule>;
    static ɵfac: i0.ɵɵFactoryDeclaration<PlatformMessagePopoverModule, never>;
    static ɵmod: i0.ɵɵNgModuleDeclaration<PlatformMessagePopoverModule, never, [typeof MessagePopoverComponent, typeof MessagePopoverFormWrapperComponent, typeof MessageViewComponent, typeof MessagePopoverFormItemDirective], [typeof MessagePopoverComponent, typeof MessagePopoverFormWrapperComponent, typeof MessageViewComponent, typeof MessagePopoverFormItemDirective]>;
    static ɵinj: i0.ɵɵInjectorDeclaration<PlatformMessagePopoverModule>;
}

/**
 * Converts Object Status into Message Popover State
 * @param status Object status
 * @returns Message Popover State.
 */
declare function convertFormStateToMessagePopoverState(state: FormStates): MessagePopoverState;
/**
 * Converts Form State into Object status type.
 * @param type Form state.
 * @returns `ObjectStatus` type.
 */
declare function convertFormState(type: FormStates): ObjectStatus;

export { FDP_MESSAGE_POPOVER_CONFIG, FDP_MESSAGE_POPOVER_DEFAULT_CONFIG, MessagePopoverComponent, MessagePopoverFormItemDirective, MessagePopoverFormWrapperComponent, MessageViewComponent, PlatformMessagePopoverModule, convertFormState, convertFormStateToMessagePopoverState };
export type { MessagePopover, MessagePopoverConfig, MessagePopoverEntry, MessagePopoverError, MessagePopoverErrorConfig, MessagePopoverErrorGroup, MessagePopoverErrorText, MessagePopoverForm, MessagePopoverState, MessagePopoverWrapper };
