import { useCallback, useState } from 'react';
const INITIAL_POPUP_STATE = {
    open: false,
    messageId: null,
    actionType: null,
    anchorElement: null,
    content: null,
    title: undefined,
    subtitle: undefined,
    actionConfig: null,
};
/**
 * Hook for managing action popup state in MessageList.
 * Handles opening, closing, and dynamic content/title updates for popups
 * triggered by message action buttons.
 *
 * @returns Popup state, open/close handlers, and whether the action popup should render.
 */
export function usePopup() {
    const [popupState, setPopupState] = useState(INITIAL_POPUP_STATE);
    const handleActionPopup = useCallback((message, action, anchorElement) => {
        if (!action.popup) {
            return;
        }
        const context = {
            setContent: (newContent) => {
                setPopupState((prev) => (Object.assign(Object.assign({}, prev), { content: newContent })));
            },
            setTitle: (newTitle) => {
                setPopupState((prev) => (Object.assign(Object.assign({}, prev), { title: newTitle })));
            },
            setSubtitle: (newSubtitle) => {
                setPopupState((prev) => (Object.assign(Object.assign({}, prev), { subtitle: newSubtitle })));
            },
            closePopup: () => {
                setPopupState(INITIAL_POPUP_STATE);
            },
        };
        const content = action.popup.getContent(message, context);
        setPopupState({
            open: true,
            messageId: message.id || null,
            actionType: action.actionType || null,
            anchorElement,
            content,
            title: action.popup.title,
            subtitle: action.popup.subtitle,
            actionConfig: action,
        });
    }, []);
    const handlePopupOpenChange = useCallback((open) => {
        if (!open) {
            setPopupState(INITIAL_POPUP_STATE);
        }
    }, []);
    const showActionPopup = popupState.open && popupState.content !== null && popupState.anchorElement !== null;
    return {
        popupState,
        handleActionPopup,
        handlePopupOpenChange,
        showActionPopup,
    };
}
//# sourceMappingURL=usePopup.js.map
