

<?php $__env->startSection('content'); ?>
    <div class="row">
        <div class="col-12">
          <div class="card mb-4">
              
            <div class="card-header py-0 bg-primary">
                <div class="d-flex align-items-center">
                   <h6 class="text-white" >Political Posts</h6>
                    
                    <div class="ms-auto mt-3">
                        <a href="<?php echo e(route('political.create')); ?>" class="btn btn-success "><i class="fas fa-plus"></i> Add Post</a>
                    </div>
                </div>
            </div>
            
            
            
            <div class="d-flex align-items-center">
                <div class="col-md-4">
                  <div class="form-group p-2">
                    <select class="form-control selectpicker" onchange="searchByCategoryID()" id="category">
                        <?php if(empty($category)): ?> 
                        <option selected="selected" disabled="disabled">Select Party</option> 
                        <?php else: ?>
                        <option disabled="disabled">Show All</option> 
                        <?php endif; ?>
                        <?php $__currentLoopData = $categories; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $c): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($c->id); ?>" <?php if(!empty($category) && $c->name == $category): ?> selected <?php endif; ?>><?php echo e($c->name); ?></a></option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
                    
                  </div>
                </div>
                
                <div class="ms-auto m-3 d-flex">
                   
                    <input type="checkbox" id="check_all" class="mt-1 me-3" style="width: 26px;height: 26px;">
            
                    <div class="dropdown">
                      <button class="btn btn-sm bg-gradient-info mb-0  btn_cust" type="button" data-toggle="dropdown">
                      Action &nbsp;&nbsp; <i class="fas fa-angle-down"></i></button>
                      <ul class="dropdown-menu" style="right:0;left:auto;">
                        <li><a class="dropdown-item" href="#" data-type="enable" data-toggle="modal" data-target="#sectionModal">Add To Section</a></li>
                        <li><a class="dropdown-item" href="#" data-type="enable" data-toggle="modal" data-target="#enableModal">Enable</a></li>
                        <li><a class="dropdown-item" href="#" data-type="enable" data-toggle="modal" data-target="#disableModal">Disable</a></li>
                        <li><a class="dropdown-item" href="#" data-type="enable" data-toggle="modal" data-target="#deleteModal">Delete</a></li>
                      </ul>
                      <form action="<?php echo e(url('/posts-action')); ?>" method="POST" id="form-select-one">
                          <?php echo csrf_field(); ?>
                          <input type="hidden" name="section_id" value="">
                          <input type="hidden" name="posts_ids" value="">
                          <input type="hidden" name="action_type" value="">
                          <input type="hidden" name="from_name" value="political">
                      </form>
                    </div>
                </div>
                
            </div>
        
            <div class="card-body mt-n3">
                
                <div class="row mb" >
                    <?php $__currentLoopData = $posts; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $post): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    
                    <div class="col-xl-3 col-l-3 col-sm-4 p-2  bg-transparent">
                        
                      <div style="background-image: url(<?php if($post->thumb_url): ?> <?php echo e(url($post->thumb_url)); ?> <?php else: ?> <?php echo e(url('/images/placeholder.jpg')); ?> <?php endif; ?>);height:240px;background-size: cover;" class="border-radius-xl">
                          
                        <div style="background-image: linear-gradient(transparent, transparent, transparent, transparent, transparent, #302d2d, black);   border-radius: 17px;" class="card-body position-relative z-index-1 p-3">
                            <div style="width: 100%;height: 56px;position: absolute;left: 0;border-radius: 16px 16px 0 0px;top: 0;background-color: rgb(12 12 12 / 17%);z-index: -1;"></div>

                            <input type="checkbox" name="post_ids[]" value="<?php echo e($post->id); ?>" class="post_ids p-2" style="float: right;width: 18px;height: 18px;">
                          
                             
                             
                            <h5 class="text-white text-sm mt-0 pb-0" ><?php echo e($post->title); ?></h5>
                            <?php if($post->section): ?> 
                                <button class="badge badge-sm bg-gradient-dark position-absolute" id="ser-<?php echo e($post->id); ?>" onclick="removeFromSection(<?php echo e($post->id); ?>)"> <?php echo e($post->section->name); ?> &nbsp; <i class="fas fa-window-close"></i>
                                </button>
                            <?php endif; ?>
                            <div class="mt-9" >
                                
                                <div class="d-flex mt-2" >
                                  <div>
                                    <a class="btn btn-icon-only btn-rounded btn-success mb-0 me-2 btn-sm d-flex align-items-center justify-content-center" href="<?php echo e(secure_url('/political/'.$post->id.'/edit')); ?>">
                                        <i class="fas fa-pencil-alt"></i>
                                    </a>
                                  </div>
                                  
                                  <div>
                                    <button class="btn btn-icon-only btn-rounded btn-danger mb-0 me-2 btn-sm d-flex align-items-center justify-content-center"  data-id="<?php echo e($post->id); ?>" data-toggle="modal" data-target="#singleDeleteModal">
                                        <i class="far fa-trash-alt"></i>
                                    </button>
                                  </div>
                                  
                                  
                                  <div class="form-switch align-items-center justify-content-center" >
                                     <input class="form-check-input status-switch" type="checkbox" data-id="<?php echo e($post->id); ?>" <?php if($post->status==0): ?> checked <?php endif; ?>>
                                  </div>
                                  
                                  <div onclick="cheakPremium(<?php echo e($post->id); ?>)" class="align-items-center justify-content-center">
                                     <button class="btn btn-sm btn-premium btn_cust" style="width:60px;padding:2px;margin:2px" id="pre-<?php echo e($post->id); ?>">
                                         <?php if($post->premium==0): ?> Free <?php else: ?> Premium <?php endif; ?>
                                         </button>
                                  </div>
                                  
                                </div>
                            
                                <form action="<?php echo e(url('political/'.$post->id)); ?>" method="POST" id="form-<?php echo e($post->id); ?>">
                                    <?php echo method_field('DELETE'); ?>
                                    <?php echo csrf_field(); ?>
                                    <input type="hidden" name="id" value="<?php echo e($post->id); ?>">
                                </form>
                            </div>
                          </div>
                      </div>
                        
                     </div>
                      
                     <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                      
                </div>
                    
            </div>
                
                <div class="d-flex justify-content-center"><?php echo e($posts->links()); ?></div>

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

