/**
 * 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_uuidv4 = require('../../../../../global/js/utils/uuidv4.js');
const require_DraggableItemsList = require('./DraggableItemsList.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/Datagrid/Datagrid/addons/CustomizeColumns/Columns.jsx
/**
* Copyright IBM Corp. 2022, 2025
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
var import_classnames = /* @__PURE__ */ require_runtime.__toESM(require_index.default);
const blockClass = `${require_settings.pkg.prefix}--datagrid`;
const Columns = ({ getVisibleColumnsCount, filterString, columns, setColumnsObject, onSelectColumn, assistiveTextInstructionsLabel, assistiveTextDisabledInstructionsLabel, selectAllLabel, customizeTearsheetHeadingLabel }) => {
	const listId = (0, react.useRef)(require_uuidv4.default());
	const listRef = (0, react.useRef)(null);
	const [ariaRegionText, setAriaRegionText] = react.default.useState("");
	const moveElement = react.default.useCallback((from, to) => {
		setColumnsObject((prev) => {
			const prevClone = [...prev];
			const item = prevClone[from];
			prevClone.splice(from, 1);
			prevClone.splice(to, 0, item);
			return prevClone;
		});
	}, [setColumnsObject]);
	const filteredStickyColumn = columns?.filter((item) => !item.sticky);
	return /* @__PURE__ */ react.default.createElement("div", {
		className: `${blockClass}__customize-columns-column-list`,
		ref: listRef
	}, /* @__PURE__ */ react.default.createElement("ol", {
		className: `${blockClass}__customize-columns-column-list--focus`,
		"aria-label": customizeTearsheetHeadingLabel,
		"aria-describedby": `${blockClass}__customize-columns--instructions`
	}, /* @__PURE__ */ react.default.createElement("span", {
		"aria-live": "assertive",
		className: `${blockClass}__shared-ui--assistive-text`
	}, ariaRegionText), /* @__PURE__ */ react.default.createElement("span", {
		id: `${blockClass}__customize-columns--instructions`,
		className: `${blockClass}__shared-ui--assistive-text`
	}, filterString.length === 0 ? assistiveTextInstructionsLabel : assistiveTextDisabledInstructionsLabel), /* @__PURE__ */ react.default.createElement("div", {
		id: `${blockClass}__customize-columns-select-all`,
		className: (0, import_classnames.default)(`${blockClass}__customize-columns-select-all`, { [`${blockClass}__customize-columns-select-all--selected`]: getVisibleColumnsCount() > 0 }),
		selected: getVisibleColumnsCount() > 0
	}, /* @__PURE__ */ react.default.createElement(_carbon_react.Checkbox, {
		className: `${blockClass}__customize-columns-checkbox-wrapper`,
		checked: getVisibleColumnsCount() === columns.length,
		indeterminate: getVisibleColumnsCount() < columns.length && getVisibleColumnsCount() > 0,
		onChange: () => {
			onSelectColumn(filteredStickyColumn, getVisibleColumnsCount() !== columns.length);
		},
		id: `${blockClass}__customization-column-select-all`,
		labelText: selectAllLabel
	})), /* @__PURE__ */ react.default.createElement(require_DraggableItemsList.DraggableItemsList, {
		id: listId.current,
		columns,
		filterString,
		moveElement,
		setAriaRegionText,
		onSelectColumn
	})));
};
Columns.propTypes = {
	assistiveTextDisabledInstructionsLabel: prop_types.default.string,
	assistiveTextInstructionsLabel: prop_types.default.string,
	columns: prop_types.default.array.isRequired,
	customizeTearsheetHeadingLabel: prop_types.default.string,
	disabledInstructionsLabel: prop_types.default.string,
	filterString: prop_types.default.string.isRequired,
	getVisibleColumnsCount: prop_types.default.func.isRequired,
	instructionsLabel: prop_types.default.string,
	onSelectColumn: prop_types.default.func.isRequired,
	selectAllLabel: prop_types.default.string,
	setColumnStatus: prop_types.default.func,
	setColumnsObject: prop_types.default.func.isRequired
};

//#endregion
exports.default = Columns;