<?php $__env->startSection('title', 'Testimoni'); ?>
<?php $__env->startSection('page-title', '⭐ Kelola Testimoni'); ?>

<?php $__env->startSection('content'); ?>

<div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:24px;">
    <p style="color:#6B7280;font-size:0.9rem;">Total <?php echo e($testimonials->count()); ?> testimoni</p>
    <div style="display:flex;gap:12px;">
        <form action="<?php echo e(route('admin.testimonials.sync')); ?>" method="POST">
            <?php echo csrf_field(); ?>
            <button type="submit" class="btn" style="background:#F3F4F6;color:#374151;border:1px solid #D1D5DB;display:flex;align-items:center;gap:6px;" onclick="return confirm('Proses ini akan menarik maksimal 5 ulasan terbaru dari Google Maps sesuai konfigurasi di .env. Lanjutkan?')">
                🔄 Tarik Ulasan Google
            </button>
        </form>
        <button class="btn btn-primary" onclick="document.getElementById('add-modal').classList.add('open')">
            + Tambah Testimoni
        </button>
    </div>
</div>

<div class="card">
    <table class="table">
        <thead>
            <tr>
                <th>Nama</th>
                <th>Rating</th>
                <th>Ulasan</th>
                <th>Tanggal</th>
                <th>Status</th>
                <th>Aksi</th>
            </tr>
        </thead>
        <tbody>
            <?php $__empty_1 = true; $__currentLoopData = $testimonials; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $t): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
            <tr>
                <td>
                    <div style="display:flex;align-items:center;gap:10px;">
                        <div style="width:36px;height:36px;border-radius:50%;background:linear-gradient(135deg,#C0392B,#800020);color:white;font-weight:700;display:flex;align-items:center;justify-content:center;font-size:0.85rem;flex-shrink:0;">
                            <?php echo e(strtoupper(substr($t->name, 0, 1))); ?>

                        </div>
                        <div style="display:flex;align-items:center;">
                            <span style="font-weight:600;"><?php echo e($t->name); ?></span>
                            <?php if($t->source === 'google'): ?>
                            <span style="background:#4285F4;color:white;padding:2px 6px;border-radius:4px;font-size:0.65rem;margin-left:8px;font-weight:700;">Google</span>
                            <?php endif; ?>
                        </div>
                    </div>
                </td>
                <td>
                    <span class="stars"><?php echo e(str_repeat('⭐', $t->rating)); ?></span>
                </td>
                <td style="max-width:300px;">
                    <span style="display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;">
                        <?php echo e($t->review); ?>

                    </span>
                </td>
                <td style="color:#9CA3AF;font-size:0.82rem;"><?php echo e($t->date); ?></td>
                <td>
                    <span class="badge <?php echo e($t->is_active ? 'badge-green' : 'badge-gray'); ?>">
                        <?php echo e($t->is_active ? 'Aktif' : 'Nonaktif'); ?>

                    </span>
                </td>
                <td>
                    <div style="display:flex;gap:8px;">
                        <button class="btn btn-sm" style="background:#F3F4F6;color:#374151;"
                                onclick="openEditModal(<?php echo e($t->id); ?>, '<?php echo e(addslashes($t->name)); ?>', <?php echo e($t->rating); ?>, '<?php echo e(addslashes($t->review)); ?>', '<?php echo e($t->date); ?>', <?php echo e($t->is_active ? 1 : 0); ?>)">
                            ✏️ Edit
                        </button>
                        <form action="<?php echo e(route('admin.testimonials.destroy', $t)); ?>" method="POST" 
                              onsubmit="return confirm('Hapus testimoni ini?')">
                            <?php echo csrf_field(); ?> <?php echo method_field('DELETE'); ?>
                            <button type="submit" class="btn btn-danger btn-sm">🗑️ Hapus</button>
                        </form>
                    </div>
                </td>
            </tr>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
            <tr>
                <td colspan="6" style="text-align:center;color:#9CA3AF;padding:40px;">
                    Belum ada testimoni. Klik "Tambah Testimoni" untuk mulai.
                </td>
            </tr>
            <?php endif; ?>
        </tbody>
    </table>
</div>

