<?php

use App\Services\Chapter1Service;
use Livewire\Component;

new class extends Component
{
    public $levels;
    public $school;
    public $cutting;
    protected $srvs;

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

    public function cmptClass($id) {
        return $this->srvs->cpteClass($id, $this->school, $this->cutting);
    }

    public function cmptEffts($id) {
        return $this->srvs->eftfLevel($id, $this->school, $this->cutting);
    }

    public function clclPourctage($id) {
        return $this->srvs->dataStds($id, $this->school, $this->cutting);
    }

    public function mount() {
        $this->levels = $this->srvs->getLevel($this->school, 4);
    }
};
?>

<div>
    <div id="accordion" role="tablist" aria-multiselectable="true">
        @foreach ($levels as $item)
        <div class="accordion-panel">
            <div class="accordion-heading" role="tab" id="headingOne">
                <h3 class="card-title accordion-title">
                    <a class="accordion-msg px-0" data-toggle="collapse" data-parent="#accordion" href="#collapse_{{ $item->id }}" aria-expanded="true" aria-controls="collapse_{{ $item->id }}">
                        <span style="font-size: 15px; text-decoration: none; color: black">
                            <span><u>Niveau</u> : {{ $item->code }}</span>
                            <i class="fas fa-chevron-circle-down" style="float: right; color: grey"></i>
                        </span>
                        <div class="table-responsive">
                            @php $dta = $this->clclPourctage($item->id) @endphp
                            <table class="table table-bordered" style="width: 100%">
                                <thead>
                                    <tr>
                                        <th class="text-center">Nbre de classe</th>
                                        <th class="text-center">Effectif</th>
                                        <th class="text-center">Classé</th>
                                        <th class="text-center">Non classé</th>
                                        <th class="text-center">Moy ≥ 10</th>
                                        <th class="text-center">8.5 ≤ Moy ≤ 9.99</th>
                                        <th class="text-center">Moy < 8.5</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr>
                                        <td class="text-center">{{ $this->cmptClass($item->id) }}</td>
                                        <td class="text-center">{{ $this->cmptEffts($item->id) }}</td>
                                        <td class="text-center">{{ $dta[0]['nbre'] }}</td>
                                        <td class="text-center">{{ $dta[1]['nbre'] }}</td>
                                        <td class="text-center">{{ $dta[2]['nbre'].' soit '.$dta[2]['pctge'] }}</td>
                                        <td class="text-center">{{ $dta[3]['nbre'].' soit '.$dta[3]['pctge'] }}</td>
                                        <td class="text-center">{{ $dta[4]['nbre'].' soit '.$dta[4]['pctge'] }}</td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </a>
                </h3>
            </div>
            <div id="collapse_{{ $item->id }}" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="heading_{{ $item->id }}">
                <div class="accordion-content accordion-desc">
                @livewire('chapter1.list_class', ['class' => $item->id, 'cutting' => $cutting, 'school' => $school])
                </div>
            </div>
        </div>
        @endforeach
    </div>
</div>