const { ipcRenderer } = require('electron')

async function showRecentFiles() {
	let recent_files = await ipcRenderer.invoke("get-store-value", "recent_files");
	if (recent_files.length === 0) {
		$("#recent-files").css("display", "none");
		$("#splash").css("width", "100%")
	} else {
		for (let file of recent_files) {
			let recent_file_link = $("<a>")
				.addClass("btn list-group-item list-group-item-action")
				.text(file.replace(/^.*[\\\/]/, ''))
				.attr({"data-bs-toggle": "tooltip", "data-bs-placement": "bottom", "title": file})
				.on("click", () => {
					ipcRenderer.send("open", file);
				});
			$("#recent-files").append(recent_file_link);
		}
	}
}

showRecentFiles();

$("#create-new").on("click", () => {
	ipcRenderer.send("create-new");
});

$("#open-file").on("click", () => {
	ipcRenderer.send("open");
})