<!-- Add Modal -->
<div class="modal-overlay" id="add-modal">
    <div class="modal">
        <div class="modal-title">➕ Tambah Testimoni</div>
        <form action="<?php echo e(route('admin.testimonials.store')); ?>" method="POST">
            <?php echo csrf_field(); ?>
            <div class="form-grid">
                <div class="form-group">
                    <label>Nama Pelanggan</label>
                    <input type="text" name="name" class="form-control" required placeholder="Nama Lengkap">
                </div>
                <div class="form-group">
                    <label>Rating (1-5)</label>
                    <select name="rating" class="form-control">
                        <option value="5">⭐⭐⭐⭐⭐ (5)</option>
                        <option value="4">⭐⭐⭐⭐ (4)</option>
                        <option value="3">⭐⭐⭐ (3)</option>
                        <option value="2">⭐⭐ (2)</option>
                        <option value="1">⭐ (1)</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label>Ulasan</label>
                <textarea name="review" class="form-control" required placeholder="Tulis ulasan pelanggan..."></textarea>
            </div>
            <div class="form-grid">
                <div class="form-group">
                    <label>Tanggal</label>
                    <input type="text" name="date" class="form-control" placeholder="1 bulan lalu / 2 hari lalu">
                </div>
                <div class="form-group" style="display:flex;align-items:center;gap:10px;margin-top:28px;">
                    <input type="checkbox" name="is_active" id="add_is_active" checked style="width:18px;height:18px;">
                    <label for="add_is_active" style="margin:0;text-transform:none;letter-spacing:0;">Tampilkan di website</label>
                </div>
            </div>
            <div class="form-actions">
                <button type="button" class="btn" style="background:#F3F4F6;" onclick="document.getElementById('add-modal').classList.remove('open')">Batal</button>
                <button type="submit" class="btn btn-primary">Simpan Testimoni</button>
            </div>
        </form>
    </div>
</div>

<!-- Edit Modal -->
<div class="modal-overlay" id="edit-modal">
    <div class="modal">
        <div class="modal-title">✏️ Edit Testimoni</div>
        <form id="edit-form" method="POST">
            <?php echo csrf_field(); ?> <?php echo method_field('PUT'); ?>
            <div class="form-grid">
                <div class="form-group">
                    <label>Nama Pelanggan</label>
                    <input type="text" name="name" id="edit_name" class="form-control" required>
                </div>
                <div class="form-group">
                    <label>Rating</label>
                    <select name="rating" id="edit_rating" class="form-control">
                        <option value="5">⭐⭐⭐⭐⭐ (5)</option>
                        <option value="4">⭐⭐⭐⭐ (4)</option>
                        <option value="3">⭐⭐⭐ (3)</option>
                        <option value="2">⭐⭐ (2)</option>
                        <option value="1">⭐ (1)</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label>Ulasan</label>
                <textarea name="review" id="edit_review" class="form-control" required></textarea>
            </div>
            <div class="form-grid">
                <div class="form-group">
                    <label>Tanggal</label>
                    <input type="text" name="date" id="edit_date" class="form-control">
                </div>
                <div class="form-group" style="display:flex;align-items:center;gap:10px;margin-top:28px;">
                    <input type="checkbox" name="is_active" id="edit_is_active" style="width:18px;height:18px;">
                    <label for="edit_is_active" style="margin:0;text-transform:none;letter-spacing:0;">Tampilkan di website</label>
                </div>
            </div>
            <div class="form-actions">
                <button type="button" class="btn" style="background:#F3F4F6;" onclick="document.getElementById('edit-modal').classList.remove('open')">Batal</button>
                <button type="submit" class="btn btn-primary">Simpan Perubahan</button>
            </div>
        </form>
    </div>
</div>

<script>
function openEditModal(id, name, rating, review, date, isActive) {
    document.getElementById('edit-form').action = `/admin/testimonials/${id}`;
    document.getElementById('edit_name').value = name;
    document.getElementById('edit_rating').value = rating;
    document.getElementById('edit_review').value = review;
    document.getElementById('edit_date').value = date;
    document.getElementById('edit_is_active').checked = isActive == 1;
    document.getElementById('edit-modal').classList.add('open');
}

// Close modal on backdrop click
document.querySelectorAll('.modal-overlay').forEach(overlay => {
    overlay.addEventListener('click', function(e) {
        if (e.target === this) this.classList.remove('open');
    });
});
</script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('admin.layout', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\Users\Dgufi\Herd\mjm\resources\views/admin/testimonials.blade.php ENDPATH**/ ?>