import { Card, CardContent } from '@/components/ui/card';
import { getLocale, t } from '@/lib/i18n';
import { listOwnerAudit } from '@/lib/owner-audit';

export default async function OwnerAuditPage() {
  const [locale, entries] = await Promise.all([getLocale(), listOwnerAudit(100)]);

  return (
    <div className="space-y-6">
      <div>
        <h1 className="text-2xl font-semibold">{t(locale, 'owner.audit.title')}</h1>
        <p className="text-sm text-muted-foreground">{t(locale, 'owner.audit.subtitle')}</p>
      </div>
      <Card>
        <CardContent className="divide-y divide-border p-0">
          {entries.length === 0 ? (
            <p className="p-4 text-sm text-muted-foreground">{t(locale, 'owner.common.empty')}</p>
          ) : (
            entries.map((entry) => (
              <div key={entry.id} className="flex flex-col gap-1 px-4 py-3 text-sm sm:flex-row sm:justify-between">
                <div>
                  <p className="font-medium">{entry.action}</p>
                  <p className="text-muted-foreground">
                    {entry.actorUserId}
                    {entry.targetType ? ` · ${entry.targetType}` : ''}
                    {entry.targetId ? ` · ${entry.targetId}` : ''}
                  </p>
                </div>
                <span className="text-muted-foreground">{new Date(entry.createdAt).toLocaleString()}</span>
              </div>
            ))
          )}
        </CardContent>
      </Card>
    </div>
  );
}
