<?php
require_once __DIR__ . '/inc/layout.php';
require_once __DIR__ . '/inc/utils.php';

require_login();
$rules = load_bid_rules();

$enabledCount = 0;
foreach ($rules as $r) {
    if (!empty($r['enabled'])) $enabledCount++;
}

page_header('Dashboard');
?>

<div class="row g-3">
    <div class="col-12">
        <div class="card soft-card">
            <div class="card-body">
                <div class="d-flex flex-column flex-lg-row justify-content-between align-items-lg-center gap-3">
                    <div>
                        <h2 class="h3 mb-1">Dashboard</h2>
                        <div class="text-muted">Quick access to ServiceDirect, Twilio, merged logs, and bid controls.</div>
                    </div>
                    <div class="d-flex flex-wrap gap-2">
                        <a class="btn btn-primary" href="view.php?log=sd&range=24h">ServiceDirect Logs</a>
                        <a class="btn btn-outline-primary" href="view.php?log=twilio&range=24h">Twilio Logs</a>
                        <a class="btn btn-outline-dark" href="view.php?log=merged&range=24h">Merged View</a>
                        <a class="btn btn-outline-success" href="bid-control/index.php">Minimum Bid Control</a>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="col-md-6 col-xl-3">
        <div class="dashboard-tile">
            <h6>ServiceDirect</h6>
            <div class="count">SD</div>
            <div class="text-muted small">Review ping, accept, bids, buyer IDs and routing decisions.</div>
            <a href="view.php?log=sd&range=24h" class="btn btn-sm btn-outline-primary mt-3">Open SD Logs</a>
        </div>
    </div>

    <div class="col-md-6 col-xl-3">
        <div class="dashboard-tile">
            <h6>Twilio</h6>
            <div class="count">TW</div>
            <div class="text-muted small">Review incoming legs, caller numbers, verticals, steps and digits.</div>
            <a href="view.php?log=twilio&range=24h" class="btn btn-sm btn-outline-primary mt-3">Open Twilio Logs</a>
        </div>
    </div>

    <div class="col-md-6 col-xl-3">
        <div class="dashboard-tile">
            <h6>Merged View</h6>
            <div class="count">MX</div>
            <div class="text-muted small">Match Twilio and ServiceDirect by CallSid in one place.</div>
            <a href="view.php?log=merged&range=24h" class="btn btn-sm btn-outline-dark mt-3">Open Merged View</a>
        </div>
    </div>

    <div class="col-md-6 col-xl-3">
        <div class="dashboard-tile">
            <h6>Active Bid Rules</h6>
            <div class="count"><?= (int)$enabledCount ?></div>
            <div class="text-muted small">Categories currently using minimum bid threshold logic.</div>
            <a href="bid-control/index.php" class="btn btn-sm btn-outline-success mt-3">Manage Thresholds</a>
        </div>
    </div>
</div>

<?php page_footer(); ?>