/** @license MIT | @cube-dev/ui-kit v0.147.0 | Cube Dev Team */
import { ItemAction } from "../../actions/ItemAction/ItemAction.js";
import { useI18n } from "../../../i18n/useI18n.js";
import { CloseIcon } from "../../../icons/CloseIcon.js";
import { MoreIcon } from "../../../icons/MoreIcon.js";
import { POPOVER_PLACEMENT_BY_TABS_PLACEMENT } from "./popover-placement.js";
import { FilterPicker } from "../../fields/FilterPicker/FilterPicker.js";
import { jsx } from "react/jsx-runtime";

//#region src/components/navigation/Tabs/TabPicker.tsx
/**
* Tab picker component that displays a dropdown menu of all tabs.
*
* Used in the Tabs suffix area when tabs overflow to provide quick navigation
* to any tab without scrolling.
*/
function TabPicker({ tabs, selectedKey, onSelect, onDelete, size, type = "default", placement = "top", isReorderable, onReorder }) {
	const { t } = useI18n();
	const isDeletable = !!onDelete;
	const pickerSize = size === "xsmall" ? "small" : size;
	const showBorderDivider = type === "file";
	const isVertical = placement === "left" || placement === "right";
	return /* @__PURE__ */ jsx(FilterPicker, {
		selectionMode: "single",
		selectedKey,
		renderSummary: false,
		icon: /* @__PURE__ */ jsx(MoreIcon, {}),
		rightIcon: null,
		shape: "sharp",
		type: "clear",
		size: pickerSize,
		placement: POPOVER_PLACEMENT_BY_TABS_PLACEMENT[placement],
		styles: { border: showBorderDivider ? {
			"": 0,
			"!:first-child": isVertical ? "top" : "left"
		} : 0 },
		triggerStyles: { border: 0 },
		"aria-label": t("tabs.selectTab", "Select tab"),
		isReorderable,
		onReorder,
		onSelectionChange: (key) => {
			if (key != null) onSelect(String(key));
		},
		children: tabs.map((tab) => /* @__PURE__ */ jsx(FilterPicker.Item, {
			icon: tab.icon,
			textValue: typeof tab.title === "string" ? tab.title : String(tab.key),
			autoHideActions: isDeletable,
			actions: isDeletable ? /* @__PURE__ */ jsx(ItemAction, {
				icon: /* @__PURE__ */ jsx(CloseIcon, {}),
				"aria-label": t("tabs.close", "Close"),
				onPress: () => {
					onDelete(tab.key);
				}
			}) : void 0,
			children: tab.title
		}, tab.key))
	});
}

//#endregion
export { TabPicker };
//# sourceMappingURL=TabPicker.js.map