import * as React from 'react'; // Cross-import the same Card component the Analytics page uses so the two // surfaces are visually identical. import { Card } from '../../../dashboard/components/Card'; import { DataContainer } from '@/components/DataContainer'; import { AnimatedTabs, TabOption } from '@/components/ui/animated-tabs'; import type { DataState } from '@/types/component-states'; export interface StatTileTab { value: T; label: string; state: DataState; body: React.ReactNode; skeleton: React.ReactNode; empty?: React.ReactNode; errorMessage?: string; onRetry?: () => void; } interface SimpleProps { title: React.ReactNode; state: DataState; body: React.ReactNode; skeleton: React.ReactNode; empty?: React.ReactNode; errorMessage?: string; onRetry?: () => void; className?: string; bodyClassName?: string; // Optional control rendered in the header's top-right (e.g. a // dropdown for switching dimension). Shrinks on narrow widths // while the title truncates. action?: React.ReactNode; } interface TabbedProps { title: React.ReactNode; tabs: StatTileTab[]; value: T; onValueChange: ( v: T ) => void; className?: string; bodyClassName?: string; } function isTabbed( props: SimpleProps | TabbedProps ): props is TabbedProps { return 'tabs' in props && Array.isArray( props.tabs ); } export function StatTile( props: SimpleProps | TabbedProps ) { const { title, className, bodyClassName } = props; if ( isTabbed( props ) ) { const active = props.tabs.find( t => t.value === props.value ) ?? props.tabs[ 0 ]; const tabOptions: TabOption[] = props.tabs.map( t => ( { value: t.value, label: t.label, } ) ); return (

{ title }

{ active.body }
); } return (

{ title }

{ props.action &&
{ props.action }
}
{ props.body }
); }