"use client" import { CheckIcon, ChevronsUpDownIcon } from "lucide-react" import Link from "next/link" import type { ReactElement } from "react" import { useI18n } from "@/i18n/provider" import { cn } from "@/lib/utils" import { Button } from "@/components/ui/button" import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu" export type WorkspaceKey = "dashboard" | "workbench" export type WorkspaceOption = { key: WorkspaceKey href: string labelKey: string } export const workspaceOptions: WorkspaceOption[] = [ { key: "dashboard", href: "/dashboard", labelKey: "workspace.dashboard", }, { key: "workbench", href: "/workbench", labelKey: "workspace.workbench", }, ] type WorkspaceSwitcherProps = { currentWorkspace: WorkspaceKey variant?: "sidebar" | "header" | "rail" className?: string trigger?: ReactElement } export function WorkspaceSwitcher({ currentWorkspace, variant = "header", className, trigger, }: WorkspaceSwitcherProps) { const t = useI18n() const currentOption = workspaceOptions.find((item) => item.key === currentWorkspace) ?? workspaceOptions[0] const triggerClassName = cn( "gap-2 text-left", variant === "header" && "h-9 rounded-md border border-border/70 bg-background px-2.5 shadow-xs hover:bg-muted", variant === "sidebar" && "data-[slot=sidebar-menu-button]:p-1.5!", variant === "rail" && "relative size-11 rounded-lg border-0 bg-transparent p-0 shadow-none hover:bg-sidebar-accent", className ) const triggerContent = variant === "rail" ? ( <> {t("app.brand")} {t("workspace.switchWorkspace")} - {t(currentOption.labelKey)} ) : ( <> {t("app.brand")}
{t("app.brand")} {t(currentOption.labelKey)}
) return ( } > {triggerContent} {t("workspace.switchWorkspace")} {workspaceOptions.map((item) => ( } className="cursor-pointer gap-2" > {t(item.labelKey)} {item.key === currentWorkspace ? ( ) : null} ))} ) }