"use client"; import { ActionIcon, Badge, Button, Group, Menu, Paper, Text, Tooltip } from "@mantine/core"; import { IconCheck, IconFolderShare, IconTrash, IconX } from "@tabler/icons-react"; import { useCurrentLayout, useRequiredBoard } from "@homarr/boards/context"; import { useEditMode } from "@homarr/boards/edit-mode"; import { getBoardLaneColumnCount, getRootSectionLane } from "@homarr/definitions"; import { useI18n } from "@homarr/translation/client"; import type { EmptySection } from "~/app/[locale]/boards/_types"; import { useBoardSelection } from "./board-selection-context"; export const BoardSelectionToolbar = () => { const [isEditMode] = useEditMode(); const { selectedItemIds, clearSelection, removeSelectedItems, moveSelectedItemsToSection } = useBoardSelection(); const board = useRequiredBoard(); const currentLayoutId = useCurrentLayout(); const currentLayout = board.layouts.find((layout) => layout.id === currentLayoutId); const t = useI18n(); if (!isEditMode || selectedItemIds.size === 0) return null; const count = selectedItemIds.size; const mainCanvasSection = board.sections .filter( (section): section is EmptySection => section.kind === "empty" && getRootSectionLane(section.xOffset) === "main", ) .toSorted((sectionA, sectionB) => sectionA.yOffset - sectionB.yOffset) .at(0); const placementOptions = [ ...(mainCanvasSection ? [{ value: mainCanvasSection.id, label: t("item.create.destination.mainCanvas") }] : []), ...board.sections.flatMap((section) => { if (section.kind !== "empty") return []; const lane = getRootSectionLane(section.xOffset); if (lane === "main" || !currentLayout || getBoardLaneColumnCount(currentLayout, lane) === 0) return []; return [ { value: section.id, label: t(`item.create.destination.${lane === "left" ? "leftRail" : "rightRail"}`), }, ]; }), ...board.sections .filter((section) => section.kind === "container") .map((section) => ({ value: section.id, label: section.options.title.trim() || t("section.container.untitled"), })), ]; return ( }> {count === 1 ? "1 item" : `${count} items`} {placementOptions.length > 1 && ( Choose destination section {placementOptions.map((opt) => ( moveSelectedItemsToSection(opt.value)}> {opt.label} ))} )} ); };