<?php
/**
 * @var string $date
 * @var array $sales
 * @var object $summary
 */
?>
<div class="page-title mb-4">
    <h5><i class="fas fa-dollar-sign me-2 text-gold"></i>Daily Sales Report</h5>
</div>

<div class="glass-card p-3 mb-4">
    <form class="row g-3 align-items-end" method="GET" action="<?= url('reports/daily-sales') ?>">
        <div class="col-md-4">
            <label class="form-label">Date</label>
            <input type="date" name="date" class="form-control" value="<?= e($date) ?>">
        </div>
        <div class="col-md-4">
            <button type="submit" class="btn btn-gold"><i class="fas fa-search me-1"></i>Generate</button>
            <a href="<?= url('reports/export/daily_sales?date=' . $date) ?>" class="btn btn-outline-gold ms-2">
                <i class="fas fa-download me-1"></i>CSV
            </a>
        </div>
    </form>
</div>

<div class="row g-4 mb-4">
    <div class="col-md-3">
        <div class="glass-card stats-card">
            <div class="stats-icon" style="background:rgba(200,164,78,0.15);border-color:rgba(200,164,78,0.3);color:var(--gold-primary);">
                <i class="fas fa-file-invoice"></i>
            </div>
            <div class="stats-info">
                <span class="stats-label">Total Invoices</span>
                <span class="stats-value"><?= $summary->total_invoices ?? 0 ?></span>
            </div>
        </div>
    </div>
    <div class="col-md-3">
        <div class="glass-card stats-card">
            <div class="stats-icon" style="background:rgba(13,202,240,0.15);border-color:rgba(13,202,240,0.3);color:#0dcaf0;">
                <i class="fas fa-dollar-sign"></i>
            </div>
            <div class="stats-info">
                <span class="stats-label">Total Sales</span>
                <span class="stats-value"><?= currency($summary->total_sales ?? 0) ?></span>
            </div>
        </div>
    </div>
    <div class="col-md-3">
        <div class="glass-card stats-card">
            <div class="stats-icon" style="background:rgba(220,53,69,0.15);border-color:rgba(220,53,69,0.3);color:#dc3545;">
                <i class="fas fa-tags"></i>
            </div>
            <div class="stats-info">
                <span class="stats-label">Discounts</span>
                <span class="stats-value"><?= currency($summary->total_discounts ?? 0) ?></span>
            </div>
        </div>
    </div>
    <div class="col-md-3">
        <div class="glass-card stats-card">
            <div class="stats-icon" style="background:rgba(25,135,84,0.15);border-color:rgba(25,135,84,0.3);color:#198754;">
                <i class="fas fa-hand-holding-usd"></i>
            </div>
            <div class="stats-info">
                <span class="stats-label">Net Total</span>
                <span class="stats-value"><?= currency($summary->net_total ?? 0) ?></span>
            </div>
        </div>
    </div>
</div>

<div class="glass-card p-0">
    <div class="card-header">
        <div class="card-header-left">
            <i class="fas fa-list card-icon"></i>
            <h6 class="card-title">Sales Details</h6>
        </div>
        <span class="badge bg-gold"><?= count($sales) ?> transactions</span>
    </div>
    <div class="table-responsive">
        <table class="table table-dark table-hover mb-0">
            <thead>
                <tr>
                    <th>Invoice #</th>
                    <th>Customer</th>
                    <th>Service</th>
                    <th>Employee</th>
                    <th>Time</th>
                    <th>Total</th>
                    <th>Payment</th>
                    <th>Status</th>
                </tr>
            </thead>
            <tbody>
                <?php if (empty($sales)): ?>
                    <tr><td colspan="8" class="text-center text-muted py-4">No sales for this date</td></tr>
                <?php else: ?>
                    <?php foreach ($sales as $sale): ?>
                        <tr>
                            <td><a href="<?= url('invoices/view/' . ($sale->invoice_number ?? '')) ?>" class="text-gold"><?= e($sale->invoice_number ?? 'N/A') ?></a></td>
                            <td><?= e(($sale->customer_first_name ?? '') . ' ' . ($sale->customer_last_name ?? '')) ?></td>
                            <td><?= e($sale->service_name ?? '-') ?></td>
                            <td><?= e(($sale->employee_first_name ?? '') . ' ' . ($sale->employee_last_name ?? '')) ?></td>
                            <td><?= $sale->created_at ? formatTime($sale->created_at) : '-' ?></td>
                            <td><?= currency($sale->total ?? 0) ?></td>
                            <td><?= e(ucwords(str_replace('_', ' ', $sale->payment_method ?? ''))) ?></td>
                            <td><span class="badge bg-<?= statusBadge($sale->status ?? '') ?>"><?= e(ucfirst($sale->status ?? '')) ?></span></td>
                        </tr>
                    <?php endforeach; ?>
                <?php endif; ?>
            </tbody>
        </table>
    </div>
</div>
