import { NavLink, useNavigate } from 'react-router-dom'
import {
Banknote, ClipboardList, BarChart2, Wallet, Vault, FileText, Settings, LogOut,
} from 'lucide-react'
import { can, type User, type CashupCap } from '../types'
interface Props {
user: User
children: React.ReactNode
}
// `cap` gates the nav item's visibility; undefined = always shown (app access is enough).
const navItems: { to: string; label: string; icon: typeof Banknote; cap?: CashupCap }[] = [
{ to: '/daily', label: 'Daily Cash Up', icon: Banknote, cap: 'count' },
{ to: '/history', label: 'History', icon: ClipboardList },
{ to: '/report', label: 'Weekly Report', icon: BarChart2, cap: 'reports' },
{ to: '/floats', label: 'Float Management', icon: Wallet, cap: 'floats' },
{ to: '/safe', label: 'Safe Count', icon: Vault, cap: 'floats' },
{ to: '/summary', label: 'Cash Summary', icon: FileText, cap: 'reports' },
{ to: '/settings',label: 'Settings', icon: Settings, cap: 'settings' },
]
export function Layout({ user, children }: Props) {
const navigate = useNavigate()
async function logout() {
await fetch('/cashup/api/auth/logout', { method: 'POST', credentials: 'include' })
navigate('/login', { replace: true })
window.location.reload()
}
return (
{/* Sidebar */}
{/* Content */}
{children}
)
}
export function PageHeader({ title, subtitle }: { title: string; subtitle?: string }) {
return (
{title}
{subtitle &&
{subtitle}
}
)
}
export function Card({ children, style }: { children: React.ReactNode; style?: React.CSSProperties }) {
return (
{children}
)
}
export function Btn({
children, onClick, variant = 'primary', disabled, small, type = 'button', style,
}: {
children: React.ReactNode
onClick?: () => void
variant?: 'primary' | 'secondary' | 'danger' | 'ghost'
disabled?: boolean
small?: boolean
type?: 'button' | 'submit'
style?: React.CSSProperties
}) {
const styles: Record = {
primary: { background: 'var(--gold)', color: 'var(--navy-dark)', border: 'none' },
secondary: { background: 'var(--card-bg)', color: 'var(--text-dark)', border: '1px solid var(--card-border)' },
danger: { background: 'var(--danger)', color: '#fff', border: 'none' },
ghost: { background: 'transparent', color: 'var(--text-mid)', border: '1px solid var(--card-border)' },
}
return (
)
}
export function StatusBadge({ status }: { status: 'draft' | 'final' }) {
const styles = {
draft: { background: '#fef9c3', color: '#ca8a04' },
final: { background: '#dcfce7', color: '#16a34a' },
}
return (
{status}
)
}