InnerVoice / frontend /lib /utils.ts
E5K7's picture
Initial commit: InnerVoice MVP
bf04727
// Utility functions for InnerVoice
export function cn(...classes: (string | undefined | null | false)[]): string {
return classes.filter(Boolean).join(" ");
}
export function getMoodEmoji(moodScore: number): string {
if (moodScore >= 80) return "🌞";
if (moodScore >= 65) return "🌤️";
if (moodScore >= 50) return "⛅";
if (moodScore >= 35) return "🌧️";
return "⛈️";
}
export function getMoodLabel(moodScore: number): string {
if (moodScore >= 80) return "Radiant";
if (moodScore >= 65) return "Good";
if (moodScore >= 50) return "Okay";
if (moodScore >= 35) return "Low";
return "Struggling";
}
export function getEmotionColor(emotion: string): string {
const colors: Record<string, string> = {
happy: "text-yellow-400",
neutral: "text-blue-400",
sad: "text-blue-300",
angry: "text-red-400",
fearful: "text-purple-300",
anxious: "text-orange-400",
disgust: "text-green-400",
surprised: "text-pink-400",
};
return colors[emotion] ?? "text-gray-400";
}
export function getEmotionBg(emotion: string): string {
const colors: Record<string, string> = {
happy: "bg-yellow-500/20 border-yellow-500/40",
neutral: "bg-blue-500/20 border-blue-500/40",
sad: "bg-blue-300/20 border-blue-300/40",
angry: "bg-red-500/20 border-red-500/40",
fearful: "bg-purple-300/20 border-purple-300/40",
anxious: "bg-orange-500/20 border-orange-500/40",
};
return colors[emotion] ?? "bg-gray-500/20 border-gray-500/40";
}
export function getSeverityColor(severity: string): string {
const map: Record<string, string> = {
info: "border-blue-500/40 bg-blue-500/10",
warning: "border-yellow-500/40 bg-yellow-500/10",
concern: "border-orange-500/40 bg-orange-500/10",
urgent: "border-red-500/40 bg-red-500/10",
};
return map[severity] ?? "border-gray-500/40 bg-gray-500/10";
}
export function getSeverityIcon(severity: string): string {
const map: Record<string, string> = {
info: "💙",
warning: "⚠️",
concern: "🟠",
urgent: "🔴",
};
return map[severity] ?? "ℹ️";
}
export function getScoreColor(score: number): string {
if (score >= 70) return "#22c55e"; // green
if (score >= 50) return "#eab308"; // yellow
if (score >= 30) return "#f97316"; // orange
return "#ef4444"; // red
}
export function formatDate(dateStr: string): string {
const d = new Date(dateStr);
return d.toLocaleDateString("en-US", { month: "short", day: "numeric" });
}
export function formatTime(dateStr: string): string {
const d = new Date(dateStr);
return d.toLocaleTimeString("en-US", { hour: "2-digit", minute: "2-digit" });
}
export function getGreeting(): string {
const hour = new Date().getHours();
if (hour < 12) return "Good morning";
if (hour < 17) return "Good afternoon";
return "Good evening";
}
export function capitalise(str: string): string {
return str.charAt(0).toUpperCase() + str.slice(1);
}