'use strict';
const path=require('node:path');
const {escape}=require('../mail/parser.cjs');
const lines=value=>escape(value).replace(/\r?\n/g,'
');
function fileLink(filePath){
if(filePath.startsWith('\\\\'))return 'file://'+filePath.slice(2).split('\\').map(encodeURIComponent).join('/');
if(/^[a-z]:[\\/]/i.test(filePath))return 'file:///'+filePath.replace(/\\/g,'/').split('/').map((p,i)=>i===0?p:encodeURIComponent(p)).join('/');
return 'file://'+filePath.split('/').map(encodeURIComponent).join('/');
}
// Content is derived from the event and its recorded archive, never current configuration.
function mailContent(orders){
const details=orders.map(order=>order.event.titleOrders?.length&&order.event.titleOrders.every(row=>typeof row.text==='string'&&row.text.trim())?order.event.titleOrders.map(row=>row.text).join('\n\n'):String(order.event.brief||'')).join('\n\n');
const seen=new Set(),directories=[];
for(const order of orders)for(const file of order.archive.files){
const windows=path.win32.isAbsolute(file.path),directory=(windows?path.win32:path.posix).dirname(file.path),key=windows?directory.toLowerCase():directory;
if(!seen.has(key)){seen.add(key);directories.push(directory);}
}
return {details,directories,htmlDetails:'