import React, { useState } from 'react';
import type { IRevisionHasPageId } from '@growi/core';
import { pagePathUtils } from '@growi/core/dist/utils';
import { useTranslation } from 'next-i18next';
import { CopyToClipboard } from 'react-copy-to-clipboard';
import {
Dropdown, DropdownToggle, DropdownMenu, DropdownItem,
} from 'reactstrap';
import { RevisionDiff } from '../PageHistory/RevisionDiff';
import styles from './RevisionComparer.module.scss';
const { encodeSpaces } = pagePathUtils;
const DropdownItemContents = ({ title, contents }) => (
<>
{title}
{contents}
>
);
type RevisionComparerProps = {
sourceRevision: IRevisionHasPageId
targetRevision: IRevisionHasPageId
currentPageId?: string
currentPagePath: string
onClose: () => void
}
export const RevisionComparer = (props: RevisionComparerProps): JSX.Element => {
const { t } = useTranslation(['translation', 'commons']);
const {
sourceRevision, targetRevision, onClose, currentPageId, currentPagePath,
} = props;
const [dropdownOpen, setDropdownOpen] = useState(false);
const toggleDropdown = () => {
setDropdownOpen(!dropdownOpen);
};
const generateURL = (pathName: string) => {
const { origin } = window.location;
const url = new URL(pathName, origin);
if (sourceRevision != null && targetRevision != null) {
const urlParams = `${sourceRevision._id}...${targetRevision._id}`;
url.searchParams.set('compare', urlParams);
}
return encodeSpaces(decodeURI(url.href));
};
const isNodiff = (sourceRevision == null || targetRevision == null) ? true : sourceRevision._id === targetRevision._id;
if (currentPageId == null || currentPagePath == null) {
return <>{ t('not_found_page.page_not_exist')}>;
}
return (
{ t('page_history.comparing_revisions') }
{ !isNodiff && (
toggleDropdown()}
>
content_paste
{/* Page path URL */}
{/* Permanent Link URL */}
) }
{ isNodiff
? (
{t('No diff')}
)
: (
)
}
);
};