let base_url = "https://u9.agniaga.com/api/v1/";

let ar = {

  'relation': {

    1: 'Komisaris',

    2: 'Direksi',

    3: 'Staff',

    6: 'Debitur',

    7: 'Kreditur',

    8: 'Customer',

    9: 'Supplier',

    10: 'Other'

  },

  'brand': {

    1: 'Samsung',

    2: 'Panasonic',

    3: 'Sharp'

  }

};



function checkConnection(url) {}



function timeOut(num = 30000) {

  setTimeout(() => {

    app.preloader.hide();

    app.dialog.alert('Operation timed out...', 'Time Out');

  }, num)

}



function promiseTimeout(ms, promise) {

  // Create a promise that rejects in <ms> milliseconds

  let timeout = new Promise((resolve, reject) => {

    let id = setTimeout(() => {

      clearTimeout(id);

      reject('Operation timed out in ' + (ms / 1000) + 's')

    }, ms)

  })

  // Returns a race between our timeout and the passed in promise

  return Promise.race([

    promise,

    timeout

  ])

}

String.prototype.replaceAt = function(index, char) {

  return this.substr(0, index - 1) + char + this.substr(index + char.length);

}



function copyToClipboard(element) {

  var $temp = $("<input>");

  $("body").append($temp);

  $temp.val($(element).text()).select();

  document.execCommand("copy");

  $temp.remove();

}



function init_swiper(Id) {

  var swiper1 = app.swiper.create(Id, {

    pagination: {

      el: '.swiper-pagination',

      type: 'bullets',

    },

    speed: 400,

    spaceBetween: 10,

    slidesPerView: 1,

    autoplay: {

      delay: 4000,

      disableOnInteraction: false

    }

  });

}



function showToast(message, type = 'Message', position = 'bottom') {

  app.toast.create({

    text: message,

    position: position,

    closeTimeout: 2000,

  }).open()

}



function SortByDate(ulid, liclass, by) {

  var $wrap = $('#' + ulid);

  if (by == 'asc') {

    $wrap.find('.' + liclass).sort(function(a, b) {

      return +a.dataset.date -

        +b.dataset.date;

    }).appendTo($wrap);

  } else {

    $wrap.find('.' + liclass).sort(function(b, a) {

      return +a.dataset.date -

        +b.dataset.date;

    }).appendTo($wrap);

  }

}



function SortByName(ulid, liclass, by) {

  var $wrap = $('#' + ulid);

  if (by == 'asc') {

    $wrap.find('.' + liclass).sort(function(a, b) {

      return +a.dataset.name -

        +b.dataset.name;

    }).appendTo($wrap);

  } else {

    $wrap.find('.' + liclass).sort(function(b, a) {

      return +a.dataset.name -

        +b.dataset.name;

    }).appendTo($wrap);

  }

}



function SortByAmount(ulid, liclass, by) {

  var $wrap = $('#' + ulid);

  if (by == 'asc') {

    $wrap.find('.' + liclass).sort(function(a, b) {

      return +a.dataset.amount -

        +b.dataset.amount;

    }).appendTo($wrap);

  } else {

    $wrap.find('.' + liclass).sort(function(b, a) {

      return +a.dataset.amount -

        +b.dataset.amount;

    }).appendTo($wrap);

  }

}



function SortById(ulid, liclass, by) {

  var $wrap = $('#' + ulid);

  if (by == 'asc') {

    $wrap.find('.' + liclass).sort(function(a, b) {

      return +a.dataset.id -

        +b.dataset.id;

    }).appendTo($wrap);

  } else {

    $wrap.find('.' + liclass).sort(function(b, a) {

      return +a.dataset.id -

        +b.dataset.id;

    }).appendTo($wrap);

  }

}



function SortBySeq(ulid, liclass, by) {

  var $wrap = $('#' + ulid);

  if (by == 'asc') {

    $wrap.find('.' + liclass).sort(function(a, b) {

      return +a.dataset.seq -

        +b.dataset.seq;

    }).appendTo($wrap);

  } else {

    $wrap.find('.' + liclass).sort(function(b, a) {

      return +a.dataset.seq -

        +b.dataset.seq;

    }).appendTo($wrap);

  }

}