// Dependencies import get from 'lodash.get' // Hooks import { useNavigation } from 'site/hooks/use-navigation.mjs' // Components import Link from 'next/link' import { LeftIcon, RightIcon } from 'shared/components/icons.mjs' const linkClasses = 'flex flex-row gap-2 items-center w-full bg-secondary py-4 px-2 ' + 'rounded-lg border-secondary bg-opacity-10 border border-solid ' + 'hover:bg-opacity-100 hover:text-secondary-content' const PrevPage = ({ t, s }) => s ? ( {t} ) : ( ) const NextPage = ({ t, s }) => s ? ( {t} ) : ( ) const getItemWithCaveat = (index, slugLut, siteNav, shouldGet) => { if (index === false || shouldGet === true) return null if (typeof shouldGet === 'function' && shouldGet(slugLut[index])) return null return get(siteNav, slugLut[index].split('/')) } export const PrevNext = ({ slug, noPrev = false, noNext = false }) => { // Grab site navigation and slug lookup table from the useNavigatin hook const { siteNav, slugLut } = useNavigation() // Lookup the current slug in the LUT const index = slugLut.indexOf(slug) if (index < 0) return null // Add 1 for the next page, unless it's the last page const iNext = index === slugLut.length - 1 ? 0 : index + 1 // Subtract 1 for the previous page, unless it's the first page let iPrev = index === 0 ? slugLut.length - 1 : index - 1 // Get the next page from the siteNav object const next = getItemWithCaveat(iNext, slugLut, siteNav, noNext) // Get the previous page from the siteNav object const prev = getItemWithCaveat(iPrev, slugLut, siteNav, noPrev) // Return content return (
{prev ? : } {next ? : }
) }