@extends('backend.layouts.master')
@section('title', 'Module Edit')
@push('css')
<link rel="stylesheet" href="{{asset('backend/plugins/select2.min.css')}}">
@endpush
<!-- page content -->
<!-- page content -->
@section('content')
    <div class="right_col" role="main">
        <div class="">
            <div class="row">
                <div class="col-md-12 col-sm-12 col-xs-12">
                    <div class="x_panel">
                        <div class="x_title">
                            <h2>Edit Module  <a href="{{route('module.list')}}" class="btn btn-xs btn-success"> Module List</a></h2>
                            <ul class="nav navbar-right panel_toolbox">
                                <li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
                                </li>
                                <li class="dropdown">
                                    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button"
                                       aria-expanded="false"><i class="fa fa-wrench"></i></a>
                                    <ul class="dropdown-menu" role="menu">
                                        <li><a href="#">Settings 1</a>
                                        </li>
                                        <li><a href="#">Settings 2</a>
                                        </li>
                                    </ul>
                                </li>
                                <li><a class="close-link"><i class="fa fa-close"></i></a>
                                </li>
                            </ul>
                            <div class="clearfix"></div>
                        </div>
                        <div class="x_content">
                            <div class="row">
                                <div class="col-sm-3 col-md-3"></div>
                                <div class="col-sm-3 col-md-6">
                                    <form action="{{route('module.update',$module->id)}}" method="post">
                                        {{ csrf_field()}}
                                        <div class="form-group">
                                            <label for="name">Module Group Name</label>
                                            <select name="group_name" class="form-control select2">
                                                <option>-- Select Group --</option>
                                                @foreach($groups as $group)
                                                    <option value="{{$group->id}}" {{$module->module_group_id == $group->id ? 'selected' : ''}}>{{$group->name}}</option>
                                                @endforeach
                                            </select>
                                            <span class="error"><b>{{$errors->first('group_name')}}</b></span>
                                        </div>
                                        <div class="form-group">
                                            <label for="name">Module Name</label>
                                            <input type="text" class="form-control" id="name" name="name" placeholder="Enter name" value="{{old('name') ?? $module->name}}">
                                            <span class="error"><b>
                                                 @if($errors->has('name'))
                                                    {{$errors->first('name')}}
                                                @endif</b>
                                            </span>
                                        </div>
                                        <div class="form-group">
                                            <label for="module_key">Module Key</label>
                                            <input type="text" class="form-control" id="module_key" name="module_key" placeholder="Enter module_key" value="{{old('name') ?? $module->module_key}}">
                                            <span class="error"><b>
                                                 @if($errors->has('module_key'))
                                                        {{$errors->first('module_key')}}
                                                    @endif</b>
                                                 </span>
                                        </div>
                                        <div class="form-group">
                                            <label for="module_url">Module Url</label>
                                            <input type="text" class="form-control" id="module_url" name="module_url" value="{{old('name') ?? $module->module_url}}" placeholder="Enter module_url">
                                            <span class="error"><b>
                                                 @if($errors->has('module_url'))
                                                        {{$errors->first('module_url')}}
                                                    @endif</b></span>
                                        </div>
                                        <div class="form-group">
                                            <label for="module_rank">Module Rank</label>
                                            <input type="text" class="form-control" id="module_rank" name="module_rank" value="{{old('name') ?? $module->module_rank}}" placeholder="Enter module_rank">
                                            <span class="error"><b>
                                                 @if($errors->has('module_rank'))
                                                        {{$errors->first('module_rank')}}
                                                    @endif</b></span>
                                        </div>
                                        <div class="form-group">
                                            <label for="module_icon">Module Icon</label>
                                            <input type="text" class="form-control" id="module_icon" name="module_icon" value="{{old('name') ?? $module->module_icon}}" placeholder="Enter module_icon (eg:- fa fa-dashboard)">
                                        </div>
                                        <div class="form-group">
                                            <label>Disply in Sidebar</label>
                                           <!-- <label>
                                                <input type="radio" name="view_sidebar" id="view_sidebar" checked="{{$module->view_sidebar == 1 ? 'checked' : ''}}" >
                                                <label for="view_sidebar">Yes </label>
                                            </label>                           
                                            <label>
                                                <input type="radio" name="view_sidebar" id="deactive"  checked="{{$module->view_sidebar == 1 ? 'checked' : ''}}" >
                                                <label for="deactive"> No</label>
                                            </label>-->
                                            <select class="form-control" name="view_sidebar">
                                                <option value="1" {{$module->view_sidebar == 1 ? 'selected' : ''}}> Yes</option>
                                                <option value="0" {{$module->view_sidebar == 0 ? 'selected' : ''}}> No</option>
                                            </select>
                                        </div>
                                        <div class="form-group">
                                            <label>Display For &nbsp;</label>
                                            @foreach($roles as $r)
                                                @php($check = '')
                                                <input type="hidden" name="roles[]" value="{{$r->id}}">
                                                @foreach($module->rm as $cp)
                                                    @if($r->id == $cp->role_id)
                                                        @php($check = 'Checked')
                                                        @php
                                                            break;
                                                        @endphp
                                                    @endif
                                                @endforeach
                                                <input type="checkbox" id="{{$r->name}}" name="rms[]" {{$check}} value="{{$r->id}}"> <label for="{{$r->name}}"> {{$r->name}} </label>
                                            @endforeach
                                        </div>
                                        <!-- /.box-body -->
                                        <hr>
                                        <div class="box-footer">
                                            <a href="{{route('module.list')}}" class="btn btn-warning">Cancel</a>
                                            <button type="submit" name="btnCreate" class="btn btn-primary">Update Module</button>
                                        </div>
                                    </form>
                                </div>
                                <div class="col-sm-3 col-md-3"></div>
                            </div>
                            
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- /page content -->
@endsection

@push('js')
<script src="{{asset('backend/plugins/select2.min.js')}}"></script>
    <script>
        $(document).ready(function(){
		    /*-----select2 section---------*/
		    $('.select2').select2();
        });
    </script>
@endpush