import { Box } from '@pikku/mantine/core'
import { usePikkuQuery } from '@project/functions-sdk/pikku/api.gen'
import { AppLayout } from './AppLayout'
import { SeminarhofHeader, SeminarhofFooter } from './SeminarhofChrome'

/**
 * Shell for the public marketing-facing pages (availability / events / enquiry).
 * Logged-in users keep the authenticated AppLayout (sidebar) so the admin
 * experience is consistent. Anonymous visitors get the seminarhof-drawehn.de
 * header + footer so the app and the marketing site feel like one website.
 *
 * Deliberately a sibling of PublicShell (not a variant) — pages opt into the
 * marketing chrome explicitly, so a future public route (e.g. kanban) can't
 * inherit it by accident.
 */
export function MarketingShell({ children }: { children: React.ReactNode }) {
  const { data, isLoading } = usePikkuQuery('me', null, { retry: false })

  if (isLoading) {
    return <Box mih="100vh" />
  }

  if (data) {
    return <AppLayout user={data}>{children}</AppLayout>
  }

  return (
    <Box mih="100vh" style={{ display: 'flex', flexDirection: 'column', background: 'var(--brand-bg)' }}>
      <SeminarhofHeader />
      <Box style={{ flex: 1 }}>{children}</Box>
      <SeminarhofFooter />
    </Box>
  )
}
