import React from 'react';
import {
  Card,
  CardHeader,
  CardContent,
  CardActions,
  Button
} from '@material-ui/core';
import { Event } from '../../types';

interface PropTypes {
  event: Event;
}

const EventCard: React.FC<PropTypes> = ({ event }) => {
  const {
    data: {
      name,
      date,
      participants,
      conferenceId,
      attendanceId
    }
  } = event;

  return (
    <Card variant="outlined">
      <CardHeader title={name || 'Event'} subheader={date}  />
      <CardContent>
        {conferenceId && <div> ConferenceID: {conferenceId} </div>}
        {attendanceId && <div> AttendanceID: {attendanceId} </div>}
        <div>
          Participants ({participants?.length || 0} / 3)
          <ul>
            {participants?.map(username => (
              <li> {username} </li>
            ))}
          </ul>
        </div>
      </CardContent>
      {(participants?.length || 0) < 3 && (
        <CardActions>
          <Button variant="contained" color="primary" size="large">
            Join
          </Button>
        </CardActions>
      )}
    </Card>
  );
};

export default EventCard;
