@extends('template')

@section('page-title') Autorisations @endsection

@section('tag-title') Autorisations @endsection

@section('page-sub-title')

@endsection

@section('main-content')
    <?php

    ?>
    <div class="row">
        <div class="col-xl-12">
            <div class="card">
                <div class="card-body">
                    <form method="POST" autocomplete="off" action="" enctype="multipart/form-data" class="form-horizontal form-label-left input_mask form-step">
                        {{csrf_field()}}
                        <input type="hidden" value="@if($model->id!=0){{$model->id}}@else{{0}}@endif" id="_id" name="_id">

                        <div class="col-sm-12">
                            <div class="form-group">
                                <label for="name" class="control-label">Role</label>
                                <input  class="form-control" value="{{$model->nom}}" name="name" id="name"  type="text" >
                            </div>
                        </div>

                        <?php
                        $menu_check_ids = $model->menus->pluck('id')->toArray();
                        $menus = \App\Models\Menu::select('*')->whereNull('menus.menu_id')->orderBy('sequence','asc')->get();
                        ?>

                        <style>
                            .checkbox{
                                margin-bottom: 0;
                                margin-top: 0;
                            }
                        </style>

                        <div class="col-sm-12">
                            <table class="table m-0  table-bordered-custom">
                                <thead>
                                <tr>
                                    <th>Menus</th>
                                    <th style="text-align: center">Attribution d'accès</th>
                                </tr>
                                </thead>
                                <tbody>
                                @foreach($menus as $p)
                                    <tr>
                                        <td class="libelle">
                                            {{$p->nom}}
                                            @if($p->menus->count()!=0)
                                                <div class="ml-15 pt-10" style="border-left: 1px solid #a6a6a6">
                                                    @foreach($p->menus as $sm)
                                                        <div class="ml-5">{{$sm->name}}</div>
                                                    @endforeach
                                                </div>
                                            @endif
                                        </td>
                                        <td  align="center" valign="top">
                                            <div class="checkbox checkbox-primary">
                                                <input name="aut_{{$p->id}}" id="checkbox-signup" @if(in_array($p->id, $menu_check_ids)) checked @endif type="checkbox" >
                                                <label for="checkbox-signup"></label>
                                            </div>
                                            @if($p->menus->count()!=0)
                                                <div class="mt-10">
                                                    @foreach($p->menus as $sm)
                                                        <div class="checkbox checkbox-custom">
                                                            <input name="aut_{{$sm->id}}" id="checkbox-signup" @if(in_array($sm->id, $menu_check_ids)) checked @endif type="checkbox" >
                                                            <label for="checkbox-signup"></label>
                                                        </div>
                                                    @endforeach
                                                </div>
                                            @endif
                                        </td>
                                    </tr>
                                @endforeach
                                </tbody>
                            </table>
                        </div>

                        <div class="col-sm-12 mt-3">
                            <button type="submit"  class="btn btn-success action-btn  float-right btn-submit-step">Enregistrer</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>

    <style>
        label{
            font-weight: bold;
        }

        .table th, .table td{
            padding: 5px 10px;
        }

    </style>

@endsection


@section('page-style')

@endsection

@section('page-script')

@endsection
