"use client"

import { Building2 } from "lucide-react"

import { ListPageCard } from "@/app/dashboard/_components"
import { AllBanksTable } from "@/components/xml-apis/all-banks/components/all-banks-table"
import { AllBanksToolbar } from "@/components/xml-apis/all-banks/components/all-banks-toolbar"
import { useAllBanks } from "@/components/xml-apis/all-banks/hooks/use-all-banks"
import { XmlApiErrorBanner } from "@/components/xml-apis/shared/xml-api-error-banner"
import type { AllBankRow } from "@/components/xml-apis/all-banks/types"

type AllBanksListPageProps = {
  initialData?: AllBankRow[]
  initialTotalCount?: number
  initialPage?: number
  initialPageSize?: number
  initialPageCount?: number
  initialErrorMessage?: string | null
}

export function AllBanksListPage({
  initialData = [],
  initialTotalCount = 0,
  initialPage = 1,
  initialPageSize = 10,
  initialPageCount = 1,
  initialErrorMessage = null,
}: AllBanksListPageProps) {
  const {
    data,
    totalCount,
    page,
    pageSize,
    pageCount,
    isLoading,
    isRefreshing,
    refresh,
    goToPage,
    changePageSize,
  } = useAllBanks({
    initialData,
    initialTotalCount,
    initialPage,
    initialPageSize,
    initialPageCount,
  })

  return (
    <ListPageCard
      icon={Building2}
      title="All Banks"
      description="Browse bank accounts with subdomain and corporate mappings."
      breadcrumb={[{ label: "XML API" }, { label: "All Banks" }]}
      actions={
        <AllBanksToolbar
          isRefreshing={isRefreshing}
          onRefresh={() => void refresh()}
        />
      }
    >
      <XmlApiErrorBanner message={initialErrorMessage} />
      <AllBanksTable
        data={data}
        totalCount={totalCount}
        page={page}
        pageSize={pageSize}
        pageCount={pageCount}
        isLoading={isLoading || isRefreshing}
        onPageChange={goToPage}
        onPageSizeChange={changePageSize}
      />
    </ListPageCard>
  )
}
