Files

132 lines
6.1 KiB
TypeScript

import React, { useState } from 'react';
import { CBT_GLOSSARY, GlossaryEntry } from '../constants';
import { X, Search, BookOpen, Brain, Activity, HelpCircle } from 'lucide-react';
import { Button } from './ui/button';
import { Input } from './ui/input';
import { Badge } from './ui/badge';
import { ScrollArea } from './ui/scroll-area';
import { Card, CardHeader, CardTitle, CardContent } from './ui/card';
interface CBTReferenceProps {
onClose: () => void;
}
const CBTReference: React.FC<CBTReferenceProps> = ({ onClose }) => {
const [search, setSearch] = useState('');
const [activeCategory, setActiveCategory] = useState<'All' | 'Distortion' | 'Technique' | 'Concept'>('All');
const filtered = CBT_GLOSSARY.filter(entry => {
const matchesSearch = entry.term.toLowerCase().includes(search.toLowerCase()) ||
entry.definition.toLowerCase().includes(search.toLowerCase());
const matchesCategory = activeCategory === 'All' || entry.category === activeCategory;
return matchesSearch && matchesCategory;
});
const categories: ('All' | 'Distortion' | 'Technique' | 'Concept')[] = ['All', 'Distortion', 'Technique', 'Concept'];
const getCategoryIcon = (cat: string) => {
switch (cat) {
case 'Distortion': return <Brain size={16} className="text-rose-500" />;
case 'Technique': return <Activity size={16} className="text-teal-500" />;
case 'Concept': return <HelpCircle size={16} className="text-amber-500" />;
default: return <BookOpen size={16} />;
}
};
return (
<div className="fixed inset-0 z-[60] flex items-center justify-center p-4 bg-slate-900/60 backdrop-blur-sm">
<div className="bg-white rounded-2xl shadow-2xl w-full max-w-4xl h-[85vh] overflow-hidden flex flex-col animate-in fade-in zoom-in duration-300">
{/* Header */}
<div className="p-6 bg-slate-50 border-b border-slate-200 flex justify-between items-center shrink-0">
<div className="flex items-center gap-3">
<div className="bg-teal-600 p-2 rounded-lg text-white">
<BookOpen size={24} />
</div>
<div>
<h2 className="text-xl font-bold text-slate-800">CBT Clinical Reference</h2>
<p className="text-xs text-slate-500 font-medium uppercase tracking-widest">Evidence-Based Concepts & Frameworks</p>
</div>
</div>
<Button variant="ghost" size="icon" onClick={onClose} className="text-slate-400 hover:bg-slate-200 rounded-xl">
<X size={20} />
</Button>
</div>
{/* Filters */}
<div className="p-6 space-y-4 border-b border-slate-100 bg-white shrink-0">
<div className="relative">
<Search className="absolute left-4 top-1/2 -translate-y-1/2 text-slate-400" size={18} />
<Input
type="text"
placeholder="Search concepts, distortions, or definitions..."
value={search}
onChange={(e) => setSearch(e.target.value)}
className="w-full pl-12 pr-4 h-12 bg-slate-50 border-slate-200 rounded-xl focus-visible:ring-teal-500/50"
/>
</div>
<div className="flex flex-wrap gap-2">
{categories.map(cat => (
<Button
key={cat}
variant={activeCategory === cat ? "default" : "outline"}
onClick={() => setActiveCategory(cat)}
className={`rounded-full text-xs font-bold ${activeCategory === cat ? 'bg-teal-600 hover:bg-teal-700 shadow-md shadow-teal-100' : 'text-slate-500 hover:text-teal-600 hover:border-teal-200'}`}
>
{cat}
</Button>
))}
</div>
</div>
{/* Content */}
<ScrollArea className="flex-grow bg-slate-50/30 p-6">
<div className="grid grid-cols-1 md:grid-cols-2 gap-4 pb-6">
{filtered.map((entry, idx) => (
<Card key={idx} className="hover:border-teal-200 transition-all group shadow-sm border-slate-200">
<CardHeader className="pb-2">
<div className="flex justify-between items-start mb-2">
<CardTitle className="text-base group-hover:text-teal-700 transition-colors">{entry.term}</CardTitle>
<Badge variant="outline" className="flex items-center gap-1.5 px-2 py-0.5 bg-slate-50 border-slate-100 rounded text-[9px] font-black uppercase tracking-tighter text-slate-500">
{getCategoryIcon(entry.category)}
{entry.category}
</Badge>
</div>
</CardHeader>
<CardContent>
<p className="text-sm text-slate-600 leading-relaxed mb-4 font-light">
{entry.definition}
</p>
{entry.example && (
<div className="bg-teal-50/50 p-3 rounded-xl border border-teal-100">
<span className="text-[9px] font-black uppercase text-teal-600 block mb-1">Clinical Example</span>
<p className="text-xs text-teal-800 italic leading-relaxed">"{entry.example}"</p>
</div>
)}
</CardContent>
</Card>
))}
{filtered.length === 0 && (
<div className="col-span-full py-20 text-center space-y-4">
<div className="w-16 h-16 bg-slate-100 rounded-full flex items-center justify-center mx-auto text-slate-400">
<Search size={32} />
</div>
<p className="text-slate-400 text-sm font-medium">No concepts matching your search parameters.</p>
</div>
)}
</div>
</ScrollArea>
{/* Footer */}
<div className="p-4 bg-white border-t border-slate-100 text-center shrink-0">
<p className="text-[10px] text-slate-400 font-medium uppercase tracking-widest">
References compiled from clinical CBT standard frameworks.
</p>
</div>
</div>
</div>
);
};
export default CBTReference;