import React, { useMemo } from 'react';
import { buildFieldActionGroups, HeaderActionsPopover, } from '../FieldActions';
const SIDE_PANEL_ACTION_GROUPS = [
    ['editField'],
    ['makePrimary', 'duplicateField', 'duplicateFieldWithContent'],
    ['delete'],
];
function toFieldActionColumn(col) {
    const isText = col.fieldType === 'SHORT_TEXT' || col.fieldType === 'LONG_TEXT';
    return {
        id: col.id,
        isPrimary: col.isPrimary,
        isSystem: col.isSystem,
        cellType: isText ? 'text' : col.fieldType,
    };
}
export function useSidePanelFieldActions(columns, fieldActions, permissions) {
    return useMemo(() => {
        const handlers = {
            editField: fieldActions?.editField
                ? (id) => fieldActions.editField(id, {})
                : undefined,
            makePrimary: (id) => fieldActions?.makePrimary?.(id),
            duplicateField: fieldActions?.duplicateField,
            duplicateFieldWithContent: fieldActions?.duplicateField,
            delete: fieldActions?.deleteField,
        };
        const result = {};
        for (const col of columns) {
            const groups = buildFieldActionGroups({
                column: toFieldActionColumn(col),
                permissions,
                handlers,
                groups: SIDE_PANEL_ACTION_GROUPS,
            });
            if (groups.length > 0) {
                result[col.id] = (React.createElement(HeaderActionsPopover, { actions: groups, dataHook: `side-panel-field-actions-${col.id}` }));
            }
        }
        return result;
    }, [columns, fieldActions, permissions]);
}
//# sourceMappingURL=useSidePanelFieldActions.js.map