"use client";

import type { ToolDescriptorView } from "@/lib/api/types";

interface ToolCardProps {
  tool: ToolDescriptorView;
  // 点击：legacy 工具导航到现有页面；新工具开 GeneratorRunner。
  onOpen: (tool: ToolDescriptorView) => void;
}

// 工具箱卡片（对齐 ProjectCard 纸感视觉）：标题 + 副标题 + 题材徽标 + NEW/可入库标。
// 纯展示；点击交由 ToolboxPage 分派（legacy 跳转 / 新工具开 runner）。
export function ToolCard({ tool, onOpen }: ToolCardProps) {
  return (
    <button
      type="button"
      onClick={() => onOpen(tool)}
      className="flex h-full min-h-[140px] flex-col rounded border border-line bg-panel p-5 text-left shadow-paper transition-colors hover:border-cinnabar focus-visible:border-cinnabar focus-visible:outline-none"
    >
      <div className="mb-2 flex flex-wrap items-center gap-2">
        <h2 className="font-serif text-xl text-ink">{tool.title}</h2>
        {tool.genre ? (
          <span className="rounded bg-bg px-2 py-0.5 text-xs text-ink-soft">
            {tool.genre}
          </span>
        ) : null}
        {tool.is_legacy ? null : (
          <span className="rounded bg-[var(--color-cinnabar-wash)] px-2 py-0.5 text-xs text-cinnabar">
            NEW
          </span>
        )}
        {tool.ingestable ? (
          <span className="rounded bg-bg px-2 py-0.5 text-xs text-ink-soft">
            可入库
          </span>
        ) : null}
      </div>
      <p className="line-clamp-2 text-sm text-ink-soft">{tool.subtitle}</p>
    </button>
  );
}
