<?php if (isset($component)) { $__componentOriginal166a02a7c5ef5a9331faf66fa665c256 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal166a02a7c5ef5a9331faf66fa665c256 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'filament-panels::components.page.index','data' => []] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('filament-panels::page'); ?>
<?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 e($this->form); ?>


    <!--[if BLOCK]><![endif]--><?php if($modalityId): ?>
        <div
            x-data="{
                startPolling() {
                    setInterval(() => {
                        window.Livewire.find('<?php echo e($_instance->getId()); ?>').dispatch('pollResults')
                    }, 5000)
                }
            }"
            x-init="startPolling()"
            class="flex flex-col mt-6 space-x-4"
        >
            <!-- Div para a tabela de resultados com rolagem horizontal -->
            <div class="rounded-lg shadow p-4 overflow-auto">
                <h3 class="text-lg font-bold mb-4">Resultados</h3>
                <div class="overflow-x-auto w-full">
                    <table class="table-auto border-collapse border border-gray-200 min-w-[1200px]">
                        <thead>
                            <tr>
                                <!--[if BLOCK]><![endif]--><?php if($isTeams): ?>
                                    <th class="border px-4 py-2">Grupo</th>
                                <?php endif; ?><!--[if ENDBLOCK]><![endif]-->
                                <th class="border px-4 py-2">Participantes</th>
                                <!--[if BLOCK]><![endif]--><?php $__currentLoopData = $rounds; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $round): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <th class="border px-4 py-2">Volta <?php echo e($round['number']); ?></th>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?><!--[if ENDBLOCK]><![endif]-->
                                <th class="border px-4 py-2">Acertos (%)</th>
                                <th class="border px-4 py-2">Total de Acertos</th>
                                <!--[if BLOCK]><![endif]--><?php if($group === 'classification'): ?>
                                    <th class="border px-4 py-2">Força</th>
                                <?php endif; ?><!--[if ENDBLOCK]><![endif]-->
                            </tr>
                        </thead>
                        <tbody>
                            <?php
                                $totalParticipants = 0;
                                $lastGroup = null;
                                $rowspanCount = 0;
                                $firstInGroup = true;
                            ?>
                            <!--[if BLOCK]><![endif]--><?php $__currentLoopData = $tableData; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $inscriptionKey => $inscription): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <!--[if BLOCK]><![endif]--><?php $__currentLoopData = $inscription; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $participant): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>

                                    <!--[if BLOCK]><![endif]--><?php if($participant['modality']): ?>
                                        <?php
                                            $totalParticipants++;
                                            // Se é um novo grupo ou o primeiro item

                                            if ($lastGroup !== $participant['inscription_group_name']) {
                                                // Conta quantos itens têm o mesmo grupo
                                                $rowspanCount = collect($tableData)
                                                    ->flatMap(fn($insc) => $insc)
                                                    ->filter(fn($p) => !empty($p['modality']))
                                                    ->filter(fn($p) => $p['inscription_group_name'] === $participant['inscription_group_name'])
                                                    ->count();
                                                $lastGroup = $participant['inscription_group_name'];
                                                $firstInGroup = true;
                                            } else {
                                                $firstInGroup = false;
                                            }
                                        ?>
                                        <tr>
                                            <!--[if BLOCK]><![endif]--><?php if($isTeams): ?>
                                                <!--[if BLOCK]><![endif]--><?php if($firstInGroup): ?>
                                                    <td class="border px-4 py-2" rowspan="<?php echo e($rowspanCount); ?>">
                                                        <?php echo e($participant['inscription_group_name']); ?>

                                                    </td>
                                                <?php endif; ?><!--[if ENDBLOCK]><![endif]-->
                                            <?php endif; ?><!--[if ENDBLOCK]><![endif]-->
                                            <td class="border px-4 py-2"><?php echo e($participant['name']); ?></td>
                                            <!--[if BLOCK]><![endif]--><?php $__currentLoopData = $rounds; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $round): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                           
                                                <td class="border px-4 py-2 text-center align-middle">
                                                    <!--[if BLOCK]><![endif]--><?php if(isset($participant['rounds'][$round['number']])): ?>
                                                        <!--[if BLOCK]><![endif]--><?php if($participant['rounds'][$round['number']] == 1): ?>
                                                            <span style="color: #4caf50; display: inline-block;">
                                                                <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="4" stroke="currentColor" width="24" height="24" class="size-6">
                                                                    <path stroke-linecap="round" stroke-linejoin="round" d="m4.5 12.75 6 6 9-13.5" />
                                                                </svg>
                                                            </span>
                                                        <?php else: ?>
                                                            <span style="color: red; display: inline-block;">
                                                                <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="4" stroke="currentColor" width="24" height="24" lass="size-6">
                                                                    <path stroke-linecap="round" stroke-linejoin="round" d="M6 18 18 6M6 6l12 12" />
                                                                </svg>
                                                            </span>
                                                        <?php endif; ?><!--[if ENDBLOCK]><![endif]-->
                                                    <?php else: ?>
                                                        -
                                                    <?php endif; ?><!--[if ENDBLOCK]><![endif]-->
                                                </td>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?><!--[if ENDBLOCK]><![endif]-->
                                            <?php
                                                $participantPercent = $participant['total_hits'] / $rounds->count() * 100;
                                            ?>
                                            <td class="border px-4 py-2 font-bold text-center"  style="<?php echo e($participantPercent >= 50 ? 'color: #4caf50;' : 'color: #f44336;'); ?>"><?php echo e($participantPercent); ?>%</td>
                                            <td class="border px-4 py-2 font-bold text-center"><?php echo e($participant['total_hits']); ?></td>
                                            <!--[if BLOCK]><![endif]--><?php if($group === 'classification'): ?>
                                                <td class="border px-4 py-2 font-bold text-center"><?php echo e($participant['group']); ?></td>
                                            <?php endif; ?><!--[if ENDBLOCK]><![endif]-->
                                        </tr>
                                    <?php endif; ?><!--[if ENDBLOCK]><![endif]-->
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?><!--[if ENDBLOCK]><![endif]-->
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?><!--[if ENDBLOCK]><![endif]-->
                        </tbody>
                        <tfoot>
                            <tr>
                                <td class="border px-4 py-2 font-bold text-center" <?php if($isTeams): ?>colspan="2"<?php endif; ?>>Total (%)</td>
                                <!--[if BLOCK]><![endif]--><?php $__currentLoopData = $rounds; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $round): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <?php
                                        $totalHits = 0;

                                        foreach ($tableData as $inscription) {
                                            foreach($inscription as $key => $participant) {
                                                if (!empty($participant['rounds']) &&
                                                    isset($participant['rounds'][$round['number']]) &&
                                                    $participant['rounds'][$round['number']] == 1) {
                                                    $totalHits++;
                                                }
                                            }
                                        }

                                        $percentage = $totalParticipants > 0 ? ($totalHits / $totalParticipants) * 100 : 0;
                                    ?>
                                    <td class="border px-4 py-2 font-semibold text-center" style="<?php echo e($percentage >= 50 ? 'color: #4caf50;' : 'color: #f44336;'); ?>">
                                        <?php echo e(round($percentage)); ?>%
                                    </td>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?><!--[if ENDBLOCK]><![endif]-->
                                <td class="border px-4 py-2" colspan="2"></td>
                            </tr>
                        </tfoot>
                    </table>
                </div>
            </div>

            <!--[if BLOCK]><![endif]--><?php if($hasClassificationRounds && $group === 'classification'): ?>
                <?php $forces = [];
                    foreach ($tableData as $inscription) {
                        foreach($inscription as $key => $participant) {
                            $forces[$participant['group'] ?? 'N/C'] = 0;
                        }
                    }

                    foreach ($forces as $forceKey => $value) {
                        $count = 0;
                        foreach ($tableData as $inscription) {
                            foreach($inscription as $key => $participant) {
                                if($participant['group'] == $forceKey) {
                                    $count++;
                                }
                            }
                        }
                        $forces[$forceKey] = $count;
                    }
                    ksort($forces);
                ?>
                <div class="w-1/2 rounded-lg shadow p-4">
                    <h3 class="text-lg font-bold mb-4">Classificação</h3>
                    <table class="table-auto border-collapse border border-gray-200 w-full">
                        <thead>
                            <tr>
                                <!--[if BLOCK]><![endif]--><?php $__currentLoopData = $forces; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $force => $quantity): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <!--[if BLOCK]><![endif]--><?php if($force !== 'null'): ?>
                                        <th class="border px-4 py-2">Força <?php echo e($force); ?></th>
                                    <?php endif; ?><!--[if ENDBLOCK]><![endif]-->
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?><!--[if ENDBLOCK]><![endif]-->
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <!--[if BLOCK]><![endif]--><?php $__currentLoopData = $forces; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $force => $quantity): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <!--[if BLOCK]><![endif]--><?php if($force !== 'null'): ?>
                                        <td class="border px-4 py-2 text-center">
                                            <?php echo e($quantity); ?>

                                        </td>
                                    <?php endif; ?><!--[if ENDBLOCK]><![endif]-->
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?><!--[if ENDBLOCK]><![endif]-->
                            </tr>
                        </tbody>
                    </table>
                </div>
            <?php endif; ?><!--[if ENDBLOCK]><![endif]-->
        </div>
    <?php endif; ?><!--[if ENDBLOCK]><![endif]-->

 <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal166a02a7c5ef5a9331faf66fa665c256)): ?>
<?php $attributes = $__attributesOriginal166a02a7c5ef5a9331faf66fa665c256; ?>
<?php unset($__attributesOriginal166a02a7c5ef5a9331faf66fa665c256); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal166a02a7c5ef5a9331faf66fa665c256)): ?>
<?php $component = $__componentOriginal166a02a7c5ef5a9331faf66fa665c256; ?>
<?php unset($__componentOriginal166a02a7c5ef5a9331faf66fa665c256); ?>
<?php endif; ?>

    <?php
        $__scriptKey = '3267243204-0';
        ob_start();
    ?>
    <script>

        $wire.on('poll-start', () => {
            if (window.resultPolling) {
                clearInterval(window.resultPolling);
            }

            window.resultPolling = setInterval(() => {
                $wire.dispatch('pollResults');
            }, 5000);
        });
    </script>
    <?php
        $__output = ob_get_clean();

        \Livewire\store($this)->push('scripts', $__output, $__scriptKey)
    ?>
<?php /**PATH C:\Users\Ramos\Herd\freelas\laco_pro\resources\views/filament/pages/result.blade.php ENDPATH**/ ?>