"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("../..");

// 3rd-Party Libraries
// Components
// Style
var classes = {};
/* istanbul ignore next */

if (typeof window !== 'undefined' || typeof _COMPILED_ === 'undefined') classes = {
  "slate": "#384248",
  "blue": "#118CFD",
  "green": "#12CA93",
  "red": "#E95F6A",
  "yellow": "#F7C543",
  "purple": "#8470BE",
  "graphite": "#4F5A66",
  "shale": "#939EAE",
  "chalk": "#c6cbd3",
  "ivory": "#F0F0F0",
  "lightGray": "#F8F8F8",
  "white": "#FFF",
  "StagingFeed": "_3QvE--StagingFeed",
  "StagingFeed_deployed": "_3DuJ4-StagingFeed_deployed",
  "StagingFeed-Inner": "_1uHlx-StagingFeed-Inner",
  "StagingFeed-Timeline": "gMX_T-StagingFeed-Timeline",
  "StagingFeed-Timeline-Heading": "i4ZwT-StagingFeed-Timeline-Heading",
  "StagingFeed-Timeline-Day": "_24GaG-StagingFeed-Timeline-Day",
  "StagingFeed-Timeline-Day-Empty": "_2epuH-StagingFeed-Timeline-Day-Empty",
  "StagingFeed-Timeline-Day-Date": "_2dKo7-StagingFeed-Timeline-Day-Date",
  "StagingFeed-Timeline-Day-Owlet": "Hs9cO-StagingFeed-Timeline-Day-Owlet",
  "StagingFeed-Timeline-Content": "_1eADl-StagingFeed-Timeline-Content"
};

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: classes['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: classes['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: classes['StagingFeed-Timeline-Day']
      }, /*#__PURE__*/_react["default"].createElement(_components.Flex, {
        align: "center",
        className: classes['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: classes['StagingFeed-Timeline-Day']
    }, /*#__PURE__*/_react["default"].createElement("div", {
      className: classes['StagingFeed-Timeline-Day-Date']
    }, new Intl.DateTimeFormat('en-US', dateOptions).format(new Date())), timelineContent.length === 0 && /*#__PURE__*/_react["default"].createElement("div", {
      className: classes['StagingFeed-Timeline-Day-Empty']
    }, "No changes since the last deploy."));
  } else {
    timeline = /*#__PURE__*/_react["default"].createElement("div", {
      className: classes['StagingFeed-Timeline-Day']
    }, /*#__PURE__*/_react["default"].createElement("div", {
      className: classes['StagingFeed-Timeline-Day-Date']
    }, new Intl.DateTimeFormat('en-US', dateOptions).format(new Date())), /*#__PURE__*/_react["default"].createElement("div", {
      className: classes['StagingFeed-Timeline-Day-Deployed_empty']
    }, "No deployment history"));
  }

  return /*#__PURE__*/_react["default"].createElement("div", {
    className: // eslint-disable-next-line dot-notation
    displayingDeployed ? [classes.StagingFeed, classes['StagingFeed_deployed']].join(' ') : classes.StagingFeed
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: classes['StagingFeed-Inner']
  }, /*#__PURE__*/_react["default"].createElement(_components.Flex, {
    className: classes['StagingFeed-Timeline']
  }, /*#__PURE__*/_react["default"].createElement(_components.Title, {
    className: classes['StagingFeed-Timeline-Heading'],
    level: 5
  }, title), /*#__PURE__*/_react["default"].createElement(_components.Flex, {
    className: classes['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;