<?php
require_once dirname(__DIR__) . '/bootstrap/chairman_bootstrap.php';
$raceDate = isset($_GET['race_date']) ? chairman_safe_date($_GET['race_date']) : date('Y-m-d');
$venue = isset($_GET['venue']) ? $_GET['venue'] : '';
$raceNum = isset($_GET['race_num']) ? intval($_GET['race_num']) : 0;
$ranking=$Chairman->getRaceRanking($raceDate,$venue,$raceNum);
$summary=$Chairman->getRaceSummary($raceDate,$venue,$raceNum);
?>
<!doctype html><html lang="zh-Hant"><head><meta charset="utf-8"><title>Chairman Dashboard v1.4</title>
<style>body{margin:0;background:#050914;color:#e7fbff;font-family:Arial,'Microsoft JhengHei';font-size:13px}.wrap{padding:22px}.hero{border:1px solid #31486b;border-radius:16px;background:#0b1325;padding:20px;margin-bottom:16px}.title{font-size:28px;font-weight:900}.gold{color:#ffc107}.panel{border:1px solid #283c59;border-radius:12px;background:#0c1423;margin-bottom:16px;overflow:hidden}.panel h3{margin:0;padding:12px;border-bottom:1px solid #283c59}.body{padding:12px}.inp{background:#091222;color:#fff;border:1px solid #314966;padding:8px}.btn{background:#ffc107;color:#111;text-decoration:none;border:0;padding:9px 12px;font-weight:900}table{width:100%;border-collapse:collapse}th,td{border-bottom:1px solid #243650;padding:7px;font-size:12px}th{background:#101a2c}.scroll{max-height:600px;overflow:auto}</style></head>
<body><div class="wrap"><div class="hero"><div class="title">🏆 Chairman Framework <span class="gold">v1.4</span></div></div>
<div class="panel"><h3>Query</h3><div class="body"><form method="get">Race Date <input class="inp" type="date" name="race_date" value="<?=chairman_h($raceDate)?>"> Venue <input class="inp" name="venue" value="<?=chairman_h($venue)?>"> Race # <input class="inp" type="number" name="race_num" value="<?=chairman_h($raceNum)?>"> <button class="btn">Load</button> <a class="btn" href="../cache/build_today_cache.php?race_date=<?=chairman_h($raceDate)?>&venue=<?=chairman_h($venue)?>&race_num=<?=chairman_h($raceNum)?>">Build Cache</a></form></div></div>
<div class="panel"><h3>Race Summary</h3><div class="scroll"><table><tr><th>Race</th><th>Mode</th><th>Top</th><th>Q</th><th>Trio</th><th>Six-up</th><th>Avoid</th></tr><?php foreach($summary as $r): ?><tr><td>R<?=chairman_h($r['race_num'])?></td><td class="gold"><?=chairman_h($r['race_mode'])?></td><td class="gold"><?=chairman_h($r['top_horse'])?></td><td><?=chairman_h($r['q_suggestion'])?></td><td><?=chairman_h($r['trio_suggestion'])?></td><td><?=chairman_h($r['sixup_suggestion'])?></td><td><?=chairman_h($r['avoid_suggestion'])?></td></tr><?php endforeach; ?></table></div></div>
<div class="panel"><h3>Production Ranking</h3><div class="scroll"><table><tr><th>Race</th><th>Rank</th><th>Horse</th><th>Name</th><th>Role</th><th>Decision</th><th>Score</th></tr><?php foreach($ranking as $r): ?><tr><td>R<?=chairman_h($r['race_num'])?></td><td class="gold">#<?=chairman_h($r['race_rank'])?></td><td class="gold"><?=chairman_h($r['horse_num'])?></td><td><?=chairman_h($r['horse_name'])?></td><td><?=chairman_h($r['role_tag'])?></td><td><?=chairman_h($r['final_decision'])?></td><td class="gold"><?=number_format(chairman_n($r['calibrated_score']),1)?></td></tr><?php endforeach; ?></table></div></div></div></body></html>
