import React from "react";
import { Button, Card } from "react-bootstrap";
import propTypes from "prop-types";
import { grammaticalListString } from "../utils/strings";
export default class MatchInfoCard extends React.Component {
    constructor(props) {
        super(props);
    }

    getParticipants() {
        let participants = [];
        this.props.match.participants.forEach(user => {
            participants.push(user.firstName);
        });
        return participants;
    }

    render() {
        return (
            <Card style={{ width: "20rem" }}>
                <Card.Body>
                    <Card.Title>{this.props.match.sport.name}</Card.Title>
                    <Card.Subtitle className="mb-2 text-muted">{this.props.match.title}</Card.Subtitle>
                    <Card.Text>
                        Join <strong>{grammaticalListString(this.getParticipants(), 4)}</strong> to play a few matches of <strong>{this.props.match.sport.name}</strong> at <strong>{this.props.match.location.toString()}</strong> on <strong>{new Date(this.props.match.when).toLocaleDateString("en-US")}</strong>!
                    </Card.Text>
                    <Button variant="primary">Join!</Button>
                </Card.Body>
            </Card>
        );
    }
}

MatchInfoCard.propTypes = {
    match: propTypes.object,
};