import React, {
FC, memo, useMemo, useRef,
} from 'react';
import { useTranslation } from 'next-i18next';
import dynamic from 'next/dynamic';
import { useRipple } from 'react-use-ripple';
import { UncontrolledTooltip } from 'reactstrap';
import {
useIsSearchPage, useIsGuestUser, useIsReadOnlyUser, useIsSearchServiceConfigured, useAppTitle, useConfidential,
} from '~/stores/context';
import { usePageCreateModal } from '~/stores/modal';
import { useCurrentPagePath } from '~/stores/page';
import { useIsDeviceSmallerThanMd } from '~/stores/ui';
import { GlobalSearchProps } from './GlobalSearch';
import styles from './GrowiNavbar.module.scss';
const NavbarRight = memo((): JSX.Element => {
const { t } = useTranslation();
const { data: currentPagePath } = useCurrentPagePath();
const { data: isGuestUser } = useIsGuestUser();
const { data: isReadOnlyUser } = useIsReadOnlyUser();
// ripple
const newButtonRef = useRef(null);
useRipple(newButtonRef, { rippleColor: 'rgba(255, 255, 255, 0.3)' });
const { open: openCreateModal } = usePageCreateModal();
const isAuthenticated = isGuestUser === false;
const authenticatedNavItem = useMemo(() => {
return (
<>
{!isReadOnlyUser
&&
}
>
);
}, [isReadOnlyUser, t, openCreateModal, currentPagePath]);
const notAuthenticatedNavItem = useMemo(() => {
return (
<>
Login
>
);
}, []);
return (
<>
{isAuthenticated ? authenticatedNavItem : notAuthenticatedNavItem}
>
);
});
NavbarRight.displayName = 'NavbarRight';
type ConfidentialProps = {
confidential?: string,
}
const Confidential: FC = memo((props: ConfidentialProps): JSX.Element => {
const { confidential } = props;
if (confidential == null || confidential.length === 0) {
return <>>;
}
return (
{confidential}
{confidential}
);
});
Confidential.displayName = 'Confidential';
type Props = {
isGlobalSearchHidden?: boolean
}
export const GrowiNavbar = (props: Props): JSX.Element => {
const { isGlobalSearchHidden } = props;
const GlobalSearch = dynamic(() => import('./GlobalSearch').then(mod => mod.GlobalSearch), { ssr: false });
const { data: appTitle } = useAppTitle();
const { data: confidential } = useConfidential();
const { data: isSearchServiceConfigured } = useIsSearchServiceConfigured();
const { data: isDeviceSmallerThanMd } = useIsDeviceSmallerThanMd();
const { data: isSearchPage } = useIsSearchPage();
return (
);
};