<div class="row justify-content-center">
    <div class="col-lg-8">
        <div class="card shadow-sm">
            <div class="card-header bg-white d-flex justify-content-between align-items-center">
                <h5 class="mb-0"><i class="bi bi-file-earmark-plus"></i> Nouvelle Demande de Dépense</h5>
                <a href="<?= site_url('requests'); ?>" class="btn btn-sm btn-outline-secondary">
                    <i class="bi bi-arrow-left"></i> Retour
                </a>
            </div>
            <div class="card-body">
                <div class="alert alert-info py-2">
                    <i class="bi bi-info-circle"></i>
                    Une demande de dépense doit être <strong>approuvée par l'Operation Manager</strong> 
                    avant que le paiement soit effectué. Référence : <code><?= $reference; ?></code>
                </div>

                <?= form_open('requests/create'); ?>

                <div class="row">
                    <!-- Catégorie -->
                    <div class="col-md-6 mb-3">
                        <label class="form-label">Catégorie <span class="text-danger">*</span></label>
                        <select name="category_id" class="form-select" required>
                            <option value="">-- Choisir --</option>
                            <?php foreach ($categories as $cat): ?>
                            <option value="<?= $cat->id; ?>" <?= set_select('category_id', $cat->id); ?>>
                                <?= $cat->label; ?>
                            </option>
                            <?php endforeach; ?>
                        </select>
                    </div>

                    <!-- Localisation -->
                    <div class="col-md-6 mb-3">
                        <label class="form-label">Localisation <span class="text-danger">*</span></label>
                        <select name="location_id" class="form-select" required>
                            <?php foreach ($locations as $loc): ?>
                            <option value="<?= $loc->id; ?>" 
                                <?= set_select('location_id', $loc->id, $this->auth_lib->location_id() == $loc->id); ?>>
                                <?= $loc->name; ?>
                            </option>
                            <?php endforeach; ?>
                        </select>
                    </div>

                    <!-- Fournisseur -->
                    <div class="col-md-6 mb-3">
                        <label class="form-label">Fournisseur (si connu)</label>
                        <input type="text" name="supplier" class="form-control"
                               value="<?= set_value('supplier'); ?>" placeholder="Optionnel">
                    </div>

                    <!-- Montant estimé -->
                    <div class="col-md-6 mb-3">
                        <label class="form-label">Montant estimé <span class="text-danger">*</span></label>
                        <div class="input-group">
                            <input type="number" name="estimated_amount" class="form-control"
                                   step="1" min="1" required value="<?= set_value('estimated_amount'); ?>">
                            <span class="input-group-text">KMF</span>
                        </div>
                    </div>

                    <!-- Description -->
                    <div class="col-12 mb-3">
                        <label class="form-label">Description / Justification <span class="text-danger">*</span></label>
                        <textarea name="description" class="form-control" rows="3" required
                                  placeholder="Décrivez le besoin, le contexte et la justification de cette dépense..."><?= set_value('description'); ?></textarea>
                    </div>
                </div>

                <hr>
                <div class="d-flex gap-2">
                    <button type="submit" class="btn btn-primary">
                        <i class="bi bi-send"></i> Soumettre la demande
                    </button>
                    <a href="<?= site_url('requests'); ?>" class="btn btn-outline-secondary">Annuler</a>
                </div>

                <?= form_close(); ?>
            </div>
        </div>
    </div>
</div>
