<?php
include($_SERVER['DOCUMENT_ROOT'] . "/COMPONENTS/root/path.php");
echo "<h5 class='userId' style='display:none;'>" . $_GET['configId'] . "</h5>";
?>



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

        <select class="form-control" name="config_id" style="display:none;">
             <option><?php echo $_GET['configId']?></option>
        </select>

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

        </select>
    </div>

    <div class="form-group secondInput">
        <label for="name" id="Description"></label>
        <input class="form-control" type="text" value="<?php echo $_GET["name"]; ?>" required name="name" id="name" placeholder="Enter description">
    </div>

    <div class="form-group serviceCharge" style="display:none;">
        <label for="name" id="serviceCharge"></label>
        <input class="form-control" type="number" value="<?php echo $_GET["amount"]; ?>" 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_editConfiguration" style="width:250px;"><span class='submitLoader'>Update</span></button>
    </div>

</form>

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