<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-arrow-left-right"></i> Nouveau Transfert</h5>
                <a href="<?= site_url('transfers'); ?>" 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 mb-4">
                    <i class="bi bi-info-circle"></i>
                    Un transfert est un <strong>mouvement interne</strong> entre caisses (approvisionnement). 
                    Ce n'est pas une dépense. Référence : <code><?= $reference; ?></code>
                </div>

                <?= form_open_multipart('transfers/create'); ?>

                <div class="row">
                    <!-- Date -->
                    <div class="col-md-4 mb-3">
                        <label class="form-label">Date du transfert <span class="text-danger">*</span></label>
                        <input type="date" name="transfer_date" class="form-control" required
                               value="<?= set_value('transfer_date', date('Y-m-d')); ?>">
                    </div>

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

                    <div class="col-md-4"></div>

                    <!-- Caisse source -->
                    <div class="col-md-5 mb-3">
                        <label class="form-label">Caisse source <span class="text-danger">*</span></label>
                        <select name="source_cashbox_id" class="form-select" required>
                            <option value="">-- Débiter de --</option>
                            <?php foreach ($cashboxes as $cb): ?>
                            <option value="<?= $cb->id; ?>" <?= set_select('source_cashbox_id', $cb->id); ?>>
                                <?= $cb->name; ?> (<?= number_format($cb->current_balance, 0, ',', ' '); ?> KMF)
                            </option>
                            <?php endforeach; ?>
                        </select>
                    </div>

                    <!-- Flèche -->
                    <div class="col-md-2 mb-3 d-flex align-items-end justify-content-center pb-2">
                        <i class="bi bi-arrow-right fs-3 text-primary"></i>
                    </div>

                    <!-- Caisse destination -->
                    <div class="col-md-5 mb-3">
                        <label class="form-label">Caisse destination <span class="text-danger">*</span></label>
                        <select name="dest_cashbox_id" class="form-select" required>
                            <option value="">-- Créditer vers --</option>
                            <?php foreach ($cashboxes as $cb): ?>
                            <option value="<?= $cb->id; ?>" <?= set_select('dest_cashbox_id', $cb->id); ?>>
                                <?= $cb->name; ?> (<?= number_format($cb->current_balance, 0, ',', ' '); ?> KMF)
                            </option>
                            <?php endforeach; ?>
                        </select>
                    </div>

                    <!-- Justificatif -->
                    <div class="col-md-6 mb-3">
                        <label class="form-label">Justificatif (reçu)</label>
                        <input type="file" name="receipt" class="form-control" accept=".jpg,.jpeg,.png,.pdf">
                        <div class="form-text">JPG, PNG ou PDF. Max 5 Mo.</div>
                    </div>

                    <!-- Notes -->
                    <div class="col-12 mb-3">
                        <label class="form-label">Notes</label>
                        <textarea name="notes" class="form-control" rows="2" 
                                  placeholder="Motif du transfert..."><?= set_value('notes'); ?></textarea>
                    </div>
                </div>

                <hr>
                <div class="d-flex gap-2">
                    <button type="submit" class="btn btn-primary">
                        <i class="bi bi-check-lg"></i> Créer le transfert
                    </button>
                    <a href="<?= site_url('transfers'); ?>" class="btn btn-outline-secondary">Annuler</a>
                </div>

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