'use client';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
export function OfflineStatus({ connection, offline }) {
    const { label, tone } = describeOfflineStatus(connection, offline);
    const baseClass = 'inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[11px] font-medium';
    const toneClass = TONE_CLASSES[tone];
    return (_jsxs("span", { className: `${baseClass} ${toneClass}`, "data-testid": "offline-status", "data-tone": tone, children: [_jsx("span", { "aria-hidden": "true", className: `inline-block h-1.5 w-1.5 rounded-full ${DOT_CLASSES[tone]}` }), label] }));
}
const TONE_CLASSES = {
    good: 'bg-emerald-50 text-emerald-700',
    warn: 'bg-amber-50 text-amber-800',
    info: 'bg-blue-50 text-blue-700',
    bad: 'bg-red-50 text-red-700',
};
const DOT_CLASSES = {
    good: 'bg-emerald-500',
    warn: 'bg-amber-500',
    info: 'bg-blue-500',
    bad: 'bg-red-500',
};
/**
 * Pure helper that maps the (connection, offline) status pair to a
 * single user-facing label + colour tone. Exported so the unit tests
 * can exercise every combination without rendering React.
 */
export function describeOfflineStatus(connection, offline) {
    if (offline === 'error')
        return { label: 'Local drafts failed', tone: 'bad' };
    if (offline === 'unsupported') {
        // No local persistence; the WebSocket is the only safety net.
        if (connection === 'connected')
            return { label: 'Synced', tone: 'good' };
        if (connection === 'connecting')
            return { label: 'Connecting…', tone: 'info' };
        return { label: 'Offline — drafts not persisted', tone: 'warn' };
    }
    if (offline === 'loading' || offline === 'pending') {
        return { label: 'Restoring local copy…', tone: 'info' };
    }
    // offline === 'ready' from here on.
    if (connection === 'connected')
        return { label: 'Saved & synced', tone: 'good' };
    if (connection === 'connecting')
        return { label: 'Saved locally — reconnecting…', tone: 'warn' };
    return { label: 'Saved locally — offline', tone: 'warn' };
}
//# sourceMappingURL=OfflineStatus.js.map