"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _react = _interopRequireDefault(require("react"));

var _propTypes = _interopRequireDefault(require("prop-types"));

var _components = require("../../components");

var _ = require("./..");

var _styleModule = _interopRequireDefault(require("./style.module.scss"));

// 3rd-Party Libraries
// Components
// Style
var StagingFeed = function StagingFeed(props) {
  var timelineContent = props.timelineContent,
      displayingDeployed = props.displayingDeployed,
      title = props.title;

  var getChangelogStuff = function getChangelogStuff(changelogs) {
    return changelogs.map(function (changelog, i) {
      return /*#__PURE__*/_react["default"].createElement(_.Log, {
        key: i,
        className: _styleModule["default"]['StagingFeed-Timeline-Day-Log_Owlet'],
        logData: changelog,
        logType: "Owlet"
      });
    });
  };

  var getAuditlogStuff = function getAuditlogStuff(auditlogs) {
    return auditlogs.map(function (auditlog, i) {
      return /*#__PURE__*/_react["default"].createElement(_.Log, {
        key: i,
        className: _styleModule["default"]['StagingFeed-Timeline-Day-Log_AuditLog'],
        logData: auditlog,
        logType: "AuditLog"
      });
    });
  };

  var dateOptions = {
    month: 'long',
    day: 'numeric',
    year: 'numeric'
  };
  var timeline;

  if (timelineContent.length > 0) {
    timeline = timelineContent.map(function (item, i) {
      var date = item.date,
          changelogs = item.changelogs,
          auditlogs = item.auditlogs;
      var changelogStuff = getChangelogStuff(changelogs);
      var auditlogStuff = getAuditlogStuff(auditlogs);
      return /*#__PURE__*/_react["default"].createElement("div", {
        key: i,
        className: _styleModule["default"]['StagingFeed-Timeline-Day']
      }, /*#__PURE__*/_react["default"].createElement(_components.Flex, {
        align: "center",
        className: _styleModule["default"]['StagingFeed-Timeline-Day-Date'],
        justify: "between"
      }, /*#__PURE__*/_react["default"].createElement("span", null, new Intl.DateTimeFormat('en-US', dateOptions).format(new Date(date)))), changelogStuff, auditlogStuff);
    });
  } else if (!displayingDeployed) {
    timeline = /*#__PURE__*/_react["default"].createElement("div", {
      className: _styleModule["default"]['StagingFeed-Timeline-Day']
    }, /*#__PURE__*/_react["default"].createElement("div", {
      className: _styleModule["default"]['StagingFeed-Timeline-Day-Date']
    }, new Intl.DateTimeFormat('en-US', dateOptions).format(new Date())));
  } else {
    timeline = /*#__PURE__*/_react["default"].createElement("div", {
      className: _styleModule["default"]['StagingFeed-Timeline-Day']
    }, /*#__PURE__*/_react["default"].createElement("div", {
      className: _styleModule["default"]['StagingFeed-Timeline-Day-Date']
    }, new Intl.DateTimeFormat('en-US', dateOptions).format(new Date())), /*#__PURE__*/_react["default"].createElement("div", {
      className: _styleModule["default"]['StagingFeed-Timeline-Day-Deployed_empty']
    }, "No deployment history"));
  }

  return /*#__PURE__*/_react["default"].createElement("div", {
    className: // eslint-disable-next-line dot-notation
    displayingDeployed ? [_styleModule["default"].StagingFeed, _styleModule["default"]['StagingFeed_deployed']].join(' ') : _styleModule["default"].StagingFeed
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: _styleModule["default"]['StagingFeed-Inner']
  }, /*#__PURE__*/_react["default"].createElement(_components.Flex, {
    className: _styleModule["default"]['StagingFeed-Timeline']
  }, /*#__PURE__*/_react["default"].createElement(_components.Title, {
    className: _styleModule["default"]['StagingFeed-Timeline-Heading'],
    level: 5
  }, title), /*#__PURE__*/_react["default"].createElement(_components.Flex, {
    className: _styleModule["default"]['StagingFeed-Timeline-Content'],
    layout: "col"
  }, timeline))));
};

StagingFeed.propTypes = {
  displayingDeployed: _propTypes["default"].bool,
  timelineContent: _propTypes["default"].array.isRequired,
  title: _propTypes["default"].string
};
var _default = StagingFeed;
exports["default"] = _default;