import React, { Suspense, lazy, useEffect, useMemo, useState, } from 'react';
import { useWixPatternsContainer } from '@wix/bex-core/react';
import { FieldActionsState } from '../../state/FieldActionsState';
const SidePanelFieldActionsRow = lazy(() => import(
/* webpackChunkName: "SidePanelFieldActions" */ './SidePanelFieldActionsRow').then((m) => ({
    default: m.SidePanelFieldActionsRow,
})));
const SidePanelFieldActionsModal = lazy(() => import(
/* webpackChunkName: "SidePanelFieldActions" */ './SidePanelFieldActionsModal'));
export function useSidePanelFieldActions(columns, fieldActions, refresh, permissions) {
    const { translate, showToast } = useWixPatternsContainer();
    const [fieldActionsState] = useState(() => new FieldActionsState(translate, fieldActions, permissions, showToast, refresh));
    useEffect(() => {
        fieldActionsState.setHandlers(fieldActions);
    }, [fieldActionsState, fieldActions]);
    useEffect(() => {
        fieldActionsState.setPermissions(permissions);
    }, [fieldActionsState, permissions]);
    useEffect(() => {
        fieldActionsState.setRefresh(refresh);
    }, [fieldActionsState, refresh]);
    const fieldActionsByColumn = useMemo(() => {
        const result = {};
        for (const col of columns) {
            result[col.id] = (React.createElement(Suspense, { fallback: null },
                React.createElement(SidePanelFieldActionsRow, { column: col, state: fieldActionsState })));
        }
        return result;
    }, [columns, fieldActionsState]);
    const fieldActionsModal = (React.createElement(Suspense, { fallback: null },
        React.createElement(SidePanelFieldActionsModal, { state: fieldActionsState })));
    return { fieldActionsByColumn, fieldActionsModal };
}
//# sourceMappingURL=useSidePanelFieldActions.js.map