import PageHeader from "@/components/app/PageHeader"
import PageShell from "@/components/app/PageShell"
import { Button } from "@/components/ui/button"
import BranchList from "@/features/branches/components/BranchList"

import { deleteBranch, listBranches } from "@/features/branches/service"

interface BranchesPageProps {
  searchParams: Promise<{ delete?: string }>
}

export default async function BranchesPage({ searchParams }: BranchesPageProps) {
  const { delete: deleteId } = await searchParams

  if (deleteId) {
    await deleteBranch(deleteId)
  }

  const branches = await listBranches()

  return (
    <PageShell>
      <PageHeader
        title="Company"
        description="Manage company and their locations."
        actions={
          <Button asChild>
            <a href="/branches/create">Add Company</a>
          </Button>
        }
      />
      <BranchList branches={branches} />
    </PageShell>
  )
}
