'use client';

import type { ReactNode } from 'react';
import { usePathname } from 'next/navigation';
import Navbar from '@/app/components/Navbar';
import Footer from '@/app/components/Footer';

/** مسارات بدون هيدر/فوتر: تسجيل الدخول، التسجيل، استعادة/تغيير كلمة المرور، OTP */
const PATHS_WITHOUT_SITE_CHROME = new Set([
  '/login',
  '/register',
  '/forgot-password',
  '/reset-password',
  '/verify-otp',
  '/verify-reset-otp',
]);

function hideSiteChrome(pathname: string | null): boolean {
  if (!pathname) return false;
  const base = pathname.split('?')[0] ?? pathname;
  return [...PATHS_WITHOUT_SITE_CHROME].some(
    (p) => base === p || base.startsWith(`${p}/`),
  );
}

/**
 * هيكل موحّد: هيدر + محتوى الصفحة + فوتر — يُستخدم من `app/layout.tsx` لجميع المسارات.
 */
export default function AppShell({ children }: { children: ReactNode }) {
  const pathname = usePathname();
  const minimal = hideSiteChrome(pathname);

  return (
    <div className="min-h-screen flex flex-col bg-[#f3f4f6]">
      {!minimal && <Navbar />}
      <div className="flex-1 w-full flex flex-col min-h-0">{children}</div>
      {!minimal && <Footer />}
    </div>
  );
}
