/**
 * 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/TagSet/TagSetModal.tsx
var import_classnames = /* @__PURE__ */ require_runtime.__toESM(require_index.default);
const componentName = "TagSetModal";
const blockClass = `${require_settings.pkg.prefix}--tag-set-modal`;
const defaults = {
	modalAriaLabel: "List of all tags",
	searchLabel: ""
};
const TagSetModal = ({ allTags, className, title, modalAriaLabel = defaults.modalAriaLabel, onClose, open, portalTarget: portalTargetIn, searchLabel = defaults.searchLabel, searchPlaceholder, ...rest }) => {
	const [filteredModalTags, setFilteredModalTags] = (0, react.useState)([]);
	const [search, setSearch] = (0, react.useState)("");
	const renderPortalUse = require_usePortalTarget.usePortalTarget(portalTargetIn);
	(0, react.useEffect)(() => {
		let newFilteredModalTags = [];
		if (open) if (search === "" && allTags) newFilteredModalTags = allTags?.slice(0);
		else {
			const lCaseSearch = search.toLocaleLowerCase();
			allTags?.forEach((tag) => {
				const dataSearch = tag["data-search"]?.toLocaleLowerCase()?.indexOf(lCaseSearch);
				const labelSearch = tag.label?.toLocaleLowerCase()?.indexOf(lCaseSearch);
				if (dataSearch > -1 || labelSearch > -1) newFilteredModalTags.push(tag);
			});
		}
		setFilteredModalTags(newFilteredModalTags);
	}, [
		allTags,
		open,
		search
	]);
	const handleSearch = (ev) => {
		setSearch(ev.target.value || "");
	};
	return renderPortalUse(/* @__PURE__ */ react.default.createElement(_carbon_react.ComposedModal, {
		...rest,
		containerClassName: `${blockClass}__container`,
		className: (0, import_classnames.default)(className, `${blockClass}`),
		size: "sm",
		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
	}, filteredModalTags.map(({ label, ...other }, index) => /* @__PURE__ */ react.default.createElement(_carbon_react.Tag, {
		...other,
		key: `all-tags-${index}`
	}, label)), /* @__PURE__ */ react.default.createElement("div", { className: `${blockClass}__fade` }))));
};
TagSetModal.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,
	open: prop_types.default.bool,
	portalTarget: prop_types.default.node,
	searchLabel: prop_types.default.string,
	searchPlaceholder: prop_types.default.string,
	title: prop_types.default.string
};
TagSetModal.displayName = componentName;
//#endregion
exports.TagSetModal = TagSetModal;
