'use client'
import {ReactNode, useEffect, useState} from 'react'
import {PageRecord} from '@/lib/api'
import {ResourcePss} from '@/lib/models'
import {useStatus} from '@/lib/states'
import {listResourcePss} from '@/actions/resource'

export type ResourcesPageProps = {}

export default function ResourcesPage(props: ResourcesPageProps) {

  // region 数据

  const [status, setStatus] = useStatus()
  const [data, setData] = useState<PageRecord<ResourcePss>>({
    page: 1,
    size: 10,
    total: 0,
    list: [],
  })

  const refresh = async (page: number, size: number) => {
    setStatus('load')
    try {
      const res = await listResourcePss({page, size})
      setStatus('done')

      if (res.success) {
        setData(res.data)
      }
      else {
        throw new Error('Failed to load resource pss')
      }
    }
    catch (e) {
      setStatus('fail')
    }
  }

  useEffect(() => {
    refresh(1, 10).then()
  }, [])

  // endregion

  // render
  return (
    <main className={`flex-auto bg-white rounded-tl-xl`}>

    </main>
  )
}
