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

interface Props {
  year: number
}

const Result: FunctionalComponent<Props> = ({ year }) => {
  const [result, setResults] = useState([])

  useEffect(() => {
    rek(`/api/results/${year}`).then(setResults)
  }, [year])

  return (
    <table>
      <tbody>
        {result.map((result) => (
          <tr>
            <td>{result.accountNumber}</td>
            <td>{result.description}</td>
            <td>{result.amount}</td>
          </tr>
        ))}
      </tbody>
    </table>
  )
}

export default Result
