import ScoreChips from './ScoreChips';

export default function ResultTable({ result }) {
  if (!result) {
    return (
      <section className="screener-card">
        <p style={{ color: '#9ca3af' }}>아직 결과 없음. "지금 실행"을 눌러보세요.</p>
      </section>
    );
  }

  return (
    <section className="screener-card">
      <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
        <h3 style={{ margin: 0 }}>
          Top {result.top_n} · 통과 {result.survivors_count} · {result.asof}
        </h3>
        {result.warnings?.length > 0 && (
          <div style={{
            background: '#7c2d12', color: '#fde68a', padding: '4px 10px',
            borderRadius: 4, fontSize: 12,
          }}>
            ⚠ {result.warnings.join(' · ')}
          </div>
        )}
      </div>

      <div style={{ overflowX: 'auto', marginTop: 12 }}>
        <table className="screener-table">
          <thead>
            <tr>
              <th>#</th><th>종목</th><th>총점</th><th>노드</th>
              <th>진입</th><th>손절</th><th>익절</th><th>R%</th>
            </tr>
          </thead>
          <tbody>
            {(result.results || []).map((r) => (
              <tr key={r.ticker}>
                <td>{r.rank}</td>
                <td>{r.name}<br /><span style={{ fontSize: 11, color: '#9ca3af' }}>{r.ticker}</span></td>
                <td style={{ fontWeight: 600 }}>{r.total_score?.toFixed(1)}</td>
                <td><ScoreChips scores={r.scores} /></td>
                <td>{r.entry_price?.toLocaleString?.()}</td>
                <td>{r.stop_price?.toLocaleString?.()}</td>
                <td>{r.target_price?.toLocaleString?.()}</td>
                <td>{r.r_pct?.toFixed?.(1)}</td>
              </tr>
            ))}
          </tbody>
        </table>
      </div>
    </section>
  );
}
