import { h } from 'preact'
import { useEffect, useState } from 'preact/hooks'
import rek from 'rek'
import Head from './head.ts'
import Invoice from './invoice.tsx'

const InvoicesPage = () => {
  const [suppliers, setSuppliers] = useState([])
  const [financialYears, setFinancialYears] = useState([])
  const [currentYear, setCurrentYear] = useState<number>(null)

  useEffect(() => {
    rek('/api/suppliers').then((suppliers) => setSuppliers(suppliers))
    // rek('/api/financial-years').then((financialYears) => {
    //   setFinancialYears(financialYears)
    //   setCurrentYear(financialYears[financialYears.length - 1].year)
    // })
  }, [])
  console.log(suppliers)

  return (
    <section>
      <Head>
        <title> : Invoices</title>
      </Head>

      <h1>Invoices</h1>
      <ul>
        {suppliers?.map((supplier) => (
          <li>
            <a href={`/invoices/by-supplier/${supplier.id}`}>
              ({supplier.id}) {supplier.name}
            </a>
          </li>
        ))}
      </ul>
    </section>
  )
}

export default InvoicesPage
