/**
 * 
 * @file Preview Navigation
 * @author Box
 */

import * as React from 'react';
import { injectIntl } from 'react-intl';
import { Route } from 'react-router-dom';
import IconNavigateLeft from '../../icons/general/IconNavigateLeft';
import IconNavigateRight from '../../icons/general/IconNavigateRight';
import PlainButton from '../../components/plain-button/PlainButton';
import messages from '../common/messages';
import { SIDEBAR_VIEW_METADATA } from '../../constants';
const PreviewNavigation = ({
  collection = [],
  currentIndex,
  intl,
  onNavigateLeft,
  onNavigateRight
}) => {
  const hasLeftNavigation = collection.length > 1 && currentIndex > 0 && currentIndex < collection.length;
  const hasRightNavigation = collection.length > 1 && currentIndex > -1 && currentIndex < collection.length - 1;
  if (!hasLeftNavigation && !hasRightNavigation) {
    return null;
  }
  const goToActiveSidebarTab = (routeParams, history) => {
    if (routeParams.deeplink) {
      if (routeParams.activeTab === SIDEBAR_VIEW_METADATA) {
        history.push(`/${routeParams.activeTab}/${routeParams.deeplink}/${routeParams[0]}`);
      } else {
        history.push(`/${routeParams.activeTab}`);
      }
    }
  };
  return /*#__PURE__*/React.createElement(Route, {
    path: ['/:activeTab/:deeplink/*', '/']
  }, ({
    match,
    history
  }) => /*#__PURE__*/React.createElement(React.Fragment, null, hasLeftNavigation && /*#__PURE__*/React.createElement(PlainButton, {
    className: "bcpr-navigate-left",
    onClick: () => {
      goToActiveSidebarTab(match.params, history);
      onNavigateLeft();
    },
    title: intl.formatMessage(messages.previousFile),
    type: "button"
  }, /*#__PURE__*/React.createElement(IconNavigateLeft, null)), hasRightNavigation && /*#__PURE__*/React.createElement(PlainButton, {
    className: "bcpr-navigate-right",
    onClick: () => {
      goToActiveSidebarTab(match.params, history);
      onNavigateRight();
    },
    title: intl.formatMessage(messages.nextFile),
    type: "button"
  }, /*#__PURE__*/React.createElement(IconNavigateRight, null))));
};
export { PreviewNavigation as PreviewNavigationComponent };
export default injectIntl(PreviewNavigation);
//# sourceMappingURL=PreviewNavigation.js.map