"use client";

import { GridColDef } from "@mui/x-data-grid-pro";
import { List } from "ui";
import { db } from "@/app/_lib/database";

export default async function Page() {
  const columns: GridColDef[] = [
    {
      field: "id",
      headerName: "ID",
      flex: 1,
    },
    {
      field: "phoneNumber",
      headerName: "Phone Number",
      flex: 2,
    },
    {
      field: "createdAt",
      headerName: "Created At",
      valueGetter: (params: any) =>
        new Date(params.row?.createdAt).toLocaleString(),
      flex: 1,
    },
    {
      field: "updatedAt",
      headerName: "Updated At",
      valueGetter: (params: any) =>
        new Date(params.row?.updatedAt).toLocaleString(),
      flex: 1,
    },
  ];

  const rows = await db.selectFrom("WhatsAppBot").selectAll().execute();

  return (
    <List
      title="Whatsapp Bots"
      rows={rows}
      columns={columns}
      onRowClick={() => {}}
    />
  );
}
