/** @license MIT | @cube-dev/ui-kit v0.0.0-canary-f1f3d22 | Cube Dev Team */
import { _Title } from "../../content/Title.js";
import { ButtonGroup } from "../../actions/ButtonGroup/ButtonGroup.js";
import { Button } from "../../actions/index.js";
import { useDialogContext } from "./context.js";
import { Content } from "../../content/Content.js";
import { Header } from "../../content/Header.js";
import { useForm } from "../../form/Form/use-form.js";
import { _SubmitButton } from "../../form/Form/SubmitButton/SubmitButton.js";
import { Form } from "../../form/Form/index.js";
import { Dialog } from "./Dialog.js";
import { jsx, jsxs } from "react/jsx-runtime";

//#region src/components/overlays/Dialog/DialogForm.tsx
/**
* DialogForms are a specific type of Dialog. They contain forms to fill.
*/
function DialogForm(props) {
	let { qa, name, form, defaultValues, onDismiss, onSubmit, onSubmitFailed, onValuesChange, labelStyles, labelPosition, requiredMark, necessityIndicator, necessityLabel, isReadOnly, validationState, validateTrigger, children, danger, noActions, submitProps, cancelProps, preserve, title, size, closeIcon, ...dialogProps } = props;
	[form] = useForm(form);
	const { onClose } = useDialogContext();
	function onLocalDismiss() {
		onClose?.();
		onDismiss?.();
		if (!preserve) setTimeout(() => {
			form?.resetFields();
		}, 250);
	}
	return /* @__PURE__ */ jsxs(Dialog, {
		qa: `${qa || ""}Dialog`,
		size,
		closeIcon,
		...dialogProps,
		children: [/* @__PURE__ */ jsx(Header, { children: /* @__PURE__ */ jsx(_Title, {
			ellipsis: true,
			children: title
		}) }), /* @__PURE__ */ jsx(Content, { children: /* @__PURE__ */ jsxs(Form, {
			qa: qa || "DialogForm",
			form,
			name,
			defaultValues,
			labelStyles,
			labelPosition,
			requiredMark,
			necessityIndicator,
			necessityLabel,
			isReadOnly,
			validationState,
			validateTrigger,
			onSubmit: async (data) => {
				await onSubmit?.(data);
				onClose?.();
				if (!preserve) setTimeout(() => {
					form.resetFields();
				}, 250);
			},
			onSubmitFailed,
			onValuesChange,
			children: [typeof children === "function" ? children(onLocalDismiss) : children, !noActions ? /* @__PURE__ */ jsxs(ButtonGroup, { children: [/* @__PURE__ */ jsx(_SubmitButton, {
				qa: `${qa || ""}SubmitButton`,
				theme: danger ? "danger" : void 0,
				label: "Submit",
				...submitProps || {}
			}), /* @__PURE__ */ jsx(Button, {
				qa: `${qa || ""}CancelButton`,
				label: "Cancel",
				onPress: onLocalDismiss,
				...cancelProps || {}
			})] }) : void 0]
		}) })]
	});
}

//#endregion
export { DialogForm };
//# sourceMappingURL=DialogForm.js.map