<script>
    $(document).ready(function() {
        $('#submit_marketing_tools_from').on('submit', function(e) {
            e.preventDefault(); // Prevent the form from submitting via the browser
            var formData = new FormData(this);
            $.ajax({
                url: '<?php echo base_url(); ?>/admin/course/upload_course_marketing_tools_for_data',
                type: 'POST',
                data: formData,
                cache: false,
                contentType: false,
                processData: false,
                success: function(response) {
                    $("#marketing_tools_from").load(window.location.href + " #marketing_tools_from");
                    swal({
                        title: "Done!",
                        text: "Data Successfully Updated",
                        icon: "success",
                    });
                    $('#marketing_tools_modal').modal('hide');
                    $('#marketing_tools_from_title').val('');
                    $('#marketing_tools_from_image').val('');
                    $('button[type="submit"]').html('Save');
                    $('button[type="submit"]').attr('disabled', false);
                },
                error: function(e) {
                    console.log(e.responseText)
                }
            });
        });

        $('#submit_certification_from').on('submit', function(e) {
            e.preventDefault(); // Prevent the form from submitting via the browser
            var formData = new FormData(this);
            $.ajax({
                url: '<?php echo base_url(); ?>/admin/course/upload_course_certification_for_data',
                type: 'POST',
                data: formData,
                cache: false,
                contentType: false,
                processData: false,
                success: function(response) {
                    $("#course_certification_from").load(window.location.href + " #course_certification_from");
                    swal({
                        title: "Done!",
                        text: "Data Successfully Updated",
                        icon: "success",
                    });
                    $('#certification_from').modal('hide');
                    $('#certification_from_title').val('');
                    $('#certification_from_image').val('');
                    $('button[type="submit"]').html('Save');
                    $('button[type="submit"]').attr('disabled', false);
                },
                error: function(e) {
                    console.log(e.responseText)
                }
            });
        });

        $('#submit_certified_from').on('submit', function(e) {
            e.preventDefault(); // Prevent the form from submitting via the browser
            var formData = new FormData(this);
            $.ajax({
                url: '<?php echo base_url(); ?>/admin/course/upload_course_certified_for_data',
                type: 'POST',
                data: formData,
                cache: false,
                contentType: false,
                processData: false,
                success: function(response) {
                    $("#course_certification_from").load(window.location.href + " #course_certification_from");
                    swal({
                        title: "Done!",
                        text: "Data Successfully Updated",
                        icon: "success",
                    });
                    $('#certified_from').modal('hide');
                    $('#certified_from_title').val('');
                    $('#certified_from_image').val('');
                    $('button[type="submit"]').html('Save');
                    $('button[type="submit"]').attr('disabled', false);
                },
                error: function(e) {
                    console.log(e.responseText)
                }
            });
        });

        $('#submit_ai_from').on('submit', function(e) {
            e.preventDefault(); // Prevent the form from submitting via the browser
            var formData = new FormData(this);
            $.ajax({
                url: '<?php echo base_url(); ?>/admin/course/upload_course_ai_tools_for_data',
                type: 'POST',
                data: formData,
                cache: false,
                contentType: false,
                processData: false,
                success: function(response) {
                    $("#ai_tools_from").load(window.location.href + " #ai_tools_from");
                    swal({
                        title: "Done!",
                        text: "Data Successfully Updated",
                        icon: "success",
                    });
                    $('#ai_tools_modal').modal('hide');
                    $('#ai_from_title').val('');
                    $('#ai_from_image').val('');
                    $('button[type="submit"]').html('Save');
                    $('button[type="submit"]').attr('disabled', false);
                },
                error: function(e) {
                    console.log(e.responseText)
                }
            });
        });

        $('#submit_hiring_partner_from').on('submit', function(e) {
            e.preventDefault(); // Prevent the form from submitting via the browser
            var formData = new FormData(this);
            $.ajax({
                url: '<?php echo base_url(); ?>/admin/course/upload_course_hiring_partner_for_data',
                type: 'POST',
                data: formData,
                cache: false,
                contentType: false,
                processData: false,
                success: function(response) {
                    $("#hiring_partner_from").load(window.location.href + " #hiring_partner_from");
                    swal({
                        title: "Done!",
                        text: "Data Successfully Updated",
                        icon: "success",
                    });
                    $('#hiring_partner_modal').modal('hide');
                    $('#hiring_partner_from_title').val('');
                    $('#hiring_partner_from_image').val('');
                    $('button[type="submit"]').html('Save');
                    $('button[type="submit"]').attr('disabled', false);
                },
                error: function(e) {
                    console.log(e.responseText)
                }
            });
        });

        $('#submit_whats_include_from').on('submit', function(e) {
            e.preventDefault(); // Prevent the form from submitting via the browser
            var formData = new FormData(this);
            $.ajax({
                url: '<?php echo base_url(); ?>/admin/course/upload_course_whats_include_for_data',
                type: 'POST',
                data: formData,
                cache: false,
                contentType: false,
                processData: false,
                success: function(response) {
                    $("#whats_include_from").load(window.location.href + " #whats_include_from");
                    swal({
                        title: "Done!",
                        text: "Data Successfully Updated",
                        icon: "success",
                    });
                    $('#whats_include_modal').modal('hide');
                    $('#whats_include_from_title').val('');
                    $('#whats_include_from_image').val('');
                    $('button[type="submit"]').html('Save');
                    $('button[type="submit"]').attr('disabled', false);
                },
                error: function(e) {
                    console.log(e.responseText)
                }
            });
        });

        $('#submit_learning_methodology_from').on('submit', function(e) {
            e.preventDefault(); // Prevent the form from submitting via the browser
            var formData = new FormData(this);
            $.ajax({
                url: '<?php echo base_url(); ?>/admin/course/upload_course_learning_methodology_for_data',
                type: 'POST',
                data: formData,
                cache: false,
                contentType: false,
                processData: false,
                success: function(response) {
                    $("#learning_methodology_from").load(window.location.href + " #learning_methodology_from");
                    swal({
                        title: "Done!",
                        text: "Data Successfully Updated",
                        icon: "success",
                    });
                    $('#learning_methodology_modal').modal('hide');
                    $('#learning_methodology_from_title').val('');
                    $('#learning_methodology_from_content').val('');
                    $('#learning_methodology_from_image').val('');
                    $('button[type="submit"]').html('Save');
                    $('button[type="submit"]').attr('disabled', false);
                },
                error: function(e) {
                    console.log(e.responseText)
                }
            });
        });

    });



    function addRowForWhoThisFor() {
        var table = document.getElementById("dynamic-table-for-who-this-for");
        var row = table.insertRow(table.rows.length);

        var cell1 = row.insertCell(0);
        var cell2 = row.insertCell(1);

        cell1.innerHTML = '<input type="text" placeholder="Enter Title *" class="form-control" name="who_this_title[]" required>';
        cell2.innerHTML = '<button type="button" class="btn btn-danger" onclick="deleteRowForWhoThisFor(this)">Delete</button>';
    }

    function deleteRowForWhoThisFor(button) {
        var row = button.parentNode.parentNode;
        row.parentNode.removeChild(row);
    }

    function addRowForkeyHighlight() {
        var table = document.getElementById("dynamic-table-for-key-highlight");
        var row = table.insertRow(table.rows.length);

        var cell1 = row.insertCell(0);
        var cell2 = row.insertCell(1);
        var cell3 = row.insertCell(2);

        cell1.innerHTML = '<input type="text" placeholder="Enter Stat Title *" class="form-control" name="highlight_title[]" required>';
        cell2.innerHTML = '<input type="text" placeholder="Enter Stat Sub Title *" class="form-control" name="highlight_sub_title[]" required>';
        cell3.innerHTML = '<button type="button" class="btn btn-danger" onclick="deleteRowForkeyHighlight(this)">Delete</button>';
    }

    function deleteRowForkeyHighlight(button) {
        var row = button.parentNode.parentNode;
        row.parentNode.removeChild(row);
    }

    function addRowForSuccessStrories() {
        var table = document.getElementById("dynamic-table-for-success-strories");
        var row = table.insertRow(table.rows.length);

        var cell1 = row.insertCell(0);
        var cell2 = row.insertCell(1);

        cell1.innerHTML = '<input type="text" placeholder="Enter Video URL *" class="form-control" name="course_success_stories[]" required>';
        cell2.innerHTML = '<button type="button" class="btn btn-danger" onclick="deleteRowForSuccessStrories(this)">Delete</button>';
    }

    function deleteRowForSuccessStrories(button) {
        var row = button.parentNode.parentNode;
        row.parentNode.removeChild(row);
    }

    function addRowForWhatsNew() {
        var table = document.getElementById("dynamic-table-for-whats-new");
        var row = table.insertRow(table.rows.length);

        var cell1 = row.insertCell(0);
        var cell2 = row.insertCell(1);

        cell1.innerHTML = '<input type="text" placeholder="Enter Content *" class="form-control" name="course_whats_new[]" required>';
        cell2.innerHTML = '<button type="button" class="btn btn-danger" onclick="deleteRowForWhatsNew(this)">Delete</button>';
    }

    function deleteRowForWhatsNew(button) {
        var row = button.parentNode.parentNode;
        row.parentNode.removeChild(row);
    }

    function addRowForBonusContent() {
        var table = document.getElementById("dynamic-table-for-bonus-content");
        var row = table.insertRow(table.rows.length);

        var cell1 = row.insertCell(0);
        var cell2 = row.insertCell(1);

        cell1.innerHTML = '<input type="text" placeholder="Enter Content *" class="form-control" name="course_bonus_content[]" required>';
        cell2.innerHTML = '<button type="button" class="btn btn-danger" onclick="deleteRowForBonusContent(this)">Delete</button>';
    }

    function deleteRowForBonusContent(button) {
        var row = button.parentNode.parentNode;
        row.parentNode.removeChild(row);
    }

    function addRowForFaq() {
        var table = document.getElementById("dynamic-table-for-faq");
        var row = table.insertRow(table.rows.length);

        var cell1 = row.insertCell(0);
        var cell2 = row.insertCell(1);
        var cell3 = row.insertCell(2);

        cell1.innerHTML = '<input type="text" placeholder="Enter Qns *" class="form-control" name="faq_qns[]" required>';
        cell2.innerHTML = '<input type="text" placeholder="Enter Ans *" class="form-control" name="faq_ans[]" required>';
        cell3.innerHTML = '<button type="button" class="btn btn-danger" onclick="deleteRowForFaq(this)">Delete</button>';
    }

    function deleteRowForFaq(button) {
        var row = button.parentNode.parentNode;
        row.parentNode.removeChild(row);
    }
</script>