import test from 'node:test';
import assert from 'node:assert/strict';
import { readFile } from 'node:fs/promises';
import { battleDetails, renderBattleCards } from '../scripts/render-battles.mjs';
import { directPreview, discoverPreview } from '../scripts/battle-previews.mjs';
const translations=JSON.parse(await readFile(new URL('../content/translations.json',import.meta.url),'utf8'));
const single={title:{en:'A single fight',fa:'یک نبرد'},url:'https://europe.albionbb.com/battles/448776222'};
const combined={title:{en:'A campaign',fa:'مجموعه نبردها'},url:'https://europe.albionbb.com/battles/multi?ids=448776222,441001581,440997498'};
const render=(battles,lang='en',previews={})=>renderBattleCards({battles,lang,previews,base:lang==='fa'?'../':'./',t:translations[lang],icon:()=>''});
test('reports use direct images without a cache and keep artwork for unavailable previews',()=>{
for(const lang of ['en','fa']){
const html=render([single,combined],lang);
assert.equal((html.match(/class="battle-art"/g)||[]).length,2);
assert.equal((html.match(/class="battle-terrain"/g)||[]).length,2);
assert.match(html,/battle-card--single/);
assert.match(html,/battle-card--campaign/);
assert.ok(html.includes(single.title[lang]));
assert.ok(html.includes(combined.title[lang]));
assert.match(html,/#441001581/);
assert.equal((html.match(/class="battle-report-image"/g)||[]).length,2);
assert.match(html,/src="https:\/\/api.albionbb.com\/eu\/preview\/448776222"/);
assert.match(html,/src="https:\/\/api.albionbb.com\/eu\/preview\/multi\?ids=448776222,441001581,440997498"/);
assert.ok(!html.includes('battle-card-stats'));
assert.ok(!html.includes('