import { phaseOf } from './config.js' /** * Who is holding a lead right now, said the way the colour rule says it: * blue = the AI, amber = a person, teal = the customer, grey = nobody (closed). * * Derived from phaseOf, so it agrees with the sidebar tallies and the lead * header. `label` is the short form for a table cell: "AI · Intake", * "Underwriter", "Customer", "Closed". */ const AI_NAMES = [ ['intake', 'Intake'], ['engage', 'Engage'], ['advisor', 'Advisor'], ['kyc', 'KYC'], ['voice', 'Meera'], ['rating', 'Rating'], ] function tidy(by) { const s = String(by || '').replace(/^(the|an|a)\s+/i, '').trim() return s ? s.charAt(0).toUpperCase() + s.slice(1) : '—' } export function holderOf(stageDef, row) { if (!stageDef) return { tone: 'grey', label: '—' } const ph = phaseOf(stageDef, row) || stageDef switch (ph.kind) { case 'auto': { const by = String(ph.by || '').toLowerCase() const hit = AI_NAMES.find(([k]) => by.includes(k)) return { tone: 'blue', label: 'AI · ' + (hit ? hit[1] : 'Engage') } } case 'customer': return { tone: 'teal', label: 'Customer' } case 'needs': return { tone: 'amber', label: tidy(ph.by) } case 'waiting': return { tone: 'grey', label: 'Calendar' } case 'end': return { tone: 'grey', label: 'Closed' } default: return { tone: 'grey', label: tidy(ph.by) } } }