"use strict";

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

/**
 * Internal dependencies
 */

function SidebarNavigationScreenDetailsFooter({
  record,
  revisionsCount,
  ...otherProps
}) {
  var _record$_links$predec;
  /*
   * 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;

  // Use incoming prop first, then the record's version history, if available.
  revisionsCount = revisionsCount || record?._links?.['version-history']?.[0]?.count || 0;

  /*
   * Enable the revisions link if there is a last revision and there is more than one revision.
   * This link is used for theme assets, e.g., templates, which have no database record until they're edited.
   * For these files there's only a "revision" after they're edited twice,
   * which means the revision.php page won't display a proper diff.
   * See: https://github.com/WordPress/gutenberg/issues/49164.
   */
  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, {
    size: "large",
    className: "edit-site-sidebar-navigation-screen-details-footer",
    children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_sidebarNavigationItem.default, {
      icon: _icons.backup,
      ...hrefProps,
      ...otherProps,
      children: (0, _i18n.sprintf)(/* translators: %d: Number of Styles revisions. */
      (0, _i18n._n)('%d Revision', '%d Revisions', revisionsCount), revisionsCount)
    })
  });
}
//# sourceMappingURL=index.js.map