${e(localized(battle.title,lang))}
- ${e(t.kills)}
- ${battle.kills==null?'—':number(battle.kills)}
- ${e(t.deaths)}
- ${battle.deaths==null?'—':number(battle.deaths)}
import { escapeHtml as e, localized } from './lib.mjs';
import { directPreview } from './battle-previews.mjs';
export function battleDetails(url) {
const u=new URL(url);
const combined=/\/battles\/multi\/?$/.test(u.pathname);
const ids=combined?[...new Set((u.searchParams.get('ids')||'').split(',').filter(id=>/^\d+$/.test(id)))]:[u.pathname.split('/').filter(Boolean).pop()].filter(id=>/^\d+$/.test(id));
return {combined,ids,region:u.hostname==='europe.albionbb.com'?'europe':u.hostname};
}
export function renderBattleCards({battles,previews,lang,base,icon,t}) {
if (!battles.length) return '';
const number=n=>new Intl.NumberFormat(lang==='fa'?'fa-IR':'en-US').format(n);
// Highlight guild performance, rather than filling the page with the newest
// reports. Incomplete stats follow verified results; the full archive stays
// available in the detailed table.
const advantage=b=>b.kills!=null&&b.deaths!=null?b.kills-b.deaths:-Infinity;
const featured=[...battles].sort((a,b)=>advantage(b)-advantage(a)||(b.kills??-1)-(a.kills??-1)||(b.date||'').localeCompare(a.date||'')).slice(0,6);
// Combined reports may overlap with single reports; count unique, explicit battle IDs.
const engagements=new Set(battles.flatMap(b=>battleDetails(b.url).ids)).size;
const cards=featured.map((battle,index)=>{
const info=battleDetails(battle.url);
const preview=previews[battle.url]||battle.preview||directPreview(battle.url);
const image=preview?``:'';
const outcome=battle.outcome||'recorded';
const date=battle.date?``:e(t.battleArchive);
return `
${e(localized(battle.title,lang))}
`:''}
${icon('shield')}${e(t.archiveMotto)}