import manifest from '../../cdn-manifest.json';

const ASSETS = manifest.assets || {};

function resolveBase() {
  if (typeof window !== 'undefined' && window.__CDN_BASE__) {
    return window.__CDN_BASE__;
  }
  // Fallback for SSR or pre-mount calls; the SHA matches resources/cdn-manifest.json
  return `https://cdn.jsdelivr.net/gh/telemagnadon/obj-vault-3a@${manifest.version}`;
}

export function cdnAsset(logicalName) {
  const path = ASSETS[logicalName];
  const base = resolveBase();
  if (!path) {
    return `${base}/missing/${logicalName}`;
  }
  return `${base}/${path}`;
}

export function cdnBase() {
  return resolveBase();
}

export default cdnAsset;
