"use client"

import { LineChart } from "lucide-react"

import { ListPageCard } from "@/app/dashboard/_components"
import { XmlApiErrorBanner } from "@/components/xml-apis/shared/xml-api-error-banner"
import { TempMarketPriceTable } from "@/components/xml-apis/temp-market-price/components/temp-market-price-table"
import { TempMarketPriceToolbar } from "@/components/xml-apis/temp-market-price/components/temp-market-price-toolbar"
import { useTempMarketPrice } from "@/components/xml-apis/temp-market-price/hooks/use-temp-market-price"
import type { TempMarketPriceRow } from "@/components/xml-apis/temp-market-price/types"

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

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

  return (
    <ListPageCard
      icon={LineChart}
      title="Temp Market Price"
      description="Temporary market price rows from imported position XML."
      breadcrumb={[{ label: "XML API" }, { label: "Temp Market Price" }]}
      actions={
        <TempMarketPriceToolbar
          isRefreshing={isRefreshing}
          onRefresh={() => void refresh()}
        />
      }
    >
      <XmlApiErrorBanner message={initialErrorMessage} />
      <TempMarketPriceTable
        data={data}
        totalCount={totalCount}
        page={page}
        pageSize={pageSize}
        pageCount={pageCount}
        isLoading={isLoading || isRefreshing}
        onPageChange={goToPage}
        onPageSizeChange={changePageSize}
      />
    </ListPageCard>
  )
}
