

<?php $__env->startSection('title', $title); ?>
<?php $__env->startSection('ad_page_title', 'Blogs'); ?>
<?php $__env->startSection('ad_page_subtitle', 'Manage blog content in English and Arabic'); ?>

<?php $__env->startSection('ad_content'); ?>
<div class="container-fluid py-4">
    <div class="d-flex flex-column flex-md-row justify-content-between align-items-md-center gap-3 mb-4">
        <div>
            <h1 class="h3 mb-1">Blogs</h1>
            <p class="text-muted mb-0">Manage blog content in English and Arabic</p>
        </div>

        <a href="<?php echo e(route('admin.blogs.create')); ?>" class="btn btn-primary">
            <i class="fa-solid fa-plus me-2"></i>Create Blog
        </a>
    </div>

    <div class="card shadow-sm border-0">
        <div class="card-body p-4">
            <form action="<?php echo e(route('admin.blogs.index')); ?>" method="GET" class="row g-3 mb-4">
                <div class="col-lg-10">
                    <input
                        type="text"
                        name="search"
                        value="<?php echo e(request('search')); ?>"
                        class="form-control"
                        placeholder="Search by H1, title, slug, category, tags or meta title"
                    >
                </div>

                <div class="col-lg-2 d-grid">
                    <button type="submit" class="btn btn-outline-primary">
                        <i class="fa-solid fa-magnifying-glass me-2"></i>Search
                    </button>
                </div>
            </form>

            <div class="table-responsive">
                <table class="table table-hover align-middle mb-0">
                    <thead>
                        <tr>
                            <th style="width: 70px;">#</th>
                            <th style="width: 110px;">Image</th>
                            <th>H1 / Title</th>
                            <th>Category</th>
                            <th>Tags</th>
                            <th>Slug</th>
                            <th>Status</th>
                            <th>Published At</th>
                            <th class="text-end" style="width: 180px;">Actions</th>
                        </tr>
                    </thead>

                    <tbody>
                        <?php $__empty_1 = true; $__currentLoopData = $blogs; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $blog): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                            <tr>
                                <td><?php echo e($blog->id); ?></td>

                                <td>
                                    <?php if($blog->image): ?>
                                        <img
                                            src="<?php echo e(asset('storage/' . $blog->image)); ?>"
                                            alt="<?php echo e($blog->title_en); ?>"
                                            width="80"
                                            height="60"
                                            class="rounded border"
                                            style="object-fit: cover;"
                                        >
                                    <?php else: ?>
                                        <div class="d-flex align-items-center justify-content-center rounded border bg-light text-muted" style="width: 80px; height: 60px;">
                                            <i class="fa-regular fa-image"></i>
                                        </div>
                                    <?php endif; ?>
                                </td>

                                <td>
                                    <div class="fw-semibold"><?php echo e($blog->h1_en ?: $blog->title_en); ?></div>

                                    <?php if($blog->h1_ar || $blog->title_ar): ?>
                                        <div dir="rtl" class="text-muted small text-end">
                                            <?php echo e($blog->h1_ar ?: $blog->title_ar); ?>

                                        </div>
                                    <?php endif; ?>

                                    <?php if($blog->title_en && $blog->h1_en && $blog->title_en !== $blog->h1_en): ?>
                                        <div class="small text-muted mt-1">Title EN: <?php echo e($blog->title_en); ?></div>
                                    <?php endif; ?>
                                </td>

                                <td>
                                    <div><?php echo e($blog->category_en ?: '-'); ?></div>
                                    <?php if($blog->category_ar): ?>
                                        <div dir="rtl" class="small text-muted text-end"><?php echo e($blog->category_ar); ?></div>
                                    <?php endif; ?>
                                </td>

                                <td style="min-width: 180px;">
                                    <?php
                                        $tagsEn = is_array($blog->tags_en ?? null)
                                            ? $blog->tags_en
                                            : array_filter(array_map('trim', explode(',', (string) $blog->tags_en)));

                                        $tagsAr = is_array($blog->tags_ar ?? null)
                                            ? $blog->tags_ar
                                            : array_filter(array_map('trim', explode(',', (string) $blog->tags_ar)));
                                    ?>

                                    <?php if(count($tagsEn)): ?>
                                        <div class="mb-1">
                                            <?php $__currentLoopData = $tagsEn; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $tag): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                <span class="badge text-bg-light border"><?php echo e($tag); ?></span>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                        </div>
                                    <?php endif; ?>

                                    <?php if(count($tagsAr)): ?>
                                        <div dir="rtl" class="text-end">
                                            <?php $__currentLoopData = $tagsAr; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $tag): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                <span class="badge text-bg-light border"><?php echo e($tag); ?></span>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                        </div>
                                    <?php endif; ?>

                                    <?php if(!count($tagsEn) && !count($tagsAr)): ?>
                                        <span class="text-muted">-</span>
                                    <?php endif; ?>
                                </td>

                                <td>
                                    <code><?php echo e($blog->slug); ?></code>
                                </td>

                                <td>
                                    <?php if($blog->is_published): ?>
                                        <span class="badge bg-success">Published</span>
                                    <?php else: ?>
                                        <span class="badge bg-secondary">Draft</span>
                                    <?php endif; ?>
                                </td>

                                <td>
                                    <?php echo e($blog->published_at?->format('Y-m-d H:i') ?? '-'); ?>

                                </td>

                                <td class="text-end">
                                    <div class="d-inline-flex gap-2">
                                        <a href="<?php echo e(route('admin.blogs.edit', $blog)); ?>" class="btn btn-sm btn-warning">
                                            <i class="fa-solid fa-pen-to-square me-1"></i>Edit
                                        </a>

                                        <form action="<?php echo e(route('admin.blogs.destroy', $blog)); ?>" method="POST">
                                            <?php echo csrf_field(); ?>
                                            <?php echo method_field('DELETE'); ?>

                                            <button
                                                type="submit"
                                                class="btn btn-sm btn-danger"
                                                onclick="return confirm('Delete this blog?')"
                                            >
                                                <i class="fa-solid fa-trash me-1"></i>Delete
                                            </button>
                                        </form>
                                    </div>
                                </td>
                            </tr>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                            <tr>
                                <td colspan="9" class="text-center py-5 text-muted">
                                    No blogs found.
                                </td>
                            </tr>
                        <?php endif; ?>
                    </tbody>
                </table>
            </div>

            <?php if($blogs->hasPages()): ?>
                <div class="mt-4">
                    <?php echo e($blogs->links()); ?>

                </div>
            <?php endif; ?>
        </div>
    </div>
</div>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('admin.ad_master', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /home/onesourceerp/public_html/project/resources/views/admin/blogs/index.blade.php ENDPATH**/ ?>