"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.PrivatePostLastRevision = PrivatePostLastRevision;
exports.default = void 0;
var _i18n = require("@wordpress/i18n");
var _components = require("@wordpress/components");
var _data = require("@wordpress/data");
var _icons = require("@wordpress/icons");
var _url = require("@wordpress/url");
var _check = _interopRequireDefault(require("./check"));
var _postPanelRow = _interopRequireDefault(require("../post-panel-row"));
var _store = require("../../store");
var _jsxRuntime = require("react/jsx-runtime");
/**
 * WordPress dependencies
 */

/**
 * Internal dependencies
 */

function usePostLastRevisionInfo() {
  return (0, _data.useSelect)(select => {
    const {
      getCurrentPostLastRevisionId,
      getCurrentPostRevisionsCount
    } = select(_store.store);
    return {
      lastRevisionId: getCurrentPostLastRevisionId(),
      revisionsCount: getCurrentPostRevisionsCount()
    };
  }, []);
}

/**
 * Renders the component for displaying the last revision of a post.
 *
 * @return {Component} The component to be rendered.
 */
function PostLastRevision() {
  const {
    lastRevisionId,
    revisionsCount
  } = usePostLastRevisionInfo();
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_check.default, {
    children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
      __next40pxDefaultSize: true,
      href: (0, _url.addQueryArgs)('revision.php', {
        revision: lastRevisionId
      }),
      className: "editor-post-last-revision__title",
      icon: _icons.backup,
      iconPosition: "right",
      text: (0, _i18n.sprintf)( /* translators: %s: number of revisions */
      (0, _i18n.__)('Revisions (%s)'), revisionsCount)
    })
  });
}
function PrivatePostLastRevision() {
  const {
    lastRevisionId,
    revisionsCount
  } = usePostLastRevisionInfo();
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_check.default, {
    children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_postPanelRow.default, {
      label: (0, _i18n.__)('Revisions'),
      children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
        href: (0, _url.addQueryArgs)('revision.php', {
          revision: lastRevisionId
        }),
        className: "editor-private-post-last-revision__button",
        text: revisionsCount,
        variant: "tertiary",
        size: "compact"
      })
    })
  });
}
var _default = exports.default = PostLastRevision;
//# sourceMappingURL=index.js.map