import React from "react";

import { Game } from "../content/games";

import { Link } from "./Link";

import styles from "./GameCard.module.css";

interface GameCardProps {
  game: Game;
}

export function GameCard({ game }: GameCardProps) {
  const isPlayable = game.status === "playable";
  const href = `/game-channel/${game.slug}`;

  return (
    <article className={styles.card}>
      <div className={styles.preview} aria-hidden="true">
        {game.coverImage ? (
          <img
            src={game.coverImage}
            className={styles.coverImg}
            alt={game.title}
          />
        ) : (
          <span>{game.title.charAt(0)}</span>
        )}
      </div>
      <div className={styles.content}>
        <div className={styles.heading}>
          <h2>{game.title}</h2>
          <span className={styles.status}>
            {isPlayable ? "Playable" : "Coming Soon"}
          </span>
        </div>
        <p>{game.description}</p>
        <p className={styles.authors}>By {game.authors.join(", ")}</p>
        <ul className={styles.tags}>
          {game.tags.map((tag) => (
            <li key={tag}>{tag}</li>
          ))}
        </ul>
        {isPlayable ? (
          <Link href={href}>Play game</Link>
        ) : (
          <span className={styles.disabledLink}>Play game</span>
        )}
      </div>
    </article>
  );
}
