import { adapters } from '@/services/serviceConfig';
export const dashboardService = { async summary() { const [projects, sessions, customers] = await Promise.all([adapters.database.list('CoverProject'), adapters.database.list('MeasurementSession'), adapters.database.list('Customer')]); const count = (status) => projects.filter(p => p.record_state === 'active' && p.status === status).length; const projectCustomers = projects.reduce((a,p) => ({ ...a, [p.customer_uuid]: (a[p.customer_uuid] || 0) + 1 }), {}); return { projects, customers, active: projects.filter(p => p.record_state === 'active' && p.status !== 'Complete').length, measurements: sessions.filter(s => s.status !== 'Complete').length, clarification: count('Awaiting customer clarification'), selection: count('Designs awaiting selection'), review: count('Awaiting workshop review'), completed: projects.filter(p => p.status === 'Complete').slice(0,5), returning: Object.values(projectCustomers).filter(v => v > 1).length }; } };