// The report kit's building blocks (plan step 6.12a): a report's page with tabs, a panel, a big
// figure, a sortable table, loading / error states, the export button. On the tokens, texts in
// `manager:reports.*`, money and dates through useFormat().
import { useState } from 'react'
import { useSearchParams } from 'react-router-dom'
import toast from 'react-hot-toast'
import { ArrowDown, ArrowUp, Download, Info } from 'lucide-react'
import { errorMessage } from '@xenia/api'
import { useFormat, useTranslation } from '@xenia/i18n'
import { Button, EmptyState, InfoTip, Page, PageHeader, Spinner, Tabs, cx } from '@xenia/ui'
import client from '../../../api/client'
import { sortRows } from './reportLogic'
/** A report page: its tabs (kept in the address as ?tab=) over the chosen tab's content. */
export function ReportPage({ title, tabs = [], children, testId }) {
const [params, setParams] = useSearchParams()
const active = tabs.find(t => t.id === params.get('tab'))?.id ?? tabs[0]?.id
const tab = tabs.find(t => t.id === active)
return (
1 ? ({ id: t.id, label: t.label, testId: `report-tab-${t.id}` }))}
onChange={id => setParams(p => { const n = new URLSearchParams(p); n.set('tab', id); return n }, { replace: true })} /> : undefined}>
{tab ? : children}
)
}
/** A card with a title, an optional tip and actions. */
export function Panel({ title, tip, actions, children, className, padded = true, testId }) {
return (
{(title || actions) && (
{title}{tip && {tip}}
{actions}
)}
{children}
)
}
const TONE = { success: 'text-success-ink', danger: 'text-danger-ink', warning: 'text-warning-ink', info: 'text-info-ink', accent: 'text-accent-ink' }
/** A figure: a label over a value, an optional line under it, a tone for the value. */
export function Stat({ label, value, sub, tip, tone, big = false, testId }) {
return (