<?php
use App\Models\Document;
use App\Models\ReportQuarter;
use Livewire\Component;
?>

<div>
    <div class="card_1">
        <div class="card-header my-0 pb-0">
            <div class="d-flex justify-content-between">
                <h6>1 - <u>Documents Pédagogiques</u></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="#myDocModal">
                        <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" style="width: 5%">N°</th>
                        <th style="width: 25%">Document</th>
                        <th class="text-center" style="width: 20%">Nombre</th>
                        <th style="width: 50%">Observation</th>
                        </tr>
                    </thead>
                    <tbody>
                        @php
                            $i = 1;
                        @endphp
                        @forelse ($data as $item)
                            <tr>
                                <th class="text-center">{{ $i < 10 ? '0'.$i++:$i++ }}</th>
                                <td>{{ ucfirst($item['type']) }}</td>
                                <td class="text-center">
                                    {{ $item['nomber'] < 10 ? '0'.$item['nomber']:$item['nomber'] }}
                                </td>
                                <td>{{ ucfirst($item['content']) }}</td>
                            </tr> 
                        @empty
                            <tr>
                                <td colspan="5" class="text-center">Underdefined data</td>
                            </tr>
                        @endforelse
                    </tbody>
                </table>
            </div>
        </div>
    </div>
    <!-- @Modal -->
    <div wire:ignore.self class="modal fade" id="myDocModal" tabindex="-1" role="dialog">
        <div class="modal-dialog modal-lg modal-dialog-centered" role="document">
            <div class="modal-content">
                <div class="modal-header bg-dark py-2">
                    <h4 class="modal-title">Documents Pédagogiques</h4>
                    <strong style="font-size: 17px">
                        {{ $input ? 'Edit':'Add' }}
                        <i class="fas fa-pencil-alt my-0"></i>
                    </strong>
                </div>
                <form action="{{ route('trimestriel.docs') }}" method="post">
                    @csrf
                    <div class="modal-body">
                        <button type="button" class="btn m-0 p-0" id="addDoc" style="width: 25px; float: right; border: 1px solid grey">+</button>
                        <table class="table table-bordered mt-" id="tableDoc" style="width: 100%">
                            <thead>
                                <tr>
                                    <th style="width: 25%">Document</th>
                                    <th style="width: 15%">Nombre</th>
                                    <th style="width: 55%">Observation</th>
                                </tr>
                            </thead>
                            <tbody>
                                @if (sizeof($input))
                                    @for($i = 0; $i < sizeof($input); $i++)
                                        <tr>
                                            <td class="p-0">
                                                <input type="text" name="docs[]" id="doc{{ $i+1 }}" class="form-control m-0" value="{{ $input[$i]['type'] }}">
                                            </td>
                                            <td class="p-0">
                                                <input type="text" name="nbre[]" id="nbre{{ $i+1 }}" class="form-control m-0 nbre" value="{{ $input[$i]['nomber'] }}">
                                            </td>
                                            <td class="p-0">
                                                <input type="text" name="text[]" id="text{{ $i+1 }}" class="form-control m-0" value="{{ $input[$i]['content'] }}">
                                            </td>
                                        </tr>
                                    @endfor
                                @else
                                    <tr>
                                        <td class="p-0">
                                            <input type="text" name="docs[]" id="doc1" class="form-control m-0">
                                        </td>
                                        <td class="p-0">
                                            <input type="text" name="nbre[]" id="nbre1" class="form-control m-0 nbre">
                                        </td>
                                        <td class="p-0">
                                            <input type="text" name="text[]" id="text1" class="form-control m-0">
                                        </td>
                                    </tr> 
                                @endif
                            </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>