<?php
require_once __DIR__.'/../includes/functions.php';
require_once __DIR__.'/../includes/v292_admin_portal_helpers.php';
$admin = require_admin(); mj292_ensure_schema();
$adminTitle = 'Admin Control Center';
$adminSubtitle = 'Clean command page for daily marketplace operations, automation, payment review and reports.';
$stats = mj292_admin_stats();
$queue = mj292_action_queue();
include __DIR__.'/_header.php';
?>
<div class="card mj-v292-card mb-3"><div class="card-body">
  <div class="d-flex flex-wrap justify-content-between align-items-center">
    <div><span class="badge badge-primary mb-2">v2.9.12</span><h3 class="font-weight-bold mb-1">Automated marketplace control room</h3><p class="text-muted mb-0">Everything runs automatically except user-to-admin manual payment proof approval and wallet top-up approval. Customer-to-seller payment is disabled.</p></div>
    <div class="mt-3 mt-md-0"><a href="action-queue.php" class="btn btn-primary mj-v292-pill"><i class="fas fa-clipboard-check mr-1"></i>Open Action Queue</a> <a href="reports.php" class="btn btn-outline-primary mj-v292-pill"><i class="fas fa-chart-line mr-1"></i>Reports</a></div>
  </div>
</div></div>
<?php mj292_quick_cards([
  ['Pending Payments','User-to-admin proof only', 'payment-center.php?tab=review', $stats['payment_pending'], 'warning', 'fas fa-receipt'],
  ['Active Listings','Published now','listings.php?status=active', $stats['listings_active'], 'success', 'fas fa-tags'],
  ['Open Invoices','Waiting payment / approval','payment-center.php?tab=invoices', $stats['invoice_open'], 'info', 'fas fa-file-invoice'],
  ['Wallet Balance','All user wallets','payment-center.php?tab=wallet', mj292_money0($stats['wallet_balance'],'SGD'), 'primary', 'fas fa-wallet'],
  ['Pending Listings','Review if auto approval is off','listings.php?status=pending', $stats['listings_pending'], 'secondary', 'fas fa-clock'],
  ['Pending Companies','Review if auto approval is off','companies.php?status=pending', $stats['companies_pending'], 'secondary', 'fas fa-building'],
  ['Support Tickets','Need admin reply','support.php', $stats['support_open'], 'danger', 'fas fa-headset'],
  ['Receipts','Generated automatically','report-receipts.php', $stats['receipts_total'], 'success', 'fas fa-receipt'],
]); ?>
<div class="row">
  <div class="col-lg-8">
    <div class="card mj-v292-card"><div class="card-header"><h3 class="card-title"><i class="fas fa-tasks mr-2"></i>Admin action queue</h3></div><div class="card-body">
      <?php foreach($queue as $q): ?>
      <a class="mj-v292-action" href="<?=e($q[2])?>"><span><i class="<?=e($q[3])?> text-<?=e($q[4])?> mr-2"></i><b><?=e($q[0])?></b><br><small class="mj-v292-muted"><?=e($q[1])?></small></span><span class="badge badge-<?=e($q[4])?> badge-pill p-2"><?=e($q[5])?></span></a>
      <?php endforeach; ?>
    </div></div>
  </div>
  <div class="col-lg-4">
    <div class="card mj-v292-card"><div class="card-header"><h3 class="card-title"><i class="fas fa-magic mr-2"></i>Automation Rules</h3></div><div class="card-body">
      <ul class="list-unstyled mb-0">
        <li class="mb-2"><i class="fas fa-check-circle text-success mr-1"></i> Wallet full invoice payment auto-approves.</li>
        <li class="mb-2"><i class="fas fa-check-circle text-success mr-1"></i> Receipt generation is automatic after paid status.</li>
        <li class="mb-2"><i class="fas fa-check-circle text-success mr-1"></i> Paid services activate automatically after approval.</li>
        <li class="mb-2"><i class="fas fa-lock text-danger mr-1"></i> User-to-admin manual payment proof still requires admin approval.</li>
        <li class="mb-2"><i class="fas fa-lock text-danger mr-1"></i> Wallet top-up still requires admin approval.</li>
      </ul><hr><a href="automation-settings.php" class="btn btn-outline-primary btn-block">Automation Settings</a>
    </div></div>
  </div>
</div>
<?php include __DIR__.'/_footer.php'; ?>
