/**
 * 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_settings = require('../../../../../settings.js');
const require_handleCheckboxChange = require('./handleCheckboxChange.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/Filtering/OverflowCheckboxes.jsx
/**
* Copyright IBM Corp. 2023, 2024
*
* 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 componentClass = `${`${require_settings.pkg.prefix}--datagrid`}-filter-panel`;
const OverflowCheckboxes = ({ components, filtersState, column, setFiltersState, type, applyFilters, viewAllLabel = "View all", viewLessLabel = "View less" }) => {
	const [showAllItems, setShowAllItems] = (0, react.useState)(false);
	const firstFiveItems = filtersState[column].value.slice(0, 5);
	const restOfTheItems = filtersState[column].value.slice(5, filtersState[column].value.length);
	const renderCheckbox = (option) => /* @__PURE__ */ react.default.createElement(_carbon_react.Checkbox, {
		key: option.labelText,
		...option,
		onChange: (_, { checked }) => require_handleCheckboxChange.handleCheckboxChange({
			checked,
			filtersState,
			column,
			option,
			setFiltersState,
			applyFilters,
			type
		}),
		checked: option.selected,
		disabled: option.disabled
	});
	const renderViewAllButtonText = () => {
		/** This should render the text "View all ([amount of checkboxes])" or "View less" */
		return showAllItems ? viewLessLabel : `${viewAllLabel} (${filtersState[column].value.length})`;
	};
	return /* @__PURE__ */ react.default.createElement(_carbon_react.FormGroup, components.FormGroup, firstFiveItems.map(renderCheckbox), showAllItems && restOfTheItems.map(renderCheckbox), /* @__PURE__ */ react.default.createElement(_carbon_react.Button, {
		className: `${componentClass}__view-all-button`,
		kind: "ghost",
		size: "sm",
		onClick: () => setShowAllItems(!showAllItems)
	}, renderViewAllButtonText()));
};
OverflowCheckboxes.propTypes = {
	applyFilters: prop_types.default.func,
	column: prop_types.default.string,
	components: prop_types.default.object,
	filtersState: prop_types.default.object,
	setFiltersState: prop_types.default.func,
	type: prop_types.default.string,
	viewAllLabel: prop_types.default.string,
	viewLessLabel: prop_types.default.string
};

//#endregion
exports.default = OverflowCheckboxes;