/* V4 UI — command palette + shared helpers */
(function () {
  window.HV4UI = {
    openCommandPalette(routes) {
      routes = routes || [
        { label: 'Command Center', href: 'command.html' },
        { label: 'Calendar', href: 'calendar.html' },
        { label: 'OTA Sync', href: 'ota.html' },
        { label: 'Inbox', href: 'inbox.html' },
        { label: 'AI Insights', href: 'ai.html' },
        { label: 'Automations', href: 'automations.html' },
        { label: 'Dashboard', href: 'dashboard.html' },
      ];
      const q = prompt('Go to (type name):\n' + routes.map((r, i) => (i + 1) + '. ' + r.label).join('\n'));
      if (!q) return;
      const n = parseInt(q, 10);
      const pick = routes[n - 1] || routes.find(r => r.label.toLowerCase().includes(q.toLowerCase()));
      if (pick) location.href = (HOSTIVA.pagesRoot || '') + pick.href;
    },
  };

  document.addEventListener('keydown', (e) => {
    if ((e.ctrlKey || e.metaKey) && e.key === 'k') {
      e.preventDefault();
      HV4UI.openCommandPalette();
    }
  });
})();
