"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = SidebarNavigationScreenDetailsFooter;
var _i18n = require("@wordpress/i18n");
var _date = require("@wordpress/date");
var _element = require("@wordpress/element");
var _url = require("@wordpress/url");
var _components = require("@wordpress/components");
var _icons = require("@wordpress/icons");
var _sidebarNavigationScreenDetailsPanel = require("../sidebar-navigation-screen-details-panel");
var _sidebarNavigationItem = _interopRequireDefault(require("../sidebar-navigation-item"));
var _jsxRuntime = require("react/jsx-runtime");
/**
 * WordPress dependencies
 */

/**
 * Internal dependencies
 */

function SidebarNavigationScreenDetailsFooter({
  record,
  ...otherProps
}) {
  var _record$_links$predec, _record$_links$versio;
  /*
   * There might be other items in the future,
   * but for now it's just modified date.
   * Later we might render a list of items and isolate
   * the following logic.
   */
  const hrefProps = {};
  const lastRevisionId = (_record$_links$predec = record?._links?.['predecessor-version']?.[0]?.id) !== null && _record$_links$predec !== void 0 ? _record$_links$predec : null;
  const revisionsCount = (_record$_links$versio = record?._links?.['version-history']?.[0]?.count) !== null && _record$_links$versio !== void 0 ? _record$_links$versio : 0;
  // Enable the revisions link if there is a last revision and there are more than one revisions.
  if (lastRevisionId && revisionsCount > 1) {
    hrefProps.href = (0, _url.addQueryArgs)('revision.php', {
      revision: record?._links['predecessor-version'][0].id
    });
    hrefProps.as = 'a';
  }
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.__experimentalItemGroup, {
    className: "edit-site-sidebar-navigation-screen-details-footer",
    children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_sidebarNavigationItem.default, {
      "aria-label": (0, _i18n.__)('Revisions'),
      ...hrefProps,
      ...otherProps,
      children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_sidebarNavigationScreenDetailsPanel.SidebarNavigationScreenDetailsPanelRow, {
        justify: "space-between",
        children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_sidebarNavigationScreenDetailsPanel.SidebarNavigationScreenDetailsPanelLabel, {
          children: (0, _i18n.__)('Last modified')
        }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_sidebarNavigationScreenDetailsPanel.SidebarNavigationScreenDetailsPanelValue, {
          children: (0, _element.createInterpolateElement)((0, _i18n.sprintf)(/* translators: %s: is the relative time when the post was last modified. */
          (0, _i18n.__)('<time>%s</time>'), (0, _date.humanTimeDiff)(record.modified)), {
            time: /*#__PURE__*/(0, _jsxRuntime.jsx)("time", {
              dateTime: record.modified
            })
          })
        }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Icon, {
          className: "edit-site-sidebar-navigation-screen-details-footer__icon",
          icon: _icons.backup
        })]
      })
    })
  });
}
//# sourceMappingURL=index.js.map