import { h } from '@stencil/core';
export function getMap(id) {
    return document.querySelector((id) ? `gl-map#${id}` : 'gl-map');
}
export function getThumbnail(item) {
    if (item.image)
        return (h("ion-thumbnail", { slot: "start" },
            h("img", { src: item.image })));
}
export function toArray(value, sep = ',') {
    if (!value)
        return [];
    if (Array.isArray(value))
        return value;
    return value.split(sep);
}
// Based on: https://davidwalsh.name/get-absolute-url
export const getAbsoluteUrl = (function () {
    let a;
    return function (url) {
        if (!a)
            a = document.createElement('a');
        a.href = url;
        return a.href;
    };
})();
export 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();
    if (window.navigator.msSaveOrOpenBlob) {
        window.navigator.msSaveOrOpenBlob(blob, `${filename}.pdf`);
    }
    else {
        window.open(window.URL.createObjectURL(blob));
    }
}
