'use client';

import type { ReactNode } from 'react';

import DiscoveryFlag from '@/components/common/DiscoveryFlag';

import { usePathname } from '@/i18n/navigation';

/** Routes that fill the whole window on their own: the games of "Az A–Z OPUS számokban". */
const BARE_PATHS = ['/hol-keszult', '/mikor-keszult'];

// The discovery tab is on every page but the story itself and the creation pages.
const showsDiscoveryFlag = (pathname: string) =>
  pathname !== '/felfedezes' && !/^\/alkotas\/[^/]+(?:\/|$)/.test(pathname);

/**
 * The site's header and footer around the page; bare routes get the page alone, under the admin
 * toolbar only.
 */
export default function SiteFrame({
  header,
  footer,
  children,
}: {
  header: ReactNode;
  footer: ReactNode;
  children: ReactNode;
}) {
  const pathname = usePathname();

  if (BARE_PATHS.includes(pathname)) {
    return <main className="pt-[var(--admin-h)]">{children}</main>;
  }

  return (
    <div className="relative w-full min-h-screen flex flex-col pt-[calc(60px+var(--admin-h))] md:pt-[calc(68px+var(--admin-h))] lg:pt-[calc(76px+var(--admin-h))]">
      {header}
      <main className="flex-1">{children}</main>
      {showsDiscoveryFlag(pathname) && <DiscoveryFlag />}
      {footer}
    </div>
  );
}
