import { useRouter } from 'next/router';
import React from 'react'
import { Table } from 'react-bootstrap'
import styles from '../styles/AvisList.module.css'

export default function AvisList({ avis }) {
    const router = useRouter();
    function handleClick(id) {
        router.push(`/avis/${id}`);
    }

    return (
        <Table>
            <thead>
                <tr>
                    <th>Date</th>
                    <th>Note globale</th>
                    <th>Commentaire</th>
                    <th>Source</th>
                </tr>
            </thead>
            <tbody>
                {avis.map(({ id, note_principale, commentaire, date, nom_source }) => {
                    return <tr onClick={() => handleClick(id)} key={id} className={styles.row}>
                        <td>{date}</td>
                        <td>{note_principale} / 10</td>
                        <td>{commentaire}</td>
                        <td>{nom_source}</td>
                    </tr>
                })}
            </tbody>
        </Table>
    )
}
