/* admin-data.jsx — admin/CMS data model */

const ADMIN_NAV = [
  { id: 'dashboard', label: 'Dashboard', icon: 'compass', group: 'Übersicht' },
  { id: 'analytics', label: 'Analytics', icon: 'target', group: 'Übersicht' },
  { id: 'audit', label: 'Audit Logs', icon: 'fileText', group: 'Übersicht' },
  { id: 'seiten', label: 'Seitenverwaltung', icon: 'layers', group: 'Inhalte' },
  { id: 'builder', label: 'Seiten-Baukasten', icon: 'clipboard', group: 'Inhalte' },
  { id: 'wiki', label: 'Wiki-Verwaltung', icon: 'fileText', group: 'Inhalte' },
  { id: 'kurse', label: 'Kursverwaltung', icon: 'dumbbell', group: 'Inhalte' },
  { id: 'shop', label: 'Shop-Links', icon: 'bag', group: 'Inhalte' },
  { id: 'medien', label: 'Medienbibliothek', icon: 'star', group: 'Inhalte' },
  { id: 'uebersetzungen', label: 'Übersetzungen', icon: 'external', group: 'System' },
  { id: 'rollen', label: 'Nutzerrollen', icon: 'user', group: 'System' },
];

/* Widget catalog for the Baukasten — spec widget types */
const WIDGET_CATALOG = [
  { cat: 'Inhalt', tint: 'oliv', items: [
    { type: 'text', name: 'Textblock', icon: 'fileText', glyph: '¶' },
    { type: 'hero', name: 'Hero', icon: 'flag', glyph: '▭' },
    { type: 'hinweis', name: 'Hinweisbox', icon: 'info', glyph: '!' },
    { type: 'faq', name: 'FAQ', icon: 'info', glyph: '?' },
  ] },
  { cat: 'Interaktion', tint: 'stahlblau', items: [
    { type: 'buttons', name: 'Button-Gruppe', icon: 'arrowRight', glyph: '▢' },
    { type: 'checkliste', name: 'Checkliste', icon: 'listChecks', glyph: '☐' },
    { type: 'download', name: 'Download', icon: 'download', glyph: '↓' },
    { type: 'social', name: 'Social-Link', icon: 'instagram', glyph: '◎' },
  ] },
  { cat: 'Module', tint: 'sandgrau', items: [
    { type: 'kurskarte', name: 'Kurskarte', icon: 'layers', glyph: '▣' },
    { type: 'kalender', name: 'Kalenderblock', icon: 'calendar', glyph: '▦' },
    { type: 'shopteaser', name: 'Shop-Teaser', icon: 'bag', glyph: '▤' },
    { type: 'video', name: 'Video / Embed', icon: 'external', glyph: '▷' },
  ] },
];

const WIDGET_LABEL = Object.fromEntries(
  WIDGET_CATALOG.flatMap(c => c.items.map(i => [i.type, i.name]))
);

/* Pages registry */
const ADMIN_PAGES = [
  { id: 'PG-001', title: 'Startseite', route: '/start', status: 'live', lang: ['DE', 'EN'], ver: 14, by: 'M. Krause', when: 'vor 2 Std', sections: 6, widgets: 23 },
  { id: 'PG-014', title: 'Wiki · Dienststart', route: '/wiki/dienststart', status: 'live', lang: ['DE', 'EN'], ver: 7, by: 'A. Berg', when: 'gestern', sections: 4, widgets: 12 },
  { id: 'PG-018', title: 'Wiki · Packliste', route: '/wiki/packliste', status: 'review', lang: ['DE'], ver: 3, by: 'A. Berg', when: 'vor 3 Std', sections: 3, widgets: 9 },
  { id: 'PG-022', title: 'Kursübersicht', route: '/kurse', status: 'live', lang: ['DE'], ver: 9, by: 'M. Krause', when: 'vor 4 Tagen', sections: 5, widgets: 18 },
  { id: 'PG-031', title: 'Shop', route: '/shop', status: 'draft', lang: ['DE'], ver: 2, by: 'L. Sommer', when: 'vor 1 Woche', sections: 3, widgets: 11 },
  { id: 'PG-040', title: 'FAQ', route: '/faq', status: 'live', lang: ['DE', 'EN'], ver: 5, by: 'T. Wagner', when: 'vor 5 Tagen', sections: 2, widgets: 8 },
];

const STATUS_LABEL = { live: { de: 'Veröffentlicht', cls: 'ok' }, review: { de: 'In Prüfung', cls: 'warn' }, draft: { de: 'Entwurf', cls: 'neutral' } };

