$(document).ready(function () {
    $("#createModal").on("show.bs.modal", function (event) {
        const button = $(event.relatedTarget);
        const data = {
            modalTitle: button.data("modal-title"),
            url: button.data("url"),
            method: button.data("method"),

            employee: button.data("employee"),
            amount: button.data("amount"),
        };

        $(".modal-title").text(data.modalTitle);
        $("#form").attr('action', data.url);
        $("#form-method").val(data.method);

        if (data.method === 'put') {
            $("#employee").val(data.employee).trigger('change');
            $("#amount").val(data.amount);
        }
    });

    $('#createModal').on('hidden.bs.modal', function () {
        const method = $("#form-method").val();
        if (method === 'put') {
            $("#employee").val('').trigger('change');
            $("#amount").val('');
        }
    });
});
