/**
 * Get random string block
 */
function chr4() {
    return Math.random().toString(16).slice(-4);
}
/**
 * Generate a UUID string with optional prefix
 *
 * @param concat
 * @returns
 */
function getId(concat = '') {
    return concat + '-' + chr4() + chr4() + '-' + chr4() + '-' + chr4() + chr4() + chr4();
}
/**
 * Check if object is empty
 *
 * @param obj
 * @returns
 */
function isEmpty(obj) {
    if (typeof obj === 'undefined') {
        return true;
    }
    if (obj == null) {
        return true;
    }
    if ((obj === null || obj === void 0 ? void 0 : obj.length) === 0) {
        return true;
    }
    if ((obj === null || obj === void 0 ? void 0 : obj.length) > 0) {
        return false;
    }
    for (const prop in obj) {
        if (obj.hasOwnProperty(prop)) {
            return false;
        }
    }
    return JSON.stringify(obj) === JSON.stringify({});
}
/**
 * Convert string to snake case
 *
 * @param str
 * @returns
 */
const toSnakeCase = (str) => {
    return str.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, '$1_$2').toLowerCase();
};
/**
 * Convert bracket to dot notation
 *
 * @param bracket
 * @returns
 */
const bracketToDot = (bracket) => {
    if (isEmpty(bracket)) {
        return null;
    }
    return `${bracket}`.replace(/\[([^\]]+)\]/g, '.$1');
};
/**
 * Filter Markdown text with data
 */
function filterData(text, data = {}) {
    if (Object.keys(data).length) {
        return Object.keys(data).reduce((text, find) => text.replaceAll(`{${find}}`, data[find]), text);
    }
    return text;
}
/**
 * Filter Markdown text style to find icon and render HTML string
 *
 * @param str
 * @returns
 */
function filterIcon(text) {
    return (text || '').replace(/(\:).+?(\:)/g, (string) => `<i class="icon-${string.replaceAll(':', '')}"></i>`);
}
/**
 * Filter Markdown text style to find bold and render HTML string
 *
 * @param str
 * @returns
 */
function filterBold(text) {
    return (text || '').replace(/(\*).+?(\*)/g, (string) => `<strong>${string.replaceAll('*', '')}</strong>`);
}
/**
 * Filter Markdown text style to find italic and render HTML string
 *
 * @param str
 * @returns
 */
function filterItalic(text) {
    return (text || '').replace(/(\_).+?(\_)/g, (string) => `<em>${string.replaceAll('_', '')}</em>`);
}
/**
 * Filter Markdown text style to find code and render HTML string
 *
 * @param str
 * @returns
 */