<div id="sectionModal" class="modal fade" role="dialog">
    <div class="modal-dialog">
      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <p>Select Section</p>
          
        </div>
        <div class="modal-body">
          <select id="section_select" class="form-control" onchange="onSectionSelect()">
              <option> Select Name </option>
              <?php $__currentLoopData = $sections; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $section): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                  <option value="<?php echo e($section->id); ?>"><?php echo e($section->name); ?></option>
              <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
          </select>
        </div>
        <div class="modal-footer">
          <?php if(Session::get('admin_type') == "Demo"): ?>
          <button class="btn btn-success demo_action" data-dismiss="modal">Submit</button>
          <?php else: ?>
          <button id="section_btn" class="btn btn-success">Submit</button>
          <?php endif; ?>
          
          <button class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
      </div>
    </div>
</div>

<div id="singleDeleteModal" class="modal fade" role="dialog">
    <div class="modal-dialog">
      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <p>Are you sure you want to Delete ?</p>
        </div>
        <div class="modal-footer">
          <?php if(Session::get('admin_type') == "Demo"): ?>
          <button class="btn btn-danger demo_action" data-dismiss="modal">Delete</button>
          <?php else: ?>
          <button id="del_btn" class="btn btn-danger">Delete</button>
          <?php endif; ?>
          
          <button class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
      </div>
    </div>
</div>

<div id="deleteModal" class="modal fade" role="dialog">
    <div class="modal-dialog">
      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <p>Are you sure you want to Delete ?</p>
        </div>
        <div class="modal-footer">
          
          <?php if(Session::get('admin_type') == "Demo"): ?>
          <button class="btn btn-danger demo_action" data-dismiss="modal">Delete</button>
          <?php else: ?>
          <button id="delete_btn" class="btn btn-danger">Delete</button>
          <?php endif; ?>
          
          <button class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
      </div>
    </div>
</div>

<div id="disableModal" class="modal fade" role="dialog">
    <div class="modal-dialog">
      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <p>Are you sure you want to disable ?</p>
        </div>
        <div class="modal-footer">
          
          <?php if(Session::get('admin_type') == "Demo"): ?>
          <button class="btn btn-danger demo_action" data-dismiss="modal">Disable</button>
          <?php else: ?>
          <button id="disable_btn" class="btn btn-warning">Disable</button>
          <?php endif; ?>
          
          <button class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
      </div>
    </div>
</div>