/* Audit log */
const AUDIT_LOG = [
  { ev: 'page_updated', user: 'M. Krause', role: 'Content Admin', t: '14:22', obj: 'Startseite · PG-001' },
  { ev: 'widget_created', user: 'A. Berg', role: 'Editor', t: '13:58', obj: 'Hinweisbox · Wiki Packliste' },
  { ev: 'translation_changed', user: 'S. Roth', role: 'Translator', t: '13:31', obj: 'EN · Dienststart' },
  { ev: 'widget_updated', user: 'A. Berg', role: 'Editor', t: '12:47', obj: 'Kurskarte · BFT' },
  { ev: 'shop_link_changed', user: 'L. Sommer', role: 'Content Admin', t: '11:20', obj: 'Alpha-Paket → extern' },
  { ev: 'role_changed', user: 'M. Krause', role: 'Super Admin', t: '10:05', obj: 'S. Roth → Translator' },
  { ev: 'widget_deleted', user: 'T. Wagner', role: 'Editor', t: '09:42', obj: 'Video · alte FAQ' },
  { ev: 'admin_login', user: 'M. Krause', role: 'Super Admin', t: '08:30', obj: 'Session · 2FA' },
  { ev: 'page_created', user: 'L. Sommer', role: 'Content Admin', t: 'gestern', obj: 'Shop · PG-031' },
  { ev: 'settings_changed', user: 'M. Krause', role: 'Super Admin', t: 'gestern', obj: 'Consent-Banner v2' },
];
const AUDIT_LABEL = {
  page_updated: 'Seite aktualisiert', widget_created: 'Widget erstellt', translation_changed: 'Übersetzung geändert',
  widget_updated: 'Widget aktualisiert', shop_link_changed: 'Shop-Link geändert', role_changed: 'Rolle geändert',
  widget_deleted: 'Widget gelöscht', admin_login: 'Admin-Login', page_created: 'Seite erstellt', settings_changed: 'Einstellung geändert',
};

/* Roles & permission matrix */
const ROLES = ['Super Admin', 'Content Admin', 'Editor', 'Translator', 'Analyst', 'Viewer'];
const PERM_MODULES = ['Seiten', 'Widgets', 'Wiki', 'Übersetzungen', 'Shop-Links', 'Medien', 'Analytics', 'Audit', 'Rollen'];
/* permission level per [module][role]: 2=voll, 1=eingeschränkt, 0=keins */
const PERM_MATRIX = {
  'Seiten':        [2, 2, 1, 0, 0, 1],
  'Widgets':       [2, 2, 2, 0, 0, 0],
  'Wiki':          [2, 2, 2, 1, 0, 1],
  'Übersetzungen': [2, 1, 0, 2, 0, 0],
  'Shop-Links':    [2, 2, 0, 0, 0, 0],
  'Medien':        [2, 2, 1, 1, 0, 1],
  'Analytics':     [2, 1, 0, 0, 2, 0],
  'Audit':         [2, 1, 0, 0, 1, 0],
  'Rollen':        [2, 0, 0, 0, 0, 0],
};
const TEAM = [
  { name: 'M. Krause', role: 'Super Admin', mail: 'm.krause', last: 'gerade aktiv', dot: 1 },
  { name: 'A. Berg', role: 'Editor', mail: 'a.berg', last: 'vor 12 Min', dot: 7 },
  { name: 'S. Roth', role: 'Translator', mail: 's.roth', last: 'vor 40 Min', dot: 4 },
  { name: 'L. Sommer', role: 'Content Admin', mail: 'l.sommer', last: 'vor 2 Std', dot: 9 },
  { name: 'T. Wagner', role: 'Editor', mail: 't.wagner', last: 'gestern', dot: 3 },
  { name: 'D. Funk', role: 'Analyst', mail: 'd.funk', last: 'vor 3 Tagen', dot: 11 },
];

/* Analytics */
const ANALYTICS = {
  kpis: [
    { label: 'Page Views', val: '48.219', delta: '+12,4 %', up: true },
    { label: 'Widget Views', val: '312.880', delta: '+8,1 %', up: true },
    { label: 'Button Clicks', val: '9.044', delta: '+3,7 %', up: true },
    { label: 'Shop-Klicks', val: '1.286', delta: '−1,2 %', up: false },
  ],
  views7: [320, 410, 380, 520, 610, 540, 690],
  days: ['Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa', 'So'],
  topPages: [
    { p: 'Startseite', v: 18420, pct: 100 },
    { p: 'KW-Plan', v: 9210, pct: 50 },
    { p: 'Dienststart-Checkliste', v: 7650, pct: 41 },
    { p: 'Wiki · Packliste', v: 5120, pct: 28 },
    { p: 'Kursübersicht', v: 4380, pct: 24 },
    { p: 'Shop', v: 2960, pct: 16 },
  ],
  device: [{ k: 'Mobil', v: 64, tint: 'oliv' }, { k: 'Desktop', v: 29, tint: 'stahlblau' }, { k: 'Tablet', v: 7, tint: 'sandgrau' }],
  lang: [{ k: 'DE', v: 88 }, { k: 'EN', v: 12 }],
  outbound: [
    { k: 'Instagram', v: 842 }, { k: 'Shop extern', v: 1286 }, { k: 'Kontakt', v: 213 },
  ],
  consent: { granted: 71, denied: 18, pending: 11 },
};

Object.assign(window, {
  ADMIN_NAV, WIDGET_CATALOG, WIDGET_LABEL, ADMIN_PAGES, STATUS_LABEL,
  AUDIT_LOG, AUDIT_LABEL, ROLES, PERM_MODULES, PERM_MATRIX, TEAM, ANALYTICS,
});
