<?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 $input = [];
    public $classes = [];
    public $datas = [];
    public $educs = [];
    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;
    }


    public function myInput(RepportService $service, Chapter3Service $service1) {
        $this->input = $this->data;
        $this->educs = $service1->getEducats($this->school);
        $this->classes = $service->getClass($this->school, $this->cutting);
    }
};
?>

<div>
    <div class="card-header my-0 pb-0">
        <div class="d-flex justify-content-between">
            <h6>b - Activités Sportives</h6>
            <span>
                <button wire:click="myInput" class="btn btn-inverse btn-outline-inverse btn-sm py-1 mt-0" title="Edit Info" data-toggle="modal" data-target="#actiModal">
                <i class="fas fa-pen m-0"></i>
                </button>
            </span>
        </div>
    </div>
    <div class="card-body table-border-style mt-2">
        @include('partials.chapter3._table_2', [
            'data' => $data,
            'title' => 'Activités sportives',
        ])
    </div>
    <!-- @Modal -->
    <div wire:ignore.self class="modal fade" id="actiModal" tabindex="-1" role="dialog">
        <div class="modal-dialog modal-lg modal-dialog-centered" role="document" style="max-width: 70%;">
            <div class="modal-content">
                <div class="modal-header bg-dark py-2">
                    <h4 class="modal-title">Activités Sportives</h4>
                    <strong style="font-size: 17px">
                        {{ count($input) ? 'Edit':'Add' }}
                        <i class="fas fa-pencil-alt my-0"></i>
                    </strong>
                </div>
                @include('partials.chapter3._form',[
                    'url' => $type,
                    'theme' => '4_b',
                    'educs' => $educs,
                    'id1' => 'clbs_b_',
                    'id2' => 'dtd_b_',
                    'id3' => 'dtf_b_',
                    'id4' => 'cls_b_',
                    'id5' => 'std_b_',
                    'id6' => 'educ_b_',
                    'datas' => $input,
                    'let' => 'b'
                ])
            </div>
        </div>
    </div>
</div>