<?php
require_once __DIR__ . '/includes/mj_v304_bootstrap.php';
require_once __DIR__ . '/includes/mj_v304_review_helper.php';
mjv304_require_login();
$userId=mjv304_current_user_id();
$status=trim((string)($_GET['status'] ?? ''));
$page=max(1,(int)($_GET['page'] ?? 1));$limit=25;$offset=($page-1)*$limit;
$where=['user_id=?'];$params=[$userId];
if($status!==''){ $where[]='status=?'; $params[]=$status; }
if(!empty($_GET['review_id'])){ $where[]='id=?'; $params[]=(int)$_GET['review_id']; }
$whereSql=implode(' AND ',$where);
$total=(int)mjv304_fetch_value("SELECT COUNT(*) FROM mj_admin_review_queue WHERE $whereSql", $params);
$rows=mjv304_fetch_all("SELECT * FROM mj_admin_review_queue WHERE $whereSql ORDER BY submitted_at DESC,id DESC LIMIT $limit OFFSET $offset", $params);
?>
<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>My Review Submissions</title><link rel="stylesheet" href="assets/css/mj-v304.css?v=304"></head><body>
<div class="mj-v304-wrap">
  <div class="mj-page-head"><div><h1>My Review Submissions</h1><p>Active item changes wait for admin approval. Old live version stays active until approved.</p></div><div><?php include __DIR__ . '/includes/mj_v304_notification_widget.php'; ?></div></div>
  <?php if(!empty($_GET['submitted'])): ?><div class="mj-card" style="border-color:#bbf7d0;background:#f0fdf4;margin-bottom:12px;">Changes submitted for admin review.</div><?php endif; ?>
  <form class="mj-card mj-filter" method="get" style="grid-template-columns:1fr auto auto;"><div><label>Status</label><select name="status"><option value="">All</option><?php foreach(['pending'=>'Pending','approved'=>'Approved','rejected'=>'Rejected'] as $k=>$v): ?><option value="<?php echo $k; ?>" <?php echo $status===$k?'selected':''; ?>><?php echo $v; ?></option><?php endforeach; ?></select></div><div><label>&nbsp;</label><button class="mj-btn mj-btn-primary">Filter</button></div><div><label>&nbsp;</label><a class="mj-btn" href="my-reviews.php">Reset</a></div></form>
  <div class="mj-table-wrap"><table class="mj-table"><thead><tr><th>ID</th><th>Item</th><th>Status</th><th>Submitted</th><th>Admin Reason</th></tr></thead><tbody>
  <?php if(!$rows): ?><tr><td colspan="5"><div class="mj-empty">No review submissions found.</div></td></tr><?php endif; ?>
  <?php foreach($rows as $r): ?><tr><td>#<?php echo (int)$r['id']; ?></td><td><?php echo mjv304_e(ucfirst($r['item_type'])); ?> #<?php echo (int)$r['item_id']; ?></td><td><span class="mj-badge <?php echo mjv304_badge_class($r['status']); ?>"><?php echo mjv304_e($r['status']); ?></span></td><td><?php echo mjv304_e(date('d M Y H:i', strtotime($r['submitted_at']))); ?></td><td><?php echo nl2br(mjv304_e($r['reject_reason'] ?: '-')); ?></td></tr><?php endforeach; ?>
  </tbody></table></div>
</div>
</body></html>
