/**
* AIInsightsBlock - AI Insights Dashboard Block
*
* Displays AI-generated insights for professional/enterprise tiers
* Shows top 2-3 insights with links to full AI Insights page
*/
import React from 'react';
import { useTranslation } from 'react-i18next';
import { Lightbulb, ArrowRight, BarChart2, TrendingUp, TrendingDown, Shield, AlertTriangle } from 'lucide-react';
interface AIInsight {
id: string;
title: string;
description: string;
type: 'cost_optimization' | 'waste_reduction' | 'safety_stock' | 'demand_forecast' | 'risk_alert';
impact: 'high' | 'medium' | 'low';
impact_value?: string;
impact_currency?: string;
created_at: string;
recommendation_actions?: Array<{
label: string;
action: string;
}>;
}
interface AIInsightsBlockProps {
insights: AIInsight[];
loading?: boolean;
onViewAll: () => void;
}
export function AIInsightsBlock({ insights = [], loading = false, onViewAll }: AIInsightsBlockProps) {
const { t } = useTranslation(['dashboard', 'common']);
// Get icon based on insight type
const getInsightIcon = (type: string) => {
switch (type) {
case 'cost_optimization': return ;
case 'waste_reduction': return ;
case 'safety_stock': return ;
case 'demand_forecast': return ;
case 'risk_alert': return ;
default: return ;
}
};
// Get impact color based on level
const getImpactColor = (impact: string) => {
switch (impact) {
case 'high': return 'bg-[var(--color-error-100)] text-[var(--color-error-700)]';
case 'medium': return 'bg-[var(--color-warning-100)] text-[var(--color-warning-700)]';
case 'low': return 'bg-[var(--color-info-100)] text-[var(--color-info-700)]';
default: return 'bg-[var(--bg-secondary)] text-[var(--text-secondary)]';
}
};
// Get impact label
const getImpactLabel = (impact: string) => {
switch (impact) {
case 'high': return t('dashboard:ai_insights.impact_high');
case 'medium': return t('dashboard:ai_insights.impact_medium');
case 'low': return t('dashboard:ai_insights.impact_low');
default: return '';
}
};
if (loading) {
return (
);
}
// Show top 3 insights
const topInsights = insights.slice(0, 3);
return (
{/* Header */}
{/* Icon */}
{/* Title & Description */}
{t('dashboard:ai_insights.title')}
{t('dashboard:ai_insights.subtitle')}
{/* View All Button */}
{/* Insights List */}
{topInsights.length > 0 ? (
{topInsights.map((insight, index) => (
{/* Icon */}
{getInsightIcon(insight.type)}
{/* Content */}
{insight.title}
{/* Impact Badge */}
{getImpactLabel(insight.impact)}
{insight.description}
{/* Recommendations */}
{insight.recommendation_actions && insight.recommendation_actions.length > 0 && (
{t('dashboard:ai_insights.recommendations', 'Recomendaciones')}:
{insight.recommendation_actions.slice(0, 2).map((action, idx) => (
-
•
{action.label || action.action}
))}
)}
{/* Impact Value */}
{insight.impact_value && (
{insight.type === 'cost_optimization' && (
💰 {insight.impact_currency}{insight.impact_value} {t('dashboard:ai_insights.savings')}
)}
{insight.type === 'waste_reduction' && (
♻️ {insight.impact_value} {t('dashboard:ai_insights.reduction')}
)}
{!['cost_optimization', 'waste_reduction'].includes(insight.type) && (
💰 {insight.impact_currency}{insight.impact_value}
)}
)}
))}
) : (
/* Empty State */
{t('dashboard:ai_insights.no_insights')}
)}
);
}
export default AIInsightsBlock;