import AddIcon from '../../../../../../node_modules/@mui/icons-material/esm/AddRounded.mjs';
import React__default from 'react';
import { ContentSpacingCore } from './ContentSpacing.mjs';
import { useModalState } from './Modal.mjs';

const ADD_NEW_BUTTON_TEXT = 'Add new';
const ListEditorCore = ({ title, description, emptyText, limit, addModalProps, hideAddButton, onAdd, addButtonText, ButtonComponent: Button, EmbeddedTableComponent: EmbeddedTable, ModalComponent: Modal, TypographyComponent: Typography, ...embeddedTableProps })=>{
    if (!addModalProps && !onAdd) {
        throw new Error('Either addModalProps or onAdd prop must be provided');
    }
    addButtonText = addButtonText || ADD_NEW_BUTTON_TEXT;
    const modalState = useModalState(addModalProps?.confirm);
    const { items, readOnly } = embeddedTableProps;
    const onClose = ()=>{
        addModalProps?.close?.();
        modalState.close();
    };
    const addNew = addModalProps ? modalState.open : onAdd;
    return /*#__PURE__*/ React__default.createElement(ContentSpacingCore, null, addModalProps && /*#__PURE__*/ React__default.createElement(Modal, {
        ...addModalProps,
        ...modalState,
        close: onClose
    }, addModalProps.content), (title || description) && /*#__PURE__*/ React__default.createElement("div", null, title && /*#__PURE__*/ React__default.createElement(Typography, {
        variant: "h4"
    }, title), description && /*#__PURE__*/ React__default.createElement(Typography, null, description)), items && items.length > 0 ? /*#__PURE__*/ React__default.createElement(EmbeddedTable, {
        ...embeddedTableProps,
        bottomAction: !hideAddButton && (!limit || items.length < limit) && /*#__PURE__*/ React__default.createElement(Button, {
            compact: true,
            onClick: addNew,
            startIcon: /*#__PURE__*/ React__default.createElement(AddIcon, null),
            variant: "text"
        }, addButtonText)
    }) : emptyText && /*#__PURE__*/ React__default.createElement(Typography, {
        variant: "body2"
    }, emptyText), !hideAddButton && !readOnly && !items.length && /*#__PURE__*/ React__default.createElement(Button, {
        compact: true,
        onClick: addNew,
        startIcon: /*#__PURE__*/ React__default.createElement(AddIcon, null),
        variant: "ghost"
    }, addButtonText));
};

export { ADD_NEW_BUTTON_TEXT, ListEditorCore };
//# sourceMappingURL=ListEditor.mjs.map
