<div class="container-fluid">
    <div class="footer">
        <p>Copyright © Revel Book </p>
    </div>
</div>
</div>
</div>
<!-- end dashboard inner -->
</div>
</div>
</div>
<!-- jQuery -->
<script src="<?=base_url()?>assets/js/jquery.min.js"></script>
<script src="<?=base_url()?>assets/js/popper.min.js"></script>
<script src="<?=base_url()?>assets/js/bootstrap.min.js"></script>
<!-- wow animation -->
<script src="<?=base_url()?>assets/js/animate.js"></script>
<!-- select country -->
<script src="<?=base_url()?>assets/js/bootstrap-select.js"></script>
<!-- owl carousel -->
<script src="<?=base_url()?>assets/js/owl.carousel.js"></script>
<!-- chart js -->
<script src="<?=base_url()?>assets/js/Chart.min.js"></script>
<script src="<?=base_url()?>assets/js/Chart.bundle.min.js"></script>
<script src="<?=base_url()?>assets/js/utils.js"></script>
<script src="<?=base_url()?>assets/js/analyser.js"></script>
<!-- nice scrollbar -->
<script src="<?=base_url()?>assets/js/perfect-scrollbar.min.js"></script>
<script>
var ps = new PerfectScrollbar('#sidebar');
</script>
<!-- fancy box js -->
<script src="<?=base_url()?>assets/js/jquery-3.3.1.min.js"></script>

<script src="<?=base_url()?>assets/js/jquery.fancybox.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>

<!-- custom js -->
<script src="<?=base_url()?>assets/js/custom.js"></script>
<!-- calendar file css -->
<script src="<?=base_url()?>assets/js/semantic.min.js"></script>
<script src="https://cdn.datatables.net/1.13.4/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.13.4/js/dataTables.bootstrap4.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/jszip-2.5.0/dt-1.10.25/b-2.0.0/b-html5-2.0.0/datatables.min.css" />

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.66/pdfmake.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.66/vfs_fonts.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/v/dt/jszip-2.5.0/dt-1.10.25/b-2.0.0/b-html5-2.0.0/datatables.min.js"></script>
<!-- Include SweetAlert CSS and JS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/sweetalert2@11/dist/sweetalert2.min.css">
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>

<script>
$(document).ready(function() {
    $('.multiselect').select2({
                placeholder: 'Please Select Atleast One Options .....', // Placeholder text
                allowClear: true // Optional: allows users to clear the selection
            });
    $('#songTable').DataTable({
        dom: 'Bfrtip', // Add the Buttons extension to the DOM
        buttons: [
            'copy', 'csv', 'excel', 'pdf', 'print' // Add the desired export buttons
        ]
    });
    $('#songTable3').DataTable({
        //
    });
    $('#songTable4').DataTable({
        //
    });
    $('#songTable5').DataTable({
        //
    });
    $('#name-search-box').on('keyup', function() {
        // Get the search value
        var value = $(this).val();

        // Set the search criteria for the Name column
        $('#songTable1').DataTable().columns(3).search(value).draw();
    });
    $('#songTable1').DataTable({
        dom: 'Bfrtip',
        columns: [{
                data: 'Admin Name',
                title: 'Admin Name'
            },
            {
                data: 'Admin Email',
                title: 'Admin Email'
            },
            {
                data: 'Log Action',
                title: 'Log Action'
            },
            {
                data: 'Log Time',
                title: 'Log Time'
            },
            {
                data: 'Log Details',
                title: 'Log Details'
            },


        ],
        // Add the Buttons extension to the DOM
        buttons: [
            'copy', 'csv', 'excel', 'pdf', 'print' // Add the desired export buttons
        ],
        order: [
            [3, "desc"]
        ], //or asc 
        columnDefs: [{
            "targets": 3,
            "type": "date"
        }],
    });
});
</script>
<script src="<?=base_url()?>assets/plugins/toast/toast.min.js"></script>
<script type="text/javascript">
<?php if ($this->session->flashdata('successmessage')) { ?>
const Toast = Swal.mixin({
    toast: true,
    position: 'top',
    showConfirmButton: false,
    timer: 5000
});
Toast.fire({
    type: 'success',
    title: '<?= $this->session->flashdata('successmessage'); ?>'
});
<?php } else if ($this->session->flashdata('warningmessage')) { ?>
const Toast = Swal.mixin({
    toast: true,
    position: 'top',
    showConfirmButton: false,
    timer: 5000
});
Toast.fire({
    type: 'error',
    title: '<?= $this->session->flashdata('warningmessage'); ?>'
});
<?php } ?>
</script>
<script>
$(function() {
    new Chart(
        document.getElementById("line_chart").getContext("2d"),
        getChartJs("line")
    );
});

