<?php echo View::make('/../include/header'); ?>


<link href="https://cdn.datatables.net/1.10.19/css/dataTables.bootstrap4.min.css" rel="stylesheet">

    <section id="main-content">
      <section class="wrapper">
      <div class="row">
          <div class="col-lg-12 main-chart">
            <!--CUSTOM CHART START -->
            <div class="border-head">
              <h3>Add Product</h3>
            <p><button type="button" class="btn btn-sm btn-success pull-right" data-toggle="modal" data-target="#exampleModalCenter">Add Page</button></p>

            </div><br><br>
        
            <table id="example" class="table table-striped table-bordered" style="width:100%">
                <thead>
                    <tr>
                        <th>Page Name</th>
                        <th>Phone Number</th>
                        <th>Image</th>
                        <th>Path</th>
                        <th>Action</th>
                    </tr>
                </thead>
                <tbody>
                <?php $__currentLoopData = $page; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $data): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <tr>
                        <td><?php echo e($data->pagename); ?></td>
                        <td><?php echo e($data->number); ?></td>
                        <td class="text-center"><img class="card-img-top" style="height:70px;" src="<?php echo e(url('uploads/'.$data->image)); ?>" alt="<?php echo e($data->image); ?>"></td>
                        <td><?php echo e($data->imgpath); ?></td>                        
                        <td class="text-center">
                            <button type="button" class="btn btn-primary btn-sm" data-id="<?php echo e($data->id); ?>" data-name="<?php echo e($data->pagename); ?>" data-phone="<?php echo e($data->number); ?>" data-image="<?php echo e(url('uploads/'.$data->image)); ?>" data-valimage="<?php echo e($data->image); ?>" data-imgpath="<?php echo e($data->imgpath); ?>" data-toggle="modal" data-target="#updatepagemodel">Edit</button>
                            <a href="" data-id="<?php echo e($data->id); ?>" class="btn btn-danger btn-sm button" data-url="">Delete </a>
                        </td>                        
                    </tr>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </tbody>
                <tfoot>
                    <tr>
                        <th>Page Name</th>
                        <th>Phone Number</th>
                        <th>Image</th>
                        <th>Path</th>
                        <th>Action</th>
                    </tr>
                </tfoot>
            </table>        
 

        </div>
        </div>
      </section>
    </section>

