import type { ReactNode } from 'react';

export type ShellNavItem = {
  href: string;
  label: string;
  icon: ReactNode;
  children?: { href: string; label: string }[];
};

export type ShellNavSection = { sectionTitle: string; items: ShellNavItem[] };

const dashboardIcon = (
  <svg className="shrink-0" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.65">
    <rect x="3" y="3" width="8" height="8" rx="2" />
    <rect x="13" y="3" width="8" height="5" rx="2" />
    <rect x="13" y="10" width="8" height="11" rx="2" />
    <rect x="3" y="13" width="8" height="8" rx="2" />
  </svg>
);

const schoolsIcon = (
  <svg className="shrink-0" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.65">
    <path d="M3 10.5 12 5l9 5.5" />
    <path d="M5 10v8.5A1.5 1.5 0 0 0 6.5 20h11A1.5 1.5 0 0 0 19 18.5V10" />
    <path d="M9 20v-5h6v5" />
  </svg>
);

const plansIcon = (
  <svg className="shrink-0" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.65">
    <path d="M12 2L2 7l10 5 10-5-10-5Z" />
    <path d="M2 17l10 5 10-5" />
    <path d="M2 12l10 5 10-5" />
  </svg>
);

const subscriptionIcon = (
  <svg className="shrink-0" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.65">
    <rect x="3" y="6" width="18" height="12" rx="2.5" />
    <path d="M3 10h18" />
    <path d="M7 14h4" />
  </svg>
);

const platformFinanceIcon = (
  <svg className="shrink-0" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.65">
    <path d="M12 2v20M17 5H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H6" />
  </svg>
);

const usersIcon = (
  <svg className="shrink-0" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.65">
    <circle cx="9" cy="8" r="3" />
    <path d="M3.5 18a5.5 5.5 0 0 1 11 0" />
    <circle cx="17" cy="9" r="2.5" />
    <path d="M14.5 18a4.5 4.5 0 0 1 6 0" />
  </svg>
);

const websiteIcon = (
  <svg className="shrink-0" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.65">
    <circle cx="12" cy="12" r="10" />
    <path d="M2 12h20" />
    <path d="M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10Z" />
  </svg>
);

const communicationsIcon = (
  <svg className="shrink-0" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.65">
    <path d="M11 5.882V19.24a1.76 1.76 0 0 1-3.417.592l-2.147-6.15M18 13a3 3 0 1 0 0-6M5.436 13.683A4.001 4.001 0 0 1 7 6h1.832c4.1 0 7.625-1.234 9.168-3v14c-1.543-1.766-5.067-3-9.168-3H7a3.988 3.988 0 0 1-1.564-.317z" />
  </svg>
);

const reportsIcon = (
  <svg className="shrink-0" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.65">
    <path d="M4 20V9" />
    <path d="M10 20V4" />
    <path d="M16 20v-7" />
    <path d="M22 20H2" />
  </svg>
);

const auditIcon = (
  <svg className="shrink-0" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.65">
    <path d="M9 5H7a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V7a2 2 0 0 0-2-2h-2" />
    <rect x="9" y="3" width="6" height="4" rx="1" />
    <path d="M9 12h6M9 16h4" />
  </svg>
);

const settingsIcon = (
  <svg className="shrink-0" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.65">
    <circle cx="12" cy="12" r="3" />
    <path d="M19.4 15a1 1 0 0 0 .2 1.1l.1.1a2 2 0 1 1-2.8 2.8l-.1-.1a1 1 0 0 0-1.1-.2 1 1 0 0 0-.6.9V20a2 2 0 1 1-4 0v-.1a1 1 0 0 0-.6-.9 1 1 0 0 0-1.1.2l-.1.1a2 2 0 1 1-2.8-2.8l.1-.1a1 1 0 0 0 .2-1.1 1 1 0 0 0-.9-.6H4a2 2 0 1 1 0-4h.1a1 1 0 0 0 .9-.6 1 1 0 0 0-.2-1.1l-.1-.1a2 2 0 1 1 2.8-2.8l.1.1a1 1 0 0 0 1.1.2 1 1 0 0 0 .6-.9V4a2 2 0 1 1 4 0v.1a1 1 0 0 0 .6.9 1 1 0 0 0 1.1-.2l.1-.1a2 2 0 1 1 2.8 2.8l-.1.1a1 1 0 0 0-.2 1.1 1 1 0 0 0 .9.6H20a2 2 0 1 1 0 4h-.1a1 1 0 0 0-.9.6Z" />
  </svg>
);

const studentsIcon = (
  <svg className="shrink-0" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.65">
    <circle cx="12" cy="8" r="3.5" />
    <path d="M4.5 20a7.5 7.5 0 0 1 15 0" />
  </svg>
);

const teachersIcon = (
  <svg className="shrink-0" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.65">
    <path d="M3 8.5 12 4l9 4.5-9 4.5-9-4.5Z" />
    <path d="M7 11v3.5a5 5 0 0 0 10 0V11" />
  </svg>
);

