import React from "react";
import { connect } from "../../../redux";
import { css } from "emotion";
import { useRouter } from "@webiny/react-router";
import { Menu, MenuItem } from "@webiny/ui/Menu";
import { getRevisions } from "../../../selectors";
import { ButtonDefault } from "@webiny/ui/Button";
import { Icon } from "@webiny/ui/Icon";
import { Typography } from "@webiny/ui/Typography";
import { ReactComponent as DownButton } from "@svgr/webpack!./icons/round-arrow_drop_down-24px.svg";
var buttonStyle = /*#__PURE__*/css({
  "&.mdc-button": {
    color: "var(--mdc-theme-text-primary-on-background) !important"
  }
}, "label:buttonStyle;");
var menuList = /*#__PURE__*/css({
  ".mdc-list-item": {
    flexDirection: "column",
    justifyContent: "center",
    alignItems: "baseline",
    textAlign: "left"
  }
}, "label:menuList;");

var Revisions = function Revisions(_ref) {
  var revisions = _ref.revisions;

  var _useRouter = useRouter(),
      history = _useRouter.history;

  return /*#__PURE__*/React.createElement(Menu, {
    className: menuList,
    onSelect: function onSelect(evt) {
      history.push("/page-builder/editor/".concat(revisions[evt.detail.index].id));
    },
    handle: /*#__PURE__*/React.createElement(ButtonDefault, {
      className: buttonStyle
    }, "Revisions ", /*#__PURE__*/React.createElement(Icon, {
      icon: /*#__PURE__*/React.createElement(DownButton, null)
    }))
  }, revisions.map(function (rev) {
    var status = "draft";

    if (rev.published) {
      status = "published";
    }

    if (rev.locked && !rev.published) {
      status = "locked";
    }

    return /*#__PURE__*/React.createElement(MenuItem, {
      key: rev.id,
      disabled: status !== "draft"
    }, /*#__PURE__*/React.createElement(Typography, {
      use: "body2"
    }, "v", rev.version), /*#__PURE__*/React.createElement(Typography, {
      use: "caption"
    }, "(", status, ") "));
  }));
};

export default connect(function (state) {
  return {
    revisions: getRevisions(state)
  };
})( /*#__PURE__*/React.memo(Revisions));
//# sourceMappingURL=Revisions.js.map