import { h } from './index-cb74209c.js';

function getMap(id) {
  return document.querySelector(id != undefined ? `gl-map#${id}` : "gl-map");
}
function getThumbnail(item) {
  if (item.image != undefined)
    return (h("ion-thumbnail", { slot: "start" },
      h("img", { src: item.image })));
}
function toArray(value, sep = ",") {
  if (value == undefined)
    return [];
  if (Array.isArray(value))
    return value;
  return value.split(sep);
}
// Based on: https://davidwalsh.name/get-absolute-url
const getAbsoluteUrl = (function () {
  let a;
  return function (url) {
    if (a == undefined)
      a = document.createElement("a");
    a.href = url;
    return a.href;
  };
})();
async function fetchPdf(url, filename, docDef) {
  let res = await fetch(url + filename, {
    method: "POST",
    mode: "cors",
    headers: {
      "Content-Type": "application/json",
    },
    body: JSON.stringify(docDef),
  });
  let blob = await res.blob();
  const nav = window.navigator;
  if (nav.msSaveOrOpenBlob) {
    nav.msSaveOrOpenBlob(blob, `${filename}.pdf`);
  }
  else {
    window.open(window.URL.createObjectURL(blob));
  }
}
async function findOrCreateOnReady(tagName) {
  let elm = document.querySelector(tagName);
  if (elm == null) {
    elm = document.createElement(tagName);
    document.body.appendChild(elm);
  }
  return typeof elm.componentOnReady === "function"
    ? elm.componentOnReady()
    : Promise.resolve(elm);
}

export { getAbsoluteUrl as a, fetchPdf as b, getThumbnail as c, findOrCreateOnReady as f, getMap as g, toArray as t };

//# sourceMappingURL=utils-0af5fee1.js.map