import React, { useMemo } from 'react';
import { useOutletContext } from 'react-router-dom';
import {
  MaterialReactTable,
  useMaterialReactTable,
  type MRT_ColumnDef,
} from 'material-react-table';
import type { Guest } from '../models';

function Dashboard() {
  const guests: Guest[] = useOutletContext();
  const columns = useMemo<MRT_ColumnDef<Guest>[]>(
    () => [
      {
        accessorKey: 'firstName',
        header: 'First Name',
        size: 50,
      },
      {
        accessorKey: 'lastName',
        header: 'Last Name',
        size: 50,
      },
      {
        accessorKey: 'attendance',
        header: 'Attendance',
        size: 50,
      },
      {
        accessorKey: 'email',
        header: 'Email',
        size: 150,
      },
      {
        accessorKey: 'message',
        header: 'Message',
        size: 200,
      },
      {
        accessorKey: 'partySize',
        header: 'Party Size',
        size: 50,
      },
    ],
    []
  );
  const table = useMaterialReactTable({
    columns,
    data: guests,
    muiPaginationProps: {
      shape: 'rounded',
      showRowsPerPage: false,
      variant: 'outlined',
    },
    paginationDisplayMode: 'pages',
    enableExpanding: true,
    filterFromLeafRows: true,
    getSubRows: (row) => row.partyList as Guest[],
  });

  return (
    <div
      style={{
        display: 'flex',
        justifyContent: 'center',
      }}
    >
      <div style={{ marginTop: 128 }}>
        <MaterialReactTable table={table} />
      </div>
    </div>
  );
}

export default Dashboard;
