
/**
 */
namespace _zeitbild.frontend_web.helpers
{
	
	/**
	 */
	var _template_cache : Record<string, string> = {};

	
	/**
	 * @todo caching
	 */
	export async function template_coin(
		name : string,
		data : Record<string, string>
	) : Promise<string>
	{
		let content : string;
		if (! (name in _template_cache)) {
			content = (
				(
					await lib_plankton.file.read(
						lib_plankton.string.coin(
							"templates/{{name}}.html.tpl",
							{
								"name": name,
							}
						)
					)
				)
				.toString()
			);
			_template_cache[name] = content;
		}
		else {
			content = _template_cache[name];
		}
		return Promise.resolve<string>(
			lib_plankton.string.coin(
				content,
				data
			)
		);
	}
	
	
	/**
	 * @todo outsource
	 */
	export async function promise_row<type_result>(
		members : Array<
			() => Promise<type_result>
		>
	) : Promise<
		Array<
			type_result
		>
	>
	{
		let results : Array<type_result> = [];
		for await (const member of members) {
			results.push(await member());
		}
		return Promise.resolve<Array<type_result>>(results);
	}
	
}
