<?php
    $canManageForms = auth()->user()->isSuperAdmin();
    $canOperateForms = auth()->user()->isAdmin(); // lock + échéances
?>

<?php if (isset($component)) { $__componentOriginal9ac128a9029c0e4701924bd2d73d7f54 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal9ac128a9029c0e4701924bd2d73d7f54 = $attributes; } ?>
<?php $component = App\View\Components\AppLayout::resolve([] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('app-layout'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\App\View\Components\AppLayout::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes([]); ?>
    <?php if (isset($component)) { $__componentOriginal91a231a9270579fa1ae9246bd51fb785 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal91a231a9270579fa1ae9246bd51fb785 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.ui.page-header','data' => ['title' => $form->title,'description' => 'Détails et filiales assignées']] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('ui.page-header'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes(['title' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute($form->title),'description' => 'Détails et filiales assignées']); ?>
         <?php $__env->slot('actions', null, []); ?> 
            <?php if($canOperateForms): ?>
                <form method="POST" action="<?php echo e(route('admin.forms.lock', $form)); ?>" class="inline">
                    <?php echo csrf_field(); ?> <?php echo method_field('PATCH'); ?>
                    <?php if($form->is_active): ?>
                        <button type="submit" class="btn-secondary btn-sm"
                                onclick="return confirm('Désactiver les modifications ? Les filiales ne pourront plus modifier leurs réponses.')">
                            Verrouiller les modifications
                        </button>
                    <?php else: ?>
                        <button type="submit" class="btn-success btn-sm">
                            Réautoriser les modifications
                        </button>
                    <?php endif; ?>
                </form>
            <?php endif; ?>
            <?php if($canManageForms): ?>
                <a href="<?php echo e(route('admin.forms.edit', $form)); ?>" class="btn-secondary btn-sm">Modifier</a>
                <a href="<?php echo e(route('admin.forms.assign', $form)); ?>" class="btn-success btn-sm">Assigner</a>
            <?php endif; ?>
            <a href="<?php echo e(route('admin.forms.submissions', $form)); ?>" class="btn-primary btn-sm">Soumissions</a>
         <?php $__env->endSlot(); ?>
     <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal91a231a9270579fa1ae9246bd51fb785)): ?>
<?php $attributes = $__attributesOriginal91a231a9270579fa1ae9246bd51fb785; ?>
<?php unset($__attributesOriginal91a231a9270579fa1ae9246bd51fb785); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal91a231a9270579fa1ae9246bd51fb785)): ?>
<?php $component = $__componentOriginal91a231a9270579fa1ae9246bd51fb785; ?>
<?php unset($__componentOriginal91a231a9270579fa1ae9246bd51fb785); ?>
<?php endif; ?>

    <?php if (isset($component)) { $__componentOriginal5194778a3a7b899dcee5619d0610f5cf = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal5194778a3a7b899dcee5619d0610f5cf = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.alert','data' => []] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('alert'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes([]); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal5194778a3a7b899dcee5619d0610f5cf)): ?>
<?php $attributes = $__attributesOriginal5194778a3a7b899dcee5619d0610f5cf; ?>
<?php unset($__attributesOriginal5194778a3a7b899dcee5619d0610f5cf); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal5194778a3a7b899dcee5619d0610f5cf)): ?>
<?php $component = $__componentOriginal5194778a3a7b899dcee5619d0610f5cf; ?>
<?php unset($__componentOriginal5194778a3a7b899dcee5619d0610f5cf); ?>
<?php endif; ?>

    <div class="mb-6 flex flex-wrap items-center gap-3 rounded-xl border px-4 py-3 text-sm
        <?php echo e($form->is_active ? 'bg-emerald-50 border-emerald-200 text-emerald-800' : 'bg-red-50 border-red-200 text-red-800'); ?>">
        <?php if($form->is_active): ?>
            <span class="badge-success">Modifiable</span>
            <span>Les filiales peuvent remplir et modifier leurs réponses.</span>
        <?php else: ?>
            <span class="badge-danger">Verrouillé</span>
            <span>Les filiales sont en lecture seule — elles ne peuvent plus modifier leurs réponses.</span>
        <?php endif; ?>
    </div>

    <div class="grid grid-cols-1 lg:grid-cols-2 gap-6">
        <div class="card p-6">
            <h3 class="font-semibold text-slate-800 mb-4">Structure (<?php echo e($form->fields->count()); ?> champ(s))</h3>
            <?php if($form->description): ?>
                <p class="text-slate-500 text-sm mb-4"><?php echo e($form->description); ?></p>
            <?php endif; ?>
            <ul class="space-y-2">
                <?php echo $__env->make('partials.admin-field-tree', ['fields' => $tree], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
            </ul>
        </div>
        <div class="card p-6">
            <h3 class="font-semibold text-slate-800 mb-4">Filiales assignées & échéances</h3>
            <?php if($form->filiales->isEmpty()): ?>
                <p class="text-slate-400 text-sm">
                    Aucune filiale.
                    <?php if($canManageForms): ?>
                        <a href="<?php echo e(route('admin.forms.assign', $form)); ?>" class="text-transtev-600 hover:underline">Assigner maintenant</a>
                    <?php endif; ?>
                </p>
            <?php else: ?>
                <?php if($canOperateForms): ?>
                    <form method="POST" action="<?php echo e(route('admin.forms.assignments.due-dates', $form)); ?>" class="mb-5 flex flex-wrap items-end gap-3 rounded-lg bg-slate-50 border border-slate-100 p-3">
                        <?php echo csrf_field(); ?> <?php echo method_field('PUT'); ?>
                        <div class="flex-1 min-w-[160px]">
                            <label class="block text-xs font-medium text-slate-600 mb-1">Appliquer une échéance à toutes</label>
                            <input type="date" name="due_date" class="input-modern text-sm" value="">
                        </div>
                        <button type="submit" class="btn-primary btn-sm">Appliquer à toutes</button>
                    </form>
                <?php endif; ?>

                <ul class="space-y-3">
                    <?php $__currentLoopData = $form->filiales; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $filiale): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <li class="p-3 rounded-lg border border-slate-100 space-y-2">
                            <div class="flex justify-between items-center gap-2">
                                <span class="font-medium text-slate-800"><?php echo e($filiale->name); ?></span>
                                <?php if($filiale->pivot->status === 'pending'): ?>
                                    <span class="badge-warning">En attente</span>
                                <?php else: ?>
                                    <span class="badge-success">Soumis</span>
                                <?php endif; ?>
                            </div>
                            <?php if($canOperateForms): ?>
                                <form method="POST" action="<?php echo e(route('admin.forms.assignments.due-date', [$form, $filiale])); ?>" class="flex flex-wrap items-end gap-2">
                                    <?php echo csrf_field(); ?> <?php echo method_field('PUT'); ?>
                                    <div class="flex-1 min-w-[140px]">
                                        <label class="block text-xs font-medium text-slate-500 mb-1">Date limite</label>
                                        <input type="date" name="due_date" class="input-modern text-sm"
                                               value="<?php echo e($filiale->pivot->due_date ? \Carbon\Carbon::parse($filiale->pivot->due_date)->format('Y-m-d') : ''); ?>">
                                    </div>
                                    <button type="submit" class="btn-secondary btn-sm">Enregistrer</button>
                                </form>
                            <?php else: ?>
                                <p class="text-xs text-slate-500">
                                    Échéance :
                                    <?php echo e($filiale->pivot->due_date ? \Carbon\Carbon::parse($filiale->pivot->due_date)->format('d/m/Y') : '—'); ?>

                                </p>
                            <?php endif; ?>
                        </li>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </ul>
            <?php endif; ?>
        </div>
    </div>
 <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal9ac128a9029c0e4701924bd2d73d7f54)): ?>
<?php $attributes = $__attributesOriginal9ac128a9029c0e4701924bd2d73d7f54; ?>
<?php unset($__attributesOriginal9ac128a9029c0e4701924bd2d73d7f54); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal9ac128a9029c0e4701924bd2d73d7f54)): ?>
<?php $component = $__componentOriginal9ac128a9029c0e4701924bd2d73d7f54; ?>
<?php unset($__componentOriginal9ac128a9029c0e4701924bd2d73d7f54); ?>
<?php endif; ?>
<?php /**PATH C:\xampp\htdocs\teyssir\resources\views/admin/forms/show.blade.php ENDPATH**/ ?>