import Link from "next/link";
import { Suspense } from "react";
import { api, HydrateClient } from "~/trpc/server";
import { Button } from "~/components/ui/button";
import { Plus, Building } from "lucide-react";
import { BusinessesDataTable } from "./_components/businesses-data-table";
import { PageHeader } from "~/components/layout/page-header";
import { DataTableSkeleton } from "~/components/data/data-table";

// Businesses Table Component
async function BusinessesTable() {
  const businesses = await api.businesses.getAll();

  return <BusinessesDataTable businesses={businesses} />;
}

export default async function BusinessesPage() {
  return (
    <>
      <PageHeader
        title="Businesses"
        description="Manage your businesses and their information"
        variant="gradient"
      >
        <Button asChild className="btn-brand-primary shadow-md">
          <Link href="/dashboard/businesses/new">
            <Plus className="mr-2 h-5 w-5" />
            <span>Add Business</span>
          </Link>
        </Button>
      </PageHeader>

      <HydrateClient>
        <Suspense fallback={<DataTableSkeleton columns={6} rows={5} />}>
          <BusinessesTable />
        </Suspense>
      </HydrateClient>
    </>
  );
}
