<?php $__env->startSection('title', 'Sales Report'); ?>

<?php $__env->startSection('header_title', 'Sales Report'); ?>
<?php $__env->startSection('header_subtitle', 'View sales report by date range'); ?>

<?php $__env->startSection('content'); ?>
    <div class="container-fluid">
        <!-- Date Filter -->
        <div class="card shadow mb-4">
            <div class="card-body">
                <form action="<?php echo e(route('admin.reports.sales')); ?>" method="GET" class="row g-3 align-items-end">
                    <div class="col-md-3">
                        <label class="form-label">Start Date</label>
                        <input type="date" name="start_date" class="form-control" value="<?php echo e($startDate); ?>">
                    </div>
                    <div class="col-md-3">
                        <label class="form-label">End Date</label>
                        <input type="date" name="end_date" class="form-control" value="<?php echo e($endDate); ?>">
                    </div>
                    <div class="col-md-3">
                        <label class="form-label">&nbsp;</label>
                        <button type="submit" class="btn btn-primary w-100">Filter</button>
                    </div>
                    <div class="col-md-3">
                        <label class="form-label">&nbsp;</label>
                        <div class="d-flex gap-1">
                            <a href="<?php echo e(route('admin.reports.sales', ['start_date' => now()->format('Y-m-d'), 'end_date' => now()->format('Y-m-d')])); ?>"
                                class="btn btn-sm <?php echo e($startDate === now()->format('Y-m-d') ? 'btn-success' : 'btn-outline-success'); ?> flex-fill">Hari Ini</a>
                            <a href="<?php echo e(route('admin.reports.sales', ['start_date' => now()->subDays(6)->format('Y-m-d'), 'end_date' => now()->format('Y-m-d')])); ?>"
                                class="btn btn-sm btn-outline-success flex-fill">7 Hari</a>
                            <a href="<?php echo e(route('admin.reports.sales', ['start_date' => now()->startOfMonth()->format('Y-m-d'), 'end_date' => now()->format('Y-m-d')])); ?>"
                                class="btn btn-sm <?php echo e($startDate === now()->startOfMonth()->format('Y-m-d') ? 'btn-success' : 'btn-outline-success'); ?> flex-fill">Bulan Ini</a>
                        </div>
                    </div>
                </form>
            </div>
        </div>

        <!-- Summary Cards -->
        <div class="row mb-4">
            <div class="col-md-6">
                <div class="card shadow bg-primary text-white">
                    <div class="card-body">
                        <h5 class="card-title">Total Orders</h5>
                        <h2 class="mb-0"><?php echo e($summary->total_orders ?? 0); ?></h2>
                    </div>
                </div>
            </div>
            <div class="col-md-6">
                <div class="card shadow bg-success text-white">
                    <div class="card-body">
                        <h5 class="card-title">Total Revenue</h5>
                        <h2 class="mb-0">Rp <?php echo e(number_format($summary->total_revenue ?? 0, 0, ',', '.')); ?></h2>
                    </div>
                </div>
            </div>
        </div>

        <!-- Top Products -->
        <div class="card shadow mb-4">
            <div class="card-header">
                <h5 class="mb-0">Top 10 Products</h5>
            </div>
            <div class="card-body">
                <div class="table-responsive">
                    <table class="table table-hover">
                        <thead>
                            <tr>
                                <th>Product</th>
                                <th>Total Qty Sold</th>
                                <th>Total Sales</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php $__empty_1 = true; $__currentLoopData = $topProducts; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                                <tr>
                                    <td><?php echo e($item->product->name ?? 'Deleted'); ?></td>
                                    <td><?php echo e($item->total_qty); ?></td>
                                    <td>Rp <?php echo e(number_format($item->total_sales, 0, ',', '.')); ?></td>
                                </tr>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                                <tr>
                                    <td colspan="3" class="text-center py-4">
                                        <p class="text-muted">No products sold in this period</p>
                                    </td>
                                </tr>
                            <?php endif; ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>

        <!-- Orders List -->
        <div class="card shadow">
            <div class="card-header">
                <h5 class="mb-0">Orders (<?php echo e($startDate); ?> - <?php echo e($endDate); ?>)</h5>
            </div>
            <div class="card-body">
                <div class="table-responsive">
                    <table class="table table-hover">
                        <thead>
                            <tr>
                                <th>Order Code</th>
                                <th>Customer</th>
                                <th>Items</th>
                                <th>Total</th>
                                <th>Payment</th>
                                <th>Status</th>
                                <th>Date</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php $__empty_1 = true; $__currentLoopData = $orders; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $order): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                                <tr>
                                    <td><?php echo e($order->order_code); ?></td>
                                    <td><?php echo e($order->user->name); ?></td>
                                    <td>
                                        <?php $__currentLoopData = $order->items; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <div><?php echo e($item->product->name); ?> x <?php echo e($item->quantity); ?></div>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </td>
                                    <td>Rp <?php echo e(number_format($order->total_amount, 0, ',', '.')); ?></td>
                                    <td><?php echo e($order->payment_method ?? '-'); ?></td>
                                    <td><span class="badge bg-<?php echo e($order->status_color); ?>"><?php echo e($order->status); ?></span></td>
                                    <td><?php echo e($order->created_at->format('d/m/Y H:i')); ?></td>
                                </tr>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                                <tr>
                                    <td colspan="7" class="text-center py-4">
                                        <p class="text-muted">No orders found in this period</p>
                                    </td>
                                </tr>
                            <?php endif; ?>
                        </tbody>
                    </table>
                    <div class="mt-4"><?php echo e($orders->links()); ?></div>
                </div>
            </div>
        </div>
    </div>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.layout-admin', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH C:\xampp\htdocs\e-commerce\resources\views/admin/report-sales.blade.php ENDPATH**/ ?>