import React from 'react';
import { NavLink } from 'react-router-dom';
import { cn } from '@/lib/utils';
import {
  ADMIN_HOME_PATH,
  ADMIN_EVENTS_PATH,
  ADMIN_SETTINGS_PATH,
  ADMIN_TASKS_PATH,
  ADMIN_BILLING_PATH,
} from '../constants';

const navItems = [
  { to: ADMIN_HOME_PATH, label: 'Dashboard', end: true },
  { to: ADMIN_EVENTS_PATH, label: 'Events' },
  { to: ADMIN_TASKS_PATH, label: 'Tasks' },
  { to: ADMIN_BILLING_PATH, label: 'Billing' },
  { to: ADMIN_SETTINGS_PATH, label: 'Einstellungen' },
];

interface AdminLayoutProps {
  title: string;
  subtitle?: string;
  actions?: React.ReactNode;
  children: React.ReactNode;
}

export function AdminLayout({ title, subtitle, actions, children }: AdminLayoutProps) {
  React.useEffect(() => {
    document.body.classList.add('tenant-admin-theme');
    return () => {
      document.body.classList.remove('tenant-admin-theme');
    };
  }, []);

  return (
    <div className="min-h-screen bg-brand-gradient text-brand-slate">
      <header className="border-b border-brand-rose-soft bg-brand-card/90 shadow-brand-primary backdrop-blur-md">
        <div className="mx-auto flex w-full max-w-6xl flex-col gap-4 px-6 py-6 md:flex-row md:items-center md:justify-between">
          <div>
            <p className="text-xs uppercase tracking-[0.35em] text-brand-rose">Fotospiel Tenant Admin</p>
            <h1 className="font-display text-3xl font-semibold text-brand-slate">{title}</h1>
            {subtitle && <p className="mt-1 text-sm font-sans-marketing text-brand-navy/75">{subtitle}</p>}
          </div>
          {actions && <div className="flex flex-wrap gap-2">{actions}</div>}
        </div>
        <nav className="mx-auto flex w-full max-w-6xl gap-3 px-6 pb-4 text-sm font-medium text-brand-navy/80">
          {navItems.map((item) => (
            <NavLink
              key={item.to}
              to={item.to}
              end={item.end}
              className={({ isActive }) =>
                cn(
                  'rounded-full px-4 py-2 transition-colors',
                  isActive
                    ? 'bg-brand-rose text-white shadow-md shadow-rose-400/40'
                    : 'bg-white/70 text-brand-navy/80 hover:bg-white hover:text-brand-slate'
                )
              }
            >
              {item.label}
            </NavLink>
          ))}
        </nav>
      </header>
      <main className="mx-auto w-full max-w-6xl px-6 py-10">
        <div className="grid gap-6">{children}</div>
      </main>
    </div>
  );
}

