import AdminResourceList from "@/app/features/AdminList/AdminResourceList";
import { IAddModalField } from "@/app/components/AddModal/types";
import { CURRENCY_FIELDS } from "../constants";
import { fetchAdminResource } from "@/app/services/adminResources";

export default async function CurrenciesPage() {
  let initialData = null;

  try {
    initialData = await fetchAdminResource({
      resource: "currencies",
      pagination: { page: 1, limit: 100 },
    });
  } catch (error) {
    console.error("Failed to fetch currencies server-side:", error);
    // Continue without initial data - component will fetch client-side
  }

  return (
    <AdminResourceList
      title="Currencies"
      endpoint="/api/dashboard/admin/currencies"
      responseCollectionKeys={["currencies", "data", "items"]}
      primaryLabelKeys={["name", "code", "title"]}
      chipKeys={["rate", "enabled", "status"]}
      addModalFields={CURRENCY_FIELDS as IAddModalField[]}
      showEnabledToggle={true}
      idField="code"
      initialData={initialData}
    />
  );
}
