import { h, type FunctionalComponent } from 'preact'
import { useEffect, useState } from 'preact/hooks'
import rek from 'rek'

interface Props {
  objectId: number
}

const Result: FunctionalComponent<Props> = ({ objectId }) => {
  const [transactions, setTransactions] = useState([])

  useEffect(() => {
    rek(`/api/objects/${objectId}`).then(setTransactions)
  }, [objectId])

  return (
    <table>
      <tbody>
        {transactions.map((transaction) => (
          <tr>
            <td>{transaction.transactionDate.slice(0, 10)}</td>
            <td>{transaction.accountNumber}</td>
            <td>{transaction.amount}</td>
          </tr>
        ))}
      </tbody>
    </table>
  )
}

export default Result
