<?php require dirname(__DIR__) . '/layouts/app.php'; ?>

<?php $isEdit = !empty($client['id']); ?>

<section class="page-heading">
    <div>
        <p class="eyebrow">Clients</p>
        <h1><?= $isEdit ? 'Modifier client' : 'Ajouter client' ?></h1>
    </div>
    <a class="button-link secondary" href="<?= url('/clients') ?>">Retour</a>
</section>

<?php if (!empty($errors)): ?>
    <div class="alert alert-error">
        <?php foreach ($errors as $error): ?>
            <div><?= e($error) ?></div>
        <?php endforeach; ?>
    </div>
<?php endif; ?>

<form class="form-panel" method="post" action="<?= url($isEdit ? '/clients/update' : '/clients/store') ?>">
    <input type="hidden" name="_token" value="<?= csrf_token() ?>">
    <?php if ($isEdit): ?>
        <input type="hidden" name="id" value="<?= (int) $client['id'] ?>">
    <?php endif; ?>

    <div class="form-grid">
        <label>
            Prenom
            <input type="text" name="first_name" value="<?= e($client['first_name']) ?>" required>
        </label>

        <label>
            Nom
            <input type="text" name="last_name" value="<?= e($client['last_name']) ?>" required>
        </label>

        <label>
            Telephone
            <input type="text" name="phone" value="<?= e($client['phone']) ?>">
        </label>

        <label>
            Email
            <input type="email" name="email" value="<?= e($client['email']) ?>">
        </label>

        <label>
            Numero identite
            <input type="text" name="identity_number" value="<?= e($client['identity_number']) ?>">
        </label>

        <label>
            Adresse
            <input type="text" name="address" value="<?= e($client['address']) ?>">
        </label>
    </div>

    <label class="full-field">
        Notes
        <textarea name="notes" rows="5"><?= e($client['notes']) ?></textarea>
    </label>

    <div class="form-actions">
        <button type="submit"><?= $isEdit ? 'Enregistrer' : 'Ajouter' ?></button>
    </div>
</form>

<?php require dirname(__DIR__) . '/layouts/app_footer.php'; ?>
