import { h, type FunctionComponent } from 'preact'
import rek from 'rek'
import Head from './head.ts'
import usePromise from '../../shared/hooks/use_promise.ts'

import type { Account } from '../../../shared/types.db.ts'

const AccountsPage: FunctionComponent = () => {
  const accounts = usePromise<Account[]>(() => rek('/api/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