function getChartJs(type) {
    var config = null;

    if (type === "line") {
        config = {
            type: "line",
            data: {
                labels: [
                    <?=$labelStr?>
                ],
                datasets: [{
                    label: "Total Users Signed Up",
                    data: [<?=$dataStr?>],
                    borderColor: "rgba(33, 150, 243, 1)",
                    backgroundColor: "rgba(33, 150, 243, 0.2)",
                    pointBorderColor: "rgba(33, 150, 243, 1)",
                    pointBackgroundColor: "rgba(255, 255, 255, 1)",
                    pointBorderWidth: 1,
                }, ],
            },
            options: {
                responsive: true,
                legend: false,
            },
        };
    }
    return config;
}

function addOptions() {
    $('#options').empty();
    let type = $('#type').val();
    let count = $('#count').val();
    if (type != 'Checkbox') {
        return;
    }
    if (count == '') {
        alert('Please select count');
        return;
    }
    count = parseInt(count);

    let optionStr = '';
    for (let i = 0; i < count; i++) {
        optionStr += `
            <label class="form-label">Option ${i+1}</label>
            <div class="form-group">
                <input type="text" name="options[]" class="form-control" placeholder="Option" required>
            </div>
        `;
    }
    $('#options').append(optionStr);

}
</script>
<!-- Your modal HTML here -->

