import { AppShell } from "@/components/app-shell"
import { SiteHeader } from "@/components/site-header"
import { prisma } from "@/lib/prisma"
import { AdminCompaniesManager } from "@/components/admin/companies/admin-companies-manager"

export const runtime = "nodejs"
export const dynamic = "force-dynamic"

export default async function AdminCompaniesPage() {
  const companiesRaw = await prisma.company.findMany({ orderBy: { name: "asc" } })
  const companies = companiesRaw.map((c: any) => ({ ...c, isAvulso: Boolean(c.isAvulso ?? false) }))
  return (
    <AppShell
      header={
        <SiteHeader
          title="Empresas & Clientes"
          lead="Gerencie os dados das empresas e controle o faturamento de clientes avulsos."
        />
      }
    >
      <div className="mx-auto w-full max-w-6xl px-6 lg:px-8">
        <AdminCompaniesManager initialCompanies={companies} />
      </div>
    </AppShell>
  )
}
