

<?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 mt-2" >Musics</h6>
                   
                   <div class="ms-auto d-flex">
                        
                    </div>
                    <div class="ms-auto mt-3 d-flex">
                        <form action="<?php echo e(url('music/search')); ?>" method="POST"  class="ms-auto me-4">
                            <?php echo csrf_field(); ?>
                            <input class="form-control" placeholder="Search" value="<?php if(!empty($search)): ?> <?php echo e($search); ?> <?php endif; ?>" type="text" name="search">
                        </form>
                        <a href="<?php echo e(route('music.create')); ?>" class="btn btn-success "><i class="fas fa-plus"></i> Add New</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 Category</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>
            
             
            <div class="card-body mt-n4">
                
                <div class="row mb" >
                    
            <!--start-->
            <div class="table-responsive p-0">
                <table class="table align-items-center mb-0">
                  <thead>
                    <tr>
                      <th class="text-center text-uppercase text-secondary text-xxs font-weight-bolder opacity-7">ID</th>
                      <th class="text-uppercase text-secondary text-xxs font-weight-bolder opacity-7">Details</th>
                      
                      <th class="text-center text-uppercase text-secondary text-xxs font-weight-bolder opacity-7">Play</th>
                      <th class="text-center text-uppercase text-secondary text-xxs font-weight-bolder opacity-7">Premium</th>
                      <th class="text-center text-uppercase text-secondary text-xxs font-weight-bolder opacity-7">Status</th>
                      <th class="text-center text-uppercase text-secondary text-xxs font-weight-bolder opacity-7">Register</th>
                      <th class="text-center text-uppercase text-secondary text-xxs font-weight-bolder opacity-7">Action</th>
                    </tr>
                  </thead>
                  <tbody>
                    <?php $__currentLoopData = $musics; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $music): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                       <tr>
                            <td class="align-middle text-center text-sm">
                                <p class="text-xs font-weight-bold mb-0"><?php echo e($music->id); ?></p>
                            </td>
                            
                            <td>
                               <div class="d-flex py-1">
                                  <div>
                                    <img src="<?php if($music->thumbnail): ?> <?php echo e(url($music->thumbnail)); ?> <?php else: ?> <?php echo e(url('/images/placeholder.jpg')); ?> <?php endif; ?>" class="avatar avatar-xl me-3" alt="user1">
                                  </div>
                                  <div class="d-flex flex-column justify-content-center" >
                                    <h6 class="mb-0" ><?php echo e($music->title); ?></h6>
                                    
                                  </div>
                                </div>
                            </td>
                            
                            <td class="align-middle text-center">
                                <a class="btn btn-icon-only btn-rounded btn btn-warning" href="<?php echo e(url($music->item_url)); ?>">
                                    <i class="fas fa-play">
                                    </i>
                                </a>
                            </td>
                            
                            <td class="align-middle text-center">
                                <div onclick="cheakPremium(<?php echo e($music->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($music->id); ?>">
                                         <?php if($music->premium==0): ?> Free <?php else: ?> Premium <?php endif; ?>
                                    </button>
                                </div>
                            </td>
                            
                            <td class="align-middle text-center">
                                <div class="form-switch align-items-center justify-content-center" >
                                    <input class="form-check-input status-switch" type="checkbox" data-id="<?php echo e($music->id); ?>" <?php if($music->status==0): ?> checked <?php endif; ?>>
                                </div>
                            </td>
                            
                            <td class="align-middle text-center">
                                <span class="text-secondary text-xs font-weight-bold"><?php echo e(date('d M, y',strtotime($music->created_at))); ?></span>
                            </td>
                            
                            <td class="align-middle">
                                <div class="ms-auto text-end align-middle text-center text-sm">
                                    <a href="#" data-id="<?php echo e($music->id); ?>" data-toggle="modal" data-target="#deleteModal" class="btn btn-icon-only btn-rounded btn-danger"><i class="far fa-trash-alt"></i></a>
                                    
                                    <a class="btn btn-icon-only btn-rounded btn btn-success" href="<?php echo e(secure_url('/music/'.$music->id.'/edit')); ?>"><i class="fas fa-edit"></i></a>
                                </div>
                            </td>
                            
                       </tr>
                       
                        <form action="<?php echo e(url('music/'.$music->id)); ?>" method="POST" id="form-<?php echo e($music->id); ?>">
                            <?php echo method_field('DELETE'); ?>
                            <?php echo csrf_field(); ?>
                            <input type="hidden" name="id" value="<?php echo e($music->id); ?>">
                        </form>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                  </tbody>
                </table>
              </div>
              
              <!--end-->
                      
                </div>
                    
            </div>
                
                <?php if(empty($search)): ?>
                <div class="d-flex justify-content-center"><?php echo e($musics->links()); ?></div>
                <?php endif; ?>
            </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>

<script>
    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('/music-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("Music set free");
              }else{
                  toastr.success("Music set premium");
              }
          },
          error (data) {
              toastr.error(JSON.stringify(data));
          }
          
        });
    }
    
    function searchByCategoryID(){
        var id = document.getElementById("category").value;
        if(id == "Show All"){
            window.location.replace("<?php echo e(url('/music')); ?>");
        }else if(id != "Select Business"){
            window.location.replace("<?php echo e(url('/musicCategory')); ?>" + "/" + id);
        }
    }
    $("#deleteModal").on('show.bs.modal', function(e){
        var id = e.relatedTarget.dataset.id;
        $("#delete_btn").attr("data-submit",id);
    });
    
    $("#delete_btn").on("click",function(){
        var id=$(this).data("submit");
        $("#form-"+id).submit();
    });
    
    $(".status-switch").change(function(){
        var checked = $(this).is(':checked');
        var id = $(this).data("id");
        
        $.ajax({
          type: "POST",
          url: "<?php echo e(secure_url('/music-status')); ?>",
          data: { checked : checked , id : id},
          headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') },
          success: function(data) {
              
              if(checked){
                  toastr.success("Music Activated");
              }else{
                  toastr.success("Music Deactivated");
              }
          },
          error (data) {
              toastr.error(JSON.stringify(data));
          }
          
        });
    });
    $(document).ready(function () {
       create_business_dropdowns();
    });
</script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('main', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /www/wwwroot/posterbanao.com/admin/resources/views/music/index.blade.php ENDPATH**/ ?>