import { type FC, type JSX, memo, useCallback } from 'react'; import Link from 'next/link'; import urljoin from 'url-join'; import type LinkedPagePath from '~/models/linked-page-path'; import styles from './PagePathHierarchicalLink.module.scss'; type PagePathHierarchicalLinkProps = { linkedPagePath: LinkedPagePath; linkedPagePathByHtml?: LinkedPagePath; basePath?: string; isInTrash?: boolean; isIconHidden?: boolean; // !!INTERNAL USE ONLY!! isInnerElem?: boolean; }; export const PagePathHierarchicalLink: FC = memo( (props: PagePathHierarchicalLinkProps): JSX.Element => { const { linkedPagePath, linkedPagePathByHtml, basePath, isInTrash, isInnerElem, } = props; const isIconHidden = props.isIconHidden ?? false; // eslint-disable-next-line react/prop-types const RootElm = useCallback( ({ children }) => { return isInnerElem ? ( <>{children} ) : ( {children} ); }, [isInnerElem], ); // render root element if (linkedPagePath.isRoot) { if (basePath != null || isIconHidden) { return <>; } return isInTrash ? ( delete / ) : ( home / ); } const isParentExists = linkedPagePath.parent != null; const isParentRoot = linkedPagePath.parent?.isRoot; const isSeparatorRequired = isParentExists && !isParentRoot; const shouldDangerouslySetInnerHTML = linkedPagePathByHtml != null; const href = encodeURI(urljoin(basePath || '/', linkedPagePath.href)); return ( {isParentExists && ( )} {isSeparatorRequired && ( / )} {shouldDangerouslySetInnerHTML ? ( // biome-ignore-start lint/a11y/useValidAnchor: ignore ) : ( {linkedPagePath.pathName} // biome-ignore-end lint/a11y/useValidAnchor: ignore )} ); }, );