$(document).ready(function() {
  $('body').bootstrapMaterialDesign();

  var height = ($(window).height() - ($('.legal').outerHeight() + $('.user-info').outerHeight() + $('.navbar').innerHeight()));

  $('#custom-slimscroll').slimScroll({
    height: height,
    size: '5px',
    color: 'rgba(0,0,0,0.5)',
    alwaysVisible: false,
    borderRadius: '0',
    railBorderRadius: '0',
    touchScrollStep : 50
  });

  $('#foodcourt-slimscroll').slimScroll({
    height: '100%',
    size: '5px',
    color: 'rgba(0,0,0,0.5)',
    alwaysVisible: false,
    borderRadius: '0',
    railBorderRadius: '0',
    touchScrollStep : 50
  });

  $('#foodcourt-table-slimscroll').slimScroll({
    height: '100%',
    size: '5px',
    color: 'rgba(0,0,0,0.5)',
    alwaysVisible: false,
    borderRadius: '0',
    railBorderRadius: '0',
    touchScrollStep : 50
  });

  $('#foodcourt-order-slimscroll').slimScroll({
    height: '100%',
    size: '5px',
    color: 'rgba(0,0,0,0.5)',
    alwaysVisible: false,
    borderRadius: '0',
    railBorderRadius: '0',
    touchScrollStep : 50
  });


  $('#foodcourt-menu-slimscroll').slimScroll({
    height: '100%',
    size: '5px',
    color: 'rgba(0,0,0,0.5)',
    alwaysVisible: false,
    borderRadius: '0',
    railBorderRadius: '0',
    touchScrollStep : 50
  });

  $('#table-slimscroll').slimScroll({
      height: height,
      size: '5px',
      color: 'rgba(0,0,0,0.5)',
      alwaysVisible: false,
      borderRadius: '0',
      railBorderRadius: '0',
      touchScrollStep : 50
  });

  $('#order-detail-slimscroll').slimScroll({
    // height: $('#order-detail-slimscroll').attr('data-height'),
    height: height-$('#order-detail-slimscroll').attr('data-height'),
    size: '5px',
    color: 'rgba(0,0,0,0.5)',
    alwaysVisible: false,
    borderRadius: '0',
    railBorderRadius: '0',
    touchScrollStep : 50
  });

  $('#menu-slimscroll').slimScroll({
    height: height-$('#menu-slimscroll').attr('data-height'),
    size: '5px',
    color: 'rgba(0,0,0,0.5)',
    alwaysVisible: false,
    borderRadius: '0',
    railBorderRadius: '0',
    touchScrollStep : 50
  });
   $('#menu1-slimscroll').slimScroll({
    height: height-$('#menu1-slimscroll').attr('data-height'),
    size: '5px',
    color: 'rgba(0,0,0,0.5)',
    alwaysVisible: false,
    borderRadius: '0',
    railBorderRadius: '0',
    touchScrollStep : 50
  });

  $('#modal-slimscroll').slimScroll({
    height: height-$('#modal-slimscroll').attr('data-height'),
    size: '5px',
    color: 'rgba(0,0,0,0.5)',
    alwaysVisible: false,
    borderRadius: '0',
    railBorderRadius: '0',
    touchScrollStep : 45
  });

  $('#modal-set-slimscroll').slimScroll({
    height: height-$('#modal-set-slimscroll').attr('data-height'),
    size: '10px',
    color: 'rgba(0,0,0,0.5)',
    alwaysVisible: false,
    borderRadius: '0',
    railBorderRadius: '0',
    touchScrollStep : 45
  });

  $('#set-menu-item-slimscroll').slimScroll({
    height: height-$('#set-menu-item-slimscroll').attr('data-height'),
    size: '10px',
    color: 'rgba(0,0,0,0.5)',
    alwaysVisible: false,
    borderRadius: '0',
    railBorderRadius: '0',
    touchScrollStep : 45
  });

  $('#customer-info-slimscroll').slimScroll({
    height: height-$('#customer-info-slimscroll').attr('data-height'),
    size: '5px',
    color: 'rgba(0,0,0,0.5)',
    alwaysVisible: false,
    borderRadius: '0',
    railBorderRadius: '0',
    touchScrollStep : 45
  });

  $('#pending-order-slimscroll').slimScroll({
    height: height-$('#pending-order-slimscroll').attr('data-height'),
    size: '5px',
    color: 'rgba(0,0,0,0.5)',
    alwaysVisible: false,
    borderRadius: '0',
    railBorderRadius: '0',
    touchScrollStep : 50
  });

  $('#make-reservation-slimscroll').slimScroll({
    height: height-$('#make-reservation-slimscroll').attr('data-height'),
    size: '5px',
    color: 'rgba(0,0,0,0.5)',
    alwaysVisible: false,
    borderRadius: '0',
    railBorderRadius: '0',
    touchScrollStep : 50
  });

  $('#process-reservation-slimscroll').slimScroll({
    height: height-$('#process-reservation-slimscroll').attr('data-height'),
    size: '5px',
    color: 'rgba(0,0,0,0.5)',
    alwaysVisible: false,
    borderRadius: '0',
    railBorderRadius: '0',
    touchScrollStep : 50
  });

  $('#reservation-info-slimscroll').slimScroll({
    height: height-$('#reservation-info-slimscroll').attr('data-height'),
    size: '5px',
    color: 'rgba(0,0,0,0.5)',
    alwaysVisible: false,
    borderRadius: '0',
    railBorderRadius: '0',
    touchScrollStep : 50
  });
  // $('.delete').click(function(){
  //   var method    = $(this).attr('data-method');
  //   var url       = $(this).attr('data-ref');
  //   var html_text = $(this).siblings( "#delete_text" ).html();
  //   //var page = url.substring(url.lastIndexOf('/') + 1);
  //   swal({
  //       title: "Confirmation",
  //       text: html_text,
  //       type: "warning",
  //       showCancelButton: true,
  //       confirmButtonColor: "#DD6B55",
  //       html: true
  //   }, function (isConfirm) {
  //       if (isConfirm) {
  //         $.ajax({
  //           type: method,
  //           url: url ,
  //           success: function(data) {
  //             location.href = data.url;
  //           }
  //        });
  //       } else {
  //           swal("Cancelled", "Your imaginary file is safe :)", "error");
  //       }
  //   });
  // });

  $("#refresh").on('click', function(){
    window.location.reload();
  })

  // for Notificaiotn message
  var placementFrom  = $("#notify_message").attr('data-placement-from');
  var placementAlign = $("#notify_message").attr('data-placement-align');
  var animateEnter   = $("#notify_message").attr('data-animate-enter');
  var animateExit    = $("#notify_message").attr('data-animate-exit');
  var colorName      = $("#notify_message").attr('data-color-name');
  var text           = $("#notify_message").attr('data-message');

  if (text != null || colorName != null){
     showNotification(colorName, text, placementFrom, placementAlign, animateEnter, animateExit);
  }

  function showNotification(colorName, text, placementFrom, placementAlign, animateEnter, animateExit) {
    if (colorName === null || colorName === '') { colorName = 'bg-black'; }
    if (animateEnter === null || animateEnter === '') { animateEnter = 'animated fadeInDown'; }
    if (animateExit === null || animateExit === '') { animateExit = 'animated fadeOutUp'; }
    var allowDismiss = true;
    $.notify({
        message: text
    },
        {
            type: colorName,
            allow_dismiss: allowDismiss,
            newest_on_top: true,
            timer: 1000,
            placement: {
                from: placementFrom,
                align: placementAlign
            },
            animate: {
                enter: animateEnter,
                exit: animateExit
            },
            template: '<div data-notify="container" class="bootstrap-notify-container alert alert-dismissible {0} ' + (allowDismiss ? "p-r-30" : "") + '" role="alert">' +
            '<button type="button" aria-hidden="true" class="close float-right m-l-20 m-t--5" data-notify="dismiss">×</button>' +
            '<span data-notify="icon"></span> ' +
            '<span data-notify="title">{1}</span> ' +
            '<span data-notify="message">{2}</span>' +
            '<div class="progress" data-notify="progressbar">' +
            '<div class="progress-bar progress-bar-{0}" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 0%;"></div>' +
            '</div>' +
            '<a href="{3}" target="{4}" data-notify="url"></a>' +
            '</div>'
        });
   }
  //end Notificaiotn message
});

/* start order reservation function */
function audioPlayBackground(shop_code,audio){
  // console.log(shop_code);
  //audio play
  var audio = new Audio('/'+audio); // define your audio
  // setTimeout(function(){
    // audio.loop = true;
    audio.play();
  // },10000);
}
/* end order reservation function */

/* online order count*/
function getOnlineOrderCount(){
  var count = 0;
  //Start Ajax
  $.ajax({
    async: false,
    type: "GET",
    url: "/origami/get_order_info",
    dataType: "json",
    success: function(data){
      console.log(data);
      if(parseInt(data) > 0){
        count = parseInt(data);
      }
    }
  });
  //end Ajax
  // alert(count);
  return count;
}
/* online order count*/
