/* ui/appbus.js — tiny app-level utilities shared by shell and modes.
   Keeps modes free of circular imports on app.js. */
'use strict';

import { h } from './dom.js';

let statusSink = null;
let titleSink = null;

export function wireAppBus({ onStatusText, onTitle }) {
  statusSink = onStatusText;
  titleSink = onTitle;
}

export function setStatusText(text) { statusSink && statusSink(text); }
export function setTitle(text) { titleSink && titleSink(text); }

export function downloadText(filename, text) {
  const a = h('a', { href: URL.createObjectURL(new Blob([text], { type: 'text/plain' })), download: filename });
  document.body.append(a);
  a.click();
  setTimeout(() => { URL.revokeObjectURL(a.href); a.remove(); }, 500);
}
