<?php $__env->startSection('title', 'Manage Page'); ?>

<?php $__env->startSection('content'); ?>
<div class="mb-5">
    <h1 class="text-2xl font-bold text-gray-800"><?php echo e($page->name); ?> - Sections</h1>
    <p class="text-sm text-gray-500">Page type: <strong><?php echo e($page->page_type); ?></strong></p>
</div>

<?php if($isDedicated): ?>
    <div class="rounded-xl border border-yellow-300 bg-yellow-50 text-yellow-800 p-4 text-sm">
        This is a dedicated module page (Events/Success Stories). Manage it from its own module CMS, not from Section Manager.
    </div>
<?php else: ?>
    <form method="POST" action="<?php echo e(route('admin.pages.update', $page)); ?>" class="space-y-5">
        <?php echo csrf_field(); ?>
        <?php echo method_field('PUT'); ?>

        <section class="bg-white rounded-xl border border-gray-200 p-5">
            <label class="inline-flex items-center gap-2 text-sm mb-4">
                <input type="checkbox" name="is_active" value="1" <?php echo e(old('is_active', $page->is_active) ? 'checked' : ''); ?>>
                Page Enabled
            </label>

            <h2 class="text-sm font-semibold text-gray-700 mb-3">Select and Order Sections</h2>
            <p class="text-xs text-gray-500 mb-3">Use Up/Down to arrange order. Checked items will be saved.</p>

            <div id="section-order-list" class="space-y-2">
                <?php $__currentLoopData = $sections; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $section): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <?php $checked = in_array((string) $section->id, array_map('strval', old('section_ids', $selectedIds))); ?>
                    <div class="flex items-center gap-3 border border-gray-200 rounded-lg px-3 py-2 bg-gray-50">
                        <input type="checkbox" name="section_ids[]" value="<?php echo e($section->id); ?>" <?php echo e($checked ? 'checked' : ''); ?>>
                        <div class="flex-1">
                            <p class="text-sm font-medium text-gray-800"><?php echo e($section->name); ?></p>
                            <p class="text-xs text-gray-500"><?php echo e($section->section_type); ?> | <?php echo e($section->title); ?></p>
                        </div>
                        <button type="button" class="move-up text-xs px-2 py-1 border border-gray-300 rounded">Up</button>
                        <button type="button" class="move-down text-xs px-2 py-1 border border-gray-300 rounded">Down</button>
                    </div>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </div>
        </section>

        <div class="bg-white rounded-xl border border-gray-200 p-4 flex gap-2 justify-end">
            <a href="<?php echo e(route('admin.pages.index')); ?>" class="px-4 py-2.5 rounded-lg border border-gray-300 text-sm text-gray-700">Back</a>
            <button type="submit" class="bg-blue-600 hover:bg-blue-700 text-white text-sm font-semibold px-5 py-2.5 rounded-lg">Save Page Sections</button>
        </div>
    </form>

    <script>
    (function() {
        const list = document.getElementById('section-order-list');
        list?.addEventListener('click', function(e) {
            const row = e.target.closest('.flex.items-center');
            if (!row) return;

            if (e.target.classList.contains('move-up')) {
                const prev = row.previousElementSibling;
                if (prev) row.parentNode.insertBefore(row, prev);
            }

            if (e.target.classList.contains('move-down')) {
                const next = row.nextElementSibling;
                if (next) row.parentNode.insertBefore(next, row);
            }
        });
    })();
    </script>
<?php endif; ?>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('admin.layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /home/gpsmigration/public_html/gpsmigration.com/resources/views/admin/pages/edit.blade.php ENDPATH**/ ?>