/**
 * 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 { pkg } from "../../settings.js";
import React from "react";
import PropTypes from "prop-types";
import { MenuItem, OverflowMenu, unstable_FeatureFlags } from "@carbon/react";
import { ArrowsVertical } from "@carbon/react/icons";
//#region src/components/AddSelect/AddSelectSort.tsx
const blockClass = `${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.createElement("div", { className: blockClass }, sortByOpts.length > 0 && /* @__PURE__ */ React.createElement(unstable_FeatureFlags, { enableV12Overflowmenu: true }, /* @__PURE__ */ React.createElement(OverflowMenu, {
		autoAlign: true,
		menuAlignment: "bottom-end",
		renderIcon: (props) => /* @__PURE__ */ React.createElement(ArrowsVertical, {
			size: 32,
			...props
		}),
		className: `${blockClass}_overflow`,
		label: sortByLabel
	}, sortByOpts.map((opt) => {
		return /* @__PURE__ */ React.createElement(MenuItem, {
			className: `${blockClass}_overflow-item`,
			key: opt?.id,
			label: `${opt?.label} ${opt?.direction}`,
			onClick: () => sortHandler(opt)
		});
	}))));
};
AddSelectSort.propTypes = {
	setSortAttribute: PropTypes.func,
	setSortDirection: PropTypes.func,
	sortBy: PropTypes.array,
	sortByLabel: PropTypes.string
};
AddSelectSort.displayName = componentName;
//#endregion
export { AddSelectSort };
