/**
 * 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: PropTypes.node,
	className: PropTypes.string,
	description: PropTypes.node.isRequired,
	disableSubmit: PropTypes.bool,
	onRequestClose: PropTypes.func,
	onRequestSubmit: PropTypes.func,
	open: PropTypes.bool,
	portalTarget: PropTypes.node,
	primaryButtonText: PropTypes.string.isRequired,
	secondaryButtonText: PropTypes.string.isRequired,
	selectorPrimaryFocus: PropTypes.string.isRequired,
	subtitle: PropTypes.node,
	title: PropTypes.node.isRequired
};
CreateModal.displayName = componentName;

//#endregion
export { CreateModal };