@extends('layouts.default')
@extends('content_wrappers.md-8')

@section('title', '| Edit Role')
@section('heading', 'Edit '.$role->name)

@section('scripts')
<script src="{{ asset('js/role_categories.js') }}"></script>
@endsection

@section('content')
    {{ Form::model($role, array('route' => array('roles.update', $role->id), 'method' => 'PUT')) }}{{-- Form model binding to automatically populate our fields with role data --}}

    <div class='form-group'>
      {{ Form::label('name', 'Name') }}
      {{ Form::text('name', null, array('class' => 'form-control')) }}
    </div>

    <div class='form-group'>
      {{ Form::label('description', 'Description') }}
      {{ Form::textarea('description', null, array('class' => 'form-control')) }}
    </div>

    <br/><h1>Permissions</h1>

    <div class='panel-group' id='accordion'>
    @foreach ($permissions as $key=>$category)
      <div class='panel panel-default'>

        <div class='panel-heading'>
          <h2 class='panel-title  @if(in_array($key,$active_cats))font-weight-bold @endif'>
            <a data-toggle='collapse' data-parent='#accordion' href='#collapse{{str_replace(' ','',$key)}}'>{{$key}}</a>
          </h2>
        </div>

        <div id='collapse{{str_replace(' ','',$key)}}' class='panel-collapse collapse'>
          <div class='panel-body'>
            @foreach ($category as $permission)
              <div class='col-md-6'>
                <div class='form-group'>
                  @if(in_array($permission->id,$active_perms))
                    {{ Form::checkbox('p_'.$permission->id,$permission->id,1)}}
                  @else
                    {{ Form::checkbox('p_'.$permission->id,$permission->id)}}
                  @endif
                  {{ Form::label('name', $permission->name) }}
                </div>
              </div>
            @endforeach
          </div>
        </div>
      </div>
    @endforeach
    </div>

    {{ Form::submit('Save', array('class' => 'btn btn-primary')) }}

    {{ Form::close() }}

@endsection
