import React from 'react';
import PropTypes from 'prop-types';
import urljoin from 'url-join';
import LinkedPagePath from '../models/linked-page-path';
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
const PagePathHierarchicalLink = (props) => {
const {
linkedPagePath, linkedPagePathByHtml, basePath, isInTrash,
} = props;
// render root element
if (linkedPagePath.isRoot) {
if (basePath != null) {
return null;
}
return isInTrash
? (
<>
/
>
)
: (
<>
/
>
);
}
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));
// eslint-disable-next-line react/prop-types
const RootElm = ({ children }) => {
return props.isInnerElem
? <>{children}>
: {children};
};
return (
{ isParentExists && (
) }
{ isSeparatorRequired && (
/
) }
{
shouldDangerouslySetInnerHTML
// eslint-disable-next-line react/no-danger
?
: {linkedPagePath.pathName}
}
);
};
PagePathHierarchicalLink.propTypes = {
linkedPagePath: PropTypes.instanceOf(LinkedPagePath).isRequired,
linkedPagePathByHtml: PropTypes.instanceOf(LinkedPagePath), // Not required
basePath: PropTypes.string,
isInTrash: PropTypes.bool,
// !!INTERNAL USE ONLY!!
isInnerElem: PropTypes.bool,
};
export default PagePathHierarchicalLink;