import { formatValue } from '../../lib/format'; import { User as UserIcon, Clock, LogOut } from 'lucide-react'; import { Button } from '../buttons/Button'; import './card.css'; export function DailyLogCard({ row, onPunchOut }: { row: Record; onPunchOut?: (row: any) => void }) { const stateName = String(row.status || row.current_state_name || 'Logged'); // User details const userObj = (row.sales_officer_name || row.user_id || row.user) as Record | null; const userName = formatValue(userObj?.name || row.user_name || 'Unknown User'); // Date let dateStr = '—'; if (row.date) dateStr = String(row.date).split('T')[0]; else if (row.created_at) dateStr = String(row.created_at).split('T')[0]; try { if (dateStr !== '—') { const d = new Date(dateStr); if (!isNaN(d.getTime())) { dateStr = d.toLocaleDateString('en-GB', { day: '2-digit', month: 'short', year: 'numeric' }).replace(/ /g, '-'); } } } catch (e) {} const formatTimeStr = (t: string | undefined | null) => { if (!t) return '—'; const str = String(t); if (str === '—') return str; try { let timeParts = str.split(':'); if (str.includes('T')) { timeParts = str.split('T')[1].replace('Z', '').split('.')[0].split(':'); } if (timeParts.length >= 2) { let h = parseInt(timeParts[0]); const m = timeParts[1]; const ampm = h >= 12 ? 'PM' : 'AM'; h = h % 12; h = h ? h : 12; const hStr = h < 10 ? '0' + h : h; return `${hStr}:${m} ${ampm}`; } return str.split('.')[0]; } catch { return str.split('.')[0]; } }; // Checkin time let checkInTimeRaw = row.time || row.created_at || row.punch_in_time; let checkInTime = formatTimeStr(checkInTimeRaw); // Check out time let checkOutTimeRaw = row.check_out_time || row.punch_out_time; if (!checkOutTimeRaw && stateName.toLowerCase().includes('out') && row.time) { checkOutTimeRaw = row.time; } let checkOutTime = checkOutTimeRaw ? formatTimeStr(checkOutTimeRaw) : null; const isPunchedIn = stateName.toLowerCase().includes('in') || stateName.toLowerCase().includes('active'); let statusClass = 'z-card-status--neutral'; if (isPunchedIn) statusClass = 'z-card-status--success'; else if (stateName.toLowerCase().includes('out')) statusClass = 'z-card-status--primary'; return (
{userName}
{stateName}
PUNCH-IN TIME
{dateStr} {checkInTime}
{checkOutTime && (
PUNCH-OUT TIME
{dateStr} {checkOutTime}
)}
{isPunchedIn && onPunchOut && (
)}
); }