//@ts-check
import { makeTemplate } from "../utils/print.mjs";
import { generateDomFromString } from "../utils/generateDomFromString.mjs";
/**
 * @typedef {import("./parseFileList.mjs").ParsedLine} ParsedLine
 */

const defaultTemplate = `<a data-link href="#{{href}}">{{title}}</a>`;

/**
 * Creates menu entries from a list of links.
 * @param {ParsedLine[]} links
 * @param {string} template a template for each link, where `{{href}}` is replaced by the href
 *                          and `{{title}}` is replaced by the title.
 *                          all the keys parsed in `parseFileList.mjs` can be used.
 */
export const createMenuEntriesFromFileList = (links, template = defaultTemplate) =>
  generateDomFromString(links.map(makeTemplate(template)).join("\n"));