function filterCode(text) {
    return (text || '').replace(/(\`).+?(\`)/g, (string) => `<code>${string.replaceAll('`', '')}</code>`);
}
/**
 * Filter Express Markdown text style and render to HTML string
 *
 * @param text
 * @param data
 * @returns
 */
function tinyMDtoHTML(text, data = {}) {
    return filterData(filterIcon(filterBold(filterItalic(filterCode(text)))), data);
}
/**
 * Get the lang value from document or html
 *
 * @returns
 */
function getLangFromDocument() {
    return document.querySelector('html').getAttribute('lang') || 'es';
}
/**
 * Get the lang value from browser
 *
 * @returns
 */
function getLangFromBrowser() {
    const lang = navigator.language;
    return lang.substring(0, 1);
}
/**
 * Get the lang
 *
 * @returns
 */
function getLang() {
    const lang = getLangFromDocument() || getLangFromBrowser();
    return ['en', 'es'].includes(lang) ? lang : 'es';
}
/**
 * Get the dialog type by HTTP response code
 *
 * @param status
 * @returns
 */
function alertCodeByStatus(status) {
    switch (status) {
        case 400:
            return 'error';
        case 401:
        case 403:
            return 'forbidden';
        case 402:
            return 'payment';
        case 404:
        case 405:
            return 'unknown';
        case 406:
            return 'no-result';
        case 412:
        case 418:
            return 'invalid';
        case 422:
            return 'missing';
        case 500:
            return 'exception';
        default:
            return 'failure';
    }
}
/**
 * Get meta header content
 *
 * @param name
 * @returns
 */
function getMeta(name) {
    var _a;
    return (_a = document.querySelector(`meta[name="${name}"]`)) === null || _a === void 0 ? void 0 : _a.getAttribute('content');
}
/**
 * Parse object logic of classes to string
 *
 * @param list
 * @returns
 */
function cls(...classes) {
    return classes.reduce((accumulator, currentValue) => {
        if (typeof currentValue === 'object' && typeof currentValue !== 'string') {
            accumulator = accumulator.concat(Object.keys(currentValue).filter(key => currentValue[key]));
        }
        if (typeof currentValue !== 'object' && typeof currentValue === 'string') {
            accumulator.push(currentValue);
        }
        return accumulator;
    }, []).join(' ');
}
/**
 * Get or create the x-overlays element container
 *
 * @returns
 */
function getOverlayContainer() {
    if (!document.querySelector('body > x-overlay-container')) {
        const overlay = document.createElement('x-overlay-container');
        document.querySelector('body').appendChild(overlay);
        return overlay;
    }
    else {
        return document.querySelector('body > x-overlay-container');
    }
}
/**
 * Evaluate the index value for overlay items
 *
 * @param el
 */
function evaluateOverlayIndex(el) {
    var _a;
    const overlay = getOverlayContainer();
    const index = parseInt((_a = overlay.dataset.lastIndex) !== null && _a !== void 0 ? _a : '0') + 1;
    el.style.zIndex = (9000 + index).toString();
    overlay.dataset.lastIndex = index.toString();
}
/**
 * Get or create the tooltip element to show
 *
 * @returns
 */
function getTooltipElement() {
    if (!getOverlayContainer().querySelector('x-tooltip-overlay')) {
        const tooltip = document.createElement('x-tooltip-overlay');
        const content = document.createElement('span');
        const arrow = document.createElement('div');
        tooltip.setAttribute('role', 'tooltip');
        arrow.classList.add('tooltip-arrow');
        tooltip.appendChild(content);
        tooltip.appendChild(arrow);
        getOverlayContainer().appendChild(tooltip);
        return tooltip;
    }
    else {
        return getOverlayContainer().querySelector('x-tooltip-overlay');
    }
}
/**
 * Get or create the notification container element
 *
 * @returns
 */
function getNotificationContainerElement(position = 'top') {
    if (!getOverlayContainer().querySelector(`x-notification-${position}`)) {
        const notification = document.createElement(`x-notification-${position}`);
        getOverlayContainer().appendChild(notification);
        return notification;
    }
    else {
        return getOverlayContainer().querySelector(`x-notification-${position}`);
    }
}
/**
 * Prefix the number value to humman read size
 */
const prefixFileSize = (size) => {
    if (isNaN(size) || size < 0)
        return '0 b';
    const units = ['b', 'Kb', 'Mb', 'Gb', 'Tb', 'Pb'];
    let i = 0;
    while (size >= 1000 && i < units.length - 1) {
        size /= 1000;
        i++;
    }
    return `${size.toFixed(1)}${units[i]}`;
};
/**
 * Calculate the REM size of the main font
 */
const getRemPixels = () => {
    return parseFloat(getComputedStyle(document.documentElement).fontSize);
};

export { getNotificationContainerElement as a, alertCodeByStatus as b, cls as c, getRemPixels as d, evaluateOverlayIndex as e, getOverlayContainer as f, getLang as g, getTooltipElement as h, getId as i, isEmpty as j, getMeta as k, filterData as l, toSnakeCase as m, bracketToDot as n, prefixFileSize as p, tinyMDtoHTML as t };
