<?php
use Livewire\Component;
use App\Models\Deces;
use App\Models\ReportQuarter;
use App\Services\RepportService;
?>

<div>
    <div class="card-header my-0 pb-0">
        <div class="d-flex justify-content-between">
            <h6>d - Les Cas de Décès</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="#dcsModal">
                <i class="fas fa-pen m-0"></i>
                </button>
            </span>
        </div>
    </div>
    <div class="card-body table-border-style mt-2">
        <div class="table-responsive">
            <table class="table table-bordered" style="width: 100%">
                <thead>
                    <tr>
                        <th class="text-center">N°</th>
                        <th>Matricule</th>
                        <th>Nom et Prénons</th>
                        <th>Sexe</th>
                        <th>Age</th>
                        <th>Classe</th>
                        <th>Date de décès</th>
                        <th>Cause de décès</th>
                    </tr>
                </thead>
                <tbody>
                @php $i = 1; @endphp
                @forelse ($data as $item)
                    <tr>
                    <th class="text-center">{{ $i < 10 ? '0'.$i++:$i++ }}</th>
                    <td class="text-center">{{ $item->inscription->student->matricule }}</td>
                    <td>
                        {{ strtoupper($item->inscription->student->first_name).' '.ucwords($item->inscription->student->last_name) }}
                    </td>
                    <td class="text-center">{{ $item->inscription->student->sexe }}</td>
                    <td class="text-center">{{ $item->inscription->student->age.' ans' }}</td>
                    <td>{{ ucfirst($item->classe->libelle) }}</td>
                    <td>{{ date('d/m/Y', strtotime($item->date)) }}</td>
                    <td>{{ ucfirst($item->cause) }}</td>
                    </tr> 
                @empty
                    <tr>
                    <td colspan="10" class="text-center">Underdefined data</td>
                    </tr>
                @endforelse
                </tbody>
            </table>
        </div>
    </div>
    <!-- @Modal -->
    <div wire:ignore.self class="modal fade" id="dcsModal" tabindex="-1" role="dialog">
        <div class="modal-dialog modal-lg modal-dialog-centered" role="document" style="max-width: 50%;">
            <div class="modal-content">
                <div class="modal-header bg-dark py-2">
                    <h4 class="modal-title">Cas de Décès</h4>
                    <strong style="font-size: 17px">
                        {{ sizeof($input) ? 'Edit':'Add' }}
                        <i class="fas fa-pencil-alt my-0"></i>
                    </strong>
                </div>
                <form action="{{ route('chapter_3.deces') }}" method="post">
                    @csrf
                    <div class="modal-body">
                        <button type="button" class="btn mb-1 p-0 btnDcs" style="width: 25px; float: right; border: 1px solid grey">+</button>
                        <table class="table table-bordered mt-" id="myTableDcs" style="width: 100%">
                        <tbody>
                            @php $i = 1; @endphp
                            @forelse ($input as $item)
                            <tr>
                                <td style="width: 100%">
                                    <div class="row">
                                        <div class="col-sm-6">
                                            <label class="col-form-label" for="class_dcs_{{ $i }}">Classe<span class="text-danger">*</span> :</label>
                                            <select name="tab1[]" id="class_dcs_{{ $i }}" class="form-control getClass" data-id="{{ $i }}" data-lib="d_dcs">
                                                <option value="">Select ...</option>
                                                @foreach ($classes as $classe)
                                                <option value="{{ $classe->id }}" {{ $classe->id == $item->classe_id  ? 'selected':null}}>{{ ucfirst($classe->libelle) }}</option>
                                                @endforeach
                                            </select>
                                        </div>
                                        <div class="col-sm-6">
                                            <label class="col-form-label" for="std_dcs_{{ $i }}">Elève<span class="text-danger">*</span> :</label>
                                            <select name="tab2[]" id="std_dcs_{{ $i }}" class="form-control">
                                                <option class="{{ 'opt_dcs_'.$i }}" value="{{ $item->inscription_id }}">
                                                    {{ strtoupper($item->inscription->student->first_name).' '.ucwords($item->inscription->student->last_name) }}
                                                </option>
                                            </select>
                                        </div>
                                        <div class="col-sm-6">
                                            <label class="col-form-label" for="dte_ds_{{ $i }}">Date de décès<span class="text-danger">*</span> :</label>
                                            <input type="date" name="tab3[]" id="dte_ds_{{ $i }}" class="form-control" value="{{ $item->date }}">
                                        </div>
                                        <div class="col-sm-6">
                                            <label class="col-form-label" for="cause_{{ $i }}">Cause de décès<span class="text-danger">*</span> :</label>
                                            <input type="text" name="tab4[]" id="cause_{{ $i }}" class="form-control" value="{{ $item->cause }}">
                                        </div>
                                    </div>
                                </td>
                            </tr>
                            @php $i++ @endphp
                            @empty
                            <tr>
                                <td style="width: 100%">
                                    <div class="row">
                                        <div class="col-sm-6">
                                            <label class="col-form-label" for="class_dcs_1">Classe<span class="text-danger">*</span> :</label>
                                            <select name="tab1[]" id="class_dcs_1" class="form-control getClass" data-id="1" data-lib="d_dcs">
                                                <option value="">Select ...</option>
                                                @foreach ($classes as $classe)
                                                <option value="{{ $classe->id }}">{{ ucfirst($classe->libelle) }}</option>
                                                @endforeach
                                            </select>
                                        </div>
                                        <div class="col-sm-6">
                                            <label class="col-form-label" for="std_dcs_1">Elève<span class="text-danger">*</span> :</label>
                                            <select name="tab2[]" id="std_dcs_1" class="form-control">
                                                <option value="">Select ...</option>
                                            </select>
                                        </div>
                                        <div class="col-sm-6">
                                            <label class="col-form-label" for="dte_ds_1">Date de décès<span class="text-danger">*</span> :</label>
                                            <input type="date" name="tab3[]" id="dte_ds_1" class="form-control" placeholder="---">
                                        </div>
                                        <div class="col-sm-6">
                                            <label class="col-form-label" for="cause_1">Cause de décès<span class="text-danger">*</span> :</label>
                                            <input type="text" name="tab4[]" id="cause_1" class="form-control" placeholder="---">
                                        </div>
                                    </div>
                                </td>
                            </tr>
                            @endforelse
                        </tbody>
                        </table>
                    </div>
                    <div class="modal-footer">
                        <input type="hidden" name="school" value="{{ $school }}">
                        <input type="hidden" name="cutting" value="{{ $cutting }}">
                        <button class="btn btn-inverse btn-outline-inverse btn-sm py-1 mx-2" data-dismiss="modal">Fermer</button>
                        <button class="btn btn-inverse btn-outline-inverse btn-sm py-1 mx-2">Valider</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>