'use client';

import { useMemo } from 'react';
import { usePathname } from 'next/navigation';
import SmartSearch from './smart-search';

const CHROMELESS_PREFIXES = ['/login', '/share'];

function isChromeless(pathname) {
  return CHROMELESS_PREFIXES.some((prefix) => pathname === prefix || pathname?.startsWith(`${prefix}/`));
}

export default function AppChrome({ children, sidebar }) {
  const pathname = usePathname();
  const chromeless = useMemo(() => isChromeless(pathname), [pathname]);
  const sidebarNode = sidebar ?? null;

  if (chromeless) {
    return <div className="chromeless-page">{children}</div>;
  }

  return (
    <>
      <div className="app-shell">
        <div className="app-rail">{sidebarNode}</div>
        <div className="app-content">{children}</div>
      </div>
      <SmartSearch />
    </>
  );
}
