<?php
/**
 * Billing Clerk dashboard template (included by dashboard.php).
 * Uses $dashboard_data from getBillingClerkDashboardData().
 * Links to central billing screen (billing_center.php).
 */
if (!isset($dashboard_data)) {
    $dashboard_data = [
        'today_revenue' => 0,
        'pending_invoices' => 0,
        'outstanding_balance' => 0,
        'today_payments' => 0
    ];
}
$today_revenue = $dashboard_data['today_revenue'] ?? 0;
$pending_invoices = $dashboard_data['pending_invoices'] ?? 0;
$outstanding_balance = $dashboard_data['outstanding_balance'] ?? 0;
$today_payments = $dashboard_data['today_payments'] ?? 0;
?>
<div class="metrics-row">
    <div class="metric-card">
        <div class="metric-icon" style="background: #d1fae5; color: #059669;">
            <i class="ri-money-dollar-circle-line"></i>
        </div>
        <div class="metric-title">Today's Collections</div>
        <div class="metric-value text-success">KES <?php echo number_format($today_revenue, 0); ?></div>
    </div>
    <div class="metric-card">
        <div class="metric-icon" style="background: #dbeafe; color: #2563eb;">
            <i class="ri-bank-line"></i>
        </div>
        <div class="metric-title">Payments Today</div>
        <div class="metric-value"><?php echo (int)$today_payments; ?></div>
    </div>
    <div class="metric-card">
        <div class="metric-icon" style="background: #fef3c7; color: #d97706;">
            <i class="ri-file-list-3-line"></i>
        </div>
        <div class="metric-title">Pending Invoices</div>
        <div class="metric-value text-warning"><?php echo (int)$pending_invoices; ?></div>
    </div>
    <div class="metric-card">
        <div class="metric-icon" style="background: #fee2e2; color: #dc2626;">
            <i class="ri-alert-line"></i>
        </div>
        <div class="metric-title">Outstanding Balance</div>
        <div class="metric-value text-danger">KES <?php echo number_format($outstanding_balance, 0); ?></div>
    </div>
</div>

<div class="quick-actions">
    <a href="billing_center.php" class="quick-action">
        <div class="quick-action-icon"><i class="ri-dashboard-3-line"></i></div>
        <div class="quick-action-title">Billing Center</div>
        <small class="text-muted">Invoices, payments & patients billed</small>
    </a>
    <a href="record_payment.php" class="quick-action">
        <div class="quick-action-icon"><i class="ri-money-dollar-circle-line"></i></div>
        <div class="quick-action-title">Record Payment</div>
    </a>
    <a href="create_invoice.php" class="quick-action">
        <div class="quick-action-icon"><i class="ri-file-add-line"></i></div>
        <div class="quick-action-title">Create Invoice</div>
    </a>
    <a href="patient_billing_summary.php" class="quick-action">
        <div class="quick-action-icon"><i class="ri-user-search-line"></i></div>
        <div class="quick-action-title">Patient Billing</div>
    </a>
    <a href="list_invoices.php" class="quick-action">
        <div class="quick-action-icon"><i class="ri-file-list-3-line"></i></div>
        <div class="quick-action-title">All Invoices</div>
    </a>
    <a href="list_payments.php" class="quick-action">
        <div class="quick-action-icon"><i class="ri-bank-line"></i></div>
        <div class="quick-action-title">All Payments</div>
    </a>
</div>

<div class="table-card">
    <div class="table-header">
        <h5 class="table-title mb-0"><i class="ri-bank-card-line me-2"></i>Central Billing</h5>
    </div>
    <div class="p-4">
        <p class="text-muted mb-3">
            Use <strong>Billing Center</strong> to see all patients who have been billed or have been through the system,
            today's collections, recent invoices and payments, and quick actions in one place.
        </p>
        <a href="billing_center.php" class="btn btn-primary">
            <i class="ri-dashboard-3-line me-2"></i>Open Billing Center
        </a>
    </div>
</div>
