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

const AccountsPage = () => {
  const [accounts, setAccounts] = useState([])

  useEffect(() => {
    rek('/api/accounts').then((accounts) => {
      setAccounts(accounts)
    })
  }, [])

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

      <h1>Accounts</h1>
      <table className='grid'>
        <thead>
          <th>Number</th>
          <th>Description</th>
        </thead>
        <tbody>
          {accounts.map((account) => (
            <tr>
              <td>{account.number}</td>
              <td>{account.description}</td>
            </tr>
          ))}
        </tbody>
      </table>
    </section>
  )
}

export default AccountsPage
