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

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

        })
    })
})