import fs from 'fs';
import path from 'path';

const translations = parseTranslations('en');

module.exports = {
	utils: {
		escapeHtmlAttribute: key => key
	},
	text: {
		get: key => translations[key] ?? key
	},
	templatePath: '.',
	login: {
		appDataPath: ''
	},
	gui: {
		getGuiElem: key => ({ label: key, value: key })
	},
	parsedTranslations: {
		get: lang => parseTranslations(lang)
	}
};

function parseTranslations(lang) {
	const translationFileContent = fs.readFileSync(path.resolve(__dirname, `../conf/text_${lang}.properties`), 'utf-8');
	return translationFileContent.split('\n')
		.filter(eachLine => eachLine && !eachLine.startsWith('#'))
		.reduce((acc, currentLine) => {
			const [key, value] = currentLine.split('=');
			return {
				...acc,
				[key]: value
			};
		}, {});
}
