'use strict';
(function exposeEtahenLinkUx(root, factory) {
const api = factory();
if (typeof module === 'object' && module.exports) module.exports = api;
if (root) root.ChimeraLinkUx = api;
})(typeof window === 'object' ? window : null, () => {
const STATES = new Set(['online', 'offline', 'unknown']);
const JOB_STATES = new Set(['none', 'staged', 'approval_required', 'recovery_required']);
const safeState = (value, allowed, fallback) => allowed.has(String(value || '')) ? String(value) : fallback;
const text = (value, fallback = '') => String(value || fallback).slice(0, 160);
function createModel(packet = {}) {
const runtime = packet.runtime || {};
const last = packet.lastInventory || null;
const etaHenState = safeState(runtime.state, STATES, 'unknown');
const agentState = safeState(packet.agent?.state, STATES, etaHenState === 'online' && last ? 'online' : 'unknown');
const chimeraState = last ? 'online' : 'unknown';
const jobState = safeState(packet.job?.state, JOB_STATES, 'none');
const stagedCount = Math.max(0, Number(packet.job?.stagedCount) || 0);
return Object.freeze({
etaHen: Object.freeze({ state: etaHenState, version: text(runtime.identity?.version, '—') }),
agent: Object.freeze({ state: agentState, paired: packet.agent?.paired === true }),
chimera: Object.freeze({ state: chimeraState, lastScanAt: last?.completedAt || null }),
transfer: Object.freeze({ state: jobState, stagedCount, installedCount: 0 }),
recoveryRequired: jobState === 'recovery_required',
approvalRequired: jobState === 'approval_required',
});
}
function exactConfirmation({ action, target, runtimeEpoch, localIntent, recoveryAvailable }) {
if (!/^[A-Z][A-Z0-9_]{2,31}$/.test(String(action || ''))) throw new Error('Invalid action.');
if (!/^[A-Za-z0-9_-]{8,96}$/.test(String(target || '')) || !/^[A-Za-z0-9_-]{8,96}$/.test(String(runtimeEpoch || ''))) throw new Error('Invalid confirmation identity.');
if (localIntent !== true) throw new Error('Local console intent is required.');
if (recoveryAvailable !== true) throw new Error('Verified recovery is required.');
return `CONFIRM ${action} ${target} ${runtimeEpoch}`;
}
function mount({ root, loadStatus, translate = (_key, fallback) => fallback } = {}) {
if (!root || typeof loadStatus !== 'function') return null;
const t = translate;
root.innerHTML = ` ${t('etahenLink.description', 'Separate health for etaHEN, the paired agent and Chimera evidence.')}${t('etahenLink.title', 'Chimera Link for etaHEN')}