import { Link, useLoaderData } from "react-router";
import { listBands } from "~/lib/db.server";

export function loader() {
  return { bands: listBands() };
}

export default function Home() {
  const { bands } = useLoaderData<typeof loader>();
  return (
    <main>
      {bands.length === 0 ? (
        <p className="muted">
          バンドがまだありません。{" "}
          <Link to="/bands/new">追加する</Link>
        </p>
      ) : (
        <ul className="band-list">
          {bands.map((band) => (
            <li key={band.id}>
              <Link to={`/bands/of/${band.id}`}>{band.name}</Link>
              {band.status === "hiatus" && (
                <span className="muted" style={{ fontSize: ".75rem" }}>活動休止</span>
              )}
            </li>
          ))}
        </ul>
      )}
    </main>
  );
}
