import { AppShell } from "@/components/app-shell"
import { SiteHeader } from "@/components/site-header"
import { TicketDetailView } from "@/components/tickets/ticket-detail-view"
import { TicketDetailStatic } from "@/components/tickets/ticket-detail-static"
import { NewTicketDialogDeferred } from "@/components/tickets/new-ticket-dialog.client"
import { getTicketById } from "@/lib/mocks/tickets"
import type { TicketWithDetails } from "@/lib/schemas/ticket"

type TicketDetailPageProps = {
  params: Promise<{ id: string }>
}

export default async function TicketDetailPage({ params }: TicketDetailPageProps) {
  const { id } = await params
  const isMock = id.startsWith("ticket-")
  const mock = isMock ? getTicketById(id) : null

  return (
    <AppShell
      header={
        <SiteHeader
          title={`Ticket #${id}`}
          lead={"Detalhes do ticket"}
          secondaryAction={<SiteHeader.SecondaryButton>Compartilhar</SiteHeader.SecondaryButton>}
          primaryAction={<NewTicketDialogDeferred />}
        />
      }
    >
      {isMock && mock ? <TicketDetailStatic ticket={mock as TicketWithDetails} /> : <TicketDetailView id={id} />}
    </AppShell>
  )
}
