"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getSystemTheme = exports.waitFor = exports.flatChildren = exports.getMenuItemNameByKey = void 0;
const constants_1 = require("../constants");
exports.getMenuItemNameByKey = (key, menu) => {
    if (!Array.isArray(menu))
        return '';
    for (const i of menu) {
        if (i.key === key)
            return i.name;
        else if (i.children) {
            const ret = exports.getMenuItemNameByKey(key, i.children);
            if (ret)
                return ret;
        }
    }
};
function flatChildren(array, key = 'children', nameKey = 'name') {
    function collect(array, result, parent) {
        array === null || array === void 0 ? void 0 : array.forEach(function (el) {
            if (!parent) {
                parent = '/';
            }
            el.parent = parent;
            if (el[key]) {
                collect(el[key], result, parent + el[nameKey] + '/');
            }
            else {
                result.push(el);
            }
        });
    }
    const ret = [];
    collect(array || [], ret);
    return ret;
}
exports.flatChildren = flatChildren;
function waitFor(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
}
exports.waitFor = waitFor;
function getSystemTheme() {
    let defaultTheme = constants_1.THEME.LIGHT;
    if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
        defaultTheme = constants_1.THEME.ONE_DARK;
    }
    return defaultTheme;
}
exports.getSystemTheme = getSystemTheme;
