"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const map_1 = __importDefault(require("lodash/map"));
const gitmoji_1 = __importDefault(require("../themes/gitmoji"));
const getFile_1 = require("./getFile");
const getGitRootDir_1 = __importDefault(require("./getGitRootDir"));
const questionConfig_1 = require("./questionConfig");
const sortObject_1 = __importDefault(require("./sortObject"));
const setState = (cliOptions) => {
    let root;
    try {
        root = (0, getGitRootDir_1.default)();
    }
    catch (error) {
        throw new Error('Could not find Git root folder');
    }
    const configDefault = gitmoji_1.default;
    const configOverride = (0, getFile_1.getConfig)(root);
    const state = {
        answers: {},
        config: {
            branch: Object.assign(Object.assign({}, configDefault.branch), configOverride.branch),
            commit: Object.assign(Object.assign({}, configDefault.commit), configOverride.commit),
            enabled: configOverride.enabled || configDefault.enabled,
            types: Object.assign(Object.assign({}, configDefault.types), configOverride.types),
        },
        types: { branch: {}, commit: {} },
    };
    const { types } = state.config;
    const typesBranch = {};
    (0, map_1.default)(types, (type) => {
        if (Boolean(type.branch)) {
            typesBranch[type.branch] = type;
        }
    });
    const typesCommit = {};
    (0, map_1.default)(types, (type) => {
        if (Boolean(type.commit)) {
            typesCommit[type.commit] = type;
        }
    });
    state.types.branch = (0, sortObject_1.default)(typesBranch);
    state.types.commit = (0, sortObject_1.default)(typesCommit);
    switch (cliOptions.mode) {
        case questionConfig_1.TYPE_BRANCH:
            state.answers = {
                branchFlag: '',
                branchName: '',
                branchPrefix: state.config.branch.prefix,
                branchTypes: '',
            };
            break;
        case questionConfig_1.TYPE_COMMIT:
        default:
            state.answers = {
                branchFlag: '',
                branchName: '',
                branchPrefix: state.config.branch.prefix,
                branchTypes: '',
                commitBody: '',
                commitBodyFlag: false,
                commitBreaking: '',
                commitBreakingFlag: '',
                commitScopes: '',
                commitSubject: '',
                commitTypes: '',
            };
            break;
    }
    return state;
};
exports.default = setState;
//# sourceMappingURL=setState.js.map