import React from 'react'; import { Link, useLocation } from 'react-router-dom'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'; import { Button } from '@/components/ui/button'; import { RefreshCw } from 'lucide-react'; import { useDashboardPeriod } from '@/hooks/useDashboardPeriod'; import { DummyDataToggle } from '../DummyDataToggle'; import { __ } from '@/lib/i18n'; import { useQueryClient } from '@tanstack/react-query'; import type { SubItem } from '@/nav/tree'; type Props = { items?: SubItem[]; fullscreen?: boolean }; export default function DashboardSubmenuBar({ items = [], fullscreen = false }: Props) { const { period, setPeriod, useDummy } = useDashboardPeriod(); const { pathname } = useLocation(); const queryClient = useQueryClient(); const handleRefresh = () => { queryClient.invalidateQueries({ queryKey: ['analytics'] }); }; if (items.length === 0) return null; // Calculate top position based on fullscreen state // Fullscreen: top-16 (below 64px header) // Normal: top-[88px] (below 40px WP admin bar + 48px menu bar) const topClass = fullscreen ? 'top-0' : 'top-[calc(7rem+32px)]'; return (
{/* Submenu Links */}
{items.map((it) => { const key = `${it.label}-${it.path || it.href}`; const isActive = !!it.path && ( it.exact ? pathname === it.path : pathname.startsWith(it.path) ); const cls = [ 'inline-flex items-center gap-2 rounded-md px-2.5 py-1.5 border text-sm whitespace-nowrap', 'focus:outline-none focus:ring-0 focus:shadow-none', isActive ? 'bg-accent text-accent-foreground' : 'hover:bg-accent hover:text-accent-foreground', ].join(' '); if (it.mode === 'spa' && it.path) { return ( {it.label} ); } if (it.mode === 'bridge' && it.href) { return ( {it.label} ); } return null; })}
{/* Period Selector, Refresh & Dummy Toggle */}
{!useDummy && ( )}
); }