
/*Ajax genral*/
const ajaxRequestGeneral = obj => {
  let body=JSON.stringify(obj.body);
  return new Promise((resolve, reject) => {
    $.ajax({
      url: obj.url,
      type: obj.type,
      headers: obj.headers,
      data: {body:body},
      beforeSend: (xhr, settings) => {
      }, success: (response, textStatus, jqXHR) => {
        resolve(response)
      }, error: (jqXHR, textStatus, errorThrown) => {
        reject({
          status: jqXHR.status,
          throw: errorThrown || {},
          jqXHR: jqXHR,
          request: obj
        })
      }
    })
  })
}
/*Ajax General*/
let createSelectOptions = (obj, valueName, textName) => {
  let options = ''
  obj.forEach((data) => {
    options += `<option value="${data[valueName]}">${data[textName]}</option>`
  })
  return options
}

let customSwal = {
  alert(title, text, type) {
    let colors = {
      success: '#66BB6A',
      error: '#EF5350',
      warning: '#FF7043'
    }
    let btnColor = colors[type]
    return new Promise((resolve, reject) => {
      swal({
        title: title,
        text: text,
        confirmButtonColor: btnColor,
        type: type
      }, (isConfirm) => {
        resolve()
      })
    })
  }
}

/**
 * Get the closest matching element up the DOM tree.
 * @private
 * @param  {Element} elem     Starting element
 * @param  {String}  selector Selector to match against
 * @return {Boolean|Element}  Returns null if not match found
 */
let getClosest = (elem, selector) => {

  // Element.matches() polyfill
  if (!Element.prototype.matches) {
    Element.prototype.matches =
      Element.prototype.matchesSelector ||
      Element.prototype.mozMatchesSelector ||
      Element.prototype.msMatchesSelector ||
      Element.prototype.oMatchesSelector ||
      Element.prototype.webkitMatchesSelector ||
      function (s) {
        var matches = (this.document || this.ownerDocument).querySelectorAll(s),
          i = matches.length
        while (--i >= 0 && matches.item(i) !== this) {
        }
        return i > -1
      }
  }
  // Get closest match
  for (; elem && elem !== document; elem = elem.parentNode) {
    if (elem.matches(selector))
      return elem
  }
  return null
}

let logOut = () =>{
    document.querySelector('#logOut').addEventListener('click', (e) => {
//        Cookies.clear("menu");
//        Cookies.clear("Authorization");
//        debugger;
//        let urls = Cookies.get("urls");
//        let url ="";
//        if(urls!==null && urls !==""){
//            url = urls.split(";");
//            for(u in url){
//                $.removeCookie('Authorization', {domain: url[u], path:'/'});
//            }
//        }
//        location.reload();
        
        window.location.href = 'http://172.16.2.53:8080/proyecto-estandar/vistas/logout'
    })
}
/* vista viene = vista de donde viene sin .jsp
 * vista va = vista a donde va con .jsp
 * */
function setActive(vistaViene,vistaVa){
    Cookies.set("lActive",vistaViene, {expiry : 100});
    window.location.href=vistaVa;
}
logOut();
//document.querySelector('#logOut').addEventListener('click', (e) => {
//  Cookies.clear('Authorization')
//  Cookies.clear('menu')
//  window.location.href = 'index.jsp'
//})
