import React from "react";
import { GameState } from "./App";

const Tile = ({
  word,
  selectWordHandler,
}: {
  selectWordHandler: () => void;
  word: GameState["words"][number];
}) => (
  <button
    onClick={selectWordHandler}
    className={`Grid-square ${word.selected ? "Selected" : ""}`}
    style={{ cursor: "pointer" }}
  >
    <h1 className="Fit-text">{word.word.toUpperCase()}</h1>
  </button>
);

export const Grid = ({
  selectWordHandler,
  words,
}: {
  selectWordHandler: (idx: number) => void;
  words: GameState["words"];
}) => (
  <div className="Grid">
    {new Array(16).fill(undefined).map((_, i) => (
      <Tile
        selectWordHandler={() => selectWordHandler(i)}
        word={words[i]}
        key={i}
      />
    ))}
  </div>
);
