// 渐进增强：release.json 单一事实源注入 + 平台高亮（不隐藏任何入口，技术提案第六节）
import release from '../data/release.json';

const $ = (sel) => document.querySelector(sel);

// 1) 版本与体积小字：以 release.json 为准覆写（静态 HTML 里的同值文案是无 JS 兜底）
const line = $('[data-release-line]');
if (line) {
  line.textContent = `v${release.version} · macOS 安装包${release.macSize} · Windows ${release.winSize}`;
}
const macMeta = $('[data-size="mac"]');
if (macMeta) macMeta.textContent = macMeta.textContent.replace(/约 \d+ MB/, release.macSize);
const winMeta = $('[data-size="win"]');
if (winMeta) winMeta.textContent = winMeta.textContent.replace(/约 \d+ MB/, release.winSize);

// 2) 平台高亮：检测当前平台，只调换主次按钮样式与导航下载目标，双按钮常显不隐藏
const ua = navigator.userAgent;
const isWin = /Windows/i.test(ua);
const isMac = /Macintosh|Mac OS X/i.test(ua) && !/iPhone|iPad/i.test(ua);
if (isWin || isMac) {
  const active = isWin ? 'win' : 'mac';
  document.querySelectorAll('.cta [data-os]').forEach((el) => {
    const on = el.dataset.os === active;
    el.classList.toggle('primary', on);
    el.classList.toggle('ghost', !on);
  });
  const nav = $('[data-nav-dl]');
  if (nav) nav.setAttribute('href', isWin ? release.winUrl : release.macUrl);
}
