<?php $__env->startSection('section'); ?>
    <div class="page-body">
        <div class="container-fluid">
            <div class="row page-title">
                <div class="col-sm-6">
                    <h3>Post List</h3>
                </div>
                <div class="col-sm-6">
                    <nav>
                        <ol class="breadcrumb justify-content-sm-end align-items-center">
                            <li class="breadcrumb-item"><a href="<?php echo e(route('dashboard')); ?>">
                                    <svg class="svg-color">
                                        <use href="<?php echo e(asset('assets/svg/iconly-sprite.svg#Home')); ?>"></use>
                                    </svg></a>
                            </li>
                            <li class="breadcrumb-item">Posts</li>
                            <li class="breadcrumb-item active">Post List</li>
                        </ol>
                    </nav>
                </div>
            </div>
        </div>

        <!-- Container-fluid starts-->
        <div class="container-fluid list-products">
            <div class="row">

                <div class="col-md-12 project-list">
                    <div class="card">
                        <div class="row align-items-center justify-content-between">
                            <!-- Left Side: Active Post Link -->
                            <div class="col-md-3 col-12 mb-2 mb-md-0">
                                <a class="btn btn-info d-inline-flex" href="<?php echo e(route('category.list')); ?>">
                                    <svg class="feather me-2">
                                        <use href="<?php echo e(asset('assets/svg/feather-icons/dist/feather-sprite.svg#target')); ?>">
                                        </use>
                                    </svg>
                                    Category List
                                </a>
                            </div>
                            <div class="col-md-3 col-12 mb-2 mb-md-0">
                                <a class="btn btn-warning d-inline-flex" href="<?php echo e(route('tag.list')); ?>">
                                    <svg class="feather me-2">
                                        <use href="<?php echo e(asset('assets/svg/feather-icons/dist/feather-sprite.svg#target')); ?>">
                                        </use>
                                    </svg>
                                    Tag List
                                </a>
                            </div>
                            <div class="col-md-3 col-12 mb-2 mb-md-0">
                                <a class="btn btn-danger d-inline-flex" href="<?php echo e(route('tra.post.list')); ?>">
                                    <svg class="feather me-2">
                                        <use href="<?php echo e(asset('assets/svg/feather-icons/dist/feather-sprite.svg#target')); ?>">
                                        </use>
                                    </svg>
                                    Deleted Post
                                </a>
                            </div>

                            <!-- Right Side: Add New Post Button -->
                            <div class="col-md-3 col-12 text-md-end">
                                <a class="btn btn-primary d-inline-flex align-items-center" href="<?php echo e(route('post.add')); ?>">
                                    <svg class="feather me-2">
                                        <use
                                            href="<?php echo e(asset('assets/svg/feather-icons/dist/feather-sprite.svg#plus-square')); ?>">
                                        </use>
                                    </svg>
                                    Add New Post
                                </a>
                            </div>
                        </div>
                    </div>
                </div>


                <!-- Post Table -->
                <div class="col-sm-12">
                    <div class="card">
                        <div class="card-body">
                            <div class="table-responsive theme-scrollbar product-table">
                                <table class="table display" id="post-datatable">
                                    <thead>
                                        <tr>
                                            <th>S.no</th>
                                            <th>Title</th>
                                            <th>Details</th>
                                            <th>Status</th>
                                            <th>Image</th>
                                            <th>Created By</th>
                                            <th>Created Date</th>
                                            <th>Action</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php $__currentLoopData = $titles; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $post): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <tr>
                                                <td><?php echo e($loop->iteration); ?></td>
                                                <td><?php echo e($post->title); ?></td>
                                                <td><?php echo e(Str::limit(strip_tags($post->content), 30)); ?></td>
                                                <td>
                                                    <span
                                                        class="badge rounded-pill toggle-status <?php echo e($post->status ? 'bg-success' : 'bg-danger'); ?>"
                                                        data-id="<?php echo e($post->id); ?>" style="cursor: pointer;">
                                                        <?php echo e($post->status ? 'Publish' : 'Unpublish'); ?>

                                                    </span>
                                                </td>
                                                <td>
                                                    <?php if($post->post_image): ?>
                                                        <img src="<?php echo e(asset($post->post_image)); ?>"
                                                            width="60" height="50" class="rounded">
                                                    <?php else: ?>
                                                        N/A
                                                    <?php endif; ?>
                                                </td>
                                                <td><?php echo e($post->author->name ?? 'N/A'); ?></td>
                                                <td><?php echo e($post->created_at ? $post->created_at->format('d/m/Y') : 'N/A'); ?>

                                                </td>
                                                <td>
                                                    <a href="<?php echo e(route('view.post', $post->id)); ?>"
                                                        class="btn btn-warning btn-xs" title="View">View</a>
                                                    <a href="<?php echo e(route('edit.post', $post->id)); ?>"
                                                        class="btn btn-primary btn-xs" title="Edit">Edit</a>
                                                    <a href="<?php echo e(route('delete.post', $post->id)); ?>"
                                                        class="btn btn-danger btn-xs" title="Delete"
                                                        onclick="return confirm('Are you sure to delete this post?')">Delete</a>
                                                </td>
                                            </tr>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- DataTables Script -->
    <script src="<?php echo e(asset('assets/js/vendors/simple-datatables/dist/umd/simple-datatables.js')); ?>"></script>
    <script>
        document.addEventListener("DOMContentLoaded", function() {
            // Initialize DataTable
            const table = document.querySelector("#post-datatable");
            if (table) new simpleDatatables.DataTable(table);

            // Toggle status via AJAX
            document.querySelectorAll('.toggle-status').forEach(btn => {
                btn.addEventListener('click', function() {
                    const postId = this.dataset.id;

                    fetch("<?php echo e(route('post.changeStatusAjax')); ?>", {
                            method: 'POST',
                            headers: {
                                'X-CSRF-TOKEN': '<?php echo e(csrf_token()); ?>',
                                'Content-Type': 'application/json'
                            },
                            body: JSON.stringify({
                                id: postId
                            })
                        })
                        .then(res => res.json())
                        .then(data => {
                            if (data.success) {
                                this.classList.toggle('bg-success', data.status == 1);
                                this.classList.toggle('bg-danger', data.status == 0);
                                this.textContent = data.status == 1 ? 'Publish' : 'Unpublish';
                            }
                        }).catch(err => console.error('Status toggle error:', err));
                });
            });
        });
    </script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('admin.layouts.main', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH D:\NEWXAMP\htdocs\nitinnewsproject\resources\views/admin/Post/index.blade.php ENDPATH**/ ?>