import { AppShell } from "@/components/app-shell"
import { SectionCards } from "@/components/section-cards"
import { SiteHeader } from "@/components/site-header"
import { RecentTicketsPanel } from "@/components/tickets/recent-tickets-panel"
import { TicketQueueSummaryCards } from "@/components/tickets/ticket-queue-summary"
import { ChartOpenedResolved } from "@/components/charts/chart-opened-resolved"
import { NewTicketDialogDeferred } from "@/components/tickets/new-ticket-dialog.client"
import { requireAuthenticatedSession } from "@/lib/auth-server"

export default async function Dashboard() {
  // Garante redirecionamento para /login quando sem sessão (aba anônima, etc.)
  await requireAuthenticatedSession()
  return (
    <AppShell
      header={
        <SiteHeader
          title="Central de operações"
          lead="Monitoramento em tempo real"
          primaryAction={<NewTicketDialogDeferred />}
        />
      }
    >
      <SectionCards />
      <div className="grid gap-6 px-4 lg:grid-cols-[minmax(0,1.1fr)_minmax(0,0.9fr)] lg:px-6 lg:[&>*]:min-w-0">
        <ChartOpenedResolved />
        <RecentTicketsPanel />
      </div>
      <div className="px-4 lg:px-6">
        <TicketQueueSummaryCards />
      </div>
    </AppShell>
  )
}

