88 lines
3.2 KiB
TypeScript
88 lines
3.2 KiB
TypeScript
import React from 'react';
|
|
import { BehaviorAnomaly, AnomalyType, AnomalySeverity } from '../../types.ts';
|
|
import { BrainIcon } from '../icons/Icons.tsx';
|
|
|
|
interface BehaviorAnomalyLogProps {
|
|
anomalies: BehaviorAnomaly[];
|
|
}
|
|
|
|
const anomalyConfig = {
|
|
[AnomalyType.AGGRESSION]: { icon: 'fa-hand-fist', color: 'text-red-600', bg: 'bg-red-100' },
|
|
[AnomalyType.ISOLATION]: { icon: 'fa-person', color: 'text-yellow-600', bg: 'bg-yellow-100' },
|
|
[AnomalyType.PANIC]: { icon: 'fa-person-running', color: 'text-purple-600', bg: 'bg-purple-100' },
|
|
[AnomalyType.REDUCED_MOBILITY]: {
|
|
icon: 'fa-person-falling',
|
|
color: 'text-blue-600',
|
|
bg: 'bg-blue-100',
|
|
},
|
|
};
|
|
|
|
const BehaviorAnomalyLog: React.FC<BehaviorAnomalyLogProps> = ({ anomalies }) => {
|
|
const formatTime = (date: Date) => {
|
|
return date.toLocaleTimeString('id-ID', { hour: '2-digit', minute: '2-digit' });
|
|
};
|
|
|
|
const formatDate = (date: Date) => {
|
|
const today = new Date();
|
|
const yesterday = new Date(today);
|
|
yesterday.setDate(yesterday.getDate() - 1);
|
|
|
|
if (date.toDateString() === today.toDateString()) {
|
|
return 'Hari Ini';
|
|
}
|
|
if (date.toDateString() === yesterday.toDateString()) {
|
|
return 'Kemarin';
|
|
}
|
|
return date.toLocaleDateString('id-ID', { day: 'numeric', month: 'short' });
|
|
};
|
|
|
|
return (
|
|
<div className="bg-white p-6 rounded-xl shadow-sm">
|
|
<h2 className="text-xl font-bold mb-4">Log Anomali Perilaku</h2>
|
|
{anomalies.length > 0 ? (
|
|
<div className="space-y-4 max-h-96 overflow-y-auto pr-2">
|
|
{anomalies.map((log) => {
|
|
const config = anomalyConfig[log.type];
|
|
return (
|
|
<div
|
|
key={log.id}
|
|
className="flex items-start space-x-4 p-3 rounded-lg hover:bg-gray-50/50"
|
|
>
|
|
<div
|
|
className={`mt-1 flex items-center justify-center h-10 w-10 rounded-full ${config.bg} ${config.color}`}
|
|
>
|
|
<i className={`fa-solid ${config.icon}`}></i>
|
|
</div>
|
|
<div className="flex-grow">
|
|
<p className="font-semibold text-gray-800">
|
|
{log.type} Terdeteksi
|
|
{log.severity === AnomalySeverity.CRITICAL && (
|
|
<span className="ml-2 text-xs font-bold text-red-700 bg-red-100 px-2 py-0.5 rounded-full">
|
|
Kritis
|
|
</span>
|
|
)}
|
|
</p>
|
|
<p className="text-sm text-gray-600">
|
|
{log.details} di <span className="font-medium">{log.location}</span>
|
|
</p>
|
|
</div>
|
|
<div className="text-right text-sm text-gray-500 flex-shrink-0">
|
|
<div>{formatTime(log.timestamp)}</div>
|
|
<div className="text-xs">{formatDate(log.timestamp)}</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
})}
|
|
</div>
|
|
) : (
|
|
<div className="text-center py-10">
|
|
<BrainIcon className="text-5xl text-gray-300 mx-auto" />
|
|
<p className="mt-3 text-gray-500">Tidak ada anomali terdeteksi.</p>
|
|
</div>
|
|
)}
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default BehaviorAnomalyLog;
|