"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var js_yaml_1 = require("js-yaml");
var path_1 = require("path");
var fs_1 = require("fs");
var electron_1 = require("electron");
exports.default_config = {
    linter: 'remark-lint',
    file_ext: {
        markdown: ['md', 'markdown', 'mkd'],
        html: ['html'],
    },
    width: 920,
    height: 800,
    ignore_path_pattern: '[\\\\/]\\.',
    voice: {
        enabled: false,
        source: '../voices/bow.mp3',
    },
    drawer: {
        responsive: true,
    },
    menu: {
        visible: true,
    },
    hide_title_bar: false,
    hide_menu_bar: true,
    markdown: {
        font_size: '',
        css_path: '../../node_modules/github-markdown-css/github-markdown.css',
        code_theme: 'github',
    },
    path_watcher: {
        follow_symlinks: false,
    },
    restore_window_state: true,
    shortcuts: {
        'j': 'PageDown',
        'k': 'PageUp',
        'down': 'PageDown',
        'up': 'PageUp',
        'pagedown': 'PageDown',
        'pageup': 'PageUp',
        'h': 'PageLeft',
        'l': 'PageRight',
        'left': 'PageLeft',
        'right': 'PageRight',
        'i': 'PageTop',
        'm': 'PageBottom',
        'home': 'PageTop',
        'end': 'PageBottom',
        'ctrl+p': 'ChangePath',
        'ctrl+l': 'Lint',
        'r': 'Reload',
        's': 'Search',
        'o': 'Outline',
    },
};
function mergeConfig(c1, c2) {
    for (var _i = 0, _a = Object.keys(c2); _i < _a.length; _i++) {
        var k = _a[_i];
        var v2 = c2[k];
        if (k in c1) {
            var v1 = c1[k];
            if (typeof (v1) === 'object' && typeof (v2) === 'object') {
                mergeConfig(v1, v2);
            }
            continue;
        }
        c1[k] = c2[k];
    }
    return c1;
}
function readConfigYAML(config_dir) {
    return new Promise(function (resolve, reject) {
        var yml = path_1.join(config_dir, 'config.yml');
        fs_1.readFile(yml, 'utf8', function (yml_err, yml_content) {
            if (!yml_err) {
                resolve(yml_content);
                return;
            }
            var yaml = path_1.join(config_dir, 'config.yaml');
            fs_1.readFile(yaml, 'utf8', function (yaml_err, yaml_content) {
                if (!yaml_err) {
                    resolve(yaml_content);
                    return;
                }
                reject(new Error("config.yml nor config.yaml was not found in '" + config_dir + "'"));
            });
        });
    });
}
var cache = null;
function loadConfig() {
    if (cache !== null) {
        return Promise.resolve(cache);
    }
    var config_dir = electron_1.app.getPath('userData');
    return readConfigYAML(config_dir).then(function (content) {
        cache = js_yaml_1.load(content);
        mergeConfig(cache, exports.default_config);
        cache._config_dir_path = config_dir;
        return cache;
    }).catch(function (err) {
        console.log(err.message);
        cache = exports.default_config;
        cache._config_dir_path = config_dir;
        return exports.default_config;
    });
}
exports.default = loadConfig;
//# sourceMappingURL=config.js.map