"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.StatusHistory = StatusHistory;

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

var _timeago = require("timeago.js");

var _renderers = require("../renderers");

var _utils = require("../utils");

var _Table = require("../../Table");

var _jsxRuntime = require("react/jsx-runtime");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function StatusHistory(_ref) {
  var check = _ref.check,
      _ref$sticky = _ref.sticky,
      sticky = _ref$sticky === void 0 ? "false" : _ref$sticky;
  var statii = check ? check.checkStatuses != null ? check.checkStatuses : [] : [];
  var data = [];
  statii.forEach(function (status) {
    data.push({
      key: "".concat(check.id, ".").concat(check.description),
      age: (0, _timeago.format)("".concat(status.time, " UTC")),
      message: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
        children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_renderers.CanaryStatus, {
          status: status
        }), " ", status.message, " ", !(0, _utils.isEmpty)(status.error) && status.error.split("\n").map(function (item) {
          return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
            children: [item, /*#__PURE__*/(0, _jsxRuntime.jsx)("br", {})]
          });
        })]
      }),
      duration: /*#__PURE__*/(0, _jsxRuntime.jsx)(_renderers.Duration, {
        ms: status.duration
      })
    });
  });
  return check && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Table.Table, {
    id: "".concat(check.id, "-table"),
    data: data,
    columns: ["Age", "Duration", "Message"],
    sticky: sticky
  });
}