'use client'; import clsx from 'clsx'; import { IconClose } from '@/components/Icons'; import BadgeHelp from '@/components/info/BadgeHelp'; import { CProps } from '@/components/props'; import useEscapeKey from '@/hooks/useEscapeKey'; import { HelpTopic } from '@/models/miscellaneous'; import { useDialogsStore } from '@/stores/dialogs'; import { PARAMETER } from '@/utils/constants'; import { prepareTooltip } from '@/utils/labels'; import Button from './Button'; import MiniButton from './MiniButton'; export interface ModalProps extends CProps.Styling { /** Title of the modal window. */ header?: string; /** Text of the submit button. */ submitText?: string; /** Tooltip for the submit button when the form is invalid. */ submitInvalidTooltip?: string; /** Indicates that form is readonly. */ readonly?: boolean; /** Indicates that submit button is enabled. */ canSubmit?: boolean; /** Indicates that the modal window should be scrollable. */ overflowVisible?: boolean; /** ID of the form to be submitted. */ formID?: string; /** Callback to be called before submit. */ beforeSubmit?: () => boolean; /** Callback to be called after submit. */ onSubmit?: () => boolean; /** Callback to be called after cancel. */ onCancel?: () => void; /** Help topic to be displayed in the modal window. */ helpTopic?: HelpTopic; /** Callback to determine if help should be displayed. */ hideHelpWhen?: () => boolean; } /** * Displays a customizable modal window. */ function Modal({ children, header, submitText = 'Продолжить', submitInvalidTooltip, readonly, canSubmit, overflowVisible, beforeSubmit, formID, onSubmit, onCancel, className, helpTopic, hideHelpWhen, ...restProps }: React.PropsWithChildren) { const hideDialog = useDialogsStore(state => state.hideDialog); useEscapeKey(hideDialog); const handleCancel = () => { hideDialog(); onCancel?.(); }; const handleSubmit = () => { if (beforeSubmit && !beforeSubmit()) { return; } if (onSubmit && !onSubmit()) { return; } if (formID) { const element = document.getElementById(formID) as HTMLFormElement; if (element) { element.requestSubmit(); } } hideDialog(); }; return (
{helpTopic && !hideHelpWhen?.() ? (
) : null} } className='float-right mt-2 mr-2' onClick={handleCancel} /> {header ?

{header}

: null}
{children}
{!readonly ? (
); } export default Modal;