import Ajax from "../../components/ajax.js"
$(() => {
  $("#button-pedido-to-prod").on("click", (event) => {
    const pedidoId = $(event.currentTarget).data("id");
    Swal.fire({
      title: '¿Estás seguro?',
      text: "Esta acción creará la orden de trabajo del pedido",
      icon: 'warning',
      showCancelButton: true,
      confirmButtonColor: '#3085d6',
      cancelButtonColor: '#d33',
      confirmButtonText: 'Sí',
      cancelButtonText: 'Cancelar',
      customClass: {
        confirmButton: 'btn btn-primary me-1',
        cancelButton: 'btn btn-label-secondary'
      },
      buttonsStyling: false
    }).then((result) => {
      if (result.isConfirmed) {
        let ajax = new Ajax(
          "/pedidos/produccion/" + pedidoId,
          null,
          null,
          (response) => {
            if(response.status){
              location.reload()
            }
            Swal.fire({
              title: response.message,
              icon: 'success',
              showCancelButton: true,
              showConfirmButton: false,
              cancelButtonText: 'Cancelar',
              customClass: {
                confirmButton: 'btn btn-primary me-1',
                cancelButton: 'btn btn-label-secondary'
              },
              buttonsStyling: false
            })
          },
          null,
        )
        ajax.post()
      }
    }).catch((err) => {

    });
  })
})