import type { ReactNode } from 'react'; import { useEffect, useRef, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { Link } from 'react-router-dom'; import { ArrowLeft, ChevronLeft, ChevronRight, MessageSquare, X } from 'lucide-react'; import { buttonVariants } from './button'; import { H2, H3, Muted } from './typography'; import { cn } from '../../lib/utils'; /* Page header: opcjonalny element przed tytułem (np. awatar), tytuł + badge, akcje zawsze w tej samej linii po prawej (nie stackują się na mobile). */ export function PageHeader({ title, leading, badge, actions, }: { title: string; /** Element przed tytułem (np. awatar). */ leading?: ReactNode; badge?: ReactNode; actions?: ReactNode; }) { return (
{leading} {/* `

` należy do topbaru (tytuł strony) — nagłówek treści to `

` */}

{title}

{badge}
{actions &&
{actions}
}
); } /* Back button — ghost, small; `to` renders a Link, `onClick` a plain button */ export function BackButton({ to, onClick, children, className = '', }: { to?: string; onClick?: () => void; children?: ReactNode; className?: string; }) { const { t } = useTranslation(); // na telefonie „Wstecz” siedzi w topmenu („<”) — tu tylko md+ const cls = cn(buttonVariants({ variant: 'ghost', size: 'sm' }), 'max-md:hidden', className); if (to) { return ( {children ?? t('back')} ); } return ( ); } /* Section header: H2 + muted description + optional actions (right) */ export function SectionHeader({ title, description, actions, className = '', }: { title: ReactNode; description?: ReactNode; actions?: ReactNode; className?: string; }) { return (

{title}

{description && {description}}
{actions &&
{actions}
}
); } /* Stat tile: bez boxa — mini etykieta (uppercase) + duża wartość */ export function StatTile({ label, value, valueClassName = 'truncate', className = '', }: { label: ReactNode; value: ReactNode; /** Styl wartości (domyślnie `truncate`; np. `break-words` dla długich tekstów). */ valueClassName?: string; className?: string; }) { return (
{label}
{value}
); } /* List row: płaski wiersz (tytuł + meta lewo, akcje prawo); w listach w karcie rodzic używa `divide-y divide-line` (dłuższe) albo `space-y-1` (krótkie). */ export function ListRow({ title, meta, actions, children, className = '', }: { title: ReactNode; meta?: ReactNode; actions?: ReactNode; children?: ReactNode; className?: string; }) { return (
{title}
{meta && {meta}}
{actions &&
{actions}
} {children}
); } /* Callout komentarza serii (SessionSet.note): akcentowa ramka + normalna czcionka — trener od razu widzi, że seria ma komentarz (ten sam styl w historii i u trenera). */ export function NoteCallout({ label, text, className = '', }: { label: string; text: string; className?: string; }) { return (
); } /* Meta item: small icon + muted text */ export function MetaItem({ icon: Icon, children, className = '', }: { icon: React.ComponentType<{ className?: string }>; children: ReactNode; className?: string; }) { return ( {children} ); } /* Chip: small pill (+ optional remove button) */ export function Chip({ children, onRemove, removeLabel, className = '', }: { children: ReactNode; onRemove?: () => void; removeLabel?: string; className?: string; }) { const { t } = useTranslation(); return ( {children} {onRemove && ( )} ); } /* Empty state */ export function EmptyState({ icon: Icon, title, description, action, }: { icon: React.ComponentType<{ className?: string }>; title: string; description?: string; action?: ReactNode; }) { return (

{title}

{description &&

{description}

} {action &&
{action}
}
); } /* Tabs — scroll bez scrollbarów ze snapem do całych zakładek (w spoczynku brak uciętych słów, brak pomiarów/przeskalowań JS — nie zacina na słabych urządzeniach). Strzałki wewnątrz kontenera montowane tylko gdy naprawdę jest co przewijać: miejsce istnieje dokładnie wtedy, gdy istnieje przycisk. */ export function Tabs({ tabs, active, onChange, }: { tabs: { id: string; label: ReactNode }[]; active: string; onChange: (id: string) => void; }) { const { t } = useTranslation(); const scrollRef = useRef(null); const [canPrev, setCanPrev] = useState(false); const [canNext, setCanNext] = useState(false); const updateArrows = () => { const el = scrollRef.current; if (!el) return; setCanPrev(el.scrollLeft > 2); setCanNext(el.scrollLeft + el.clientWidth < el.scrollWidth - 2); }; useEffect(() => { updateArrows(); const onResize = () => updateArrows(); window.addEventListener('resize', onResize); return () => window.removeEventListener('resize', onResize); }, [tabs.length]); // aktywna zakładka zawsze wycentrowana w pasku (prosty, przewidywalny // efekt kierunkowy bez snap-kombinacji — działa też na Safari/iOS) useEffect(() => { const el = scrollRef.current; const btn = el?.querySelector(`[data-tab-id="${CSS.escape(active)}"]`); if (!el || !btn) return; const br = btn.getBoundingClientRect(); const er = el.getBoundingClientRect(); const target = el.scrollLeft + (br.left - er.left) + br.width / 2 - er.width / 2; const clamped = Math.max(0, Math.min(el.scrollWidth - el.clientWidth, target)); if (Math.abs(clamped - el.scrollLeft) > 2) el.scrollTo({ left: clamped, behavior: 'smooth' }); }, [active]); const scrollByGroup = (dir: 1 | -1) => { const el = scrollRef.current; if (el) el.scrollBy({ left: dir * el.clientWidth * 0.9, behavior: 'smooth' }); }; return (
{/* strzałki zawsze w DOM — szerokość i widoczność animowane, więc miejsce pojawia się płynnie razem z przyciskiem (bez „żabkowania” layoutu) */}
{tabs.map((t) => ( ))}
{/* miękkie wygaszenie krawędzi — ucięty tekst znika zanim dojdzie do strzałki */} ); }