import React from 'react';
import { observer } from 'mobx-react-lite';
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,
    };
}
function _SidePanelFieldActionsRow({ column, state, }) {
    const { handlers: fieldActions, permissions } = state;
    const handlers = {};
    if (fieldActions?.editField) {
        handlers.editField = (id) => fieldActions.editField(id, {});
    }
    if (fieldActions?.makePrimary) {
        handlers.makePrimary = (id) => state.makePrimary(id);
    }
    if (fieldActions?.duplicateField) {
        handlers.duplicateField = (id) => state.duplicate(id);
    }
    if (fieldActions?.duplicateFieldWithContent) {
        handlers.duplicateFieldWithContent = (id) => state.duplicateWithContent(id);
    }
    if (fieldActions?.deleteField) {
        handlers.delete = (id) => state.confirmDelete(id);
    }
    const groups = buildFieldActionGroups({
        column: toFieldActionColumn(column),
        permissions,
        handlers,
        loading: {
            makePrimary: state.isMakingPrimary,
            duplicateField: state.isDuplicating,
            duplicateFieldWithContent: state.isDuplicatingWithContent,
        },
        groups: SIDE_PANEL_ACTION_GROUPS,
    });
    if (groups.length === 0) {
        return null;
    }
    return (React.createElement(HeaderActionsPopover, { actions: groups, dataHook: `side-panel-field-actions-${column.id}` }));
}
export const SidePanelFieldActionsRow = observer(_SidePanelFieldActionsRow);
//# sourceMappingURL=SidePanelFieldActionsRow.js.map