</div>
<!-- End of Main Content -->

<!-- Footer -->
<footer class="sticky-footer bg-white">
    <div class="container my-auto">
        <div class="copyright text-center my-auto">
            <span>Copyright &copy; 
            <?php if($this->session->userdata('selectedpanel')=="blueline"){ ?>
            Blue Line Admin Panel
            <?php } ?>
            <?php if($this->session->userdata('selectedpanel')=="letts"){ ?>
            Letts Of London 
            <?php } ?>
            <?php if($this->session->userdata('selectedpanel')=="filofax"){ ?>
            Filo Fax Admin Panel
            <?php } ?>

            </span>
        </div>
    </div>
</footer>
<!-- End of Footer -->

</div>
<!-- End of Content Wrapper -->

</div>
<!-- End of Page Wrapper -->

<!-- Scroll to Top Button-->
<a class="scroll-to-top rounded" href="#page-top">
    <i class="fas fa-angle-up"></i>
</a>

<!-- Logout Modal-->
<div class="modal fade" id="logoutModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLabel">Ready to Leave?</h5>
                <button class="close" type="button" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">×</span>
                </button>
            </div>
            <div class="modal-body">Select "Logout" below if you are ready to end your current session.</div>
            <div class="modal-footer">
                <button class="btn btn-secondary" type="button" data-dismiss="modal">Cancel</button>
                <a class="btn btn-primary" href="login.html">Logout</a>
            </div>
        </div>
    </div>
</div>


<!-- Custom scripts for all pages-->
<script src="<?=base_url()?>assets/theme/js/sb-admin-2.min.js"></script>
<script src="http://137.184.111.69/carpooling/assets/js/Chart.min.js"></script>
<script src="http://137.184.111.69/carpooling/assets/js/Chart.bundle.min.js"></script>
<script src="<?=base_url()?>assets/theme/vendor/datatables/jquery.dataTables.min.js"></script>
<script src="<?=base_url()?>assets/theme/vendor/datatables/dataTables.bootstrap4.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/buttons/1.7.1/css/buttons.dataTables.min.css">
    <script type="text/javascript" src="https://cdn.datatables.net/buttons/1.7.1/js/dataTables.buttons.min.js"></script>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/pdfmake.min.js"></script>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/vfs_fonts.js"></script>
    <script type="text/javascript" src="https://cdn.datatables.net/buttons/1.7.1/js/buttons.html5.min.js"></script>


<script src="<?=base_url()?>assets/theme/js/demo/datatables-demo.js"></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 } ?>

var table = $("#songpad").DataTable({
});
var table = $("#dataTableevent").DataTable({
    // Add your DataTable options here
      order: [[0, 'desc']],
    // Define column options
    columnDefs: [
      {
        // Hide the first column (index 0)
        targets: 0,
        visible: false
      }
    ]
  });

  // Set the first column to sort in descending order by default
 // table.order([0, 'desc']).draw();
</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: true,
            },
        };
    }
    return config;
}
</script>
<script>
$(document).ready(function () {
    let lastDoc = null;

    const table = $('#mydataTable').DataTable({
        processing: true,
        serverSide: true,
        paging: true,
        searching: false, // Disable default search
        ajax: function (data, callback, settings) {
            const pageSize = data.length;
            const draw = data.draw;

            const searchParams = {
                searchFullName: $('#searchFullName').val(),
                searchUserName: $('#searchUserName').val(),
                searchPhone: $('#searchPhone').val(),
                searchTotalReminder: $('#searchTotalReminder').val(),
                searchArchived: $('#searchArchived').val(),
                searchEmail: $('#searchEmail').val(),
                searchCountry: $('#searchCountry').val(),
                searchLogin: $('#searchLogin').val(),
            };

            $.ajax({
                url: 'https://us-central1-filofax-96375.cloudfunctions.net/widgets/getuserlistpagination1',
                type: 'GET',
                data: {
                    limit: pageSize,
                    lastDoc: lastDoc || '',
                    ...searchParams,
                },
                success: function (response) {
                    const users = response.users;
                    lastDoc = response.lastDoc;

                    const records = users.map(user => [
                        `${user.firstName} ${user.lastName}`,
                        user.userName || 'N/A',
                        user.phoneNumber || 'N/A',
                        user.totalReminders || 0,
                        user.archived || 0,
                        user.email || 'N/A',
                        user.country || 'N/A',
                        user.deviceType || 'N/A',
                        user.image
                            ? `<img src="${user.image}" width="50" height="50" class="img-thumbnail">`
                            : '<img src="http://placehold.jp/50x50.png" class="img-thumbnail">',
                        `<a href="customer/filodeleteCustomer/${user.id}" class="btn btn-danger btn-sm">Delete</a>`
                    ]);

                    callback({
                        draw: draw,
                        recordsTotal: response.totalUsers,
                        recordsFiltered: response.filteredUsers || response.totalUsers,
                        data: records
                    });
                },
                error: function (error) {
                    console.error('Error fetching data:', error);
                    callback({
                        draw: draw,
                        recordsTotal: 0,
                        recordsFiltered: 0,
                        data: []
                    });
                }
            });
        },
        columns: [
            { title: "Full Name", data: 0 },
            { title: "UserName", data: 1 },
            { title: "Phone", data: 2 },
            { title: "Total Reminder", data: 3 },
            { title: "Archived Reminder", data: 4 },
            { title: "Email", data: 5 },
            { title: "Country", data: 6 },
            { title: "Login", data: 7 },
            { title: "Image", data: 8 },
            { title: "Actions", data: 9 }
        ],
        initComplete: function () {
            // Add search inputs programmatically
            $('#mydataTable thead tr').clone(true).appendTo('#mydataTable thead');
            $('#mydataTable thead tr:eq(1) th').each(function (i) {
                if (i < 8) { // Add inputs for the first 8 columns
                    $(this).html('<input type="text" placeholder="Search" class="form-control" />');
                    $('input', this).on('keyup change', function () {
                        table.ajax.reload(null, false); // Reload table with search filters
                    });
                } else {
                    $(this).html(''); // No inputs for Image and Actions
                }
            });
        }
    });
});


</script>
<script>
$(document).ready(function() {
    $('#generateCSV').on('click', function() {
        var $button = $(this);

        // Disable button and show loading state
        $button.prop('disabled', true).text('Generating CSV...');

        $.ajax({
            url: 'http://137.184.111.69/superadmin/customer/makenewcsv', // Update with your actual PHP endpoint
            type: 'GET',
            dataType: 'json',
            success: function(response) {
                console.log(response)
                if (response.status === 'success') {
                    var downloadLink = $('<a>', {
                        href: response.file_url,          // URL of the generated CSV
                        text: 'Click here to download your CSV file', // Text for the link
                        target: '_blank',     
                        class: 'btn btn-success'  ,            // Open link in a new tab
                        download: response.file_url.split('/').pop() // Set the download attribute to the file name
                    });

                    // Append the link to the body (or any other container element)
                    $('#downloadContainer').html(downloadLink); 

                } else {
                    alert('Failed to generate CSV.');
                }
            },
            error: function() {
                alert('An error occurred while generating CSV.');
            },
            complete: function() {
                // Enable button and reset text
                $button.prop('disabled', false).text('Genrate CSV');
            }
        });
    });
});
</script>

</body>

</html>