<!-- Place the script at the end of the body -->
<script>
$(document).ready(function() {
    $('.openModalButton').click(function(event) {
     //   $('#editModal').modal('show');
   var question = $(this).data('question');
   var quaizid = $(this).data('quaizid');
   
    var answer1 = $(this).data('answer1');
    var answer2 = $(this).data('answer2');
    var answer3 = $(this).data('answer3');
    var answer4 = $(this).data('answer4');
    var correct = $(this).data('correct');
    $('#quaizid').val(quaizid);
    $('#editQuestion').val(question);
    $('#editAnswer1').val(answer1);
    $('#editAnswer2').val(answer2);
    $('#editAnswer3').val(answer3);
    $('#editAnswer4').val(answer4);
    $('#editCorrect' + correct).prop('checked', true);

    })
    $('.openchapterModalButton').click(function(event) {
        var quaizid = $(this).data('quaizid');
        var answer1 = $(this).data('title');
        var answer2 = $(this).data('description'); 
      //  alert(quaizid);
        $('#chapterId').val(quaizid);
        $('#chaptertitle').val(answer1);
        $('#chapterdescription').val(answer2);
        //chapterId 
    });
});
</script>
<?php /*
<script>

const dropArea = document.getElementById('dropArea');
const videoInput = document.getElementById('video');

// Drag and Drop functionality for video file only
dropArea.addEventListener('dragover', (event) => {
  event.preventDefault();
  dropArea.style.borderColor = '#007bff';
});

dropArea.addEventListener('dragleave', () => {
  dropArea.style.borderColor = '#ccc';
});

dropArea.addEventListener('drop', (event) => {
  event.preventDefault();
  dropArea.style.borderColor = '#ccc';

  const file = event.dataTransfer.files[0];
  if (file && file.type.startsWith('video/')) {
    videoInput.files = event.dataTransfer.files;
    dropArea.innerHTML = `<p>${file.name} selected</p>`;
  } else {
    Swal.fire({
      icon: 'error',
      title: 'Invalid File',
      text: 'Please upload a valid video file.',
    });
  }
});

// Form submission with AJAX and loader
$('#addchapter').on('submit', function(event) {
  event.preventDefault();  // Prevent default form submission

  // Custom validation to check if a video file is selected
  if (videoInput.files.length === 0) {
    Swal.fire({
      icon: 'error',
      title: ' Required File',
      text: 'Please select a video file.',
    });
    return;  // Stop submission if no file selected
  }

  $('#loaderOverlay').show();
  $('#progressBar').css('width', '0%').attr('aria-valuenow', 0).text('0%');
  // Create FormData object
  var formData = new FormData(this);
  
  // Get the selected video file
  var file = videoInput.files[0];
  var chunkSize = 5 * 1024 * 1024; // 5MB chunks
  var totalChunks = Math.ceil(file.size / chunkSize);
  var currentChunk = 0;

  function uploadNextChunk() {
    var start = currentChunk * chunkSize;
    var end = Math.min(start + chunkSize, file.size);
    var chunk = file.slice(start, end);
    var chunkFormData = new FormData();
    
    chunkFormData.append('video', chunk, file.name);
    chunkFormData.append('chunkNumber', currentChunk);
    chunkFormData.append('totalChunks', totalChunks);
    chunkFormData.append('courseId', $("input[name='courseId']").val());

    $.ajax({
      url: "<?php echo base_url().'course/addchapterdata' ?>", // Your server-side handler
      type: 'POST',
      data: chunkFormData,
      contentType: false,
      processData: false,
      xhr: function() {
        var xhr = new window.XMLHttpRequest();
        // Upload progress
        xhr.upload.addEventListener("progress", function(evt) {
          if (evt.lengthComputable) {
            var percentComplete = Math.round((evt.loaded / evt.total) * 100);
            $('#progressBar').css('width', percentComplete + '%').attr('aria-valuenow', percentComplete).text(percentComplete + '%');
          }
        }, false);
        return xhr;
      },
      success: function(response) {
        currentChunk++;
        if (currentChunk < totalChunks) {
          uploadNextChunk();  // Upload the next chunk
        } else {
          $('#loaderOverlay').hide();  // Hide loader on success
          Swal.fire({
            icon: 'success',
            title: 'Success!',
            text: 'Chapter Added successfully!',
          }).then(() => {
            location.reload();  // Reload the page after SweetAlert closes
          });
        }
      },
      error: function(xhr, status, error) {
        $('#loaderOverlay').hide();  // Hide loader on error
        Swal.fire({
          icon: 'error',
          title: 'Error',
          text: `An error occurred: ${xhr.responseText}`,
        });
      }
    });
  }

  uploadNextChunk();  // Start uploading the first chunk
});

</script> 
*/?>

<script>
  $(document).ready(function() {
 
    const dropArea = document.getElementById('dropArea');
    const videoInput = document.getElementById('video');

    // Drag and Drop functionality for Video file only
    dropArea.addEventListener('dragover', (event) => {
      event.preventDefault();
      dropArea.style.borderColor = '#007bff';
    });

    dropArea.addEventListener('dragleave', () => {
      dropArea.style.borderColor = '#ccc';
    });

    dropArea.addEventListener('drop', (event) => {
      event.preventDefault();
      dropArea.style.borderColor = '#ccc';

      const file = event.dataTransfer.files[0];
      if (file && file.type.startsWith('video/')) {
        videoInput.files = event.dataTransfer.files;
        dropArea.innerHTML = `<p>${file.name} selected</p>`;
      } else {
        Swal.fire({
        icon: 'error',
        title: 'Invalid File',
        text: 'Please upload a valid video file.',
      });
       
      }
    });

    // Form submission with AJAX and loader
    $('#addchapter').on('submit', function(event) {
      event.preventDefault();  // Prevent default form submission
         // Custom validation to check if a video file is selected
  if (videoInput.files.length === 0) {

    Swal.fire({
        icon: 'error',
        title: ' Required File',
        text: 'Please select a video file.',
      });
    
    return;  // Stop submission if no file selected
  }

      $('#loaderOverlay').show();
      $('#progressBar').css('width', '0%').attr('aria-valuenow', 0).text('0%');
      // Create FormData object
      var formData = new FormData(this);

      $.ajax({
        url: "<?php echo base_url().'course/addchapterdata' ?>", // Change to your API endpoint
        type: 'POST',
        data: formData,
        contentType: false,
        processData: false,
        xhr: function() {
        var xhr = new window.XMLHttpRequest();
        // Upload progress
        xhr.upload.addEventListener("progress", function(evt) {
          if (evt.lengthComputable) {
            var percentComplete = Math.round((evt.loaded / evt.total) * 100);
            $('#progressBar').css('width', percentComplete + '%').attr('aria-valuenow', percentComplete).text(percentComplete + '%');
          }
        }, false);
        return xhr;
         },
        success: function(response) {
          $('#loaderOverlay').hide();  // Hide loader on success
          Swal.fire({
          icon: 'success',
          title: 'Success!',
          text: 'Chapter Added successfully!',
        }).then(() => {
          location.reload();  // Reload the page after SweetAlert closes
        });
        },
        error: function(xhr, status, error) {
          $('#loaderOverlay').hide();  // Hide loader on error
          Swal.fire({
          icon: 'error',
          title: 'Error',
          text: `An error occurred: ${xhr.responseText}`,
        });
        }
      });
    });
  });
