"use client";

import * as React from "react";

import { getCoreRowModel, useReactTable } from "@tanstack/react-table";

import { DataTableShell } from "@/app/dashboard/_components/data-table";
import { ErrorBanner } from "@/components/shared/error-banner";

import { paymentGatewayColumns } from "./columns";
import type { PaymentGatewayRow } from "./schema";

type PaymentGatewaysTableProps = {
  data: PaymentGatewayRow[];
  errorMessage?: string | null;
};

export function PaymentGatewaysTable({
  data,
  errorMessage = null,
}: PaymentGatewaysTableProps) {
  const table = useReactTable({
    data,
    columns: paymentGatewayColumns,
    getCoreRowModel: getCoreRowModel(),
    getRowId: (row) => row.id,
  });

  return (
    <div className="space-y-4">
      {errorMessage ? <ErrorBanner message={errorMessage} /> : null}
      <DataTableShell
        table={table}
        columnCount={paymentGatewayColumns.length}
        emptyMessage="No payment gateways are registered. Enable gateway extensions first."
      />
    </div>
  );
}
