<?php

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

new class extends Component
{
    public $school;
    public $cutting;
    public $tls = [];
    public $sndA = [];
    public $sndC = [];
    public $sndT = [];
    public $premA = [];
    public $premC = [];
    public $premD = [];
    public $premT = [];
    public $tleA = [];
    public $tleC = [];
    public $tleD = [];
    public $tleT = [];
    public $a = 1;
    public $c = 4;
    public $d = 5;
    protected $srvs;

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

    public function mount() {
        $this->sndA = $this->srvs->cycle2Effectif(14, $this->school, $this->cutting, $this->a);
        $this->sndC = $this->srvs->cycle2Effectif(14, $this->school, $this->cutting, $this->c);
        $this->sndT = $this->srvs->effectif(14, $this->school, $this->cutting);

        $this->premA = $this->srvs->cycle2EffectifA(15, $this->school, $this->cutting);
        $this->premC = $this->srvs->cycle2Effectif(15, $this->school, $this->cutting, $this->c);
        $this->premD = $this->srvs->cycle2Effectif(15, $this->school, $this->cutting, $this->d);
        $this->premT = $this->srvs->effectif(15, $this->school, $this->cutting);

        $this->tleA = $this->srvs->cycle2EffectifA(16, $this->school, $this->cutting);
        $this->tleC = $this->srvs->cycle2Effectif(16, $this->school, $this->cutting, $this->c);
        $this->tleD = $this->srvs->cycle2Effectif(16, $this->school, $this->cutting, $this->d);
        $this->tleT = $this->srvs->effectif(16, $this->school, $this->cutting);

        $this->tls = $this->srvs->cmpte1tls($this->school, $this->cutting, 14, 16);
    }
};
?>

<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>
                    @include('partials.chapter2._2nd_table',[
                        'sndA' => $sndA, 
                        'sndC' => $sndC, 
                        'sndT' => $sndT
                    ])
                    @include('partials.chapter2._1ere_table', [
                        'premA' => $premA, 
                        'premC' => $premC, 
                        'premD' => $premD,
                        'premT' => $premT
                    ])
                    @include('partials.chapter2._tle_table', [
                        'tleA' => $tleA, 
                        'tleC' => $tleC, 
                        'tleD' => $tleD,
                        'tleT' => $tleT
                    ])
                    <tr class="p-0">
                        <th class="p-0">
                            <table class="m-0" style="width: 100%">
                            <tr>
                                <td class="text-center py-1" style="width: 100%">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: 100%">{{ $tls[9] < 9 ? '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] < 9 ? '0'.$tls[0]:$tls[0] }}</td>
                                    <td class="text-center py-1" style="width: 30%">{{ $tls[1] < 9 ? '0'.$tls[1]:$tls[1] }}</td>
                                    <td class="text-center py-1" style="width: 40%">{{ $tls[2] < 9 ? '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] < 9 ? '0'.$tls[3]:$tls[3] }}</td>
                                    <td class="text-center py-1" style="width: 30%">{{ $tls[4] < 9 ? '0'.$tls[4]:$tls[4] }}</td>
                                    <td class="text-center py-1" style="width: 40%">{{ $tls[5] < 9 ? '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] < 9 ? '0'.$tls[6]:$tls[6] }}</td>
                                    <td class="text-center py-1" style="width: 30%">{{ $tls[7] < 9 ? '0'.$tls[7]:$tls[7] }}</td>
                                    <td class="text-center py-1" style="width: 40%">{{ $tls[8] < 9 ? '0'.$tls[8]:$tls[8] }}</td>
                                </tr>
                            </table>
                        </th>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>