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

<h3 class="mb-3"><?= $client ? lang('App.edit') : lang('App.add_new') ?> - <?= lang('App.clients') ?></h3>

<div class="card p-4" style="max-width:600px;">
<form method="post" action="<?= $client ? '/admin/clients/' . $client['id'] : '/admin/clients' ?>">
    <?= csrf_field() ?>
    <div class="mb-3">
        <label class="form-label"><?= lang('App.name') ?></label>
        <input type="text" name="name" class="form-control" value="<?= esc($client['name'] ?? '') ?>" required>
    </div>
    <div class="mb-3">
        <label class="form-label"><?= lang('App.email') ?></label>
        <input type="email" name="email" class="form-control" value="<?= esc($client['email'] ?? '') ?>" required>
    </div>
    <div class="mb-3">
        <label class="form-label"><?= lang('App.phone') ?></label>
        <input type="text" name="phone" class="form-control" value="<?= esc($client['phone'] ?? '') ?>">
    </div>
    <div class="mb-3">
        <label class="form-label"><?= lang('App.address') ?></label>
        <textarea name="address" class="form-control"><?= esc($client['address'] ?? '') ?></textarea>
    </div>
    <div class="mb-3">
        <label class="form-label">المسوّق</label>
        <select name="marketer_id" class="form-select">
            <option value="">-</option>
            <?php foreach ($marketers as $m): ?>
                <option value="<?= $m['id'] ?>" <?= ($client['marketer_id'] ?? null) == $m['id'] ? 'selected' : '' ?>><?= esc($m['name']) ?></option>
            <?php endforeach; ?>
        </select>
    </div>
    <div class="mb-3">
        <label class="form-label">لغة المراسلة</label>
        <select name="preferred_locale" class="form-select">
            <option value="ar" <?= ($client['preferred_locale'] ?? 'ar') === 'ar' ? 'selected' : '' ?>>العربية</option>
            <option value="en" <?= ($client['preferred_locale'] ?? '') === 'en' ? 'selected' : '' ?>>English</option>
        </select>
    </div>
    <div class="mb-3">
        <label class="form-label"><?= lang('App.password') ?> (بوابة العميل)</label>
        <input type="password" name="password" class="form-control" <?= $client ? '' : 'required' ?>>
    </div>
    <div class="form-check mb-3">
        <input type="checkbox" name="is_active" class="form-check-input" value="1" <?= ($client['is_active'] ?? 1) ? 'checked' : '' ?>>
        <label class="form-check-label"><?= lang('App.status') ?></label>
    </div>
    <button class="btn btn-dark"><?= lang('App.save') ?></button>
    <a href="/admin/clients" class="btn btn-light"><?= lang('App.cancel') ?></a>
</form>
</div>
<?= $this->endSection() ?>
