<div class="row justify-content-center">
    <div class="col-lg-8">
        <div class="card">
            <div class="card-header"><h5 class="mb-0"><i class="fas fa-plus me-2"></i><?= lang('reports.create_schedule') ?></h5></div>
            <div class="card-body">
                <form id="schedule-form" data-ajax="true" method="POST" action="/api/reports/schedules">
                    <?= csrf_field() ?>
                    <div class="row g-3">
                        <div class="col-md-6">
                            <label class="form-label">Schedule Name <span class="text-danger">*</span></label>
                            <input type="text" name="schedule_name" class="form-control" required>
                            <div class="invalid-feedback" data-field="schedule_name"></div>
                        </div>
                        <div class="col-md-6">
                            <label class="form-label">Report <span class="text-danger">*</span></label>
                            <select name="report_id" class="form-select" required>
                                <option value="">-- Select --</option>
                                <?php foreach ($reports as $r): ?>
                                <option value="<?= (int)$r['id'] ?>"><?= e($r['report_name_en']) ?> (<?= e($r['report_code']) ?>)</option>
                                <?php endforeach; ?>
                            </select>
                            <div class="invalid-feedback" data-field="report_id"></div>
                        </div>
                        <div class="col-md-4">
                            <label class="form-label">Frequency <span class="text-danger">*</span></label>
                            <select name="frequency" class="form-select" required>
                                <option value="daily">Daily</option>
                                <option value="weekly">Weekly</option>
                                <option value="monthly" selected>Monthly</option>
                                <option value="quarterly">Quarterly</option>
                                <option value="yearly">Yearly</option>
                            </select>
                        </div>
                        <div class="col-md-4">
                            <label class="form-label">Day of Week (for weekly)</label>
                            <select name="day_of_week" class="form-select">
                                <option value="">N/A</option>
                                <option value="0">Sunday</option><option value="1">Monday</option><option value="2">Tuesday</option><option value="3">Wednesday</option><option value="4">Thursday</option><option value="5">Friday</option><option value="6">Saturday</option>
                            </select>
                        </div>
                        <div class="col-md-4">
                            <label class="form-label">Day of Month</label>
                            <input type="number" name="day_of_month" class="form-control" min="1" max="28" value="1">
                        </div>
                        <div class="col-md-4">
                            <label class="form-label">Time <span class="text-danger">*</span></label>
                            <input type="time" name="time_of_day" class="form-control" value="06:00" required>
                        </div>
                        <div class="col-md-4">
                            <label class="form-label">Output Format <span class="text-danger">*</span></label>
                            <select name="output_format" class="form-select" required>
                                <option value="pdf">PDF</option>
                                <option value="excel">Excel</option>
                                <option value="csv">CSV</option>
                            </select>
                        </div>
                        <div class="col-md-4">
                            <label class="form-label">Delivery <span class="text-danger">*</span></label>
                            <select name="delivery_method" class="form-select" required>
                                <option value="email">Email</option>
                                <option value="in_app">In-App</option>
                                <option value="save">Save to Server</option>
                                <option value="both_email_save">Email + Save</option>
                            </select>
                        </div>
                        <div class="col-12">
                            <label class="form-label">Recipients (comma-separated emails)</label>
                            <input type="text" name="recipients" class="form-control" placeholder="admin@club.com, finance@club.com">
                        </div>
                    </div>
                    <div class="mt-4 d-flex gap-2">
                        <button type="submit" class="btn btn-primary"><i class="fas fa-save me-1"></i><?= lang('common.save') ?></button>
                        <a href="/reports/schedules" class="btn btn-secondary"><?= lang('common.cancel') ?></a>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>