'use client'; import clsx from 'clsx'; import { BadgeHelp, 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 { Button, MiniButton, SubmitButton } from '../Control'; import { IconClose } from '../Icons'; import { CProps } from '../props'; import { ModalBackdrop } from './ModalBackdrop'; export interface ModalProps extends CProps.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; } /** * Displays a customizable modal window with submit form. */ export function ModalForm({ children, className, header, overflowVisible, canSubmit = true, submitText = 'Продолжить', submitInvalidTooltip, beforeSubmit, onSubmit, helpTopic, hideHelpWhen, ...restProps }: React.PropsWithChildren) { const hideDialog = useDialogsStore(state => state.hideDialog); useEscapeKey(hideDialog); function handleSubmit(event: React.FormEvent) { if (beforeSubmit && !beforeSubmit()) { return; } onSubmit(event); hideDialog(); } return (
{helpTopic && !hideHelpWhen?.() ? (
) : null} } className='float-right mt-2 mr-2' onClick={hideDialog} /> {header ?

{header}

: null}
{children}
); }