/**
 * Shared primitives for ThreadForm components.
 * Utility functions, avatar, status badge, icons, and constants.
 */
'use client';
import { jsx as _jsx } from "react/jsx-runtime";
// ============================================================================
// Utility
// ============================================================================
export function cn(...classes) {
    return classes.filter(Boolean).join(' ');
}
export function format_time(iso) {
    const d = new Date(iso);
    return d.toLocaleDateString('en-AU', { month: 'short', day: 'numeric' }) +
        ', ' + d.toLocaleTimeString('en-AU', { hour: 'numeric', minute: '2-digit', hour12: true });
}
export function format_date(iso) {
    return new Date(iso).toLocaleDateString('en-AU', { month: 'short', day: 'numeric' });
}
export function format_relative(iso) {
    const d = new Date(iso);
    const now = new Date();
    const diff = now.getTime() - d.getTime();
    const days = Math.floor(diff / 86400000);
    if (days === 0)
        return 'Today';
    if (days === 1)
        return 'Yesterday';
    if (days < 7)
        return `${days}d ago`;
    return d.toLocaleDateString('en-AU', { month: 'short', day: 'numeric' });
}
// ============================================================================
// Constants
// ============================================================================
export const MSG_BG = {
    agent: 'bg-[#F0F4FF] border-[#DDE4F0]',
    client: 'bg-[#F0FAF4] border-[#D5EBE0]',
    system: 'bg-[#F8F8F8] border-[#EBEBEB]',
};
export const STATUS_CONFIG = {
    pending: { label: 'Pending', color: 'text-gray-500', bg: 'bg-gray-100' },
    in_progress: { label: 'In Progress', color: 'text-blue-600', bg: 'bg-blue-50' },
    completed: { label: 'Completed', color: 'text-green-600', bg: 'bg-green-50' },
    needs_attention: { label: 'Needs Attention', color: 'text-amber-600', bg: 'bg-amber-50' },
};
const ROLE_AVATAR_BG = {
    agent: 'bg-[#1E3A5F]',
    client: 'bg-[#059669]',
    system: 'bg-[#94A3B8]',
};
// ============================================================================
// Components
// ============================================================================
export function RoleAvatar({ role, name, size = 'sm' }) {
    const initial = name ? name[0].toUpperCase() : '?';
    const sz = size === 'sm' ? 'w-6 h-6 text-[10px]' : 'w-8 h-8 text-xs';
    return (_jsx("div", { className: cn('rounded-full flex items-center justify-center text-white font-bold flex-shrink-0', sz, ROLE_AVATAR_BG[role] || 'bg-[#94A3B8]'), children: initial }));
}
export function StatusBadge({ status }) {
    const cfg = STATUS_CONFIG[status] || STATUS_CONFIG.pending;
    return _jsx("span", { className: cn('text-xs font-medium px-2 py-0.5 rounded-full', cfg.color, cfg.bg), children: cfg.label });
}
export function PdfIcon({ className }) {
    return (_jsx("svg", { className: cn('w-4 h-4 text-red-500 flex-shrink-0', className), fill: "currentColor", viewBox: "0 0 20 20", children: _jsx("path", { d: "M4 18h12a2 2 0 002-2V6l-4-4H4a2 2 0 00-2 2v12a2 2 0 002 2zm8-14l4 4h-4V4z" }) }));
}
export function WarningIcon({ className }) {
    return (_jsx("svg", { className: cn('w-4 h-4 text-amber-500 flex-shrink-0', className), fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: _jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.833-1.964-.833-2.732 0L4.082 16.5c-.77.833.192 2.5 1.732 2.5z" }) }));
}
export function DocumentIcon({ className }) {
    return (_jsx("svg", { className: cn('w-3.5 h-3.5 text-[#64748B]', className), fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: _jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 1.5, d: "M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" }) }));
}
export function LightbulbIcon({ className }) {
    return (_jsx("svg", { className: cn('w-3 h-3 text-[#6366F1]', className), fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: _jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M9.663 17h4.673M12 3v1m6.364 1.636l-.707.707M21 12h-1M4 12H3m3.343-5.657l-.707-.707m2.828 9.9a5 5 0 117.072 0l-.548.547A3.374 3.374 0 0014 18.469V19a2 2 0 11-4 0v-.531c0-.895-.356-1.754-.988-2.386l-.548-.547z" }) }));
}
// ============================================================================
// Data lookup helpers
// ============================================================================
/** Build lookup: content_id → AiContentResult from all ai_analysis messages */
export function build_ai_lookup(messages) {
    const map = new Map();
    for (const msg of messages) {
        if (msg.type === 'ai_analysis' && msg.ai_analysis) {
            for (const item of msg.ai_analysis.items) {
                map.set(item.content_ref, item);
            }
        }
    }
    return map;
}
/**
 * Find the latest doc check for a content_id (file-based). Walks the messages
 * in reverse so a later verdict (e.g. the aggregate sum_match resolver)
 * overrides an earlier per-file "passed" emitted by the upload pipeline.
 */
export function find_doc_check(messages, content_id) {
    for (let i = messages.length - 1; i >= 0; i--) {
        const m = messages[i];
        if (m.type === 'doc_check' && m.doc_check?.content_ref === content_id) {
            return m.doc_check;
        }
    }
    return null;
}
/** Find text-based doc checks that reference a message_id */
export function find_text_doc_checks(messages, message_id) {
    return messages.filter(m => m.type === 'doc_check' && m.doc_check?.content_ref === message_id && m.doc_check?.source_type === 'text');
}
/**
 * Group messages for timeline rendering.
 * Each user message (comment, content) is its own group/panel.
 * Consecutive send_back messages that share the same source_content_id are
 * merged into a single group so the file row renders once with N stacked
 * ACTION REQUIRED boxes (one per rule) — avoids N separate panels.
 */
export function group_messages(messages, role) {
    const visible = messages.filter(m => !(role === 'client' && m.visibility === 'agent_only'));
    const groups = [];
    for (const msg of visible) {
        const last = groups[groups.length - 1];
        const last_msg = last?.[last.length - 1];
        const can_merge = last_msg &&
            last_msg.type === 'send_back' &&
            msg.type === 'send_back' &&
            last_msg.send_back?.source_content_id === msg.send_back?.source_content_id;
        if (can_merge) {
            last.push(msg);
        }
        else {
            groups.push([msg]);
        }
    }
    return groups;
}
//# sourceMappingURL=shared.js.map