/**
 * 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_InlineEditContext = require("../InlineEdit/InlineEditContext/InlineEditContext.js");
const require_CustomizeColumnsTearsheet = require("./CustomizeColumnsTearsheet.js");
let react = require("react");
react = require_runtime.__toESM(react);
let prop_types = require("prop-types");
prop_types = require_runtime.__toESM(prop_types);
//#region src/components/Datagrid/Datagrid/addons/CustomizeColumns/TearsheetWrapper.jsx
const TearsheetWrapper = ({ instance, launcherButtonRef }) => {
	const { onSaveColumnPrefs, isTearsheetOpen, setIsTearsheetOpen, labels, ...rest } = instance.customizeColumnsProps;
	const { state } = (0, react.useContext)(require_InlineEditContext.InlineEditContext);
	const { featureFlags } = state || {};
	(0, react.useEffect)(() => {
		if (featureFlags && !featureFlags?.["enable-datagrid-useCustomizeColumns"]) console.error(`Datagrid useCustomizeColumns extension has not been enabled via feature flag.`);
	}, [featureFlags]);
	return /* @__PURE__ */ react.default.createElement(require_CustomizeColumnsTearsheet.default, {
		...rest,
		...labels,
		isOpen: isTearsheetOpen,
		setIsTearsheetOpen,
		launcherButtonRef,
		columnDefinitions: instance.allColumns,
		originalColumnDefinitions: instance.columns,
		onSaveColumnPrefs: (updatedColDefs) => {
			setTimeout(() => {
				const hiddenIds = updatedColDefs.filter((colDef) => !colDef.isVisible).map((colDef) => colDef.id);
				instance.setHiddenColumns(hiddenIds);
				if (typeof instance.setColumnOrder === "function") instance.setColumnOrder(updatedColDefs.map((colDef) => colDef.id));
				else console.warn("Column order can not be updated. Did you forget to add 'useColumnOrder' in 'useDatagrid'");
			}, 0);
			if (typeof onSaveColumnPrefs === "function") onSaveColumnPrefs(updatedColDefs);
		}
	});
};
TearsheetWrapper.propTypes = { instance: prop_types.default.object.isRequired };
//#endregion
exports.default = TearsheetWrapper;
