// ---------- 6. Adapters ----------
PAGES.adapters = async () => {
  const ws = document.getElementById("workspace");
  ws.innerHTML = `<div class="text-slate-400 text-sm">加载中…</div>`;
  try {
    const { adapters, orphans } = await api("/api/adapters");
    const rows = adapters.map(a => `
      <tr class="border-t border-slate-100">
        <td class="px-4 py-3 mono text-sm">${esc(a.adapter_id)}</td>
        <td class="px-4 py-3 text-sm text-slate-600">${esc(a.summary || "—")}</td>
        <td class="px-4 py-3 text-center text-xs">${a.has_default_selectors ? pill("内置", "blue") : pill("—", "slate")}</td>
        <td class="px-4 py-3 text-center text-xs">${a.site_count}</td>
      </tr>`).join("");
    const orphanRows = orphans.map(o => `
      <tr class="border-t border-slate-100 bg-amber-50/40">
        <td class="px-4 py-3 mono text-sm text-amber-900">${esc(o.adapter_id)}</td>
        <td class="px-4 py-3 text-sm text-amber-800">DB 中有站点绑定，但代码里未注册 — 需要检查</td>
        <td class="px-4 py-3 text-center">${pill("orphan", "amber")}</td>
        <td class="px-4 py-3 text-center text-xs">${o.site_count}</td>
      </tr>`).join("");
    ws.innerHTML = card({
      title: "已注册的 CMS 适配器",
      actions: `<button onclick="go('registry')" class="text-xs px-3 py-1 rounded bg-[#1D4ED8] text-white">打开全局栏目目录</button>`,
      body: `
        <table class="w-full text-sm">
          <thead class="bg-slate-50 text-slate-500 text-xs uppercase">
            <tr>
              <th class="text-left px-4 py-2">adapter_id</th>
              <th class="text-left px-4 py-2">摘要</th>
              <th class="px-4 py-2">默认选择器</th>
              <th class="px-4 py-2">绑定站点数</th>
            </tr>
          </thead>
          <tbody>${rows}${orphanRows}${(!rows && !orphanRows) ? `<tr><td colspan="4" class="p-8 text-center text-slate-400">没有注册任何 adapter</td></tr>` : ""}</tbody>
        </table>`
    });
  } catch (e) {
    ws.innerHTML = `<div class="card p-6 text-sm text-red-600">加载失败：${esc(e.message)}</div>`;
  }
};
