<?php $__env->startSection('title'); ?>
    Agent
<?php $__env->stopSection(); ?>

<?php $__env->startSection('style'); ?>

<?php $__env->stopSection(); ?>

<?php $__env->startSection('content'); ?>
<div class="content-wrapper" >
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
                <span class="fa fa-user-plus"></span> New Agent
            </h1>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-user-plus"></i> Admin Panel</a></li>
                <li class="active">New Agent</li>
            </ol>
        </section>

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

                    <div class="form-group has-feedback <?php if($errors->has('email_ad')): ?> has-error <?php endif; ?>">
                        <label for="email_ad" class="control-label">Email Address</label>
                        <input type="email" name="email_ad" id="email_ad" class="form-control" value="">
                        <span class="glyphicon glyphicon-envelope form-control-feedback"></span>
                        <?php if($errors->has('email_ad')): ?> <span class="help-block"><?php echo e($errors->first('email_ad')); ?></span> <?php endif; ?>
                    </div>
                </div>

                <div class="col-md-6">
                    <div class="form-group has-feedback <?php if($errors->has('address')): ?> has-error <?php endif; ?>">
                        <label for="address" class="control-label">Address</label>
                        <input type="text" name="address" id="address" class="form-control" value="">
                        <span class="glyphicon glyphicon-book form-control-feedback"></span>
                        <?php if($errors->has('address')): ?> <span class="help-block"><?php echo e($errors->first('address')); ?></span> <?php endif; ?>
                    </div>

                    <div class="form-group has-feedback <?php if($errors->has('fb')): ?> has-error <?php endif; ?>">
                        <label for="fb" class="control-label">Facebook</label>
                        <input type="text" name="fb" id="fb" class="form-control" value="">
                        <span class="glyphicon glyphicon-facebook form-control-feedback"></span>
                        <?php if($errors->has('fb')): ?> <span class="help-block"><?php echo e($errors->first('fb')); ?></span> <?php endif; ?>
                    </div>

                    <div class="form-group has-feedback <?php if($errors->has('contact_no')): ?> has-error <?php endif; ?>">
                        <label for="contact_no" class="control-label">Contact No.</label>
                        <input type="text" name="contact_no" id="contact_no" class="form-control" value="">
                        <span class="glyphicon glyphicon-phone form-control-feedback"></span>
                        <?php if($errors->has('contact_no')): ?> <span class="help-block"><?php echo e($errors->first('contact_no')); ?></span> <?php endif; ?>
                    </div>

                    <div class="form-group has-feedback <?php if($errors->has('position')): ?> has-error <?php endif; ?>">
                        <label for="position" class="control-label">Position</label>
                        <select name="position" id="position" class="form-control">
                           <?php $__currentLoopData = $pst; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $value): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($value); ?>"><?php echo e($value); ?></option>
                           <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </select>
                        <?php if($errors->has('position')): ?> <span class="help-block"><?php echo e($errors->first('position')); ?></span> <?php endif; ?>
                    </div>

                    <div class="form-group has-feedback <?php if($errors->has('team_id')): ?> has-error <?php endif; ?>">
                        <label for="team_id" class="control-label">Team</label>
                        <select name="team_id" id="team_id" class="form-control">
                            <option value="">Select Team</option>
                            <?php $__currentLoopData = $team; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $tm): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <option value="<?php echo e($tm->id); ?>"><?php echo e($tm->name); ?></option>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </select>
                        <?php if($errors->has('team_id')): ?> <span class="help-block"><?php echo e($errors->first('team_id')); ?></span> <?php endif; ?>
                    </div>
                </div>

                
                
                            
                            

                            

                <div class="form-group" style="padding: 10px;">
                    <button type="submit" id="btnSave" name="btnSave" class="btn btn-success btn-s"><i class="fa fa-save"></i> Save</button>
                    <a href="<?php echo e(route('agents')); ?>" class="btn btn-primary"><i class="fa fa-arrow-left"></i> Cancel</a>
                </div>
                <?php echo e(csrf_field()); ?>

            </form>

        </section>
        <?php 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> <?php echo e(Session('info')); ?></div>
            </div>
            </div>
        <?php 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" id="modBody" style="background-color: #BB2E0F;color: white;"> 
                <h3 id="h22"></h3>
                <h5 id="h44"></h5>
              </div>
            </div>
          </div>
        </div>

</div>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('script'); ?>

<script>
    $(document).ready(function () {
        /*$('[key]').change(function () {
            var key = $(this).attr('key');
            $($('[name="checked[' + key + ']"]')).val($(this).is(':checked') ? 1 : 0);
            var r = $($('[name="checked[' + key + ']"]')).val($(this).is(':checked') ? 1 : 0);
            var t = $('#checked['+key+']');
            //alert(t);
            console.log(t);
        });*/
    });
</script>

<script>

    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 () {
        //alert('ready');
        var fullname = $('#fullname').val();
        //alert(fullname);
        //alert($option.val());
        /*if(fullname==''){
            $('#fullname').val('');
            }
            else{*/
                //$('#spinner').modal({backdrop: 'static', keyboard: false});
                    $.ajax({
                    url:"<?php echo e(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);
                }
            });
            //} //end else
    });

    /*$('#checkbox-value').text($('#checkbox4').val());

    $("#checkbox4").on('change', function() {
      if ($(this).is(':checked')) {
        $(this).attr('value', 1);
      } else {
        $(this).attr('value', 0);
      }
      $('#checkbox-value4').val($('#checkbox4').val());
    });*/

</script>

<?php $__env->stopSection(); ?>
<?php echo $__env->make('admin.layouts.master', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>