@extends('admin.layouts.master')

@section('title')
    Agent
@stop

@section('style')
    {{--<link href="https://gitcdn.github.io/bootstrap-toggle/2.2.2/css/bootstrap-toggle.min.css" rel="stylesheet">--}}
    <link rel="stylesheet" type="text/css" href="{{asset('/css/bootstrap-toggle.min.css')}}">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

    <style>
    .checkbox label:after {
      content: '';
      display: table;
      clear: both;
    }

    .checkbox .cr {
      position: relative;
      display: inline-block;
      border: 1px solid #a9a9a9;
      border-radius: .25em;
      width: 1.3em;
      height: 1.3em;
      float: left;
      margin-right: .5em;
    }

    .checkbox .cr .cr-icon {
      position: absolute;
      font-size: .8em;
      line-height: 0;
      top: 50%;
      left: 15%;
    }

    .checkbox label input[type="checkbox"] {
      display: none;
    }

    .checkbox label input[type="checkbox"]+.cr>.cr-icon {
      opacity: 0;
    }

    .checkbox label input[type="checkbox"]:checked+.cr>.cr-icon {
      opacity: 1;
    }

    .checkbox label input[type="checkbox"]:disabled+.cr {
      opacity: .5;
    }
    </style>
@stop

@section('content')
    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper" >
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
                <span class="fa fa-user-plus"></span> Edit Agent
            </h1>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-user-plus"></i> Admin Panel</a></li>
                <li class="active">Edit Agent</li>
            </ol>
        </section>

        <!-- Main content -->
        <section class="content" style=" padding-bottom: 10%;">
            <div class="page-header">
                <a href="{{route('agents')}}" class="btn btn-primary"><i class="fa fa-backward"></i> Back</a>
            </div>
            <form method="post" action="{{route('agents.update')}}">
                <input type="hidden" name="agent_id" id="agent_id" class="form-control" value="{{$agent->id}}" readonly>
                <div class="col-md-6">
                    <div class="form-group has-feedback @if($errors->has('code')) has-error @endif">
                        <label for="code" class="control-label">Agent Code</label>
                        <input type="text" name="code" id="code" class="form-control" value="{{$agent->code}}">
                        <span class="glyphicon glyphicon-barcode form-control-feedback"></span>
                        @if($errors->has('code')) <span class="help-block">{{$errors->first('code')}}</span> @endif
                    </div>
                    <div class="form-group has-feedback @if($errors->has('username')) has-error @endif">
                        <label for="username" class="control-label">Username</label>
                        <input type="text" name="username" id="username" class="form-control" value="{{$agent->username}}">
                        <span class="glyphicon glyphicon-user form-control-feedback"></span>
                        @if($errors->has('username')) <span class="help-block">{{$errors->first('username')}}</span> @endif
                    </div>
                    <div class="form-group has-feedback @if($errors->has('fullname')) has-error @endif">
                        <label for="fullname" class="control-label">Agent Name</label>
                        <input type="text" name="fullname" id="fullname" class="form-control" value="{{$agent->fullname}}">
                        <span class="glyphicon glyphicon-user form-control-feedback"></span>
                        @if($errors->has('fullname')) <span class="help-block">{{$errors->first('fullname')}}</span> @endif
                    </div>

                    <div class="form-group has-feedback @if($errors->has('address')) has-error @endif">
                        <label for="address" class="control-label">Address</label>
                        <input type="text" name="address" id="email" class="form-control" value="{{$agent->address}}">
                        <span class="glyphicon glyphicon-book form-control-feedback"></span>
                        @if($errors->has('address')) <span class="help-block">{{$errors->first('address')}}</span> @endif
                    </div>
                    <div class="form-group has-feedback @if($errors->has('email_ad')) has-error @endif">
                        <label for="email_ad" class="control-label">Email Address</label>
                        <input type="text" name="email_ad" id="email_ad" class="form-control" value="{{$agent->email_ad}}">
                        <span class="glyphicon glyphicon-envelope form-control-feedback"></span>
                        @if($errors->has('email_ad')) <span class="help-block">{{$errors->first('email_ad')}}</span> @endif
                    </div>
                </div>

                <div class="col-md-6">
                    <div class="form-group has-feedback @if($errors->has('fb')) has-error @endif">
                        <label for="fb" class="control-label">Facebook</label>
                        <input type="text" name="fb" id="fb" class="form-control" value="{{$agent->fb}}">
                        <span class="glyphicon glyphicon-envelope form-control-feedback"></span>
                        @if($errors->has('fb')) <span class="help-block">{{$errors->first('fb')}}</span> @endif
                    </div>

                    <div class="form-group has-feedback @if($errors->has('contact_no')) has-error @endif">
                        <label for="contact_no" class="control-label">Contact No.</label>
                        <input type="text" name="contact_no" id="contact_no" class="form-control" value="{{$agent->contact_no}}">
                        <span class="glyphicon glyphicon-book form-control-feedback"></span>
                        @if($errors->has('contact_no')) <span class="help-block">{{$errors->first('contact_no')}}</span> @endif
                    </div>

                    <div class="form-group has-feedback @if($errors->has('position')) has-error @endif">
                        <label for="position" class="control-label">Position</label>
                        <select name="position" id="position" class="form-control">
                            @foreach ($pst as $key => $value)
                                @if ($agent->position == $value)
                                    <option value="{{$value}}" selected=selected>{{$value}}</option>
                                @else
                                    <option value="{{$value}}">{{$value}}</option>
                                @endif
                            @endforeach
                        </select>
                        {{--<span class="fa fa-user-md form-control-feedback"></span>--}}
                        @if($errors->has('position')) <span class="help-block">{{$errors->first('position')}}</span> @endif
                    </div>

                    <div class="form-group has-feedback @if($errors->has('team_id')) has-error @endif">
                        <label for="team_id" class="control-label">Team</label>
                        <select name="team_id" id="team_id" class="form-control">
                            @foreach($team as $tm)
                                @if ($agent->team_id == $tm->id)
                                    <option value="{{$tm->id}}" selected="selected">{{$tm->name}}</option>
                                @else
                                    <option value="{{$tm->id}}">{{$tm->name}}</option>
                                @endif
                            @endforeach
                            {{--<option value="{{$agent->team->id}}">{{$agent->team->name}}</option>--}}
                        </select>
                        @if($errors->has('team_id')) <span class="help-block">{{$errors->first('team_id')}}</span> @endif
                    </div>

                    <div class="form-group has-feedback @if($errors->has('active')) has-error @endif">
                        <label for="active" class="control-label">Active</label>
                        <select name="active" id="active" class="form-control">
                            <option value="{{$agent->active}}">{{$agent->active}}</option>
                        </select>
                        @if($errors->has('active')) <span class="help-block">{{$errors->first('active')}}</span> @endif
                    </div>
                </div>

                {{--Checkbox--}}
                <div class="col-md-12">
                    <div style="border: solid #257AAF;padding:10px; border-radius: 3px;margin-bottom: 8px;">
                        <fieldset style="padding: 3px;">
                            <legend>Requirements</legend>
                            <div class="form-group has-feedback @if($errors->has('valid_id')) has-error @endif">
                                <div class="checkbox">
                                  <label for="valid_id" class="custom-checkbox checked">
                                    @if ($agent->valid_id == 1)
                                        <input type="checkbox" id="valid_id" name="valid_id" value="{{$agent->valid_id}}" checked>
                                    @else
                                        <input type="checkbox" id="valid_id" name="valid_id" value="">
                                    @endif
                                        <span class="cr"><i class="cr-icon glyphicon glyphicon-ok"></i></span>Valid ID
                                  </label>
                                </div>
                            </div>

                            <div class="form-group has-feedback @if($errors->has('tin_id')) has-error @endif">
                                <div class="checkbox">
                                  <label for="tin_id" class="custom-checkbox checked">
                                    @if ($agent->tin_id == 1)
                                        <input type="checkbox" id="tin_id" name="tin_id" value="{{$agent->tin_id}}" checked>
                                    @else
                                        <input type="checkbox" id="tin_id" name="tin_id" value="">
                                    @endif
                                        <span class="cr"><i class="cr-icon glyphicon glyphicon-ok"></i></span>Tax ID
                                  </label>
                                </div>
                            </div>

                            <div class="form-group has-feedback @if($errors->has('nbi_clearance')) has-error @endif">
                                <div class="checkbox">
                                  <label for="nbi_clearance" class="custom-checkbox checked">
                                    @if ($agent->nbi_clearance == 1)
                                        <input type="checkbox" id="nbi_clearance" name="nbi_clearance" value="{{$agent->nbi_clearance}}" checked>
                                    @else
                                        <input type="checkbox" id="nbi_clearance" name="nbi_clearance" value="">
                                    @endif
                                        <span class="cr"><i class="cr-icon glyphicon glyphicon-ok"></i></span>NBI Clearance
                                  </label>
                                </div>
                            </div>

                            <div class="form-group has-feedback @if($errors->has('orientation')) has-error @endif">
                                <div class="checkbox">
                                  <label for="orientation" class="custom-checkbox checked">
                                    @if ($agent->orientation == 1)
                                        <input type="checkbox" id="orientation" name="orientation" value="{{$agent->orientation}}" checked>
                                    @else
                                        <input type="checkbox" id="orientation" name="orientation" value="">
                                    @endif
                                        <span class="cr"><i class="cr-icon glyphicon glyphicon-ok"></i></span>Orientation
                                  </label>
                                </div>
                            </div>
                        </fieldset>
                    </div>
                </div>

                <div class="form-group" style="padding: 10px;padding-top:20px;">
                    <button type="submit" class="btn btn-success btn-s"><i class="fa fa-check"></i> Update</button>
                    <a href="{{route('agents')}}" class="btn btn-primary"><i class="fa fa-arrow-left"></i> Cancel</a>
                </div>
                {{csrf_field()}}
            </form>

        </section>
        @if(Session('info'))
            <div class="row">
            <div class="col-md-6 col-md-offset-3 text-center">
            <div class="tem alert alert-success navbar-fixed-bottom"><span class="glyphicon glyphicon-ok-circle"></span> {{Session('info')}}</div>
            </div>
            </div>
        @endif
        <!--Modal Notif-->
        {{--<div class="modal fade bs-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" style=" padding-right: 0px;background-color: rgba(4, 4, 4, 0.8);">
          <div class="modal-dialog modal-lg" style="top: 20%;width: 70%;text-align: center;">
            <div class="modal-content" style="border-radius: 0px;border: none;top: 40%;">
              <div class="modal-body" style="background-color: #BB2E0F;color: white;">
                <h3 id="h22"></h3>
                <h5 id="h44"></h5>
              </div>
            </div>
          </div>
        </div>--}}

    </div>
