(function attachFindabilityTestTable(global) {
  const React = global.React;
  if (!React) return;
  function pct(value) { return `${Math.round((Number(value) || 0) * 100)}%`; }
  function FindabilityTestTable({ run }) {
    const tests = run && run.findabilityTests || [];
    return <section className="free-seo-card">
      <h2>AI-style Questions</h2>
      {!tests.length ? <p className="muted">No tests yet.</p> : <div className="table-scroll"><table><thead><tr><th>Score</th><th>Question</th><th>Answerable</th><th>Citation</th><th>Best pages</th><th>Gaps</th></tr></thead><tbody>{tests.map((test) => <tr key={test.id}><td>{pct(test.likelihoodScore)}</td><td>{test.question}</td><td>{test.answerable ? 'Yes' : 'No'}</td><td>{test.citationReady ? 'Ready' : 'Not yet'}</td><td>{(test.bestPages || []).slice(0, 2).map((page) => <div key={page.url}>{page.title || page.url} ({pct(page.score)})</div>)}</td><td>{(test.missingFacts || []).map((gap) => <span className="pill warn" key={gap.code}>{gap.code}</span>)}</td></tr>)}</tbody></table></div>}
    </section>;
  }
  global.FindabilityTestTable = FindabilityTestTable;
})(window);
