<?php

use Livewire\Component;

use App\Models\ReportQuarter;
use App\Models\ActivitParaScolaire;
use App\Services\RepportService;
use App\Services\Chapter3Service;
new class extends Component
{
    public $type = 2;
    public $data = [];
    public $school;
    public $cutting;

    public function mount() {
        $report = ReportQuarter::where('school_id', $this->school)->where('cutting_school_year_id', $this->cutting)->first();
        $dts = $report ? ActivitParaScolaire::where('report_quarter_id', $report->id)->where('type', $this->type)->orderBy('order')->get():[];
        $this->data = $dts;
    }
};
?>

<div>
    <div class="table-responsive">
        <table class="table table-bordered" style="width: 100%">
            <thead>
                <tr>
                    <th class="text-center" style="padding: 8px">N°</th>
                    <th style="padding: 8px">Activités sportives</th>
                    <th style="padding: 8px">Période</th>
                    <th style="padding: 8px">Elèves responsable</th>
                    <th style="padding: 8px">Educateurs</th>
                </tr>
            </thead>
            <tbody>
                @php $i = 1; @endphp
                @forelse ($data as $item)
                    <tr>
                        <th class="text-center" style="padding: 8px">{{ $i < 10 ? '0'.$i++:$i++ }}</th>
                        <td style="padding: 8px">
                            {{ ucfirst($item->activit) }}
                        </td>
                        <td style="padding: 8px">
                            Du {{ date('d/m/Y', strtotime($item->date_dbt)).' au '.date('d/m/Y', strtotime($item->date_fin)) }}
                        </td>
                        <td style="padding: 8px">
                            {{ strtoupper($item->inscription->student->first_name).' '.ucwords($item->inscription->student->last_name) }}
                        </td>
                        <td style="padding: 8px">
                            {{ ($item->user->sexe == 'F' ? 'Mme':'Mr').' '.strtoupper($item->user->first_name).' '.ucwords($item->user->last_name) }}
                        </td>
                    </tr> 
                @empty
                    <tr>
                        <td colspan="5" class="text-center" style="padding: 8px">Underdefined data</td>
                    </tr>
                @endforelse
            </tbody>
        </table>
    </div>
</div>