import { useLocation } from "react-router-dom";
import type { ApiSettings, AuthInfo } from "../types";
import IconRail from "./IconRail";
import Titlebar from "./Titlebar";
import BreadcrumbBar from "./BreadcrumbBar";

type Props = {
  children: React.ReactNode;
  settings: ApiSettings;
  auth: AuthInfo | null;
  onSettingsChange: (settings: ApiSettings) => void;
  onAuthChange: (auth: AuthInfo | null, accessToken?: string) => void;
  publicMode?: boolean;
};

export default function AppShell({
  children,
  settings,
  auth,
  onSettingsChange,
  onAuthChange,
  publicMode = false
}: Props) {
  const location = useLocation();

  if (publicMode) {
    return (
      <div className="app-shell public-shell">
        <IconRail compact />
        <div className="app-main public-main">
          <Titlebar settings={settings} auth={auth} onSettingsChange={onSettingsChange} onAuthChange={onAuthChange} />
          <main className="public-content">{children}</main>
        </div>
      </div>
    );
  }

  return (
    <div className="app-shell">
      <IconRail />
      <div className="app-main">
        <Titlebar settings={settings} auth={auth} onSettingsChange={onSettingsChange} onAuthChange={onAuthChange} />
        <BreadcrumbBar pathname={location.pathname} />
        <main className="app-content">{children}</main>
      </div>
    </div>
  );
}
