import React from 'react';
import PropTypes from 'prop-types';
import { withTranslation } from 'react-i18next';
import { DevidedPagePath } from '@growi/core';
import PagePathHierarchicalLink from '~/components/PagePathHierarchicalLink';
import LinkedPagePath from '~/models/linked-page-path';
import { withUnstatedContainers } from '../UnstatedUtils';
import AppContainer from '~/client/services/AppContainer';
import NavigationContainer from '~/client/services/NavigationContainer';
import PageContainer from '~/client/services/PageContainer';
import { useCurrentCreatedAt } from '~/stores/context';
import CopyDropdown from '../Page/CopyDropdown';
import TagLabels from '../Page/TagLabels';
import SubnavButtons from './SubNavButtons';
import PageEditorModeManager from './PageEditorModeManager';
import AuthorInfo from './AuthorInfo';
import DrawerToggler from './DrawerToggler';
const PagePathNav = ({
// eslint-disable-next-line react/prop-types
pageId, pagePath, isEditorMode, isCompactMode,
}) => {
const dPagePath = new DevidedPagePath(pagePath, false, true);
let formerLink;
let latterLink;
// one line
if (dPagePath.isRoot || dPagePath.isFormerRoot || isEditorMode) {
const linkedPagePath = new LinkedPagePath(pagePath);
latterLink = ;
}
// two line
else {
const linkedPagePathFormer = new LinkedPagePath(dPagePath.former);
const linkedPagePathLatter = new LinkedPagePath(dPagePath.latter);
formerLink = ;
latterLink = ;
}
const copyDropdownId = `copydropdown${isCompactMode ? '-subnav-compact' : ''}-${pageId}`;
const copyDropdownToggleClassName = 'd-block text-muted bg-transparent btn-copy border-0 py-0';
return (
{formerLink}
{latterLink}
);
};
const GrowiSubNavigation = (props) => {
const {
appContainer, navigationContainer, pageContainer, isCompactMode,
} = props;
const { isDrawerMode, editorMode, isDeviceSmallerThanMd } = navigationContainer.state;
const {
pageId, path, creator, updatedAt, revisionAuthor, isPageExist,
} = pageContainer.state;
const { data: createdAt } = useCurrentCreatedAt();
const { isGuestUser } = appContainer;
const isEditorMode = editorMode !== 'view';
// Tags cannot be edited while the new page and editorMode is view
const isTagLabelHidden = (editorMode !== 'edit' && !isPageExist);
function onPageEditorModeButtonClicked(viewType) {
navigationContainer.setEditorMode(viewType);
}
return (
{/* Left side */}
{ isDrawerMode && (
) }
{ pageContainer.isAbleToShowTagLabel && !isCompactMode && !isTagLabelHidden && (
) }
{/* Right side */}
{pageContainer.isAbleToShowPageEditorModeManager && (
)}
{/* Page Authors */}
{ (pageContainer.isAbleToShowPageAuthors && !isCompactMode) && (
) }
);
};
/**
* Wrapper component for using unstated
*/
const GrowiSubNavigationWrapper = withUnstatedContainers(GrowiSubNavigation, [AppContainer, NavigationContainer, PageContainer]);
GrowiSubNavigation.propTypes = {
t: PropTypes.func.isRequired, // i18next
appContainer: PropTypes.instanceOf(AppContainer).isRequired,
navigationContainer: PropTypes.instanceOf(NavigationContainer).isRequired,
pageContainer: PropTypes.instanceOf(PageContainer).isRequired,
isCompactMode: PropTypes.bool,
};
export default withTranslation()(GrowiSubNavigationWrapper);