import Ajax from "../../components/ajax.js"
import Modal from "../../components/modal.js";
$(() => {
    let maquinaId = $("#maquinaForm").data("id");
    const uri = '/maquinas/duplicate/' + maquinaId;
    let modalPapelDuplicate = new Modal($("#modalMaquinaDuplicate"))
    $("#btn-maquina-duplicate").on("click", (event) => {
        $("#duplicated_name").removeClass("is-valid").removeClass("is-invalid")
        modalPapelDuplicate.toggle();
        $("#btn-new-maquina-duplicate").on("click", () => {
            let name = $("#duplicated_name").val()
            const ajax = new Ajax(uri,
                { name: name },
                null,
                (response) => {
                    modalPapelDuplicate.toggle();
                    $("#btn-new-maquina-duplicate").off();
                    $("#duplicated_name").addClass("is-valid").removeClass('d-none');
                    $("#duplicated_name").val("")
                    window.open('/configuracion/maquinas/edit/' + response.data.id)

                },
                (error) => {
                    $("#duplicated_name").removeClass("is-valid").addClass("is-invalid")
                }
            )
            ajax.post()

        })
    })
})