/** DB rows → admin UI shapes (admin-dashboard/src/lib/types.ts). */
export const toAdminUser = (a: {
  id: string | number;
  name: string;
  email: string;
  role: string;
  status: string;
  last_login_at?: string | null;
}) => ({
  id: String(a.id),
  name: a.name,
  email: a.email,
  role: a.role,
  status: a.status,
  lastActive: a.last_login_at ? String(a.last_login_at).slice(0, 10) : null,
});

const STATUS_TO_UI: Record<string, string> = { in_progress: 'in-progress' };
export const toInboxRequest = (m: {
  id: string | number;
  topic: string;
  name: string | null;
  contact: string;
  message: string;
  page_ref: string | null;
  status: string;
  created_at: string;
}) => ({
  id: String(m.id),
  topic: m.topic,
  name: m.name ?? '',
  contact: m.contact,
  message: m.message,
  ...(m.page_ref ? { ref: m.page_ref } : {}),
  status: STATUS_TO_UI[m.status] ?? m.status,
  createdAt: String(m.created_at).replace(' ', 'T'),
});
export const messageStatusToDb = (s: string) => (s === 'in-progress' ? 'in_progress' : s);

export const toActivity = (a: {
  id: string | number;
  created_at: string;
  admin_name: string | null;
  action: string;
  entity: string;
  label: string | null;
}) => ({
  id: String(a.id),
  at: String(a.created_at).replace(' ', 'T'),
  who: a.admin_name ?? 'System',
  action: a.action,
  target: a.label ? `${a.label} (${a.entity})` : a.entity,
});
