"use strict";

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

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

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

var _columns = require("../ConfigViewer/columns");

var _index = require("../index");

var _JSONViewer = require("../JSONViewer");

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

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

var columns = [{
  Header: "Type",
  accessor: "change_type",
  cellClass: "px-5 py-2"
}, {
  Header: "Created",
  accessor: "created_at",
  Cell: _columns.DateCell,
  cellClass: "px-5 py-2"
}, {
  Header: "Changes",
  accessor: "patches",
  Cell: function JSONViewCell(_ref) {
    var row = _ref.row,
        column = _ref.column;
    return /*#__PURE__*/(0, _jsxRuntime.jsx)(_JSONViewer.JSONViewer, {
      code: JSON.stringify(row === null || row === void 0 ? void 0 : row.values[column.id], null, 2)
    });
  },
  cellClass: "px-5 py-2"
}];
var configLinkCol = [{
  Header: "Config",
  accessor: "config_id",
  Cell: function ConfigLink(_ref2) {
    var row = _ref2.row,
        column = _ref2.column;
    var id = row === null || row === void 0 ? void 0 : row.values[column.id];
    return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactRouterDom.Link, {
      className: "underline text-blue-600 hover:text-blue-800 visited:text-purple-600",
      to: "/config/".concat(id),
      children: "Show Config"
    });
  },
  cellClass: "px-5 py-2"
}];

function ConfigChangeHistory(_ref3) {
  var data = _ref3.data,
      isLoading = _ref3.isLoading,
      linkConfig = _ref3.linkConfig;
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_index.DataTable, {
    columns: linkConfig ? columns.concat(configLinkCol) : columns,
    data: data,
    tableStyle: {
      borderSpacing: "0"
    },
    isLoading: isLoading
  });
}