<?= $this->extend('admin/layout/main') ?>
<?= $this->section('content') ?>
<h3 class="mb-3"><?= $testimonial ? lang('App.edit') : lang('App.add_new') ?> - رأي عميل</h3>
<div class="card p-4" style="max-width:500px;">
<form method="post" action="<?= $testimonial ? '/admin/site-testimonials/' . $testimonial['id'] : '/admin/site-testimonials' ?>" enctype="multipart/form-data">
    <?= csrf_field() ?>
    <div class="mb-3">
        <label class="form-label">اسم العميل</label>
        <input type="text" name="client_name" class="form-control" value="<?= esc($testimonial['client_name'] ?? '') ?>" required>
    </div>
    <div class="mb-3">
        <label class="form-label">صورة (اختياري)</label><br>
        <?php if (!empty($testimonial['photo'])): ?>
            <img src="<?= base_url('uploads/testimonials/' . $testimonial['photo']) ?>" style="width:50px;height:50px;border-radius:50%;object-fit:cover;margin-bottom:8px;display:block;">
        <?php endif; ?>
        <input type="file" name="photo" accept="image/*" class="form-control">
    </div>
    <div class="mb-3">
        <label class="form-label">التقييم</label>
        <select name="rating" class="form-select">
            <?php for ($i = 5; $i >= 1; $i--): ?>
                <option value="<?= $i ?>" <?= ($testimonial['rating'] ?? 5) == $i ? 'selected' : '' ?>><?= str_repeat('⭐', $i) ?></option>
            <?php endfor; ?>
        </select>
    </div>
    <div class="mb-3">
        <label class="form-label">الرأي / التعليق</label>
        <textarea name="content" class="form-control" rows="3" required><?= esc($testimonial['content'] ?? '') ?></textarea>
    </div>
    <div class="form-check mb-3">
        <input type="checkbox" name="is_active" class="form-check-input" value="1" <?= ($testimonial['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/site-testimonials" class="btn btn-light"><?= lang('App.cancel') ?></a>
</form>
</div>
<?= $this->endSection() ?>
