import { GetLabelType, NetworkProps } from '@m4l/core';
import { ReactNode } from 'react';
import { CookieType, EmmitNewModalProps, AreaPanelSizeUpdate, EmmitNewPopupProps, EmmitNewWindowProps, AreaWindowProps, EmmitNewLayoutProps, EmmitNewPanelProps, WindowQueryCloseHandler, WindowQueryCloseRequest } from '../../types';
import { DebouncedFunc } from 'lodash';
import { LayoutItem } from '../../../GridLayout';
import { ContainerChangeEvent } from '../../../GridLayout/subcomponents/Responsive/types';
import { Layout, Breakpoint, Layouts } from '../../../GridLayout/types';
import { PopupsProviderStoreStateWithActions } from '../../../popups/components/PopupsProvider/contexts/PopupsContext/types';
import { ModuleAction, WinType } from '../../../WindowBase/types';
export type WinLayoutItem = LayoutItem & {
    winType: WinType;
};
export type Breakpoints = {
    [P: string]: number;
};
export type Cols = {
    [P: string]: number;
};
export type ViewAreaMode = 'multiple' | 'single';
export type AreaStatus = 'init' | 'loading' | 'load' | 'loaded' | 'error';
export interface Area {
    /**
     * Logical identifier for the work area.
     */
    id: string;
    /**
     * Display name shown for the work area.
     */
    name: string;
    /**
     * Current loading status for the work area.
     */
    status: AreaStatus;
    /**
     * Legacy popup z-index marker kept for compatibility.
     * @deprecated Popup stacking is now owned by PopupsProvider.
     */
    zPopUpIndex: number;
    /**
     * Whether this area should load its windows.
     * Newly created areas start without windows, but existing areas can lazily
     * load their windows the first time they are opened.
     */
    loadWindows: boolean;
    /**
     * Height of the rendered area container.
     * This state lives per area because resize events only arrive while the area
     * is visible, and new windows depend on this value to compute their size.
     */
    containerHeight?: number;
    /**
     * Current responsive breakpoint for the work area.
     */
    currentBreakpoint?: Breakpoint;
    /**
     * Grid layouts stored for the work area.
     */
    layouts: Layouts;
    /**
     * Identifier of the maximized window, if the area currently has one.
     */
    maximizedId?: string | undefined;
    /**
     * Window ids in insertion order for this area.
     */
    layoutItemsIds: string[];
    /**
     * Panel window ids in insertion order for this area.
     * The first panel iteration keeps one logical panel per side.
     */
    panelItemsIds: string[];
    /**
     * Identifier of the currently selected layout window.
     */
    currentLayoutId: string;
    /**
     * Responsive breakpoint widths for the work area.
     */
    breakpoints: Breakpoints;
    /**
     * Number of grid columns available per breakpoint.
     */
    cols: Cols;
}
/**
 * Loading state for the Areas workspace.
 */
export type AreasStatus = 'init' | 'loading' | 'loaded' | 'error';
export type OwnerState = {
    /**
     * Current lifecycle status for the Areas provider.
     */
    status: AreasStatus;
    /**
     * Whether the provider has finished its mount-time effect and subscribed to
     * the event emitter. This is commonly relevant in isolation and Storybook.
     */
    readyForHooks: boolean;
};
/**
 * State owned outside the store and synchronized through React hooks.
 */
export type ExternalOwnerState = Pick<OwnerState, 'readyForHooks'>;
/**
 * Store state contract for the Areas runtime.
 */
