/* ============================================================ aiassistant.js — ChatGPT-style AI Recruiter Assistant (UI only) + AI Studio (future modules gallery). API-ready, no AI wired. ============================================================ */ window.Views = window.Views || {}; window.AI = {}; // simulated (non-AI) canned responses keyed by intent — clearly a UI stub AI._reply = function (prompt) { const p = prompt.toLowerCase(); if (p.includes('rank')) { const top = [...DB.candidates].sort((a, b) => b.aiScore - a.aiScore).slice(0, 5); return `

Here are the top-ranked candidates by ATS match score:

This is a UI preview. Connect an LLM endpoint to generate live rankings from resume + JD embeddings.

`; } if (p.includes('compare')) { const two = DB.candidates.slice(0, 2); return `

Comparing ${two[0].name} vs ${two[1].name}:

Suggested: ${two[0].aiScore >= two[1].aiScore ? two[0].name : two[1].name} appears stronger on core criteria.

`; } if (p.includes('job description') || p.includes('jd')) { return `

Senior Product Designer

We're looking for a Senior Product Designer to craft intuitive, delightful experiences across our platform. You'll own end-to-end design, from research to polished UI, and partner closely with product and engineering.

Responsibilities: lead design for key initiatives, run user research, build and maintain design systems, mentor peers.

Requirements: 5+ years product design, strong portfolio, fluency in Figma, systems thinking.

`; } if (p.includes('interview question')) { return `

Here are role-specific interview questions:

`; } if (p.includes('summar')) { const c = DB.candidates[0]; return `

Resume summary — ${c.name}

${c.experience} years of experience, currently ${c.currentTitle} at ${c.currentCompany}. Strong in ${c.skills.slice(0, 3).join(', ')}. ATS match ${c.aiScore}% for ${c.jobTitle}. ${c.recommendation}.

`; } if (p.includes('email')) { return `

Subject: Interview Invitation — Next Steps

Hi [Candidate],

Thank you for applying. We were impressed by your background and would love to invite you to an interview. Please share your availability for this week.

Best regards,
Talent Team

`; } if (p.includes('offer letter')) { return `

Offer Letter

Dear [Candidate], We are pleased to offer you the position of Product Manager at a base salary of $160,000, plus equity and benefits. This offer is contingent on standard background checks.

We're excited about the possibility of you joining the team.

`; } if (p.includes('skill gap')) { return `

Skill Gap Analysis — Engineering pipeline

Consider sourcing candidates with cloud-native infra experience.

`; } if (p.includes('pipeline')) { const total = DB.candidates.length; return `

Pipeline health analysis

Recommendation: accelerate assessment turnaround to improve velocity.

`; } if (p.includes('productivity') || p.includes('recruiter')) { return `

Team productivity this month

`; } if (p.includes('recommend') || p.includes('suggest')) { const c = [...DB.candidates].sort((a, b) => b.aiScore - a.aiScore)[0]; return `

Top recommendation: ${c.name} (${c.aiScore}% match) for ${c.jobTitle}. Strong on ${c.matchedSkills.slice(0, 2).join(' & ')}. I'd prioritise scheduling a screen this week.

`; } return `

I can help with ranking candidates, comparing profiles, drafting JDs, interview questions, emails, offer letters, skill-gap and pipeline analysis, and more.

This is a fully-designed interface. Wire an AI endpoint (Claude / OpenAI) into AI.send() to make responses live.

`; }; AI._chatHtml = function (compact) { const promptsHtml = DB.aiPrompts.slice(0, compact ? 6 : 12).map(p => ``).join(''); return `

AI Recruiter Assistant

Ask anything about your candidates, jobs, and pipeline

${promptsHtml}

UI preview · responses are simulated. ${UI.icon('lock')} API-ready for backend integration.

`; }; AI._bindChat = function () { const input = document.getElementById('chatInput'); const send = document.getElementById('chatSend'); if (!input) return; input.oninput = () => { input.style.height = 'auto'; input.style.height = Math.min(input.scrollHeight, 140) + 'px'; }; input.onkeydown = e => { if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); AI.send(); } }; send.onclick = AI.send; AI._started = false; }; AI.usePrompt = function (btn, prompt) { const input = document.getElementById('chatInput'); input.value = prompt; AI.send(); }; AI.send = function () { const input = document.getElementById('chatInput'); const scroll = document.getElementById('chatScroll'); const text = input.value.trim(); if (!text) return; if (!AI._started) { scroll.innerHTML = ''; AI._started = true; } // user message scroll.insertAdjacentHTML('beforeend', `
${UI.icon('users')}
You
${text.replace(/
`); input.value = ''; input.style.height = 'auto'; scroll.scrollTop = scroll.scrollHeight; // typing indicator const typingId = 'typing_' + Math.random().toString(36).slice(2, 7); scroll.insertAdjacentHTML('beforeend', `
${UI.icon('sparkles')}
AI Assistant
`); scroll.scrollTop = scroll.scrollHeight; setTimeout(() => { const t = document.getElementById(typingId); if (t) t.querySelector('.chat-bubble').innerHTML = `
AI Assistant
${AI._reply(text)}
`; scroll.scrollTop = scroll.scrollHeight; }, 850 + Math.random() * 500); }; // ---------------- Full page ---------------- Views.aiassistant = function () { const html = `

AI Assistant

Your recruiting copilot — powered by AI (interface preview)

Model endpoint · Not connected
${AI._chatHtml(false)}
`; return { html, onMount() { AI._bindChat(); } }; }; AI.newChat = function () { const mount = document.getElementById('aiChatMount'); if (mount) { mount.innerHTML = AI._chatHtml(false); AI._bindChat(); } else { AI._dockOpen(true); } }; // ---------------- Floating dock ---------------- AI._dockOpen = function (force) { const dock = document.getElementById('aiDock'); const inner = document.getElementById('aiDockInner'); const willOpen = force || !dock.classList.contains('open'); if (willOpen) { inner.innerHTML = `

${UI.icon('sparkles')} AI Assistant

${AI._chatHtml(true)}
`; dock.classList.add('open'); AI._bindChat(); } else { AI._dockClose(); } }; AI._dockClose = function () { document.getElementById('aiDock').classList.remove('open'); }; // ---------------- AI Studio (future modules) ---------------- Views.aistudio = function () { const cards = DB.aiModules.map(m => `
${UI.icon(m.icon)} ${UI.badge(m.status, m.status === 'Beta' ? 'b-indigo' : 'b-gray')}
${m.name}
${m.desc}
${m.status === 'Beta' ? 'Try it' : 'Join waitlist'} ${UI.icon('arrow-right')}
`).join(''); const html = `

AI Studio

Next-generation AI modules — designed and API-ready for backend integration

${DB.aiModules.filter(m => m.status === 'Beta').length} in Beta

Everything is API-ready

Each module below ships with a complete, production-grade interface. Connect your model endpoint to activate them — no UI work required.

${cards}
`; return { html }; }; AI.moduleDetail = function (name) { const m = DB.aiModules.find(x => x.name === name); UI.modal({ title: m.name, subtitle: m.status + ' · AI Module', body: `
${UI.icon(m.icon)}
${m.name}
${m.desc}
API Contract (preview)
POST /api/ai/${m.name.toLowerCase().replace(/ /g, '-')} { "context": { "jobId": "JOB-1001", "candidateIds": [...] }, "options": { "model": "claude-opus", "stream": true } } → 200 OK { "result": { ... }, "usage": { "tokens": 1240 } }

${UI.icon('lock')} This feature's UI is complete. Backend wiring is the only remaining step.

`, footer: ` `, size: 'modal-lg' }); };