

<?php $__env->startSection('content'); ?>
<main>
    <div style="padding: 24px; max-width: 1200px; margin: 0 auto; width: 100%;">
        <div style="display:flex; justify-content:space-between; align-items:center; margin-bottom: 24px;">
            <h2>Diagram Templates</h2>
            <div>
                <a href="<?php echo e(route('admin.templates.create')); ?>" class="btn btn-primary">Create New Template</a>
            </div>
        </div>

        <?php if(auth()->user()->hasRole('admin')): ?>
        <div class="panel" style="margin-bottom: 24px; padding: 20px;">
            <form action="<?php echo e(route('admin.templates.index')); ?>" method="GET" style="display: flex; gap: 16px; align-items: flex-end; flex-wrap: wrap;">
                <div style="flex: 1; min-width: 200px;">
                    <label style="display: block; margin-bottom: 8px; font-weight: 600; font-size: 14px;">Template Name</label>
                    <input type="text" name="name" value="<?php echo e(request('name')); ?>" class="input" placeholder="Search by name..." style="width: 100%;">
                </div>
                <div style="flex: 1; min-width: 200px;">
                    <label style="display: block; margin-bottom: 8px; font-weight: 600; font-size: 14px;">Created By</label>
                    <select name="creator_id" class="input" style="width: 100%;">
                        <option value="">All Creators</option>
                        <?php $__currentLoopData = $creators; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $creator): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($creator->id); ?>" <?php echo e(request('creator_id') == $creator->id ? 'selected' : ''); ?>>
                                <?php echo e($creator->name); ?>

                            </option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
                </div>
                <div style="flex: 1; min-width: 200px;">
                    <label style="display: block; margin-bottom: 8px; font-weight: 600; font-size: 14px;">Created Date</label>
                    <input type="date" name="date" value="<?php echo e(request('date')); ?>" class="input" style="width: 100%;">
                </div>
                <div style="display: flex; gap: 8px;">
                    <button type="submit" class="btn btn-primary">Filter</button>
                    <a href="<?php echo e(route('admin.templates.index')); ?>" class="btn">Reset</a>
                </div>
            </form>
        </div>
        <?php endif; ?>

        <div class="panel" style="padding: 0;">
            <table style="width: 100%; border-collapse: collapse; text-align: left;">
                <thead>
                    <tr style="border-bottom: 1px solid var(--border); background: var(--bg-main);">
                        <th style="padding: 12px 16px;">ID</th>
                        <th style="padding: 12px 16px;">Template Name</th>
                        <th style="padding: 12px 16px;">Created By</th>
                        <th style="padding: 12px 16px;">Created Date</th>
                        <th style="padding: 12px 16px; text-align:right;">Actions</th>
                    </tr>
                </thead>
                <tbody>
                    <?php $__currentLoopData = $templates; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $template): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <tr style="border-bottom: 1px solid var(--border);">
                        <td style="padding: 12px 16px;">#<?php echo e($template->id); ?></td>
                        <td style="padding: 12px 16px; font-weight:600;"><?php echo e($template->name); ?></td>
                        <td style="padding: 12px 16px;"><?php echo e($template->creator->name ?? 'Unknown'); ?></td>
                        <td style="padding: 12px 16px;"><?php echo e($template->created_at->format('M d, Y')); ?></td>
                        <td style="padding: 12px 16px; text-align:right;">
                            <a href="<?php echo e(route('admin.templates.show', $template)); ?>" class="btn" style="color:green; border-color:#dcfce7; padding: 4px 12px;">View</a>
                            <a href="<?php echo e(route('admin.templates.edit', $template)); ?>" class="btn" style="color:var(--primary); border-color:var(--primary-light); padding: 4px 12px; margin-left: 4px;">Edit</a>
                            <form action="<?php echo e(route('admin.templates.destroy', $template)); ?>" method="POST" style="display:inline;" onsubmit="return confirm('Delete this template?');">
                                <?php echo csrf_field(); ?>
                                <?php echo method_field('DELETE'); ?>
                                <button type="submit" class="btn" style="color:#ef4444; border-color:#fee2e2; padding: 4px 12px; margin-left: 4px;">Delete</button>
                            </form>
                        </td>
                    </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </tbody>
            </table>
            <?php if($templates->isEmpty()): ?>
            <div style="padding: 24px; text-align:center; color: var(--text-muted);">
                No templates found.
                 <!-- Create one from the <a href="<?php echo e(route('admin.templates.create')); ?>">Diagram Viewer</a>. -->
            </div>
            <?php endif; ?>
        </div>
        <div style="margin-top: 16px;">
            <?php echo e($templates->links()); ?>

        </div>
    </div>
</main>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.master', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH D:\xampp\htdocs\pump-selection-backend\resources\views/pages/templates/index.blade.php ENDPATH**/ ?>