export interface AreasStoreState {
    /**
     * Optional identifier used to distinguish this store instance.
     */
    storeId?: string;
    /**
     * Whether areas should be loaded from and persisted to the API.
     */
    loadAreasFromNetwork: boolean;
    /**
     * Whether window cookies should be loaded from and persisted to the API.
     */
    loadCookiesFromNetwork: boolean;
    /**
     * Identifier of the currently selected work area.
     */
    currentAreaId: string;
    /**
     * Identifier of the currently selected module.
     */
    currentModuleId: string;
    /**
     * Owner state consumed by the view layer and styling hooks.
     */
    ownerState: OwnerState;
    /**
     * Modal window ids in insertion order.
     */
    windowsModalsIds: string[];
    /**
     * Work-area ids in the order exposed by AreasAdmin.
     */
    areasIds: string[];
    /**
     * Normalized area registry.
     */
    hashAreas: Record<string, Area>;
    /**
     * Normalized logical window registry for layouts, popups, and modals.
     */
    hashWindows: Record<string, AreaWindowProps>;
    /**
     * Network implementation used by the store for API calls.
     */
    networkOperation: (props: NetworkProps) => Promise<any>;
    /**
     * Dictionary label resolver used by store-side workflows such as area creation.
     */
    getLabel: GetLabelType;
    /**
     * Zustand cannot read React-context methods directly, so popup shell methods
     * must be injected when the Areas store is created.
     */
    popupsProviderMethods: {
        addPopup: PopupsProviderStoreStateWithActions['popupsActions']['addPopup'];
        removePopup: PopupsProviderStoreStateWithActions['popupsActions']['removePopup'];
        removePopupsByGroupId: PopupsProviderStoreStateWithActions['popupsActions']['closePopupsByGroupId'];
        bringPopupOnFront: PopupsProviderStoreStateWithActions['popupsActions']['bringPopupOnFront'];
        closeAllPopupsByParentId: PopupsProviderStoreStateWithActions['popupsActions']['closeAllPopupsByParentId'];
        setSelectedPopupId: PopupsProviderStoreStateWithActions['popupsActions']['setSelectedPopupId'];
    };
}
export interface AreasStoreStateWithActions extends AreasStoreState {
    areasActions: {
        /**
         * Initialize the store by loading work areas.
         * Once the flow finishes it updates `ownerState.status` to `loaded`.
         * In production this is normally asynchronous because it calls the Areas API.
         */
        init: () => void;
        /**
         * Add a work area, select it, and clear `currentModuleId`.
         * When `loadAreasFromNetwork` is enabled, this also triggers the Areas POST endpoint.
         * @returns id of the created work area
         */
        addArea: () => string;
        /**
         * Update the work-area name and optionally synchronize the change with the API.
         */
        editArea: (idArea: string, newName: string) => void;
        /**
         * Select the target area and align `currentModuleId` with the selected layout in that area.
         * This keeps the module switch visible in the menu and can lazily load windows the
         * first time the area is selected when `loadAreasFromNetwork` is enabled.
         * @param newAreaId area id to select
         */
        selectArea: (newAreaId: string) => void;
        /**
         * Delete a work area and optionally propagate the removal to the API.
         * @param areaId area id to delete
         */
        deleteArea: (areaId: string) => void;
        /**
         * Refresh the `getLabel` handler stored in Zustand.
         * The callback identity can change after the module dictionary finishes loading,
         * so the store keeps the latest resolver explicitly.
         * @param newHandler dictionary label resolver
         */
        setHandlerGetLabel: (newHandler: GetLabelType) => void;
        /**
         * Update the externally synchronized owner state.
         */
        setExternalState: (newExternalState: Partial<ExternalOwnerState>) => void;
    };
    areaActions: {
        /**
         * Add a new window and route it to the correct emergence flow: layout, popup, or modal.
         */
        addWindow: (newWindow: EmmitNewWindowProps) => void;
        /**
         * Add a layout window to the Area grid.
         */
        addLayout: (areaId: string, windowId: string, newWindow: EmmitNewLayoutProps) => void;
        /**
         * Close a layout window and remove it from the Area grid.
         */
        closeLayout: (areaId: string, removePopUpId: string) => void;
        /**
         * Mark a layout as the currently selected one.
         */
        selectLayout: (areaId: string, layoutId: string, saveCookie?: boolean) => void;
        /**
         * Collapse a layout so only its header remains visible.
         */
        colapseLayoutItem: (areaId: string, layoutId: string) => void;
        /**
         * Expand a previously collapsed layout back to its full size.
         */
        unColapseLayoutItem: (areaId: string, layoutId: string) => void;
        /**
         * Return layouts to their normal state and clear the maximized selection.
         * TODO: Revisit how this should coordinate with popups.
         */
        normalizeLayouts: (areaId: string) => void;
        /**
         * Maximize a layout and update the area's `maximizedId`.
         */
        maximizeLayout: (areaId: string, layoutId?: string) => void;
        /**
         * Persist the current layouts to the API.
         */
        saveLayouts: (areaId: string) => void;
        /**
         * Update Area grid layouts after a browser resize, as long as no window is maximized.
         */
        onBreakpointsLayoutsChange: (areaId: string, currentLayout: Layout, newAllLayouts: Layouts) => void;
        /**
         * Register a popup in the Areas logical registry and delegate the visible shell to PopupsProvider.
         */
        addPopup: (areaId: string, windowId: string, newWindowProps: EmmitNewPopupProps) => void;
        /**
         * Register a panel in the Areas logical registry.
         * Panels render inside the area flow and do not use PopupsProvider.
         */
        addPanel: (areaId: string, windowId: string, newWindowProps: EmmitNewPanelProps) => void;
        /**
         * Remove a panel from the Areas logical registry.
         */
        closePanel: (areaId: string, removePanelId: string) => void;
        /**
         * Toggle whether a panel stays docked in the area flow.
         */
        setPanelPinned: (areaId: string, panelId: string, pinned: boolean) => void;
        /**
         * Persist the current panel size in the axis owned by its emergence side.
         */
        setPanelSize: (areaId: string, panelId: string, nextPanelSize: AreaPanelSizeUpdate) => void;
        /**
         * Remove the popup from the Areas logical registry after the popup-provider teardown path runs.
         * TODO: Revisit this seam if a future popup path can bypass the provider callback.
         */
        closePopup: (areaId: string, removePopupId: string) => void;
        /**
         * Register a modal in `hashWindows` and `windowsModalsIds`.
         */
        addWindowModal: (areaId: string, windowId: string, newWindowModalProps: EmmitNewModalProps) => void;
        /**
         * Remove a modal from both `hashWindows` and `windowsModalsIds`.
         */
        closeWindowModal: (removeModalId: string) => void;
        /**
         * Update area container state after the browser viewport changes size.
         */
        onContainerChange: (areaId: string, e: ContainerChangeEvent) => void;
        /**
         * Debounced wrapper that persists layouts to the API.
         */
        bouncedSaveBreakpointsLayouts: DebouncedFunc<(areaId: string) => void>;
        /**
         * Load windows from the API the first time an area is selected.
         */
        loadWindowsFromApi: (areaId: string) => void;
    };
    windowActions: {
        setActions: (windowId: string, newActions: ModuleAction[], version?: string, buildTime?: string) => void;
        getCookie: (windowId: string, id: string) => Record<string, any> | undefined;
        getCookies: (windowId: string, type: CookieType) => Record<string, any>;
        setCookie: (windowId: string, id: string, type: CookieType, cookie: Record<string, any>) => void;
        close: (windowId: string, useFnQueryClose?: boolean, queryCloseRequest?: WindowQueryCloseRequest) => void;
        startProgress: (windowId: string) => void;
        stopProgress: (windowId: string) => void;
        loadCookiesFromApi: (windowId: string) => void;
        saveModuleCookies: (windowId: string) => void;
        resetModuleCookies: (windowId: string) => void;
        setFnQueryClose: (windowId: string, fnQueryClose: WindowQueryCloseHandler) => void;
        setWindowTitle: (windowId: string, title: string) => void;
        setWindowSubTitle: (windowId: string, subTitle: string) => void;
        setWindowEditionInfo: (windowId: string, editionInfo: string) => void;
    };
}
export type DefaultAreasStoreProps = Omit<AreasStoreState, 'currentArea'>;
export type InitialAreasStoreProps = Pick<AreasStoreState, 'networkOperation' | 'loadAreasFromNetwork' | 'loadCookiesFromNetwork' | 'getLabel' | 'ownerState' | 'popupsProviderMethods' | 'storeId'> & Partial<DefaultAreasStoreProps>;
export interface AreasProviderProps {
    /**
     * Optional identifier for the store instance.
     */
    storeId?: string;
    /**
     * Whether store devtools should be enabled for this provider instance.
     */
    storeDevtoolsEnabled?: boolean;
    children: ReactNode;
    loadAreasFromNetwork: boolean;
    loadCookiesFromNetwork: boolean;
    onSelectLayout?: (moduleId: string) => void;
    /**
     * Notify when area data finished loading.
     */
    onLoad?: () => void;
    /**
     * Notify when the provider is ready to receive host open-window events.
     */
    onReady?: () => void;
}
//# sourceMappingURL=types.d.ts.map