import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
import { Badge } from "@/components/ui/badge";
import { CHANGE_LOG_ENTRIES } from "@/lib/changelog";
import { formatDateShanghai } from "@/lib/time";
import { GitBranch, ListChecks, ScrollText } from "lucide-react";

export default function ChangeLog() {
  return (
    <div className="space-y-6">
      <section className="rounded-[28px] border border-border/60 bg-[radial-gradient(circle_at_top_left,_rgba(14,165,233,0.1),_transparent_28%),linear-gradient(180deg,rgba(255,255,255,1),rgba(248,250,252,0.96))] p-6 shadow-sm">
        <div className="flex items-start gap-4">
          <div className="flex h-12 w-12 items-center justify-center rounded-2xl bg-primary/10 text-primary">
            <ScrollText className="h-6 w-6" />
          </div>
          <div>
            <h1 className="text-2xl font-semibold tracking-tight">更新日志</h1>
            <p className="mt-2 text-sm leading-6 text-muted-foreground">
              这里会按版本记录已上线的新功能、对应仓库版本和验证结果。后续每次改动测试通过并提交后，都会继续追加到这里。
            </p>
          </div>
        </div>
      </section>

      <div className="space-y-4">
        {CHANGE_LOG_ENTRIES.map((entry) => (
          <Card key={`${entry.version}-${entry.repoVersion}`} className="border-0 shadow-sm">
            <CardHeader className="pb-3">
              <div className="flex flex-col gap-3 lg:flex-row lg:items-start lg:justify-between">
                <div>
                  <CardTitle className="text-lg">{entry.version}</CardTitle>
                  <CardDescription className="mt-2">{entry.summary}</CardDescription>
                </div>
                <div className="flex flex-wrap gap-2">
                  <Badge variant="secondary">{formatDateShanghai(entry.releaseDate)}</Badge>
                  <Badge variant="outline" className="gap-1">
                    <GitBranch className="h-3 w-3" />
                    {entry.repoVersion}
                  </Badge>
                </div>
              </div>
            </CardHeader>
            <CardContent className="space-y-4">
              <div>
                <div className="text-sm font-medium">上线内容</div>
                <div className="mt-2 flex flex-wrap gap-2">
                  {entry.features.map((feature) => (
                    <Badge key={feature} variant="secondary">{feature}</Badge>
                  ))}
                </div>
              </div>
              <div>
                <div className="flex items-center gap-2 text-sm font-medium">
                  <ListChecks className="h-4 w-4 text-primary" />
                  验证记录
                </div>
                <ul className="mt-2 list-disc space-y-1 pl-5 text-sm text-muted-foreground">
                  {entry.tests.map((item) => <li key={item}>{item}</li>)}
                </ul>
              </div>
            </CardContent>
          </Card>
        ))}
      </div>
    </div>
  );
}
