import { useState } from 'react'
import { useQuery } from '@tanstack/react-query'
import AuditLogTable from '@/components/AuditLogTable'
import { getAuditLogs } from '@/services/admin-api'

export default function AuditLogPage() {
  const [page, setPage] = useState(1)
  const [pageSize, setPageSize] = useState(20)

  const { data, isLoading } = useQuery({
    queryKey: ['audit-logs', page, pageSize],
    queryFn: () => getAuditLogs({ page, limit: pageSize }),
  })

  return (
    <AuditLogTable
      headerTitle="操作日志"
      dataSource={data?.items || []}
      loading={isLoading}
      pagination={data ? { current: data.page, pageSize: data.limit, total: data.total } : undefined}
      onPageChange={(p, ps) => { setPage(p); setPageSize(ps) }}
    />
  )
}
