<?php

use App\Models\Document;
use App\Models\ReportQuarter;
use Livewire\Component;

new class extends Component
{
    public $data = [];
    public $input = [];
    public $school;
    public $cutting;

    public function __contruct($cutting, $school) {
        $this->cutting = $cutting;
        $this->school = $school;
    }

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

    public function myInput() {
        $this->input = $this->data;
    }
};
?>

<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 style="width: 25%">Nombre</th>
                        <th style="width: 45%">Observation</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                            $i = 1;
                        ?>
                        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::openLoop(); ?><?php endif; ?><?php $__empty_1 = true; $__currentLoopData = $data; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::startLoop($loop->index); ?><?php endif; ?>
                            <tr>
                                <th class="text-center"><?php echo e($i < 10 ? '0'.$i++:$i++); ?></th>
                                <td><?php echo e(ucfirst($item['type'])); ?></td>
                                <td class="text-center">
                                    <?php echo e($item['nomber'] < 10 ? '0'.$item['nomber']:$item['nomber']); ?>

                                </td>
                                <td><?php echo e(ucfirst($item['content'])); ?></td>
                            </tr> 
                        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::endLoop(); ?><?php endif; ?><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><?php \Livewire\Features\SupportCompiledWireKeys\SupportCompiledWireKeys::closeLoop(); ?><?php endif; ?>
                            <tr>
                                <td colspan="5" class="text-center">Underdefined data</td>
                            </tr>
                        <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                    </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">
                        <?php echo e($input ? 'Edit':'Add'); ?>

                        <i class="fas fa-pencil-alt my-0"></i>
                    </strong>
                </div>
                <form action="<?php echo e(route('trimestriel.docs')); ?>" method="post">
                    <?php echo csrf_field(); ?>
                    <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>
                                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if(sizeof($input)): ?>
                                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php for($i = 0; $i < sizeof($input); $i++): ?>
                                        <tr>
                                            <td class="p-0">
                                                <input type="text" name="docs[]" id="doc<?php echo e($i+1); ?>" class="form-control m-0" value="<?php echo e($input[$i]['type']); ?>">
                                            </td>
                                            <td class="p-0">
                                                <input type="text" name="nbre[]" id="nbre<?php echo e($i+1); ?>" class="form-control m-0 nbre" value="<?php echo e($input[$i]['nomber']); ?>">
                                            </td>
                                            <td class="p-0">
                                                <input type="text" name="text[]" id="text<?php echo e($i+1); ?>" class="form-control m-0" value="<?php echo e($input[$i]['content']); ?>">
                                            </td>
                                        </tr>
                                    <?php endfor; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                                <?php 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> 
                                <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                            </tbody>
                        </table>
                    </div>
                    <div class="modal-footer">
                        <input type="hidden" name="school" value="<?php echo e($school); ?>">
                        <input type="hidden" name="cutting" value="<?php echo e($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><?php /**PATH C:\Users\EDUCAS\Desktop\App\V4_001\resources\views\components\chapter1\document.blade.php ENDPATH**/ ?>