<div class="col-md-12">
    <form id="wsForm" class="form-horizontal">
        <div class="form-group row mb-4">
            <label class="col-12 col-md-2 control-label" for="lwsDesc">Title</label>
            <div class="col-12 col-md-10"><input class="form-control form-control-sm" type="text" name="lwsDesc" id="lwsDesc" value="" /></div>
        </div>
        <div class="row text-center">
            <input type="submit" class="btn btn-info" value="Create entry" />
            <input type="hidden" name="mode" value="setLWS">
            <input type="hidden" name="clientnumber" value="<?= $_REQUEST['clientnumber']?>">
            <input type="hidden" name="tenant" value="<?= $_REQUEST['tenant']?>">
        </div>
    </form>

</div>

<script>
document.querySelector("#wsForm input[type='submit']").addEventListener('click', function(event) {
    event.preventDefault();

    var description = document.getElementById('lwsDesc').value.trim();

    if (description === "") {
        showResponse('warning', 'YOU MUST SET A DESCRIPTION FOR YOUR LOLER WS');
    } else {
        var formData = new FormData(document.getElementById('wsForm'));

        fetch(ROOT_URL + '/includes/master/lws_functions.php', {
                method: 'POST',
                body: formData
            })
            .then(response => response.text())
            .then(result => {
                if (result.trim() === "success") {
                    showResponse('success', 'THE LWS HAS BEEN CREATED SUCCESSFULLY');
                    relLWs();
                    killModal("wsBox");
                } else {
                    showResponse('danger', 'THERE WAS AN ERROR CREATING THE WS');
                }
            })
            .catch(error => {
                console.error('Error:', error);
                showResponse('danger', 'THERE WAS AN ERROR PROCESSING THE REQUEST');
            });
    }
});
</script>