@include('layouts.commons.success')
@include('layouts.commons.errors')

<form method="POST" action="{{ route('projets.update-suivi', $projet->id) }}">
    @csrf
    {{ method_field('PUT') }}
    <input type="hidden" name="projet_id" value="{{ $projet->id }}">

    <div class="row">
        <h4>Etat actuel</h4>
        <div class="col-3 ml-auto">
            <div class="multi-step">
                <ul class="multi-step-list">
                    @for($i = 1; $i <= ETAPE_PROJET::NOMBRE_ETAPE; $i++)
                        <li class="multi-step-item progress-{{ $i }} @isset($projet) @if(in_array(ETAPE_PROJET::ETAPES_ORDERED[$i - 1], $projet->etapes())) current @endif @endisset">
                            <div class="item-wrap">
                                <p class="item-title">{{ $i }}</p>
                            </div>
                        </li>
                    @endfor
                </ul>
            </div>
        </div>
    </div>
    <div class="row custom-frame pt-3">
        {{-- Risques & Etapes --}}
        <div class="col-12 form-group">
            <label>Définir le niveau de criticité</label>
            <div>
                <div class="form-check form-check-inline">
                    <input class="form-check-input" type="radio" name="risque" id="maitrise" value="maitrise" @if($projet->risque === 'maitrise') checked @endif>
                    <label class="form-check-label" for="maitrise">
                        Risques maîtrisés
                    </label>
                </div>
                <div class="form-check form-check-inline">
                    <input class="form-check-input" type="radio" name="risque" id="retard" value="retard" @if($projet->risque === 'retard') checked @endif>
                    <label class="form-check-label" for="retard">
                        Risques de retard, difficultés à atteindre les objectifs
                    </label>
                </div>
                <div class="form-check form-check-inline">
                    <input class="form-check-input" type="radio" name="risque" id="retard_important" value="retard_important" @if($projet->risque === 'retard_important') checked @endif>
                    <label class="form-check-label" for="retard_important">
                        Risques de retard important, voire de non réalisation de l’action
                    </label>
                </div>
            </div>
        </div>
                    

        {{-- Etat d'avancement --}}
        <div class="col-12 form-group">
            <label for="etat_avancement" class="col-form-label">Etat d'avancement du projet</label>
            <div class="col-12">
                <textarea rows="5" class="form-control form-control-sm" id="etat_avancement" name="etat_avancement">{{ old('etat_avancement', $projet->etat_avancement) }}</textarea>
            </div>
        </div>
    </div>

    <h4>Etat futur</h4>
    <div class="row custom-frame pt-3">
        <div class="col-6 form-row">
            <label for="prochaine_echeance" class="col-4 col-form-label">Prochaine échéance</label>
            <div class="col-8">
                <div class="input-group">
                    <input type="text" class="form-control form-control-sm" id="prochaine_echeance" name="prochaine_echeance" value="{{ old('prochaine_echeance', date('d/m/Y', strtotime($projet->prochaine_echeance))) }}">
                    <div class="input-group-append">
                        <span class="input-group-text">
                            <svg width="1em" height="1em" viewBox="0 0 16 16" class="bi bi-calendar3" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
                                <path fill-rule="evenodd" d="M14 0H2a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V2a2 2 0 0 0-2-2zM1 3.857C1 3.384 1.448 3 2 3h12c.552 0 1 .384 1 .857v10.286c0 .473-.448.857-1 .857H2c-.552 0-1-.384-1-.857V3.857z"/>
                                <path fill-rule="evenodd" d="M6.5 7a1 1 0 1 0 0-2 1 1 0 0 0 0 2zm3 0a1 1 0 1 0 0-2 1 1 0 0 0 0 2zm3 0a1 1 0 1 0 0-2 1 1 0 0 0 0 2zm-9 3a1 1 0 1 0 0-2 1 1 0 0 0 0 2zm3 0a1 1 0 1 0 0-2 1 1 0 0 0 0 2zm3 0a1 1 0 1 0 0-2 1 1 0 0 0 0 2zm3 0a1 1 0 1 0 0-2 1 1 0 0 0 0 2zm-9 3a1 1 0 1 0 0-2 1 1 0 0 0 0 2zm3 0a1 1 0 1 0 0-2 1 1 0 0 0 0 2zm3 0a1 1 0 1 0 0-2 1 1 0 0 0 0 2z"/>
                            </svg>
                        </span>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-6 form-row">
            <label for="niveau_priorite" class="col-4 col-form-label">Niveau de priorité</label>
            <div class="col-8">
                <input type="number" class="form-control"
                    id="niveau_priorite" name="niveau_priorite" min="0" max="99"
                    value="{{ old('niveau_priorite', $projet->niveau_priorite ?? '') }}"
                    @cannot('edit_niveau_priorite') disabled @endcannot>
            </div>
        </div>
        <div class="col form-group">
            <label for="prochaine_etape" class="col-form-label">Prochaine étape</label>
            <div class="col-12">
                <textarea rows="5" class="form-control form-control-sm" id="prochaine_etape" name="prochaine_etape">{{ old('prochaine_etape', $projet->prochaine_etape) }}</textarea>
            </div>
        </div>
    </div>
 

    <div class="row">
        <div class="col-12">
            <div class="form-group row text-right">
                <div class="col-sm-12">
                    <a href="{{ route('projets.index') }}" class="btn btn-outline-warning">Annuler</a>
                    @if(Auth::user()->can('edit_projet') && $editable)
                        <input type="submit" class="btn btn-outline-success" value="Enregistrer">
                    @endif
                </div>
            </div>
        </div>
    </div>
</form>

<script>
    $(function() {
        flatpickr('#prochaine_echeance', {
            dateFormat: 'd/m/Y',
            minDate: 'today'
        });
    });
</script>