<?php echo View::make('/../include/footer'); ?>



                <div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
                    <div class="modal-dialog modal-dialog-centered" role="document">
                        <div class="modal-content">
                        <div class="modal-header">
                            <h5 class="modal-title" id="exampleModalLongTitle">Add Page</h5>
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                            </button>
                        </div>
                        <form method="post" action="/registerpagepost" enctype="multipart/form-data">
                          <?php echo e(csrf_field()); ?>

                        <div class="modal-body">                    
                            <div class="form-group row">
                                <label for="" class="col-sm-2 col-form-label">Page Name</label>
                                <div class="col-sm-10">
                                <input type="text" class="form-control" id="name" name="name" placeholder="Page Name"required>
                                </div>
                            </div>
                            <div class="form-group row">
                                <label for="" class="col-sm-2 col-form-label">Phone Number</label>
                                <div class="col-sm-10">
                                <input type="text" class="form-control" id="number" name="number" placeholder="Phone Number" required>
                                </div>
                            </div>
                            <div class="form-group row">
                                <label for="" class="col-sm-2 col-form-label">Upload Logo</label>
                                <div class="col-sm-10">
                                <input  name="input_img" type="file" id="profile-img2">
                                <img src="" id="profile-img-tag2" width="200px" />                                
                                </div>
                            </div>
                            <div class="form-group row">
                                <label for="" class="col-sm-2 col-form-label">Image Path</label>
                                <div class="col-sm-10">
                                <input type="text" class="form-control" id="imgpath" name="imgpath" placeholder="Image Path" required>
                                </div>
                            </div>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                            <button type="submit" class="btn btn-primary">Save changes</button>
                        </div>
                        </form>
                        </div>
                    </div>
                </div>



                <div class="modal fade" id="updatepagemodel" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
                    <div class="modal-dialog modal-dialog-centered" role="document">
                        <div class="modal-content">
                        <div class="modal-header">
                            <h5 class="modal-title" id="exampleModalLongTitle">Add Page</h5>
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                            </button>
                        </div>
                        <form method="post" action="/updateregisterpagepost" enctype="multipart/form-data">
                          <?php echo e(csrf_field()); ?>

                        <div class="modal-body"> 
                            <input type="hidden" name="id" id="id">                   
                            <div class="form-group row">
                                <label for="" class="col-sm-2 col-form-label">Page Name</label>
                                <div class="col-sm-10">
                                <input type="text" class="form-control" id="name" name="name" placeholder="Page Name"required>
                                </div>
                            </div>
                            <div class="form-group row">
                                <label for="" class="col-sm-2 col-form-label">Phone Number</label>
                                <div class="col-sm-10">
                                <input type="text" class="form-control" id="number" name="number" placeholder="Phone Number" required>
                                </div>
                            </div>
                            <div class="form-group row">
                                <label for="" class="col-sm-2 col-form-label">Upload Logo</label>
                                <div class="col-sm-10">
                                <input name="input_img" type="file" id="profile-img" value="">
                                <img src="" id="profile-img-tag" width="200px" />
                                </div>
                            </div>
                            <div class="form-group row">
                                <label for="" class="col-sm-2 col-form-label">Image Path</label>
                                <div class="col-sm-10">
                                <input type="text" class="form-control" id="imgpath" name="imgpath" placeholder="Image Path" required>
                                </div>
                            </div>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                            <button type="submit" class="btn btn-primary">Save changes</button>
                        </div>
                        </form>
                        </div>
                    </div>
                </div>
<script>
$(document).ready(function() {
    $('#example').DataTable();
} );
</script>

<script>
$('#updatepagemodel').on('show.bs.modal', function (event) {

  var button = $(event.relatedTarget) // Button that triggered the modal
  var recipient = button.data('id') 
  var name = button.data('name') 
  var phone = button.data('phone') 
  var imgpath = button.data('imgpath') 
  var image = button.data('image') 
  var image2 = button.data('valimage') 
  
  
  var modal = $(this)
//   modal.find('.modal-title').text('New message to ' + recipient)
  modal.find('.modal-body #name').val(name)
//   modal.find('.modal-body #nameproduct').val(proname)
  modal.find('.modal-body #number').val(phone)
  modal.find('.modal-body #id').val(recipient)
  modal.find('.modal-body #imgpath').val(imgpath)
//   $('#preview').attr('src',image);
//   $('.profile-img').attr("href",  image)
  $('#profile-img-tag').attr('src', image);
  $('#profile-img').attr('value', image);
//   modal.find('.modal-body #input_img').val(image)

  
})
</script>

<script>
$(document).on('click', '.btn-danger', function (e) {
    e.preventDefault();
    var id = $(this).data('id');
    let ele = this;
    console.log(id);

            swal({
            title: "Are you sure?",
            text: "Are you Sure to Remove Order Item",
            icon: "warning",
            showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, delete it!',
            dangerMode: true,
        }).then(function(isConfirm) {
            
            if (isConfirm.value===true) {

                    $.ajax({
                        url: "<?php echo e(url('/deletepage')); ?>/"+id ,
                        method: "POST",
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        cache: false,
                        contentType: false,
                        processData: false,
                        dataType: 'JSON',
                        data:{
                            "id":id
                        },
                        success: function (result, code, ex) {
                            swal("Done!", "It was successfully deleted!", "success");
                            $(ele).closest('tr').hide();
                            // $("#here").load(location.href + " #here");
                        },
                        error: function (jqXHR, textStatus, errorThrown) {
                            swal("Warning", "Unable to Process your request", "error");
                        },
                    });

            } else {
                swal("Cancelled", "No Treatment Removed", "error");
            }
        })
});
</script>