"use strict";

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

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

var _reactRouterDom = require("react-router-dom");

var _dayjs = _interopRequireDefault(require("dayjs"));

var _uuid = require("uuid");

var _responders = _interopRequireDefault(require("../../../data/responders.json"));

var _incidentSeverity = require("../incident-severity");

var _incidentStatus = require("../incident-status");

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

var _excluded = ["list"];

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

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

function IncidentList(_ref) {
  var list = _ref.list,
      rest = _objectWithoutProperties(_ref, _excluded);

  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
    className: "border border-gray-200 rounded-md",
    children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("table", _objectSpread(_objectSpread({
      className: "table-auto w-full",
      "aria-label": "table"
    }, rest), {}, {
      children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("thead", {
        className: "rounded-md",
        children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("tr", {
          className: "border-b border-gray-200 uppercase bg-column-background rounded-t-md items-center",
          children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("th", {
            className: "px-6 py-3 text-gray-500 font-medium text-xs col-span-2 text-left",
            colSpan: 2,
            children: "Name"
          }), /*#__PURE__*/(0, _jsxRuntime.jsx)("th", {
            className: "px-3 py-3 text-gray-500 font-medium text-xs text-left",
            children: "Severity"
          }), /*#__PURE__*/(0, _jsxRuntime.jsx)("th", {
            className: "px-3 py-3 text-gray-500 font-medium text-xs text-left",
            children: "Status"
          }), /*#__PURE__*/(0, _jsxRuntime.jsx)("th", {
            className: "px-3 py-3 text-gray-500 font-medium text-xs text-left",
            children: "Age"
          }), /*#__PURE__*/(0, _jsxRuntime.jsx)("th", {
            className: "px-3 py-3 text-gray-500 font-medium text-xs col-span-2 text-left",
            colSpan: 2,
            children: "Responders"
          })]
        })
      }), /*#__PURE__*/(0, _jsxRuntime.jsx)("tbody", {
        className: "flex-1 overflow-y-auto",
        children: list.map(function (incident) {
          return /*#__PURE__*/(0, _jsxRuntime.jsx)(IncidentItem, {
            incident: incident
          }, (0, _uuid.v4)());
        })
      })]
    }))
  });
}

function IncidentItem(_ref2) {
  var incident = _ref2.incident;
  var title = incident.title,
      id = incident.id,
      createdAt = incident.created_at;
  var age = (0, _dayjs.default)(createdAt).fromNow();
  var navigate = (0, _reactRouterDom.useNavigate)();

  var navigateToIncidentDetails = function navigateToIncidentDetails(id) {
    navigate("/incidents/".concat(id));
  };

  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("tr", {
    className: "last:border-b-0 border-b cursor-pointer",
    onClick: function onClick() {
      return navigateToIncidentDetails(id);
    },
    children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("td", {
      colSpan: 2,
      className: "px-6 py-4 text-gray-900 col-span-2 text-sm leading-5 font-medium",
      children: title
    }), /*#__PURE__*/(0, _jsxRuntime.jsx)("td", {
      className: "py-4 px-3",
      children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
        className: "flex flex-row items-center",
        children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_incidentSeverity.IncidentSeverity, {
          incident: incident
        })
      })
    }), /*#__PURE__*/(0, _jsxRuntime.jsx)("td", {
      className: "px-3 py-4 shrink-0",
      children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_incidentStatus.IncidentStatus, {
        incident: incident
      })
    }), /*#__PURE__*/(0, _jsxRuntime.jsx)("td", {
      className: "px-3 text-gray-500 text-sm py-4",
      children: age
    }), /*#__PURE__*/(0, _jsxRuntime.jsx)("td", {
      className: "px-3 text-sm py-4",
      colSpan: 2,
      children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
        className: "flex",
        children: _responders.default.map(function (_ref3) {
          var image = _ref3.image,
              name = _ref3.name;
          return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
            className: "flex flex-row mr-4 items-center justify-between",
            children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("img", {
              className: "h-6 w-6 rounded-full bg-gray-400",
              src: image,
              alt: ""
            }), /*#__PURE__*/(0, _jsxRuntime.jsx)("p", {
              className: "ml-1 text-sm text-dark-gray font-normal",
              children: name
            })]
          }, name);
        })
      })
    })]
  });
}