import { Outlet, createFileRoute } from '@tanstack/react-router'
import { Separator } from '@radix-ui/react-select'
import { AppSidebar } from '@/components/app-sidebar'
import {
  SidebarInset,
  SidebarProvider,
  SidebarTrigger,
} from '@/components/ui/sidebar'
import Breadcrumbs from '@/components/applicationBreadcrumbs'
import { enforceLogin } from '@/lib/oidc'
import { Suspense } from 'react'
import { Skeleton } from '@/components/ui/skeleton'
import NotFound from '@/components/404'

export const Route = createFileRoute('/_sidebar')({
  component: RouteComponent,
  beforeLoad: enforceLogin,
  errorComponent: ({ error }) => {
    return <div>ERROR {error.message}</div>
  },
  notFoundComponent: () => {
    return <NotFound />
  },
})

function RouteComponent() {
  return (
    <SidebarProvider>
      <AppSidebar />
      <SidebarInset className="sidebar-width max-h-screen flex">
        <header className="flex h-16 shrink-0 items-center gap-2">
          <div className="flex items-center gap-2 px-4">
            <SidebarTrigger className="-ml-1" />
            <Separator
              // orientation="vertical"
              className="mr-2 data-[orientation=vertical]:h-4"
            />
            <Breadcrumbs />
          </div>
        </header>
        <div className="p-4 pt-0 flex grow w-full overflow-scroll">
          <Suspense fallback={<Skeleton className="w-full h-full"></Skeleton>}>
            <Outlet />
          </Suspense>
        </div>
      </SidebarInset>
    </SidebarProvider>
  )
}
