// Hooks
import { useState, Fragment } from 'react'
import { useRouter } from 'next/router'
// Depenencies
import get from 'lodash.get'
// Components
import Link from 'next/link'
import { PrimaryNavigation } from 'shared/components/navigation/primary.mjs'
import { RightIcon, LeftIcon, FreeSewingIcon } from 'shared/components/icons.mjs'
import { Header } from 'site/components/header/index.mjs'
import { Footer } from 'shared/components/footer/index.mjs'
import { Search } from 'site/components/search.mjs'
export const PageTitle = ({ app, slug, title }) => {
if (title) return
{title}
if (slug) return {get(app.navigation, slug.split('/')).__title}
return FIXME: This page has no title
}
const Breadcrumbs = ({ app, slug = false }) => {
if (!slug) return null
const crumbs = []
const chunks = slug.split('/')
for (const i in chunks) {
const j = parseInt(i) + parseInt(1)
const page = get(app.navigation, chunks.slice(0, j))
if (page) crumbs.push([page.__linktitle, '/' + chunks.slice(0, j).join('/'), j < chunks.length])
}
return (
-
{crumbs.map((crumb) => (
- »
-
{crumb[2] ? (
{crumb[0]}
) : (
{crumb[0]}
)}
))}
)
}
const asideClasses = `
fixed top-0 right-0
pt-28
sm:pt-8 sm:mt-16
pb-4 px-2
sm:relative sm:transform-none
h-screen w-screen
bg-base-100
sm:bg-base-50
sm:flex
sm:sticky
overflow-y-scroll
z-20
bg-base-100 text-base-content
transition-all
xl:w-1/4
`
export const DefaultLayout = ({
app,
title = false,
children = [],
search,
setSearch,
noSearch = false,
workbench = false,
AltMenu = null,
}) => {
const startNavigation = () => {
app.startLoading()
// Force close of menu on mobile if it is open
if (app.primaryNavigation) app.setPrimaryNavigation(false)
// Force close of search modal if it is open
if (search) setSearch(false)
}
const router = useRouter()
router.events?.on('routeChangeStart', startNavigation)
router.events?.on('routeChangeComplete', () => app.stopLoading())
const slug = router.asPath.slice(1)
const [collapsePrimaryNav, setCollapsePrimaryNav] = useState(workbench || false)
const [collapseAltMenu, setCollapseAltMenu] = useState(false)
return (
{title && (
<>
>
)}
{children}
{workbench && AltMenu && (
)}
{!noSearch && search && (
<>
>
)}
)
}