<?php

use App\Services\Chapter2Service;
use Livewire\Component;

new class extends Component
{
    public $data;
    public $school;
    public $cutting;
    public $tls = [];
    protected $srvs;

    public function boot(Chapter2Service $srvs) {
        $this->srvs = $srvs;
    }

    public function mount() {
        $this->data = $this->srvs->getCycle($this->school, 3);
        $this->tls = $this->srvs->cmpte1tls($this->school, $this->cutting);
    }


    public function compte($level) {
        return $this->srvs->effectif($level, $this->school, $this->cutting);
    }
};
?>

<div>
    <div class="card-block table-border-style">
        <div class="table-responsive">
            <table class="table table-bordered" style="width: 100%">
                <thead>
                    <tr>
                        <th class="text-center py-0">Niveau</th>
                        <th class="text-center py-0">Nombre <br> classes</th>
                        <th class="p-0">
                            <table class="m-0" style="width: 100%">
                                <tr>
                                    <th class="text-center py-1" colspan="3">Filles</th>
                                </tr>
                                <tr>
                                    <th class="text-center py-1" style="width: 30%">Red</th>
                                    <th class="text-center py-1" style="width: 30%">N-Red</th>
                                    <th class="text-center py-1" style="width: 40%">Total</th>
                                </tr>
                            </table>
                        </th>
                        <th class="p-0">
                            <table class="m-0" style="width: 100%">
                                <tr>
                                    <th class="text-center py-1" colspan="3">Garçons</th>
                                </tr>
                                <tr>
                                    <th class="text-center py-1" style="width: 30%">Red</th>
                                    <th class="text-center py-1" style="width: 30%">N-Red</th>
                                    <th class="text-center py-1" style="width: 40%">Total</th>
                                </tr>
                            </table>
                        </th>
                        <th class="p-0">
                            <table class="m-0" style="width: 100%">
                                <tr>
                                    <th class="text-center py-1" colspan="3">Effectif total</th>
                                </tr>
                                <tr>
                                    <th class="text-center py-1" style="width: 30%">Red</th>
                                    <th class="text-center py-1" style="width: 30%">N-Red</th>
                                    <th class="text-center py-1" style="width: 40%">Total</th>
                                </tr>
                            </table>
                        </th>
                    </tr>
                </thead>
                <tbody>
                    @foreach ($data as $item)
                    @php $dts = $this->compte($item->id) @endphp
                    <tr>
                        <td class="p-0">
                            <table class="m-0" style="width: 100%">
                                <tr>
                                    <td class="text-center py-1" style="width: 30%">{{ $item->code }}</td>
                                </tr>
                            </table>
                        </td>
                        <td class="p-0">
                            <table class="m-0" style="width: 100%">
                                <tr>
                                    <td class="text-center py-1" style="width: 30%">{{ $dts[9] < 10 ? '0'.$dts[9]:$dts[9] }}</td>
                                </tr>
                            </table>
                        </td>
                        <td class="p-0">
                            <table class="m-0" style="width: 100%">
                                <tr>
                                    <td class="text-center py-1" style="width: 30%">{{ $dts[0] < 10 ? '0'.$dts[0]:$dts[0] }}</td>
                                    <td class="text-center py-1" style="width: 30%">{{ $dts[1] < 10 ? '0'.$dts[1]:$dts[1] }}</td>
                                    <td class="text-center py-1" style="width: 40%">{{ $dts[2] < 10 ? '0'.$dts[2]:$dts[2] }}</td>
                                </tr>
                            </table>
                        </td>
                        <td class="p-0">
                            <table class="m-0" style="width: 100%">
                                <tr>
                                    <td class="text-center py-1" style="width: 30%">{{ $dts[3] < 10 ? '0'.$dts[3]:$dts[3] }}</td>
                                    <td class="text-center py-1" style="width: 30%">{{ $dts[4] < 10 ? '0'.$dts[4]:$dts[4] }}</td>
                                    <td class="text-center py-1" style="width: 40%">{{ $dts[5] < 10 ? '0'.$dts[5]:$dts[5] }}</td>
                                </tr>
                            </table>
                        </td>
                        <td class="p-0">
                            <table class="m-0" style="width: 100%">
                                <tr>
                                    <td class="text-center py-1" style="width: 30%">{{ $dts[6] < 10 ? '0'.$dts[6]:$dts[6] }}</td>
                                    <td class="text-center py-1" style="width: 30%">{{ $dts[7] < 10 ? '0'.$dts[7]:$dts[7] }}</td>
                                    <td class="text-center py-1" style="width: 40%">{{ $dts[8] < 10 ? '0'.$dts[8]:$dts[8] }}</td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                    @endforeach
                    <tr class="p-0">
                        <th class="p-0">
                            <table class="m-0" style="width: 100%">
                                <tr>
                                    <td class="text-center py-1" style="width: 30%">Total</td>
                                </tr>
                            </table>
                        </th>
                        <th class="p-0">
                            <table class="m-0" style="width: 100%">
                                <tr>
                                    <td class="text-center py-1" style="width: 30%">{{ $tls[9] < 10 ? '0'.$tls[9]:$tls[9] }}</td>
                                </tr>
                            </table>
                        </th>
                        <th class="p-0">
                            <table class="m-0" style="width: 100%">
                                <tr>
                                    <td class="text-center py-1" style="width: 30%">{{ $tls[0] < 10 ? '0'.$tls[0]:$tls[0] }}</td>
                                    <td class="text-center py-1" style="width: 30%">{{ $tls[1] < 10 ? '0'.$tls[1]:$tls[1] }}</td>
                                    <td class="text-center py-1" style="width: 40%">{{ $tls[2] < 10 ? '0'.$tls[2]:$tls[2] }}</td>
                                </tr>
                            </table>
                        </th>
                        <th class="p-0">
                            <table class="m-0" style="width: 100%">
                                <tr>
                                    <td class="text-center py-1" style="width: 30%">{{ $tls[3] < 10 ? '0'.$tls[3]:$tls[3] }}</td>
                                    <td class="text-center py-1" style="width: 30%">{{ $tls[4] < 10 ? '0'.$tls[4]:$tls[4] }}</td>
                                    <td class="text-center py-1" style="width: 40%">{{ $tls[5] < 10 ? '0'.$tls[5]:$tls[5] }}</td>
                                </tr>
                            </table>
                        </th>
                        <th class="p-0">
                            <table class="m-0" style="width: 100%">
                                <tr>
                                    <td class="text-center py-1" style="width: 30%">{{ $tls[6] < 10 ? '0'.$tls[6]:$tls[6] }}</td>
                                    <td class="text-center py-1" style="width: 30%">{{ $tls[7] < 10 ? '0'.$tls[7]:$tls[7] }}</td>
                                    <td class="text-center py-1" style="width: 40%">{{ $tls[8] < 10 ? '0'.$tls[8]:$tls[8] }}</td>
                                </tr>
                            </table>
                        </th>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>