export const DebugDefaults = {
    debug: false,
    'debug.background': false,
    'debug.source': false,
    'debug.cog': false,
    'debug.screenshot': false,
    'debug.layer.linz-aerial': 0,
    'debug.layer.linz-topographic': 0,
    'debug.layer.osm': 0,
};
export class ConfigDebug {
    static toUrl(opt, url) {
        if (opt.debug !== true)
            return;
        url.append('debug', 'true');
        for (const [key, value] of Object.entries(opt)) {
            if (key === 'debug')
                continue;
            const defaultVal = DebugDefaults[key];
            if (defaultVal === value)
                continue;
            url.append(key, String(value));
        }
    }
    static fromUrl(opt, url) {
        const isDebug = url.get('debug') != null;
        let isChanged = false;
        if (isDebug === false) {
            // Debug is off reset to default
            for (const [key, value] of Object.entries(DebugDefaults)) {
                isChanged = setKey(opt, key, value) || isChanged;
            }
            return isChanged;
        }
        isChanged = setKey(opt, 'debug', true);
        isChanged = setKey(opt, 'debug.background', url.get('debug.background')) || isChanged;
        isChanged = setKey(opt, 'debug.source', url.get('debug.source') != null) || isChanged;
        isChanged = setKey(opt, 'debug.cog', url.get('debug.cog') != null) || isChanged;
        isChanged = setKey(opt, 'debug.screenshot', url.get('debug.screenshot') != null) || isChanged;
        isChanged = setNum(opt, 'debug.layer.linz-aerial', url.get('debug.layer.linz-aerial')) || isChanged;
        isChanged = setNum(opt, 'debug.layer.linz-topographic', url.get('debug.layer.linz-topographic')) || isChanged;
        isChanged = setNum(opt, 'debug.layer.osm', url.get('debug.layer.osm')) || isChanged;
        return isChanged;
    }
}
function toNum(val, defaultValue = 0) {
    if (val == null)
        return defaultValue;
    const num = Number(val);
    if (isNaN(num))
        return defaultValue;
    return num;
}
function setKey(opt, key, value) {
    if (value == null)
        value = DebugDefaults[key];
    if (opt[key] === value)
        return false;
    opt[key] = value;
    return true;
}
function setNum(opt, key, value) {
    return setKey(opt, key, toNum(value));
}
//# sourceMappingURL=config.debug.js.map