<?php
use Livewire\Component;
use App\Models\Grossesse;
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>b - Les Cas de Grossesse</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="#gsseModal">
                <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 dépot <br> du certificat de grossesse</th>
                        <th>Date possible <br> d'accouchement</th>
                        <th>Qualité de l'auteur</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_depot)) }}</td>
                    <td>{{ date('d/m/Y', strtotime($item->date_accouch)) }}</td>
                    <td>{{ ucfirst($item->qualite) }}</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="gsseModal" 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 Grossesse</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.grsse') }}" method="post">
                    @csrf
                    <div class="modal-body">
                        <button type="button" class="btn mb-1 p-0 btnGsse" style="width: 25px; float: right; border: 1px solid grey">+</button>
                        <table class="table table-bordered mt-" id="myTableGsse" 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_g_{{ $i }}">Classe<span class="text-danger">*</span> :</label>
                                            <select name="tab1[]" id="class_g_{{ $i }}" class="form-control getClass" data-id="{{ $i }}" data-lib="b_gss">
                                                <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_gss_{{ $i }}">Elève<span class="text-danger">*</span> :</label>
                                            <select name="tab2[]" id="std_gss_{{ $i }}" class="form-control">
                                                <option class="{{ 'opt_gss_'.$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_d_{{ $i }}">Date dépot du certificat de grossesse<span class="text-danger">*</span> :</label>
                                            <input type="date" name="tab3[]" id="dte_d_{{ $i }}" class="form-control" value="{{ $item->date_depot }}">
                                        </div>
                                        <div class="col-sm-6">
                                            <label class="col-form-label" for="dte_p_{{ $i }}">Date possible d'accouchement<span class="text-danger">*</span> :</label>
                                            <input type="date" name="tab4[]" id="dte_p_{{ $i }}" class="form-control" value="{{ $item->date_accouch }}">
                                        </div>
                                        <div class="col-sm-12">
                                            <label class="col-form-label" for="qlt_{{ $i }}">Qualité de l'auteur<span class="text-danger">*</span> :</label>
                                            <input type="text" name="tab5[]" id="qlt_{{ $i }}" class="form-control" value="{{ $item->qualite }}">
                                        </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_g_1">Classe<span class="text-danger">*</span> :</label>
                                            <select name="tab1[]" id="class_g_1" class="form-control getClass" data-id="1" data-lib="b_gss">
                                                <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_gss_1">Elève<span class="text-danger">*</span> :</label>
                                            <select name="tab2[]" id="std_gss_1" class="form-control">
                                                <option value="">Select ...</option>
                                            </select>
                                        </div>
                                        <div class="col-sm-6">
                                            <label class="col-form-label" for="dte_d_1">Date dépot du certificat de grossesse<span class="text-danger">*</span> :</label>
                                            <input type="date" name="tab3[]" id="dte_d_1" class="form-control" placeholder="---">
                                        </div>
                                        <div class="col-sm-6">
                                            <label class="col-form-label" for="dte_p_1">Date possible d'accouchement<span class="text-danger">*</span> :</label>
                                            <input type="date" name="tab4[]" id="dte_p_1" class="form-control" placeholder="---">
                                        </div>
                                        <div class="col-sm-12">
                                            <label class="col-form-label" for="qlt_1">Qualité de l'auteur<span class="text-danger">*</span> :</label>
                                            <input type="text" name="tab5[]" id="qlt_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>