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

const InvoicesPage = () => {
  const [suppliers, setSuppliers] = useState([])

  useEffect(() => {
    rek('/api/suppliers').then((suppliers) => setSuppliers(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
