/**
 * 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 uuidv4 from "../../../../../global/js/utils/uuidv4.js";
import { DraggableItemsList } from "./DraggableItemsList.js";
import React, { useRef } from "react";
import PropTypes from "prop-types";
import { Checkbox } from "@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__ */ __toESM(require_classnames());
const blockClass = `${pkg.prefix}--datagrid`;
const Columns = ({ getVisibleColumnsCount, filterString, columns, setColumnsObject, onSelectColumn, assistiveTextInstructionsLabel, assistiveTextDisabledInstructionsLabel, selectAllLabel, customizeTearsheetHeadingLabel }) => {
	const listId = useRef(uuidv4());
	const listRef = useRef(null);
	const [ariaRegionText, setAriaRegionText] = React.useState("");
	const moveElement = React.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.createElement("div", {
		className: `${blockClass}__customize-columns-column-list`,
		ref: listRef
	}, /* @__PURE__ */ React.createElement("ol", {
		className: `${blockClass}__customize-columns-column-list--focus`,
		"aria-label": customizeTearsheetHeadingLabel,
		"aria-describedby": `${blockClass}__customize-columns--instructions`
	}, /* @__PURE__ */ React.createElement("span", {
		"aria-live": "assertive",
		className: `${blockClass}__shared-ui--assistive-text`
	}, ariaRegionText), /* @__PURE__ */ React.createElement("span", {
		id: `${blockClass}__customize-columns--instructions`,
		className: `${blockClass}__shared-ui--assistive-text`
	}, filterString.length === 0 ? assistiveTextInstructionsLabel : assistiveTextDisabledInstructionsLabel), /* @__PURE__ */ React.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.createElement(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.createElement(DraggableItemsList, {
		id: listId.current,
		columns,
		filterString,
		moveElement,
		setAriaRegionText,
		onSelectColumn
	})));
};
Columns.propTypes = {
	assistiveTextDisabledInstructionsLabel: PropTypes.string,
	assistiveTextInstructionsLabel: PropTypes.string,
	columns: PropTypes.array.isRequired,
	customizeTearsheetHeadingLabel: PropTypes.string,
	disabledInstructionsLabel: PropTypes.string,
	filterString: PropTypes.string.isRequired,
	getVisibleColumnsCount: PropTypes.func.isRequired,
	instructionsLabel: PropTypes.string,
	onSelectColumn: PropTypes.func.isRequired,
	selectAllLabel: PropTypes.string,
	setColumnStatus: PropTypes.func,
	setColumnsObject: PropTypes.func.isRequired
};
//#endregion
export { Columns as default };
