/**
 * 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_props_helper = require("../../global/js/utils/props-helper.js");
const require_usePortalTarget = require("../../global/js/hooks/usePortalTarget.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/TagOverflow/TagOverflowModal.tsx
var import_classnames = /* @__PURE__ */ require_runtime.__toESM(require_index.default);
const componentName = "TagOverflowModal";
const blockClass = `${require_settings.pkg.prefix}--tag-overflow-modal`;
const defaults = {
	modalAriaLabel: "List of all tags",
	searchLabel: ""
};
const TagOverflowModal = ({ allTags, className, title, modalAriaLabel = defaults.modalAriaLabel, onClose, onTagClose, open, overflowType, portalTarget: portalTargetIn, searchLabel = defaults.searchLabel, searchPlaceholder, ...rest }) => {
	const [search, setSearch] = (0, react.useState)("");
	const renderPortalUse = require_usePortalTarget.usePortalTarget(portalTargetIn);
	const getFilteredItems = () => {
		if (open && search && allTags) return allTags.filter((tag) => tag.label?.toLocaleLowerCase()?.includes(search.toLocaleLowerCase()));
		return allTags || [];
	};
	const handleSearch = (evt) => {
		setSearch(evt.target.value || "");
	};
	return renderPortalUse(/* @__PURE__ */ react.default.createElement(_carbon_react.ComposedModal, {
		...rest,
		containerClassName: `${blockClass}__container`,
		className: (0, import_classnames.default)(className, blockClass),
		size: "sm",
		"aria-label": "Search all",
		open,
		onClose
	}, /* @__PURE__ */ react.default.createElement(_carbon_react.ModalHeader, {
		className: `${blockClass}__header`,
		closeModal: onClose,
		title
	}, /* @__PURE__ */ react.default.createElement(_carbon_react.Search, {
		"data-modal-primary-focus": true,
		className: `${blockClass}__search`,
		labelText: searchLabel,
		placeholder: searchPlaceholder,
		onChange: handleSearch,
		size: "lg"
	})), /* @__PURE__ */ react.default.createElement(_carbon_react.ModalBody, {
		className: `${blockClass}__body`,
		hasForm: true,
		hasScrollingContent: true,
		"aria-label": modalAriaLabel
	}, getFilteredItems().map(({ label, id, filter, onClose }) => {
		return overflowType === "tag" && (typeof onClose === "function" || filter) ? /* @__PURE__ */ react.default.createElement(_carbon_react.DismissibleTag, {
			key: id,
			text: label,
			onClose: () => onTagClose?.({
				label,
				id
			})
		}) : /* @__PURE__ */ react.default.createElement(_carbon_react.Tag, { key: id }, label);
	}), /* @__PURE__ */ react.default.createElement("div", { className: `${blockClass}__fade` }))));
};
TagOverflowModal.propTypes = {
	allTags: prop_types.default.arrayOf(prop_types.default.shape({
		...require_props_helper.prepareProps(_carbon_react.Tag.propTypes, "filter"),
		label: prop_types.default.string.isRequired
	})),
	className: prop_types.default.string,
	onClose: prop_types.default.func,
	onTagClose: prop_types.default.func,
	open: prop_types.default.bool,
	overflowType: prop_types.default.oneOf(["default", "tag"]),
	portalTarget: prop_types.default.node,
	searchLabel: prop_types.default.string,
	searchPlaceholder: prop_types.default.string,
	title: prop_types.default.string
};
TagOverflowModal.displayName = componentName;
//#endregion
exports.TagOverflowModal = TagOverflowModal;
