"use client"

import { Percent } from "lucide-react"

import { ListPageCard } from "@/app/dashboard/_components"
import { XmlApiErrorBanner } from "@/components/xml-apis/shared/xml-api-error-banner"
import { TempAccruedTable } from "@/components/xml-apis/temp-accrued/components/temp-accrued-table"
import { TempAccruedToolbar } from "@/components/xml-apis/temp-accrued/components/temp-accrued-toolbar"
import { useTempAccrued } from "@/components/xml-apis/temp-accrued/hooks/use-temp-accrued"
import type { TempAccruedRow } from "@/components/xml-apis/temp-accrued/types"

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

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

  return (
    <ListPageCard
      icon={Percent}
      title="Temp Accrued"
      description="Temporary accrued interest records from XML imports."
      breadcrumb={[{ label: "XML API" }, { label: "Temp Accrued" }]}
      actions={
        <TempAccruedToolbar
          isRefreshing={isRefreshing}
          onRefresh={() => void refresh()}
        />
      }
    >
      <XmlApiErrorBanner message={initialErrorMessage} />
      <TempAccruedTable
        data={data}
        totalCount={totalCount}
        page={page}
        pageSize={pageSize}
        pageCount={pageCount}
        isLoading={isLoading || isRefreshing}
        onPageChange={goToPage}
        onPageSizeChange={changePageSize}
      />
    </ListPageCard>
  )
}
