import type { Metadata } from "next";
import { Suspense } from "react";
import { Skeleton } from "@/components/ui/skeleton";
import { getAllTransactionsAction } from "@/features/payment/actions/transactions-actions";
import { TransactionsClient } from "@/roles/admin/components/transactions/transactions-client";

export const metadata: Metadata = {
  title: "All Transactions | Ameera Holidays Admin",
  description:
    "View all payment transactions with module, booking, gateway, and response details.",
  robots: { index: false, follow: false },
};

function TransactionsLoading() {
  return (
    <div className="space-y-6">
      <div>
        <Skeleton className="h-8 w-56" />
        <Skeleton className="mt-2 h-4 w-96" />
      </div>
      <div className="grid gap-4 sm:grid-cols-2 xl:grid-cols-5">
        {[...Array(5)].map((_, index) => (
          <Skeleton key={index} className="h-24 rounded-xl" />
        ))}
      </div>
      <Skeleton className="h-12 w-full rounded-xl" />
      <Skeleton className="h-96 w-full rounded-xl" />
    </div>
  );
}

export default async function AllTransactionsPage() {
  const initialResult = await getAllTransactionsAction({
    page: 1,
    per_page: 20,
  });

  return (
    <main>
      <Suspense fallback={<TransactionsLoading />}>
        <TransactionsClient
          initialData={
            initialResult.success ? (initialResult.data ?? null) : null
          }
          initialError={
            initialResult.success ? null : (initialResult.error ?? null)
          }
        />
      </Suspense>
    </main>
  );
}
