import type { Metadata } from "next";
import Link from "next/link";
import { getPosts } from "@/lib/posts";

export const metadata: Metadata = { title: "Notebook" };

export default function NotebookPage() {
  const posts = getPosts("notebook");

  return (
    <div style={{ maxWidth: "100%" }}>
      <div className="page-title">Notebook</div>
      <p style={{ fontSize: "0.8rem", color: "var(--text-muted)", marginBottom: "2rem" }}>
        Anlık düşünceler, kısa notlar — twitter&apos;ın sessiz versiyonu
      </p>

      {posts.length === 0 ? (
        <div className="card" style={{ color: "var(--text-muted)", fontSize: "0.85rem" }}>Henüz not yok.</div>
      ) : (
        <div style={{ display: "flex", flexDirection: "column", gap: "0.75rem" }}>
          {posts.map((post) => (
            <article key={post.slug} className="card" style={{ borderLeft: "3px solid var(--accent)" }}>
              <div style={{ display: "flex", alignItems: "flex-start", justifyContent: "space-between", gap: "1rem", marginBottom: "0.4rem" }}>
                <Link href={`/notebook/${post.slug}`}>
                  <h2 style={{ fontSize: "0.9rem", fontWeight: 600, color: "var(--text)", lineHeight: 1.4 }}>
                    {post.title}
                  </h2>
                </Link>
                <span style={{ fontSize: "0.7rem", color: "var(--text-muted)", flexShrink: 0 }}>
                  {new Date(post.date).toLocaleDateString("tr-TR", { month: "short", day: "numeric" })}
                </span>
              </div>
              <p style={{ fontSize: "0.82rem", color: "var(--text-muted)", lineHeight: 1.6 }}>
                {post.excerpt}
              </p>
              {post.tags.length > 0 && (
                <div style={{ display: "flex", gap: "0.3rem", flexWrap: "wrap", marginTop: "0.5rem" }}>
                  {post.tags.map((t) => <span key={t} className="tag">{t}</span>)}
                </div>
              )}
            </article>
          ))}
        </div>
      )}
    </div>
  );
}
