import { Box, Chip, Typography } from '@mui/material'

interface DashboardHeaderProps {
  orgName?: string
  lastUpdated?: string
}

function formatLastUpdated(iso: string): string {
  try {
    return new Intl.DateTimeFormat('de-CH', {
      dateStyle: 'short',
      timeStyle: 'short',
    }).format(new Date(iso))
  } catch {
    return iso
  }
}

export function DashboardHeader({ orgName = 'Demo Organisation', lastUpdated }: DashboardHeaderProps) {
  return (
    <Box>
      <Box sx={{ display: 'flex', alignItems: 'center', gap: 1, mb: 0.5 }}>
        <Typography sx={{ fontWeight: 700, fontSize: '1.125rem', lineHeight: 1.3, color: '#0f172a' }}>
          {orgName}
        </Typography>
        <Chip label="Demo" size="small" color="info" variant="outlined" />
      </Box>
      {lastUpdated && (
        <Typography variant="body2" color="text.secondary">
          Zuletzt aktualisiert: {formatLastUpdated(lastUpdated)}
        </Typography>
      )}
    </Box>
  )
}
