function menuOrder(name, date, menu) {
  Swal.fire({
    title: 'Dodavanje narudžbe',
    text: 'Želite li odabrati menu '+menu+'?',
    icon: 'question',
    showCancelButton: true,
    cancelButtonText: 'Poništi',
    confirmButtonText: 'Dodaj'
  }).then((result) => {
    if (result.isConfirmed) {
        var url = 'helpers/menu-order.php';
        var params = "date="+date+"&menu="+menu;
        var xhr = new XMLHttpRequest();
        xhr.open('GET', url+"?"+params, true);
        xhr.onreadystatechange = function() {
            if (xhr.readyState === 4 && xhr.status === 200) {
            }
        };
        xhr.send();
        Swal.fire(
          'Dodano!',
          'Narudžba je dodana.',
          'success'
        ).then((result) => {
            if (result.isConfirmed) {
              var xhr = new XMLHttpRequest();
              xhr.open('GET', './inc/send_mail_new.php?name='+name+'&menu='+menu+'&date='+date+'&change=no', true);
              xhr.onreadystatechange = function() {
                  if (xhr.readyState === 4 && xhr.status === 200) {}
              };
              xhr.send();
              location.reload();
            }
        })
      }
  });
}

function menuOrderChange(name, date, menu) {
  Swal.fire({
    title: 'Ažuriranje narudžbe',
    text: 'Želite li odabrati menu '+menu+'?',
    icon: 'question',
    showCancelButton: true,
    cancelButtonText: 'Poništi',
    confirmButtonText: 'Ažuriraj'
  }).then((result) => {
    if (result.isConfirmed) {
        var url = 'helpers/menu-order.php';
        var params = "date="+date+"&menu="+menu;
        var xhr = new XMLHttpRequest();
        xhr.open('GET', url+"?"+params, true);
        xhr.onreadystatechange = function() {
            if (xhr.readyState === 4 && xhr.status === 200) {
            }
        };
        xhr.send();
        Swal.fire(
          'Ažurirano!',
          'Narudžba je ažurirana.',
          'success'
        ).then((result) => {
            if (result.isConfirmed) {
              var xhr = new XMLHttpRequest();
              xhr.open('GET', './inc/send_mail_new.php?name='+name+'&menu='+menu+'&date='+date+'&change=yes', true);
              xhr.onreadystatechange = function() {
                  if (xhr.readyState === 4 && xhr.status === 200) {}
              };
              xhr.send();
              location.reload();
            }
        })
      }
  });
}

function menuOrderDuplicate() {
  Swal.fire(
    '',
    'Ovaj menu je već odabran.',
    'warning'
  )
}
