import { chevronDown, chevronUp } from "solid-heroicons/solid";
import { createEffect, createSignal, For } from "solid-js";
import { usePageContext } from "vike-solid/usePageContext";
import { navigation } from "@/libs/navigation";
import { Link } from "@/components/Link";
import { Icon } from "solid-heroicons";
import clsx from "clsx";
type NavigationItemProps = {
section: (typeof navigation)[number];
onLinkClick?: (event: MouseEvent) => void;
};
function NavigationItem(props: NavigationItemProps) {
const { urlPathname } = usePageContext();
const [isOpened, setIsOpened] = createSignal(
props.section.links.some(
(link) =>
link.href === urlPathname ||
link.subitems?.some((subitem) => subitem.href === urlPathname),
),
);
return (
<>
{isOpened() && (
{(link) => (
-
subitem.href === urlPathname,
)
}
/>
)}
)}
>
);
}
type NavigationSubItemProps = {
link: (typeof navigation)[number]["links"][number];
onLinkClick?: (event: MouseEvent) => void;
isOpened?: boolean;
};
function NavigationSubItem(props: NavigationSubItemProps) {
const [isOpened, setIsOpened] = createSignal(props.isOpened);
const { urlPathname } = usePageContext();
createEffect(() => {
setIsOpened(
props.link.href === urlPathname ||
props.link.subitems?.some((subitem) => subitem.href === urlPathname),
);
}, [urlPathname, props.link]);
return (
<>
{props.link.subitems.length > 0 && (
)}
{props.link.title}
{props.link.subitems.length > 0 && (
({props.link.subitems.length})
)}
{props.link.subitems.length > 0 && isOpened() && (
{(subitem) => (
-
{subitem.title}
)}
)}
>
);
}
export function Navigation(props: {
class?: string;
onLinkClick?: (event: MouseEvent) => void;
}) {
const firstSections = navigation.filter(
(section) => section.position === "start",
);
const lastSections = navigation.filter(
(section) => section.position === "end",
);
const filteredSections = navigation
.filter(
(section) =>
section.position === "auto" || section.position === undefined,
)
.reduce(
(acc, section) => {
if (!acc[section.type]) {
acc[section.type] = [];
}
acc[section.type].push(section);
return acc;
},
{} as Record,
);
return (
);
}