/**
 * 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.
 */

const require_runtime = require("../../_virtual/_rolldown/runtime.js");
const require_index = require("../../node_modules/classnames/index.js");
const require_settings = require("../../settings.js");
const require_usePreviousValue = require("../../global/js/hooks/usePreviousValue.js");
const require_devtools = require("../../global/js/utils/devtools.js");
const require_usePortalTarget = require("../../global/js/hooks/usePortalTarget.js");
const require_uuidv4 = require("../../global/js/utils/uuidv4.js");
let react = require("react");
react = require_runtime.__toESM(react);
let prop_types = require("prop-types");
prop_types = require_runtime.__toESM(prop_types);
let _carbon_react = require("@carbon/react");
//#region src/components/RemoveModal/RemoveModal.tsx
var import_classnames = /* @__PURE__ */ require_runtime.__toESM(require_index.default);
const componentName = "RemoveModal";
const RemoveModal = (0, react.forwardRef)(({ body, className, iconDescription, inputInvalidText, inputLabelText, inputPlaceholderText, label, onClose, onRequestSubmit, open, portalTarget: portalTargetIn, preventCloseOnClickOutside, primaryButtonDisabled, primaryButtonText, primaryDangerDescription, resourceName, secondaryButtonText, textConfirmation, title, ...rest }, ref) => {
	const previousState = require_usePreviousValue.usePreviousValue({ open });
	const [userInput, setUserInput] = (0, react.useState)("");
	const idRef = (0, react.useRef)(require_uuidv4.default());
	const renderPortalUse = require_usePortalTarget.usePortalTarget(portalTargetIn);
	const onChangeHandler = (e) => {
		setUserInput(e.target.value);
	};
	const checkPrimaryButtonDisabled = () => {
		if (primaryButtonDisabled) return true;
		else if (textConfirmation && userInput !== resourceName) return true;
		return false;
	};
	const primaryButtonStatus = checkPrimaryButtonDisabled();
	const blockClass = `${require_settings.pkg.prefix}--remove-modal`;
	(0, react.useEffect)(() => {
		if (!open && previousState?.open) setUserInput("");
	}, [open, previousState?.open]);
	return renderPortalUse(/* @__PURE__ */ react.default.createElement(_carbon_react.ComposedModal, {
		...rest,
		className: (0, import_classnames.default)(blockClass, className),
		size: "sm",
		"aria-label": title,
		open,
		ref,
		preventCloseOnClickOutside,
		onClose,
		...require_devtools.getDevtoolsProps(componentName)
	}, /* @__PURE__ */ react.default.createElement(_carbon_react.ModalHeader, {
		title,
		label,
		iconDescription
	}), /* @__PURE__ */ react.default.createElement(_carbon_react.ModalBody, null, typeof body === "string" ? /* @__PURE__ */ react.default.createElement("p", { className: `${blockClass}__body` }, body) : body, textConfirmation && /* @__PURE__ */ react.default.createElement(_carbon_react.TextInput, {
		id: `${idRef.current}-confirmation-input`,
		className: `${blockClass}__input`,
		invalidText: inputInvalidText,
		labelText: inputLabelText,
		placeholder: inputPlaceholderText,
		onChange: onChangeHandler,
		value: userInput,
		"data-modal-primary-focus": true
	})), /* @__PURE__ */ react.default.createElement(_carbon_react.ModalFooter, null, /* @__PURE__ */ react.default.createElement(_carbon_react.Button, {
		type: "button",
		kind: "secondary",
		onClick: onClose,
		"data-modal-primary-focus": !textConfirmation
	}, secondaryButtonText), /* @__PURE__ */ react.default.createElement(_carbon_react.Button, {
		type: "submit",
		kind: "danger",
		dangerDescription: primaryDangerDescription,
		onClick: onRequestSubmit,
		disabled: primaryButtonStatus
	}, primaryButtonText))));
});
RemoveModal.propTypes = {
	/**
	* The content to be displayed in the body of the modal
	*/
	body: prop_types.default.node.isRequired,
	/**
	* Optional classname
	*/
	className: prop_types.default.string,
	/**
	* Provide a description for "close" icon that can be read by screen readers
	*/
	iconDescription: prop_types.default.string.isRequired,
	/**
	* Message showed when user input fails validation
	*/
	inputInvalidText: prop_types.default.string,
	/**
	* Label for text box
	*/
	inputLabelText: prop_types.default.node,
	/**
	* Placeholder for text box
	*/
	inputPlaceholderText: prop_types.default.string,
	/**
	* Specify the modal label texts
	*/
	label: prop_types.default.string,
	/**
	* Callback function that runs when user closes the modal
	*/
	onClose: prop_types.default.func,
	/**
	* Callback function that runs when user submits the modal
	*/
	onRequestSubmit: prop_types.default.func,
	/**
	* Specify whether the Modal is currently open
	*/
	open: prop_types.default.bool.isRequired,
	/**
	* The DOM node the tearsheet should be rendered within. Defaults to document.body.
	*/
	portalTarget: prop_types.default.node,
	/**
	* Prevent closing on click outside of modal
	*/
	preventCloseOnClickOutside: prop_types.default.bool,
	/**
	* Specify whether the primary button should be disabled. This value will override textConfirmation
	*/
	primaryButtonDisabled: prop_types.default.bool,
	/**
	* Specify the text for the primary button
	*/
	primaryButtonText: prop_types.default.string,
	/**
	* Specify the danger description on the primary button
	*/
	primaryDangerDescription: prop_types.default.string,
	/**
	* The name of the resource being acted upon
	*/
	resourceName: prop_types.default.string.isRequired,
	/**
	* Specify the text for the secondary button
	*/
	secondaryButtonText: prop_types.default.string,
	/**
	* Specify whether or not to show the text confirmation input
	*/
	textConfirmation: prop_types.default.bool,
	/**
	* The text displayed at the top of the modal
	*/
	title: prop_types.default.string.isRequired
};
RemoveModal.displayName = componentName;
//#endregion
exports.RemoveModal = RemoveModal;
