import get from 'lodash.get'
import Link from 'next/link'
import { useContext } from 'react'
import { NavigationContext } from 'shared/context/navigation-context.mjs'
import { BulletIcon, RightIcon } from 'shared/components/icons.mjs'
import { pageHasChildren } from 'shared/utils.mjs'
import orderBy from 'lodash.orderby'
export const getRoot = {
dev: (root, nav) => {
if (!root) return nav
if (root.indexOf('/') === -1) return nav[root]
return get(nav, root.split('/'))
},
org: (root, nav) => {
// Fixme: make this work for org
if (!root) return nav
if (root.indexOf('/') === -1) return get(nav, root)
return get(nav, root.split('/'))
},
}
/*
* This is a recursive function, so it needs to be lean
*/
const RenderTree = ({ tree, recurse, depth = 1, level = 0, active = false }) => {
const orderedTree = orderBy(tree, ['o', 't'], ['asc', 'asc']).filter(
(item) => typeof item === 'object'
)
return (
{orderedTree.map((item, i) => {
/*
* Does this have children?
*/
const hasChildren =
recurse && (!depth || level < depth) && pageHasChildren(item)
? item.s.replaceAll('/', '')
: false
/*
* The rotation of the chevron should in principle be possible with Tailwind's group variant modifiers
* However, despite my best efforts, I can't seem to make it work. So this relies on a bit of CSS.
* The 'summary-chevron' class is what does the trick.
*/
return (