@extends('layouts.app')

@section('content')
    <div class="container">
 
        <h2>Resp.Soc.Env.</h2>

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

        <div class="row">
            <div class="col custom-frame pt-3 mr-1">
                <div class="row mb-1">
                    <div class="col">
                        <div class="float-right">
                            @if($has_action)
                            <button type="submit" class="btn btn-outline-success" form="form-resp-soc-env" >
                                Sauvegarder
                            </button>
                        @endif
                        </div>
                    </div>
                </div>
                <form method="POST" id="form-resp-soc-env" action="{{ route('resp-soc-env.update') }}">
                    @csrf
                    {{ method_field('PUT') }}
        
                    @if(sizeof($thematiques) > 0)
                        <span>Sélectionnez les actions que vous souhaitez voir apparaitre dans le formulaire :</span>
                        <ul>
                            @foreach($thematiques as $t)
                                <li>{{ $t->nom }}</li>
                                <ul>
                                    @if(sizeof($t->actions)  > 0)
                                        @foreach($t->actions as $a)
                                            <li>
                                                <input class="form-check-input" type="checkbox" name="{{ $a->id }}" @if($a->visible) checked @endif>
                                                <label class="form-check-label" for="action_{{ $a->id }}">
                                                    {{ $a->nom }}
                                                </label>
                                            </li>
                                        @endforeach
                                    @else
                                        <li>Pas d'action disponible</li>
                                    @endif
                                </ul>
                            @endforeach
                        </ul>
                    @else
                        <h4>Pas de thématique disponible.</h4>
                    @endif
                </form>
            </div>
    
            <div class="col custom-frame pt-3 ml-1">
                <div class="row mb-1">
                    <div class="col">
                        <h4 class="d-inline">Unités d'oeuvre</h4>
                        <div class="float-right">
                            <a class="btn btn-outline-success" href="{{ route('action_unite_oeuvre.create') }}">
                                Ajouter
                            </a>
                        </div>
                    </div>
                </div>
                <table class="table table-striped table-bordered">
                    <thead>
                        <tr>
                            <th scope="col">ID</th>
                            <th scope="col">Libellé</th>
                            <th scope="col">Actions</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach($actions_unite_oeuvre as $a)
                            <tr>
                                <td>{{ $loop->iteration }}</td>
                                <td>{{ $a->libelle }}</td>
                                <td style="width: 25%;">
                                    <a class="btn btn-outline-primary" href="{{ route('action_unite_oeuvre.edit', $a->id) }}" 
                                        data-toggle="tooltip" data-placement="top" title="Editer">
                                        <i class="fas fa-pencil-alt"></i>
                                    </a>
                                    <form class="inline-form-table" action="{{ route('action_unite_oeuvre.destroy', $a->id) }}" method="POST">
                                        @csrf
                                        {{ method_field('DELETE') }}
                                        <button type="submit" class="btn btn-outline-danger"
                                            data-toggle="tooltip" data-placement="top" title="Supprimer">
                                            <i class="fas fa-trash-alt"></i>
                                        </button>
                                    </form>
                                </td>
                            </tr>
                        @endforeach
                    </tbody>
                </table>
            </div>
        </div>
        


    </div>
@endsection
