<?= $this->extend('layout/main') ?>
<?= $this->section('content') ?>

<h5 class="mb-4">Parametres de l'entreprise</h5>

<div class="row">
    <div class="col-lg-8">
        <div class="table-card">
            <form method="POST" action="/settings" enctype="multipart/form-data">
                <?= csrf_field() ?>
                <div class="row g-3">
                    <div class="col-md-6">
                        <label class="form-label">Nom court *</label>
                        <input type="text" name="name" class="form-control" value="<?= $company['name'] ?? '' ?>" required>
                    </div>
                    <div class="col-md-6">
                        <label class="form-label">Nom complet</label>
                        <input type="text" name="full_name" class="form-control" value="<?= $company['full_name'] ?? '' ?>">
                    </div>
                    <div class="col-md-8">
                        <label class="form-label">Adresse</label>
                        <textarea name="address" class="form-control" rows="2"><?= $company['address'] ?? '' ?></textarea>
                    </div>
                    <div class="col-md-4">
                        <label class="form-label">Logo</label>
                        <input type="file" name="logo" class="form-control" accept="image/*">
                        <?php if (!empty($company['logo'])): ?>
                            <small class="text-muted">Actuel: <?= $company['logo'] ?></small>
                        <?php endif; ?>
                    </div>
                    <div class="col-md-4">
                        <label class="form-label">Ville</label>
                        <input type="text" name="city" class="form-control" value="<?= $company['city'] ?? '' ?>">
                    </div>
                    <div class="col-md-4">
                        <label class="form-label">Pays</label>
                        <input type="text" name="country" class="form-control" value="<?= $company['country'] ?? 'Tunisie' ?>">
                    </div>
                    <div class="col-md-4">
                        <label class="form-label">Telephone</label>
                        <input type="text" name="phone" class="form-control" value="<?= $company['phone'] ?? '' ?>">
                    </div>
                    <div class="col-md-4">
                        <label class="form-label">Fax</label>
                        <input type="text" name="fax" class="form-control" value="<?= $company['fax'] ?? '' ?>">
                    </div>
                    <div class="col-md-4">
                        <label class="form-label">GSM</label>
                        <input type="text" name="gsm" class="form-control" value="<?= $company['gsm'] ?? '' ?>">
                    </div>
                    <div class="col-md-6">
                        <label class="form-label">Email</label>
                        <input type="email" name="email" class="form-control" value="<?= $company['email'] ?? '' ?>">
                    </div>
                    <div class="col-md-6">
                        <label class="form-label">Matricule fiscal</label>
                        <input type="text" name="tax_id" class="form-control" value="<?= $company['tax_id'] ?? '' ?>">
                    </div>
                    <div class="col-md-6">
                        <label class="form-label">ICE</label>
                        <input type="text" name="ice" class="form-control" value="<?= $company['ice'] ?? '' ?>">
                    </div>
                    <div class="col-md-3">
                        <label class="form-label">Devise</label>
                        <select name="currency" class="form-select">
                            <option value="TND" <?= ($company['currency'] ?? '') === 'TND' ? 'selected' : '' ?>>TND</option>
                            <option value="EUR" <?= ($company['currency'] ?? '') === 'EUR' ? 'selected' : '' ?>>EUR</option>
                            <option value="USD" <?= ($company['currency'] ?? '') === 'USD' ? 'selected' : '' ?>>USD</option>
                        </select>
                    </div>
                    <div class="col-md-3">
                        <label class="form-label">TVA par defaut (%)</label>
                        <input type="number" step="0.01" name="default_vat_rate" class="form-control" value="<?= ($company['default_vat_rate'] ?? 0.19) * 100 ?>">
                    </div>
                    <div class="col-md-4">
                        <label class="form-label">Prefix facture</label>
                        <input type="text" name="invoice_prefix" class="form-control" value="<?= $company['invoice_prefix'] ?? 'FAC' ?>">
                    </div>
                    <div class="col-md-4">
                        <label class="form-label">N debut facture</label>
                        <input type="number" name="invoice_start_number" class="form-control" value="<?= $company['invoice_start_number'] ?? 1 ?>">
                    </div>
                    <div class="col-md-4">
                        <label class="form-label">Delai paiement (jours)</label>
                        <input type="number" name="payment_terms" class="form-control" value="<?= $company['payment_terms'] ?? 30 ?>">
                    </div>
                    <div class="col-md-6">
                        <label class="form-label">Banque</label>
                        <input type="text" name="bank_name" class="form-control" value="<?= $company['bank_name'] ?? '' ?>">
                    </div>
                    <div class="col-md-6">
                        <label class="form-label">RIB</label>
                        <input type="text" name="bank_rib" class="form-control" value="<?= $company['bank_rib'] ?? '' ?>">
                    </div>
                </div>
                <div class="d-flex justify-content-between mt-4">
                    <a href="/dashboard" class="btn btn-outline-secondary">Annuler</a>
                    <button type="submit" class="btn btn-primary">
                        <i class="bi bi-check-lg"></i> Enregistrer
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>

<?= $this->endSection() ?>