<div id="enableModal" class="modal fade" role="dialog">
    <div class="modal-dialog">
      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <p>Are you sure you want to enable ?</p>
        </div>
        <div class="modal-footer">
          
          <?php if(Session::get('admin_type') == "Demo"): ?>
          <button class="btn btn-danger demo_action" data-dismiss="modal">Enable</button>
          <?php else: ?>
          <button id="enable_btn" class="btn btn-success">Enable</button>
          <?php endif; ?>
          
          <button class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
      </div>
    </div>
</div>

<script>

    function searchByCategoryID(){
        var id = document.getElementById("category").value;
        if(id == "Show All"){
            window.location.replace("<?php echo e(url('/political')); ?>");
        }else if(id != "Select Party"){
            window.location.replace("<?php echo e(url('/politicalCategory')); ?>" + "/" + id);
        }
    }

    function cheakPremium(id){
        var cheak = document.getElementById("pre-"+id).innerHTML;
        if(cheak == "Free"){
            document.getElementById("pre-"+id).innerHTML = "Premium";
            cheak = 1;
        }else{
            document.getElementById("pre-"+id).innerHTML = "Free";
            cheak = 0;
        }
        $.ajax({
          type: "POST",
          url: "<?php echo e(secure_url('/posts-premium-action')); ?>",
          data: { id : id, type : cheak},
          headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') },
          success: function(data) {
              if(cheak == 0){
                  toastr.success("Post set free");
              }else{
                  toastr.success("Post set premium");
              }
          },
          error (data) {
              toastr.error(JSON.stringify(data));
          }
          
        });
    }
    function removeFromSection(id){
        document.getElementById("ser-"+id).remove();
        $.ajax({
          type: "POST",
          url: "<?php echo e(secure_url('/posts-remove-section')); ?>",
          data: { id : id},
          headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') },
          success: function(data) {
              
              toastr.success("Removed from section");
              
          },
          error (data) {
              toastr.error(JSON.stringify(data));
          }
          
        });
    }
    
    function onSectionSelect(){
        $("input[name='section_id']").val(document.getElementById("section_select").value);
    }

    $("#section_btn").on("click",function(){
        $("#form-select-one").submit();
    });

    $('#sectionModal').on('show.bs.modal', function(e) {
        $("input[name='action_type']").val("section");
    });

    $("#enable_btn").on("click",function(){
        $("#form-select-one").submit();
    });

    $('#enableModal').on('show.bs.modal', function(e) {
        $("input[name='action_type']").val("enable");
    });
    
    $("#disable_btn").on("click",function(){
        $("#form-select-one").submit();
    });

    $('#disableModal').on('show.bs.modal', function(e) {
        $("input[name='action_type']").val("disable");
    });
    
    $("#delete_btn").on("click",function(){
        $("#form-select-one").submit();
    });

    $('#deleteModal').on('show.bs.modal', function(e) {
        $("input[name='action_type']").val("delete");
    });
    
    //Signle Delete
    $("#singleDeleteModal").on('show.bs.modal', function(e){
        var id = e.relatedTarget.dataset.id;
        $("#del_btn").attr("data-submit",id);
    });
    
    $("#del_btn").on("click",function(){
        var id=$(this).data("submit");
        $("#form-"+id).submit();
    });
    
    var checkarray = [];
    $("#check_all").click(function() {
    	checkarray = [];
    	$("input[name='post_ids[]']").not(this).prop('checked', this.checked);
    	$.each($("input[name='post_ids[]']:checked"), function() {
    		checkarray.push($(this).val());
    	});
    	$("input[name='posts_ids']").val(checkarray);
    });
    
    $(".post_ids").click(function(e) {
        
    	if ($(this).prop("checked") == true) {
    		checkarray.push($(this).val());
    	} else if ($(this).prop("checked") == false) {
    		checkarray.splice($.inArray($(this).val(), checkarray), 1);
    	}
    	$("input[name='posts_ids']").val(checkarray);
    });
    
    $(".status-switch").change(function(){
        var checked = $(this).is(':checked');
        var id = $(this).data("id");
        
        $.ajax({
          type: "POST",
          url: "<?php echo e(secure_url('/posts-status')); ?>",
          data: { checked : checked , id : id},
          headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') },
          success: function(data) {
              
              if(checked){
                  toastr.success("Post Activated");
              }else{
                  toastr.success("Post Deactivated");
              }
          },
          error (data) {
              toastr.error(JSON.stringify(data));
          }
          
        });
    });
      
    $(document).ready(function () {
       create_custom_dropdowns();
    });
</script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('main', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /www/wwwroot/extended.posterbanao.com/resources/views/political/index.blade.php ENDPATH**/ ?>