const branchesIcon = (
  <svg className="shrink-0" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.65">
    <path d="M4 20h16" />
    <path d="M6 20V8h4v12" />
    <path d="M14 20V4h4v16" />
  </svg>
);

const galleryIcon = (
  <svg className="shrink-0" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.65">
    <rect x="3" y="3" width="18" height="18" rx="2.5" />
    <circle cx="8.5" cy="8.5" r="1.5" />
    <path d="m3 15 5-5 4 4" />
    <path d="m14 14 3-3 4 4" />
  </svg>
);

const reportCardIcon = (
  <svg className="shrink-0" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.65">
    <path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z" />
    <path d="M14 2v6h6" />
    <path d="M9 13h6M9 17h4" />
    <circle cx="9" cy="10" r="1" fill="currentColor" />
  </svg>
);

const academicIcon = (
  <svg className="shrink-0" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.65">
    <path d="M3 8.5 12 4l9 4.5-9 4.5-9-4.5Z" />
    <path d="M7 11v4a5 5 0 0 0 10 0v-4" />
    <path d="M21 8.5v5" />
  </svg>
);

const classroomsIcon = (
  <svg className="shrink-0" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.65">
    <rect x="3" y="5" width="18" height="14" rx="2" />
    <path d="M8 10h8M8 14h5" />
  </svg>
);

const financeIcon = (
  <svg className="shrink-0" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.65">
    <rect x="3" y="6" width="18" height="12" rx="2.5" />
    <path d="M3 10h18" />
    <path d="M7 14h4" />
  </svg>
);

const attendanceIcon = (
  <svg className="shrink-0" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.65">
    <path d="M5 4h14v16H5z" />
    <path d="M8 9h8M8 13h8M8 17h5" />
  </svg>
);

const eventsCalendarIcon = (
  <svg className="shrink-0" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.65">
    <path d="M8 2v4M16 2v4M3 10h18M5 4h14a1 1 0 0 1 1 1v2H4V5a1 1 0 0 1 1-1Z" />
    <path d="M8 14h.01M12 14h.01M16 14h.01M8 18h.01M12 18h.01M16 18h.01" strokeLinecap="round" />
  </svg>
);

const leaveIcon = (
  <svg className="shrink-0" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.65">
    <path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-2 15l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z" />
  </svg>
);

const mealMenuIcon = (
  <svg className="shrink-0" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.65">
    <path d="M8 3v3M8 10v11M12 3v18M16 3v8M16 14v7" strokeLinecap="round" />
    <path d="M4 21h16" />
  </svg>
);

const feedIcon = (
  <svg className="shrink-0" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.65">
    <path d="M22 3H2v5c0 2.5 2 4.5 4.5 4.5H9c2.5 0 4.5-2 4.5-4.5V3h5l3 3v12a2 2 0 0 1-2 2H2" />
    <path d="M2 10h20" />
    <path d="M2 16h20" />
  </svg>
);

const notificationsIcon = (
  <svg className="shrink-0" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.65">
    <path d="M6 9a6 6 0 0 1 12 0v5l2 2H4l2-2V9Z" />
    <path d="M10 19a2 2 0 0 0 4 0" />
  </svg>
);

const messagesIcon = (
  <svg className="shrink-0" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.65">
    <path d="M4 5h16v10H8l-4 4V5Z" />
  </svg>
);

const invoicesIcon = (
  <svg className="shrink-0" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.65">
    <path d="M6 3h12v18l-3-2-3 2-3-2-3 2V3Z" />
    <path d="M9 8h6M9 12h6" />
  </svg>
);

export const superAdminNavSections: ShellNavSection[] = [
  {
    sectionTitle: 'Panel',
    items: [{ href: '/platform/dashboard', label: 'Dashboard', icon: dashboardIcon }],
  },
  {
    sectionTitle: 'Yönetim',
    items: [
      { href: '/platform/schools', label: 'Okullar', icon: schoolsIcon },
      { href: '/platform/plans', label: 'Planlar', icon: plansIcon },
      { href: '/platform/subscriptions', label: 'Abonelikler', icon: subscriptionIcon },
      { href: '/platform/finance', label: 'Finans', icon: platformFinanceIcon },
      { href: '/platform/users', label: 'Yöneticiler', icon: usersIcon },
    ],
  },
  {
    sectionTitle: 'İçerik & İletişim',
    items: [
      { href: '/platform/website', label: 'Website CMS', icon: websiteIcon },
      { href: '/platform/communications', label: 'Duyurular', icon: communicationsIcon },
    ],
  },
  {
    sectionTitle: 'Analiz & Sistem',
    items: [
      { href: '/platform/reports', label: 'Raporlar', icon: reportsIcon },
      { href: '/platform/audit-logs', label: 'Audit Log', icon: auditIcon },
      { href: '/platform/settings', label: 'Ayarlar', icon: settingsIcon },
    ],
  },
];

