"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _base = _interopRequireDefault(require("@emotion/styled/base"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _react = _interopRequireDefault(require("react"));
var _reactImmutableProptypes = _interopRequireDefault(require("react-immutable-proptypes"));
var _react2 = require("@emotion/react");
var _reactPolyglot = require("react-polyglot");
var _reactRouterDom = require("react-router-dom");
var _decapCmsUiDefault = require("decap-cms-ui-default");
var _reactRedux = require("react-redux");
var _UI = require("../UI");
var _status = require("../../actions/status");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function _EMOTION_STRINGIFIED_CSS_ERROR__() { return "You have tried to stringify object returned from `css` function. It isn't supposed to be used directly (e.g. as value of the `className` prop), but rather handed to emotion so it can handle it (e.g. as value of `css` prop)."; }
const styles = {
  buttonActive: /*#__PURE__*/(0, _react2.css)("color:", _decapCmsUiDefault.colors.active, ";;label:buttonActive;" + (process.env.NODE_ENV === "production" ? "" : "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,[encoded data, 8196 characters] */"))
};
function AppHeader(props) {
  return (0, _react2.jsx)("header", _extends({
    css: /*#__PURE__*/(0, _react2.css)(_decapCmsUiDefault.shadows.dropMain, ";position:sticky;width:100%;top:0;background-color:", _decapCmsUiDefault.colors.foreground, ";z-index:", _decapCmsUiDefault.zIndex.zIndex300, ";height:", _decapCmsUiDefault.lengths.topBarHeight, ";;label:AppHeader;" + (process.env.NODE_ENV === "production" ? "" : "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,[encoded data, 8192 characters] */"))
  }, props));
}
const AppHeaderContent = /*#__PURE__*/(0, _base.default)("div", {
  target: "e1rbzf6g4",
  label: "AppHeaderContent"
})(process.env.NODE_ENV === "production" ? {
  name: "jxf21e",
  styles: "display:flex;justify-content:space-between;min-width:800px;max-width:1440px;padding:0 12px;margin:0 auto"
} : {
  name: "jxf21e",
  styles: "display:flex;justify-content:space-between;min-width:800px;max-width:1440px;padding:0 12px;margin:0 auto",
  map: "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,[encoded data, 8196 characters] */",
  toString: _EMOTION_STRINGIFIED_CSS_ERROR__
});
const AppHeaderButton = /*#__PURE__*/(0, _base.default)("button", {
  target: "e1rbzf6g3",
  label: "AppHeaderButton"
})(_decapCmsUiDefault.buttons.button, ";background:none;color:#7b8290;font-family:inherit;font-size:16px;font-weight:500;display:inline-flex;padding:16px 20px;align-items:center;", _decapCmsUiDefault.Icon, "{margin-right:4px;color:#b3b9c4;}&:hover,&:active,&:focus-visible{", styles.buttonActive, ";", _decapCmsUiDefault.Icon, "{", styles.buttonActive, ";}}", props => /*#__PURE__*/(0, _react2.css)("&.", props.activeClassName, "{", styles.buttonActive, ";", _decapCmsUiDefault.Icon, "{", styles.buttonActive, ";}};label:AppHeaderButton;" + (process.env.NODE_ENV === "production" ? "" : "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,[encoded data, 8196 characters] */")), ";" + (process.env.NODE_ENV === "production" ? "" : "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,[encoded data, 8196 characters] */"));
const AppHeaderNavLink = AppHeaderButton.withComponent(_reactRouterDom.NavLink, {
  target: "e1rbzf6g5",
  label: "AppHeaderNavLink"
});
const AppHeaderActions = /*#__PURE__*/(0, _base.default)("div", {
  target: "e1rbzf6g2",
  label: "AppHeaderActions"
})(process.env.NODE_ENV === "production" ? {
  name: "8irbms",
  styles: "display:inline-flex;align-items:center"
} : {
  name: "8irbms",
  styles: "display:inline-flex;align-items:center",
  map: "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,[encoded data, 8196 characters] */",
  toString: _EMOTION_STRINGIFIED_CSS_ERROR__
});
const AppHeaderQuickNewButton = /*#__PURE__*/(0, _base.default)(_decapCmsUiDefault.StyledDropdownButton, {
  target: "e1rbzf6g1",
  label: "AppHeaderQuickNewButton"
})(_decapCmsUiDefault.buttons.button, ";", _decapCmsUiDefault.buttons.medium, ";", _decapCmsUiDefault.buttons.gray, ";margin-right:8px;&:after{top:11px;}" + (process.env.NODE_ENV === "production" ? "" : "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,[encoded data, 8196 characters] */"));
const AppHeaderNavList = /*#__PURE__*/(0, _base.default)("ul", {
  target: "e1rbzf6g0",
  label: "AppHeaderNavList"
})(process.env.NODE_ENV === "production" ? {
  name: "1vufzxm",
  styles: "display:flex;margin:0;list-style:none"
} : {
  name: "1vufzxm",
  styles: "display:flex;margin:0;list-style:none",
  map: "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,[encoded data, 8196 characters] */",
  toString: _EMOTION_STRINGIFIED_CSS_ERROR__
});
class Header extends _react.default.Component {
  constructor(...args) {
    super(...args);
    _defineProperty(this, "intervalId", void 0);
    _defineProperty(this, "handleCreatePostClick", collectionName => {
      const {
        onCreateEntryClick
      } = this.props;
      if (onCreateEntryClick) {
        onCreateEntryClick(collectionName);
      }
    });
  }
  componentDidMount() {
    this.intervalId = setInterval(() => {
      this.props.checkBackendStatus();
    }, 5 * 60 * 1000);
  }
  componentWillUnmount() {
    clearInterval(this.intervalId);
  }
  render() {
    const {
      user,
      collections,
      onLogoutClick,
      openMediaLibrary,
      hasWorkflow,
      displayUrl,
      isTestRepo,
      t,
      showMediaButton
    } = this.props;
    const creatableCollections = collections.filter(collection => collection.get('create')).toList();
    return (0, _react2.jsx)(AppHeader, null, (0, _react2.jsx)(AppHeaderContent, null, (0, _react2.jsx)("nav", null, (0, _react2.jsx)(AppHeaderNavList, null, (0, _react2.jsx)("li", null, (0, _react2.jsx)(AppHeaderNavLink, {
      to: "/",
      activeClassName: "header-link-active",
      isActive: (match, location) => location.pathname.startsWith('/collections/')
    }, (0, _react2.jsx)(_decapCmsUiDefault.Icon, {
      type: "page"
    }), t('app.header.content'))), hasWorkflow && (0, _react2.jsx)("li", null, (0, _react2.jsx)(AppHeaderNavLink, {
      to: "/workflow",
      activeClassName: "header-link-active"
    }, (0, _react2.jsx)(_decapCmsUiDefault.Icon, {
      type: "workflow"
    }), t('app.header.workflow'))), showMediaButton && (0, _react2.jsx)("li", null, (0, _react2.jsx)(AppHeaderButton, {
      onClick: openMediaLibrary
    }, (0, _react2.jsx)(_decapCmsUiDefault.Icon, {
      type: "media-alt"
    }), t('app.header.media'))))), (0, _react2.jsx)(AppHeaderActions, null, creatableCollections.size > 0 && (0, _react2.jsx)(_decapCmsUiDefault.Dropdown, {
      renderButton: () => (0, _react2.jsx)(AppHeaderQuickNewButton, null, " ", t('app.header.quickAdd')),
      dropdownTopOverlap: "30px",
      dropdownWidth: "160px",
      dropdownPosition: "left"
    }, creatableCollections.map(collection => (0, _react2.jsx)(_decapCmsUiDefault.DropdownItem, {
      key: collection.get('name'),
      label: collection.get('label_singular') || collection.get('label'),
      onClick: () => this.handleCreatePostClick(collection.get('name'))
    }))), (0, _react2.jsx)(_UI.SettingsDropdown, {
      displayUrl: displayUrl,
      isTestRepo: isTestRepo,
      imageUrl: user === null || user === void 0 ? void 0 : user.avatar_url,
      onLogoutClick: onLogoutClick
    }))));
  }
}
_defineProperty(Header, "propTypes", {
  user: _propTypes.default.object.isRequired,
  collections: _reactImmutableProptypes.default.map.isRequired,
  onCreateEntryClick: _propTypes.default.func.isRequired,
  onLogoutClick: _propTypes.default.func.isRequired,
  openMediaLibrary: _propTypes.default.func.isRequired,
  hasWorkflow: _propTypes.default.bool.isRequired,
  displayUrl: _propTypes.default.string,
  isTestRepo: _propTypes.default.bool,
  t: _propTypes.default.func.isRequired,
  checkBackendStatus: _propTypes.default.func.isRequired
});
const mapDispatchToProps = {
  checkBackendStatus: _status.checkBackendStatus
};
var _default = exports.default = (0, _reactRedux.connect)(null, mapDispatchToProps)((0, _reactPolyglot.translate)()(Header));