/**
 * 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 { usePreviousValue } from "../../global/js/hooks/usePreviousValue.js";
import { getDevtoolsProps } from "../../global/js/utils/devtools.js";
import { usePortalTarget } from "../../global/js/hooks/usePortalTarget.js";
import uuidv4 from "../../global/js/utils/uuidv4.js";
import React, { forwardRef, useEffect, useRef, useState } from "react";
import PropTypes from "prop-types";
import { Button, ComposedModal, ModalBody, ModalFooter, ModalHeader, TextInput } from "@carbon/react";

//#region src/components/RemoveModal/RemoveModal.tsx
var import_classnames = /* @__PURE__ */ __toESM(require_classnames());
const componentName = "RemoveModal";
const RemoveModal = 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 = usePreviousValue({ open });
	const [userInput, setUserInput] = useState("");
	const idRef = useRef(uuidv4());
	const renderPortalUse = 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 = `${pkg.prefix}--remove-modal`;
	useEffect(() => {
		if (!open && previousState?.open) setUserInput("");
	}, [open, previousState?.open]);
	return renderPortalUse(/* @__PURE__ */ React.createElement(ComposedModal, {
		...rest,
		className: (0, import_classnames.default)(blockClass, className),
		size: "sm",
		"aria-label": title,
		open,
		ref,
		preventCloseOnClickOutside,
		onClose,
		...getDevtoolsProps(componentName)
	}, /* @__PURE__ */ React.createElement(ModalHeader, {
		title,
		label,
		iconDescription
	}), /* @__PURE__ */ React.createElement(ModalBody, null, typeof body === "string" ? /* @__PURE__ */ React.createElement("p", { className: `${blockClass}__body` }, body) : body, textConfirmation && /* @__PURE__ */ React.createElement(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.createElement(ModalFooter, null, /* @__PURE__ */ React.createElement(Button, {
		type: "button",
		kind: "secondary",
		onClick: onClose,
		"data-modal-primary-focus": !textConfirmation
	}, secondaryButtonText), /* @__PURE__ */ React.createElement(Button, {
		type: "submit",
		kind: "danger",
		dangerDescription: primaryDangerDescription,
		onClick: onRequestSubmit,
		disabled: primaryButtonStatus
	}, primaryButtonText))));
});
RemoveModal.propTypes = {
	body: PropTypes.node.isRequired,
	className: PropTypes.string,
	iconDescription: PropTypes.string.isRequired,
	inputInvalidText: PropTypes.string,
	inputLabelText: PropTypes.node,
	inputPlaceholderText: PropTypes.string,
	label: PropTypes.string,
	onClose: PropTypes.func,
	onRequestSubmit: PropTypes.func,
	open: PropTypes.bool.isRequired,
	portalTarget: PropTypes.node,
	preventCloseOnClickOutside: PropTypes.bool,
	primaryButtonDisabled: PropTypes.bool,
	primaryButtonText: PropTypes.string,
	primaryDangerDescription: PropTypes.string,
	resourceName: PropTypes.string.isRequired,
	secondaryButtonText: PropTypes.string,
	textConfirmation: PropTypes.bool,
	title: PropTypes.string.isRequired
};
RemoveModal.displayName = componentName;

//#endregion
export { RemoveModal };