import Link from "next/link";
import type { Metadata } from "next";
import { getBlogList } from "@/services/blog.service";

export const metadata: Metadata = {
  title: "技术博客",
};

export default async function BlogListPage() {
  const posts = await getBlogList().catch(() => []);

  return (
    <div className="mx-auto max-w-4xl px-6 py-24">
      <h1 className="mb-12 text-4xl font-bold text-slate-900">技术博客</h1>
      <ul className="space-y-6">
        {posts.map((post) => (
          <li key={post.id} className="border-b border-slate-100 pb-6">
            <Link
              href={`/blog/${post.meta.slug}`}
              className="text-2xl font-semibold text-slate-900 hover:text-primary"
            >
              {post.title}
            </Link>
            {post.intro && <p className="mt-2 text-slate-600">{post.intro}</p>}
          </li>
        ))}
        {posts.length === 0 && (
          <p className="text-slate-500">暂无文章，或后端服务未连接。</p>
        )}
      </ul>
    </div>
  );
}
