@extends('admin.layout.dashboard_master')

@section('content')
    <main id="main" class="main">
        <div class="pagetitle">
            <div class="d-flex justify-content-between align-items-center">
                <div>
                    <h1>Koombiyo Reports</h1>
                    <nav>
                        <ol class="breadcrumb">
                            <li class="breadcrumb-item"><a href="index.html">American Plastic</a></li>
                            <li class="breadcrumb-item">Dashboard</li>
                            <li class="breadcrumb-item active">Koombiyo Reports</li>
                        </ol>
                    </nav>
                </div>
            </div>
        </div><!-- End Page Title -->

        <section class="section">
            <div class="row">
                <div class="col-lg-12">
                    <div class="card">
                        <div class="card-body">
                            <h5 class="card-title">Generate Order Reports</h5>

                            <form id="reportForm" action="{{ route('admin.koombiyo.download') }}" method="POST">
                                @csrf

                                <div class="row mb-3">
                                    <div class="col-md-4">
                                        <label for="start_date" class="form-label">Start Date</label>
                                        <input type="date" class="form-control" id="start_date" name="start_date" required>
                                    </div>

                                    <div class="col-md-4">
                                        <label for="end_date" class="form-label">End Date</label>
                                        <input type="date" class="form-control" id="end_date" name="end_date" required>
                                    </div>

                                </div>

                                <div class="row mb-3">
                                    <div class="col-md-4">
                                        <label for="report_type" class="form-label">Report Format</label>
                                        <select class="form-select" id="report_type" name="report_type" required>
                                            <option value="excel">Excel (.xlsx)</option>
                                            <option value="csv">CSV (.csv)</option>
                                        </select>
                                    </div>
                                    <div class="col-md-4">
                                        <label for="status" class="form-label">Order Status</label>
                                        <select class="form-select" id="status" name="status">
                                            <option value="all">All Orders</option>
                                            <option value="processing">Processing</option>
                                            <option value="ready">Ready for Pickup</option>
                                            <option value="picked">Picked</option>
                                            <option value="on_the_way">On The Way</option>
                                            <option value="delivered">Delivered</option>
                                            <option value="cancelled">Cancelled</option>
                                        </select>
                                    </div>
                                </div>

                                <div class="text-center">
                                    <button type="submit" class="btn btn-primary">
                                        <i class="bi bi-download me-1"></i> Download Report
                                    </button>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </section>

    </main><!-- End #main -->

    @push('scripts')
        <script>
            document.addEventListener('DOMContentLoaded', function() {
                // Set default dates (optional)
                const today = new Date();
                const oneWeekAgo = new Date();
                oneWeekAgo.setDate(today.getDate() - 7);

                document.getElementById('start_date').valueAsDate = oneWeekAgo;
                document.getElementById('end_date').valueAsDate = today;

                // Validate date range
                document.getElementById('reportForm').addEventListener('submit', function(e) {
                    const startDate = new Date(document.getElementById('start_date').value);
                    const endDate = new Date(document.getElementById('end_date').value);

                    if (startDate > endDate) {
                        e.preventDefault();
                        alert('End date must be greater than or equal to start date');
                    }
                });
            });
        </script>
    @endpush
@endsection
