<?php

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

new class extends Component
{
    public $data = null;
    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();
        $text = $report ? Introductif::where('report_quarter_id', $report->id)->first():null;

        $paragraphs = explode("\n", $text ? $text->content:null);
        $paragraphs = array_map(function ($p) {
            return ucfirst(trim($p));
        }, $paragraphs);
        $this->data = implode("\n", $paragraphs);
    }

    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">
                <h5><u>Introduction</u></h5>
                <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="#myModal">
                        <i class="fas fa-pen m-0"></i>
                    </button>
                </span>
            </div>
        </div>
        <!-- <hr class="my-1 mx-3"> -->
        <div class="card-body table-border-style p-3 mt-2">
            <?php echo nl2br(e(ucfirst($data))); ?>

        </div>
    </div>
    <!-- @Modal -->
    <div wire:ignore.self class="modal fade" id="myModal" 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">Introduction</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.store')); ?>" method="post">
                    <?php echo csrf_field(); ?>
                    <div class="modal-body">
                        <label for='text'>Texte introductif<span class="text-danger">*</span> :</label>
                        <textarea name="text" rows="10" cols="5" class="form-control" id="text" placeholder="Entrez le texte introductif ici ..." style="resize: none;"><?php echo e($input); ?></textarea>
                    </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\raport\⚡introductif.blade.php ENDPATH**/ ?>