@stop

@section('script')

    {{--<script src="https://gitcdn.github.io/bootstrap-toggle/2.2.2/js/bootstrap-toggle.min.js"></script>--}}
    <script type="text/javascript" src="{{ asset('js/bootstrap-toggle.min.js') }}" ></script>

    <script>
        $(document).ready(function () {

        });

        function notifPopup(title,body) {
            $('#h22').text(title);
            $('#h44').text(body);
            $('.bs-modal-lg').modal('toggle');
            setTimeout(function() {$('.bs-modal-lg').modal('hide');}, 5000);
        }

        $('#fullname').on('blur', function () {

            /*var fullname = $('#fullname').val();

                        $.ajax({
                        url:"{{route('agents.chkFullname')}}",
                        method: 'get',
                        headers:  {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
                        data:{
                          'fullname':fullname
                        },
                        dataType:'json',
                        success:function(data){
                            console.log(data.chk);
                            if (data.chk == true) {
                                //alert('naa');
                                notifPopup('Notification', 'Agent name already exist. Please provide another name');
                                $('#btnSave').prop("disabled", true);
                            } else {
                                $('#btnSave').prop("disabled", false);
                            }
                            //$('#spinner').modal('toggle');
                    },
                    error: function (jqXHR, exception) {
                        console.log(jqXHR);
                    }
                });*/
        });

    </script>
@stop