<?php
include($_SERVER['DOCUMENT_ROOT'] . "/COMPONENTS/root/path.php");
?>

<form action="#" class="pl-3 pr-3" id="form_addConfiguration">
    <h1 style='font-size:18px; text-align:center; color:black;' class="configHeading"></h1>
    <div class="form-group fourthInput">
        <label for="emailaddress1">Config Type</label>

        <select class="form-control configType" name="config_type_id">

        </select>
    </div>

    <div class="form-group secondInput">
        <label for="name" class="Description"></label>
        <input class="form-control" type="text" required name="name" id="name" placeholder="Enter description">
    </div>

    <div class="form-group serviceCharge" style="display:none;">
        <label for="amount" class="serviceChargeLabel"></label>
        <input class="form-control" type="number" name="amount" id="amount" placeholder="Enter amount" pattern='[0-9]+([.][0.00-9.00]+)' step='0.01'>
    </div>





    <div class="form-group text-center">
        <button type="submit" class="btn btn-rounded btn-primary submit_addConfiguration" style="width:250px;"><span class='submitLoader'>Submit</span></button>
    </div>

</form>

<script>
   
   

    $(".submit_addConfiguration").on("click", function() {
      
        $("#form_addConfiguration").submit(function(e) {
            $.ajax({
                url: domain_api + "/other-configs/create.php",
                type: "POST",
                data: $(this).serialize(),
                beforeSend: function() {
                 
                    $(".submit_addConfiguration").attr("disabled", "disabled");
                    $(".submitLoader").html("<i class='fa fa-spinner fa-spin'></i>")
                },
                success: function(data) {
                    $(".submitLoader").html("Submit");
                    $(".submit_addConfiguration").attr("disabled", false);
                    if (data.code == 200) {
                        swal("Succes!", "Configuration was successfully saved!", "success");
                    } else {
                        swal("Oops!", "Saving was not successful, you should try again!", "error");
                    }
                }
            });
            e.preventDefault();
        })
        $(this).off();
    });
</script>