'use client'; import clsx from 'clsx'; import { BadgeHelp, type HelpTopic } from '@/features/help'; import { useEscapeKey } from '@/hooks/useEscapeKey'; import { useDialogsStore } from '@/stores/dialogs'; import { PARAMETER } from '@/utils/constants'; import { prepareTooltip } from '@/utils/utils'; import { Overlay } from '../Container'; import { Button, MiniButton, SubmitButton } from '../Control'; import { IconClose } from '../Icons'; import { type Styling } from '../props'; import { ModalBackdrop } from './ModalBackdrop'; export interface ModalProps extends Styling { /** Title of the modal window. */ header?: string; /** Indicates that the modal window should be scrollable. */ overflowVisible?: boolean; /** Help topic to be displayed in the modal window. */ helpTopic?: HelpTopic; /** Callback to determine if help should be displayed. */ hideHelpWhen?: () => boolean; } interface ModalFormProps extends ModalProps { /** Text of the submit button. */ submitText?: string; /** Tooltip for the submit button when the form is invalid. */ submitInvalidTooltip?: string; /** Indicates that submit button is enabled. */ canSubmit?: boolean; /** Callback to be called before submit. */ beforeSubmit?: () => boolean; /** Callback to be called after submit. */ onSubmit: (event: React.FormEvent) => void; /** Callback to be called when modal is canceled. */ onCancel?: () => void; } /** * Displays a customizable modal window with submit form. */ export function ModalForm({ children, className, header, overflowVisible, canSubmit = true, submitText = 'Продолжить', submitInvalidTooltip, beforeSubmit, onSubmit, onCancel, helpTopic, hideHelpWhen, ...restProps }: React.PropsWithChildren) { const hideDialog = useDialogsStore(state => state.hideDialog); function handleCancel() { onCancel?.(); hideDialog(); } useEscapeKey(handleCancel); function handleSubmit(event: React.FormEvent) { if (beforeSubmit && !beforeSubmit()) { return; } onSubmit(event); hideDialog(); } return (
{helpTopic && !hideHelpWhen?.() ? (
) : null} } className='float-right mt-2 mr-2' onClick={handleCancel} /> {header ?

{header}

: null}
{children}
); }