<!DOCTYPE html>
<html lang="en">
<?php echo $__env->make('includes.head', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
<body id="kt_body" class="header-fixed header-tablet-and-mobile-fixed toolbar-enabled toolbar-fixed aside-enabled aside-fixed">
    <div class="d-flex flex-column flex-root">
        <div class="page d-flex flex-row flex-column-fluid">
            <?php echo $__env->make('includes.side-nav', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
            <div class="wrapper d-flex flex-column flex-row-fluid" id="kt_wrapper">
                <?php echo $__env->make('includes.header', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
                <div class="content d-flex flex-column flex-column-fluid" id="kt_content">
                    <div class="toolbar" id="kt_toolbar">
                        <div id="kt_toolbar_container" class="container-fluid d-flex flex-stack">
                            <div class="page-title">
                                <h1 class="text-dark fw-bolder fs-3">Testimonials</h1>
                            </div>
                            <button type="button" class="btn btn-sm btn-primary" data-bs-toggle="modal" data-bs-target="#testimonialModal" onclick="resetForm()">Add Testimonial</button>
                        </div>
                    </div>
                    <div class="post d-flex flex-column-fluid" id="kt_post">
                        <div id="kt_content_container" class="container-xxl">
                            <div class="card">
                                <?php echo $__env->make('includes.messages', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
                                <div class="card-header border-0 pt-6">
                                    <form method="GET" action="<?php echo e(route('testimonial.list')); ?>" class="d-flex align-items-center">
                                        <div class="d-flex align-items-center position-relative me-5">
                                            <span class="svg-icon svg-icon-1 position-absolute ms-6">
                                                <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">
                                                    <rect opacity="0.5" x="17.0365" y="15.1223" width="8.15546" height="2" rx="1" transform="rotate(45 17.0365 15.1223)" fill="black" />
                                                    <path d="M11 19C6.55556 19 3 15.4444 3 11C3 6.55556 6.55556 3 11 3C15.4444 3 19 6.55556 19 11C19 15.4444 15.4444 19 11 19ZM11 5C7.53333 5 5 7.53333 5 11C5 14.4667 7.53333 17 11 17C14.4667 17 17 14.4667 17 11C17 7.53333 14.4667 5 11 5Z" fill="black" />
                                                </svg>
                                            </span>
                                            <input type="text" name="search" value="<?php echo e(request('search')); ?>" class="form-control form-control-solid w-250px ps-15" placeholder="Search by client name..." />
                                        </div>
                                        <button type="submit" class="btn btn-primary me-2">Filter</button>
                                        <a href="<?php echo e(route('testimonial.list')); ?>" class="btn btn-secondary">Reset</a>
                                    </form>
                                </div>
                                <div class="card-body pt-0">
                                    <div class="table-responsive">
                                        <table class="table align-middle table-row-dashed fs-6 gy-5">
                                            <thead>
                                                <tr class="text-start text-gray-400 fw-bolder fs-7 text-uppercase">
                                                    <th>ID</th>
                                                    <th>Image</th>
                                                    <th>Client Name</th>
                                                    <th>Rating</th>
                                                    <th>Comment</th>
                                                    <th>Status</th>
                                                    <th class="text-end">Actions</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                <?php $__currentLoopData = $testimonials; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                <tr id="row-<?php echo e($item->id); ?>">
                                                    <td><?php echo e($item->id); ?></td>
                                                    <td>
                                                        <?php if($item->image): ?>
                                                            <img src="<?php echo e($baseImgPath); ?><?php echo e($item->image); ?>" style="width: 50px; height: 50px; object-fit: cover;" class="rounded">
                                                        <?php else: ?>
                                                            <span class="badge badge-light">No Image</span>
                                                        <?php endif; ?>
                                                    </td>
                                                    <td><?php echo e($item->client_name); ?><br><small class="text-muted"><?php echo e($item->designation); ?></small></td>
                                                    <td>
                                                        <?php for($i=1; $i<=5; $i++): ?>
                                                            <?php if($i <= $item->rating): ?>
                                                                <i class="fas fa-star text-warning"></i>
                                                            <?php else: ?>
                                                                <i class="far fa-star text-muted"></i>
                                                            <?php endif; ?>
                                                        <?php endfor; ?>
                                                    </td>
                                                    <td><?php echo e(Str::limit($item->comment, 60)); ?></td>
                                                    <td>
                                                        <span class="badge <?php echo e($item->status ? 'badge-success' : 'badge-danger'); ?>">
                                                            <?php echo e($item->status ? 'Active' : 'Inactive'); ?>

                                                        </span>
                                                    </td>
                                                    <td class="text-end">
                                                        <button class="btn btn-sm btn-primary edit-btn" data-id="<?php echo e($item->id); ?>">Edit</button>
                                                        <button class="btn btn-sm btn-danger delete-btn" data-id="<?php echo e($item->id); ?>">Delete</button>
                                                    </td>
                                                </tr>
                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                            </tbody>
                                        </table>
                                    </div>
                                    <?php echo e($testimonials->links('pagination::bootstrap-4')); ?>

                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <?php echo $__env->make('includes.footer', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
            </div>
        </div>
    </div>
    <?php echo $__env->make('includes.scripts', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>

    <!-- Modal Add/Edit -->
    <div class="modal fade" id="testimonialModal" tabindex="-1" data-bs-backdrop="static">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="modalTitle">Add Testimonial</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
                </div>
                <div class="modal-body">
                    <form id="testimonialForm" enctype="multipart/form-data">
                        <?php echo csrf_field(); ?>
                        <input type="hidden" name="id" id="recordId">
                        <div class="row mb-3">
                            <div class="col-md-6">
                                <label class="required">Client Name</label>
                                <input type="text" name="client_name" id="client_name" class="form-control" required>
                            </div>
                            <div class="col-md-6">
                                <label>Designation</label>
                                <input type="text" name="designation" id="designation" class="form-control">
                            </div>
                        </div>
                        <div class="row mb-3">
                            <div class="col-md-6">
                                <label>Rating (1-5)</label>
                                <select name="rating" id="rating" class="form-select">
                                    <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 class="col-md-6">
                                <label>Image</label>
                                <input type="file" name="image" id="image" class="form-control" accept="image/*">
                                <div id="imagePreview" class="mt-2"></div>
                            </div>
                        </div>
                        <div class="row mb-3">
                            <div class="col-md-12">
                                <label>Comment</label>
                                <textarea name="comment" id="comment" class="form-control" rows="4"></textarea>
                            </div>
                        </div>
                        <div class="row mb-3">
                            <div class="col-md-6">
                                <label>Status</label>
                                <select name="status" id="status" class="form-select">
                                    <option value="1">Active</option>
                                    <option value="0">Inactive</option>
                                </select>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
                    <button class="btn btn-primary" id="saveBtn">Save</button>
                </div>
            </div>
        </div>
    </div>

    <script>
        function resetForm() {
            $('#testimonialForm')[0].reset();
            $('#recordId').val('');
            $('#imagePreview').html('');
            $('#modalTitle').text('Add Testimonial');
        }

        // Preview image
        $('#image').on('change', function() {
            let file = this.files[0];
            if (file) {
                let reader = new FileReader();
                reader.onload = function(e) {
                    $('#imagePreview').html('<img src="'+e.target.result+'" style="max-width:100px;" class="img-thumbnail">');
                };
                reader.readAsDataURL(file);
            } else {
                $('#imagePreview').html('');
            }
        });

        // Save
        $('#saveBtn').click(function() {
            let formData = new FormData($('#testimonialForm')[0]);
            let id = $('#recordId').val();
            let url = id ? "<?php echo e(route('testimonial.update', '')); ?>/" + id : "<?php echo e(route('testimonial.store')); ?>";
            if (id) formData.append('_method', 'PUT');

            $.ajax({
                url: url,
                type: 'POST',
                data: formData,
                processData: false,
                contentType: false,
                success: function(res) {
                    if (res.success) location.reload();
                    else alert('Error saving');
                },
                error: function(xhr) {
                    let errors = xhr.responseJSON.errors;
                    if (errors) alert(Object.values(errors).flat().join('\n'));
                    else alert('Something went wrong');
                }
            });
        });

        // Edit
        $('.edit-btn').click(function() {
            let id = $(this).data('id');
            $.get("<?php echo e(route('testimonial.edit', '')); ?>/" + id, function(res) {
                if (res.success) {
                    let t = res.testimonial;
                    $('#recordId').val(t.id);
                    $('#client_name').val(t.client_name);
                    $('#designation').val(t.designation);
                    $('#rating').val(t.rating);
                    $('#comment').val(t.comment);
                    $('#status').val(t.status);
                    if (t.image_url) $('#imagePreview').html('<img src="'+t.image_url+'" style="max-width:100px;" class="img-thumbnail">');
                    else $('#imagePreview').html('');
                    $('#modalTitle').text('Edit Testimonial');
                    $('#testimonialModal').modal('show');
                } else alert('Not found');
            });
        });

        // Delete
        $('.delete-btn').click(function() {
            if (confirm('Delete this testimonial?')) {
                let id = $(this).data('id');
                $.ajax({
                    url: "<?php echo e(route('testimonial.delete', '')); ?>/" + id,
                    type: 'DELETE',
                    data: { _token: '<?php echo e(csrf_token()); ?>' },
                    success: function(res) {
                        if (res.success) $('#row-'+id).remove();
                        else alert('Delete failed');
                    }
                });
            }
        });
    </script>
</body>
</html>
<?php /**PATH /home/creattat/public_html/creativevalley9.website/laravel/resources/views/Admin/Testimonial/list.blade.php ENDPATH**/ ?>