var G_WS_SERVICE = "ws://localhost:6025";
var G_PRINTER = "POS";

var g_cln_printer_ready = false;
var g_cln_socket = new WebSocket(G_WS_SERVICE);
socket.onmessage = function(msg) {

};
socket.onopen = function() {

};
socket.onerror = function(msg) {

};
function cln_svc_name(svc) {
   switch(svc) {
      case "UMUM":
         return "Pasien Umum";
      case "COM" :
         return "Pasien Rekanan";
      case "KLINIK" :
         return "Pasien Klinik";
      case "ONLINE" :
         return "Pasien Online";
      case "RES" :
         return "Pengambilan Hasil";
      case "APPDR" :
         return "Mobile Dokter";
      case "MEMBER" :
         return "Pasien Member";
      default :
         return "OTHER";
   }
}
// inp
//    prev_number
//    remaining_queue
//    queue_day
//    serviceCode
//    number
//    queue_date
//    queue_time
function one_print_antrian(inp,fn_cb) {
   var set_center =String.fromCharCode(0x1b,0x61,0x01) ; 
   var set_font_size_big = String.fromCharCode(0x1b,0x21,0x10);
   var set_font_size = "";
   var set_font_size_large = String.fromCharCode(0x1d,0x21,0x21);
   var set_cutter =String.fromCharCode(0x1d, 0x56, 0x41, 0x03); 
   var reset_mode = String.fromCharCode(0x1b,0x40);
   var nomor_sebelumnya = inp.prev_number;
   var sisa_antrian = inp.remaining_queue;
   var hari = inp.queue_day;

   var fmt_data = reset_mode +
      set_font_size_big + 
      set_center + "PRAMITA LAB - Cik Di Tiro\n" +
      set_center + "\n" +
      set_center + cln_svc_name(inp.serviceCode) + "\n" +
      "\n" + set_font_size_large + 
      set_center  + inp.number + "\n" +
      "\n" + reset_mode +
      set_center + "Nomor sebelumnya " + nomor_sebelumnya + "\n" +
   set_center + "Sisa Antrian " + sisa_antrian + "\n"  +
   set_center  + hari + " " +  inp.queue_date + " " + inp.queue_time + "\n" +
   set_center  + "Terima Kasih\n\n\n" ;

   fmt_data = fmt_data + set_cutter;
   var data_print = {
      printer : G_PRINTER,
      type : "zpl",
      data : fmt_data
   };
   socket.send(JSON.stringify(data_print));    
   fn_cb();
}

window.one_print_antrian = one_print_antrian;
