/**
 * 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');
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");
let _carbon_react_icons = require("@carbon/react/icons");

//#region src/components/AddSelect/AddSelectSort.tsx
const blockClass = `${require_settings.pkg.prefix}--add-select-sort`;
const componentName = "AddSelectSort";
const AddSelectSort = ({ setSortAttribute, setSortDirection, sortBy, sortByLabel }) => {
	const sortByOpts = sortBy ? sortBy?.reduce((acc, cur) => {
		const opts = [{
			id: `${cur}-asc`,
			label: cur,
			direction: "asc",
			attribute: cur
		}, {
			id: `${cur}-desc`,
			label: cur,
			direction: "desc",
			attribute: cur
		}];
		return [...acc, ...opts];
	}, []) : [];
	const sortHandler = ({ direction, attribute }) => {
		setSortAttribute?.(attribute);
		setSortDirection?.(direction);
	};
	return /* @__PURE__ */ react.default.createElement("div", { className: blockClass }, sortByOpts.length > 0 && /* @__PURE__ */ react.default.createElement(_carbon_react.unstable_FeatureFlags, { enableV12Overflowmenu: true }, /* @__PURE__ */ react.default.createElement(_carbon_react.OverflowMenu, {
		autoAlign: true,
		menuAlignment: "bottom-end",
		renderIcon: (props) => /* @__PURE__ */ react.default.createElement(_carbon_react_icons.ArrowsVertical, {
			size: 32,
			...props
		}),
		className: `${blockClass}_overflow`,
		label: sortByLabel
	}, sortByOpts.map((opt) => {
		return /* @__PURE__ */ react.default.createElement(_carbon_react.MenuItem, {
			className: `${blockClass}_overflow-item`,
			key: opt?.id,
			label: `${opt?.label} ${opt?.direction}`,
			onClick: () => sortHandler(opt)
		});
	}))));
};
AddSelectSort.propTypes = {
	setSortAttribute: prop_types.default.func,
	setSortDirection: prop_types.default.func,
	sortBy: prop_types.default.array,
	sortByLabel: prop_types.default.string
};
AddSelectSort.displayName = componentName;

//#endregion
exports.AddSelectSort = AddSelectSort;