export const schoolAdminNavSections: ShellNavSection[] = [
  {
    sectionTitle: 'Panel',
    items: [{ href: '/school/dashboard', label: 'Dashboard', icon: dashboardIcon }],
  },
  {
    sectionTitle: 'Kayıt & personel',
    items: [
      { href: '/school/students', label: 'Öğrenciler', icon: studentsIcon },
      {
        href: '/school/teachers',
        label: 'Öğretmenler',
        icon: teachersIcon,
        children: [
          { href: '/school/teachers', label: 'Öğretmenler' },
          { href: '/school/teachers/new', label: 'Öğretmen Ekle' },
        ],
      },
    ],
  },
  {
    sectionTitle: 'Kurum',
    items: [
      { href: '/school/branches', label: 'Şubeler', icon: branchesIcon },
      { href: '/school/classrooms', label: 'Sınıflar', icon: classroomsIcon },
      { href: '/school/academic', label: 'Eğitim Yılları', icon: academicIcon },
      { href: '/school/gallery', label: 'Galeri', icon: galleryIcon },
    ],
  },
  {
    sectionTitle: 'Operasyon',
    items: [
      {
        href: '/school/finance',
        label: 'Finans',
        icon: financeIcon,
        children: [
          { href: '/school/finance', label: 'Genel Bakış' },
          { href: '/school/finance/tuition', label: 'Aidat Yönetimi' },
          { href: '/school/finance/invoices/new', label: 'Yeni Fatura' },
          { href: '/school/finance/report', label: 'Rapor' },
        ],
      },
      { href: '/school/subscription', label: 'Aboneliğim', icon: financeIcon },
      { href: '/school/attendance', label: 'Yoklama', icon: attendanceIcon },
      { href: '/school/leave-requests', label: 'İzin Talepleri', icon: leaveIcon },
      { href: '/school/feed', label: 'Akış', icon: feedIcon },
      {
        href: '/school/report-cards',
        label: 'Günlük Karne',
        icon: reportCardIcon,
        children: [
          { href: '/school/report-cards', label: 'Karneler' },
          { href: '/school/report-cards/categories', label: 'Kategoriler' },
        ],
      },
      { href: '/school/events', label: 'Etkinlikler', icon: eventsCalendarIcon },
      { href: '/school/meals', label: 'Yemek menüsü', icon: mealMenuIcon },
    ],
  },
  {
    sectionTitle: 'İletişim',
    items: [
      { href: '/school/messages', label: 'Mesajlar', icon: messagesIcon },
      { href: '/school/notifications', label: 'Duyurular', icon: notificationsIcon },
    ],
  },
];

export const teacherNavSections: ShellNavSection[] = [
  {
    sectionTitle: 'Panel',
    items: [{ href: '/teacher/dashboard', label: 'Dashboard', icon: dashboardIcon }],
  },
  {
    sectionTitle: 'Ders & kayıt',
    items: [
      { href: '/teacher/attendance', label: 'Yoklama', icon: attendanceIcon },
      { href: '/teacher/report-cards', label: 'Günlük Karne', icon: reportCardIcon },
      { href: '/teacher/feed', label: 'Akış', icon: feedIcon },
      { href: '/teacher/activities', label: 'Sınıf Etkinlikleri', icon: eventsCalendarIcon },
      { href: '/teacher/leave-requests', label: 'İzin Talepleri', icon: leaveIcon },
      { href: '/teacher/gallery', label: 'Galeri', icon: galleryIcon },
    ],
  },
  {
    sectionTitle: 'İletişim',
    items: [{ href: '/teacher/messages', label: 'Mesajlar', icon: messagesIcon }],
  },
];

export const parentNavSections: ShellNavSection[] = [
  {
    sectionTitle: 'Panel',
    items: [{ href: '/parent/dashboard', label: 'Dashboard', icon: dashboardIcon }],
  },
  {
    sectionTitle: 'Veli',
    items: [
      { href: '/parent/children', label: 'Çocuklarım', icon: studentsIcon },
      { href: '/parent/report-cards', label: 'Günlük Karne', icon: reportCardIcon },
      { href: '/parent/feed', label: 'Akış', icon: feedIcon },
      { href: '/parent/gallery', label: 'Galeri', icon: galleryIcon },
      { href: '/parent/invoices', label: 'Faturalar', icon: invoicesIcon },
      { href: '/parent/messages', label: 'Mesajlar', icon: messagesIcon },
      { href: '/parent/notifications', label: 'Bildirimler', icon: notificationsIcon },
    ],
  },
];

export function getNavSectionsForRole(role: string): ShellNavSection[] {
  if (role === 'SUPER_ADMIN') return superAdminNavSections;
  if (role === 'TEACHER') return teacherNavSections;
  if (role === 'PARENT') return parentNavSections;
  return schoolAdminNavSections;
}

export function flattenNavItems(sections: ShellNavSection[]): ShellNavItem[] {
  return sections.flatMap((s) => s.items);
}
