|
| 1 | +import { useState } from 'react' |
| 2 | +import { useTranslation } from 'react-i18next' |
| 3 | +import { AtSign, Paperclip, Sparkles } from 'lucide-react' |
| 4 | +import { useSocAi } from '@/features/soc-ai/SocAiProvider' |
| 5 | +import { useSocAiConfigured } from '@/features/soc-ai/lib/useSocAiConfig' |
| 6 | +import { IconBtn } from './IconBtn' |
| 7 | + |
| 8 | +const SUGGESTION_KEYS = ['threatHunt', 'observableTriage', 'writeRule', 'systemStatus'] as const |
| 9 | + |
| 10 | +export function ChatHero() { |
| 11 | + const { t } = useTranslation() |
| 12 | + const configured = useSocAiConfigured() |
| 13 | + const { submit } = useSocAi() |
| 14 | + const [value, setValue] = useState('') |
| 15 | + |
| 16 | + // Hidden entirely until SOC-AI has a provider configured — same gate the |
| 17 | + // floating composer/panel use, so we never show a dead chat box. |
| 18 | + if (!configured) return null |
| 19 | + |
| 20 | + const send = () => { |
| 21 | + const text = value.trim() |
| 22 | + if (!text) return |
| 23 | + submit(text, { openPanel: false, scope: 'home' }) |
| 24 | + setValue('') |
| 25 | + } |
| 26 | + |
| 27 | + return ( |
| 28 | + <section className="flex flex-col items-center"> |
| 29 | + <h2 className="mb-4 text-center text-base font-medium text-foreground">{t('home.hero.title')}</h2> |
| 30 | + <div className="relative w-full max-w-3xl"> |
| 31 | + <div |
| 32 | + aria-hidden |
| 33 | + className="absolute -inset-px rounded-xl bg-[conic-gradient(from_180deg_at_50%_50%,#1a8cff_0deg,#0ea5e9_120deg,#2563eb_240deg,#1a8cff_360deg)] opacity-50 blur-[1px]" |
| 34 | + /> |
| 35 | + <div className="relative rounded-xl bg-card p-4"> |
| 36 | + <textarea |
| 37 | + rows={3} |
| 38 | + value={value} |
| 39 | + onChange={(e) => setValue(e.target.value)} |
| 40 | + onKeyDown={(e) => { |
| 41 | + if (e.key === 'Enter' && !e.shiftKey) { |
| 42 | + e.preventDefault() |
| 43 | + send() |
| 44 | + } |
| 45 | + }} |
| 46 | + placeholder={t('home.hero.placeholder')} |
| 47 | + className="w-full resize-none border-0 bg-transparent text-sm text-foreground placeholder:text-muted-foreground focus:outline-none" |
| 48 | + /> |
| 49 | + <div className="mt-2 flex items-center justify-between"> |
| 50 | + <div className="flex items-center gap-2 text-muted-foreground"> |
| 51 | + <IconBtn label={t('home.hero.mention')}><AtSign size={16} strokeWidth={1.75} /></IconBtn> |
| 52 | + <IconBtn label={t('home.hero.attach')}><Paperclip size={16} strokeWidth={1.75} /></IconBtn> |
| 53 | + </div> |
| 54 | + <button |
| 55 | + onClick={send} |
| 56 | + disabled={!value.trim()} |
| 57 | + className="flex h-7 w-7 items-center justify-center rounded-md bg-primary text-primary-foreground shadow-sm hover:opacity-90 disabled:opacity-40" |
| 58 | + aria-label={t('home.hero.send')} |
| 59 | + > |
| 60 | + <Sparkles size={14} strokeWidth={2} /> |
| 61 | + </button> |
| 62 | + </div> |
| 63 | + </div> |
| 64 | + </div> |
| 65 | + <div className="mt-4 flex flex-wrap justify-center gap-2"> |
| 66 | + {SUGGESTION_KEYS.map((key) => { |
| 67 | + const label = t(`home.hero.suggestions.${key}`) |
| 68 | + return ( |
| 69 | + <button |
| 70 | + key={key} |
| 71 | + onClick={() => submit(label, { openPanel: false, scope: 'home' })} |
| 72 | + className="rounded-full border border-border bg-card px-3 py-1.5 text-xs text-muted-foreground hover:bg-muted hover:text-foreground" |
| 73 | + > |
| 74 | + {label} |
| 75 | + </button> |
| 76 | + ) |
| 77 | + })} |
| 78 | + </div> |
| 79 | + </section> |
| 80 | + ) |
| 81 | +} |
0 commit comments