import "choerodon-ui/pro/lib/table/style";
import _Table from "@hzero-front-ui/c7n-ui/lib/TablePro";

function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }

function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }

function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

import React, { Fragment, useState } from 'react';
import { Action } from '@choerodon/boot';
import StatusTags from "../../../../../../components/status-tag";
import TimePopover from "../../../../../../components/timePopover";
import { useNodeContentStore } from "../stores";
import LogSiderbar from "../../../../../../components/log-siderbar";
import { useClusterStore } from "../../../../stores";
import "./index.less";
var Column = _Table.Column;

var NodePodsTable = function NodePodsTable() {
  var _useNodeContentStore = useNodeContentStore(),
      formatMessage = _useNodeContentStore.formatMessage,
      nodePodsDs = _useNodeContentStore.nodePodsDs;

  var _useClusterStore = useClusterStore(),
      parentId = _useClusterStore.clusterStore.getSelectedMenu.parentId;

  var _useState = useState(false),
      _useState2 = _slicedToArray(_useState, 2),
      visible = _useState2[0],
      setVisible = _useState2[1];

  var _useState3 = useState(),
      _useState4 = _slicedToArray(_useState3, 2),
      recordData = _useState4[0],
      setRecordData = _useState4[1];

  var renderStatus = function renderStatus(_ref) {
    var record = _ref.record;
    var status = record.get('status');
    var name = record.get('name');
    return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(StatusTags, {
      name: status,
      colorCode: status
    }), /*#__PURE__*/React.createElement("span", null, name));
  };

  var renderCreationDate = function renderCreationDate(_ref2) {
    var record = _ref2.record;
    var creationDate = record.get('creationDate');
    return /*#__PURE__*/React.createElement(TimePopover, {
      content: creationDate
    });
  };

  function openLog(record) {
    setRecordData(record.toData());
    setVisible(true);
  }

  function closeLog() {
    setVisible(false);
  }

  function renderActions(_ref3) {
    var record = _ref3.record;
    var actionData = [{
      service: [],
      text: formatMessage({
        id: 'node.log'
      }),
      action: function action() {
        return openLog(record);
      }
    }];
    return /*#__PURE__*/React.createElement(Action, {
      data: actionData
    });
  }

  return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(_Table, {
    dataSet: nodePodsDs,
    border: false,
    queryBar: "none",
    className: "c7ncd-node-pods-table"
  }, /*#__PURE__*/React.createElement(Column, {
    header: formatMessage({
      id: 'status'
    }),
    renderer: renderStatus
  }), /*#__PURE__*/React.createElement(Column, {
    renderer: renderActions
  }), /*#__PURE__*/React.createElement(Column, {
    header: formatMessage({
      id: 'ciPipeline.createdAt'
    }),
    renderer: renderCreationDate
  })), visible && /*#__PURE__*/React.createElement(LogSiderbar, {
    visible: visible,
    onClose: closeLog,
    record: recordData,
    clusterId: parentId
  }));
};

export default NodePodsTable;