/**
 * Copyright IBM Corp. 2020, 2026
 *
 * This source code is licensed under the Apache-2.0 license found in the
 * LICENSE file in the root directory of this source tree.
 */

import { __toESM } from "../../_virtual/_rolldown/runtime.js";
import { require_classnames } from "../../node_modules/classnames/index.js";
import { pkg } from "../../settings.js";
import { getDevtoolsProps } from "../../global/js/utils/devtools.js";
import { usePortalTarget } from "../../global/js/hooks/usePortalTarget.js";
import React from "react";
import PropTypes from "prop-types";
import { Button, ComposedModal, Form, ModalBody, ModalFooter, ModalHeader } from "@carbon/react";
//#region src/components/CreateModal/CreateModal.tsx
/**
* Copyright IBM Corp. 2021, 2025
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
var import_classnames = /* @__PURE__ */ __toESM(require_classnames());
const componentName = "CreateModal";
const blockClass = `${pkg.prefix}--create-modal`;
/**
* The `CreateModal` component provides a way for a user to quickly generate a new
resource. It is triggered by a user’s action, appears on top of the main page
content, and is persistent until dismissed. The purpose of this modal should be
immediately apparent to the user, with a clear and obvious path to completion.
*/
const CreateModal = React.forwardRef((props, ref) => {
	const { className, children, onRequestClose, onRequestSubmit, open, title, subtitle, description, secondaryButtonText, portalTarget: portalTargetIn, primaryButtonText, disableSubmit, selectorPrimaryFocus, ...rest } = props;
	return usePortalTarget(portalTargetIn)(/* @__PURE__ */ React.createElement(ComposedModal, {
		...rest,
		selectorPrimaryFocus,
		className: (0, import_classnames.default)(blockClass, className),
		open,
		ref,
		"aria-label": title,
		size: "sm",
		preventCloseOnClickOutside: true,
		onClose: () => {
			onRequestClose?.();
			return false;
		},
		...getDevtoolsProps(componentName)
	}, /* @__PURE__ */ React.createElement(ModalHeader, {
		title,
		titleClassName: `${blockClass}__title`
	}, subtitle && /* @__PURE__ */ React.createElement("p", { className: `${blockClass}__subtitle` }, subtitle)), /* @__PURE__ */ React.createElement(ModalBody, { hasForm: true }, description && /* @__PURE__ */ React.createElement("p", { className: `${blockClass}__description` }, description), /* @__PURE__ */ React.createElement(Form, {
		className: `${blockClass}__form`,
		"aria-label": title,
		onSubmit: (e) => e.preventDefault()
	}, children)), /* @__PURE__ */ React.createElement(ModalFooter, null, /* @__PURE__ */ React.createElement(Button, {
		type: "button",
		kind: "secondary",
		onClick: onRequestClose
	}, secondaryButtonText), /* @__PURE__ */ React.createElement(Button, {
		type: "submit",
		kind: "primary",
		onClick: onRequestSubmit,
		disabled: disableSubmit
	}, primaryButtonText))));
});
CreateModal.propTypes = {
	/**
	* Children refers to all form items within a form inside of the modal's body.
	*/
	children: PropTypes.node,
	/**
	* Specify an optional className to be applied to the modal root node
	*/
	className: PropTypes.string,
	/**
	* The description of the CreateModal serves to provide more information about the modal.
	*/
	description: PropTypes.node.isRequired,
	/**
	* Specifies a boolean for disabling or enabling the primary button. This is important for form validation
	* Returning `true` prevents the primary button from being clicked until required fields are completed.
	*/
	disableSubmit: PropTypes.bool,
	/**
	* Specifies an optional handler which is called when the CreateModal
	* is closed.
	*/
	onRequestClose: PropTypes.func,
	/**
	* Specifies an optional handler which is called when the CreateModal
	* primary button is pressed.
	*/
	onRequestSubmit: PropTypes.func,
	/**
	* Specifies whether the CreateModal is open or not.
	*/
	open: PropTypes.bool,
	/**
	* The DOM node the tearsheet should be rendered within. Defaults to document.body.
	*/
	portalTarget: PropTypes.node,
	/**
	* Specifies the primary button's text in the modal.
	*/
	primaryButtonText: PropTypes.string.isRequired,
	/**
	* Specifies the secondary button's text in the modal.
	*/
	secondaryButtonText: PropTypes.string.isRequired,
	/**
	* Specifies which DOM element in the form should be focused.
	*/
	selectorPrimaryFocus: PropTypes.string.isRequired,
	/**
	* The subtitle of the CreateModal is optional and serves to provide more information about the modal.
	*/
	subtitle: PropTypes.node,
	/**
	* The title of the CreateModal is usually the product or service name.
	*/
	title: PropTypes.node.isRequired
};
CreateModal.displayName = componentName;
//#endregion
export { CreateModal };