</script>

<script>
  $(document).ready(function() {
    const dropAreaEdit = document.getElementById('dropAreaEdit');
    const videoInput = document.getElementById('video2');

    // Drag and Drop functionality for Video file only
    dropAreaEdit.addEventListener('dragover', (event) => {
      event.preventDefault();
      dropAreaEdit.style.borderColor = '#007bff';
    });

    dropAreaEdit.addEventListener('dragleave', () => {
      dropAreaEdit.style.borderColor = '#ccc';
    });

    dropAreaEdit.addEventListener('drop', (event) => {
      event.preventDefault();
      dropAreaEdit.style.borderColor = '#ccc';

      const file = event.dataTransfer.files[0];
      if (file && file.type.startsWith('video/')) {
        videoInput.files = event.dataTransfer.files;
        dropAreaEdit.innerHTML = `<p>${file.name} selected</p>`;
      } else {
        Swal.fire({
        icon: 'error',
        title: 'Invalid File',
        text: 'Please upload a valid video file.',
      });
       
      }
    });

    // Form submission with AJAX and loader
    $('#editchapter').on('submit', function(event) {
      event.preventDefault();  // Prevent default form submission
      //$('#loaderOverlay1').show();  // Show loader
      $('#loaderOverlay1').show();
      $('#progressBar1').css('width', '0%').attr('aria-valuenow', 0).text('0%');
      // Create FormData object
      var formData = new FormData(this);

      $.ajax({
        url: "<?php echo base_url().'course/updatechapterdata' ?>", // Adjust to your endpoint
        type: 'POST',
        data: formData,
        contentType: false,
        processData: false,
        xhr: function() {
        var xhr = new window.XMLHttpRequest();
        // Upload progress
        xhr.upload.addEventListener("progress", function(evt) {
          if (evt.lengthComputable) {
            var percentComplete = Math.round((evt.loaded / evt.total) * 100);
            $('#progressBar1').css('width', percentComplete + '%').attr('aria-valuenow', percentComplete).text(percentComplete + '%');
          }
        }, false);
        return xhr;
         },
        success: function(response) {
          $('#loaderOverlay1').hide();  // Hide loader on success
          Swal.fire({
          icon: 'success',
          title: 'Success!',
          text: 'Chapter updated successfully!',
        }).then(() => {
          location.reload();  // Reload the page after SweetAlert closes
        });
        },
        error: function(xhr, status, error) {
          $('#loaderOverlay1').hide();  // Hide loader on error
          Swal.fire({
          icon: 'error',
          title: 'Error',
          text: `An error occurred: ${xhr.responseText}`,
        });
        }
      });
    });
  });

</script>
<script>
        // Show/hide conditional fields based on selected payment method
        document.getElementById('paymentMethod').addEventListener('change', function() {
            const method = this.value;
            document.getElementById('bankDetails').style.display = method === 'bank' ? 'block' : 'none';
            document.getElementById('paypalDetails').style.display = method === 'paypal' ? 'block' : 'none';
        });
    </script>
</body>

</html>