import "choerodon-ui/pro/lib/table/style";
import _Table from "@hzero-front-ui/c7n-ui/lib/TablePro";
import React, { Fragment } from 'react';
import { observer } from 'mobx-react-lite';
import StatusIcon from "../../../../../components/StatusIcon";
import StatusTags from "../../../../../components/status-tag";
import AppName from "../../../../../components/appName";
import PodStatus from "./components/pod-status";
import { useResourceStore } from "../../../stores";
import { useIstListStore } from "./stores";
import Modals from "./modals";
import UploadIcon from "./components/upload-icon";
import ResourceListTitle from "../../components/resource-list-title";
import "./index.less";
var Column = _Table.Column;
var Content = observer(function () {
  var _useResourceStore = useResourceStore(),
      prefixCls = _useResourceStore.prefixCls,
      intlPrefix = _useResourceStore.intlPrefix,
      parentId = _useResourceStore.resourceStore.getSelectedMenu.parentId,
      id = _useResourceStore.AppState.currentMenuType.id;

  var _useIstListStore = useIstListStore(),
      istListDs = _useIstListStore.istListDs,
      formatMessage = _useIstListStore.intl.formatMessage;

  function renderName(_ref) {
    var value = _ref.value,
        record = _ref.record;
    var status = record.get('status');
    var error = record.get('error');
    return /*#__PURE__*/React.createElement(StatusIcon, {
      name: value,
      width: 0.2,
      status: status || '',
      error: error || ''
    });
  }

  function renderVersion(_ref2) {
    var record = _ref2.record;
    return /*#__PURE__*/React.createElement(UploadIcon, {
      dataSource: record.toData()
    });
  }

  function renderAppName(_ref3) {
    var value = _ref3.value,
        record = _ref3.record;
    var appServiceType = record.get('appServiceType');
    var iconType;

    if (appServiceType === 'share_service') {
      iconType = 'share';
    } else if (['middleware_service', 'market_service'].includes(appServiceType)) {
      iconType = 'application_market';
    } else {
      iconType = 'widgets';
    }

    return /*#__PURE__*/React.createElement(AppName, {
      width: 0.18,
      name: value,
      showIcon: !!record.get('projectId'),
      self: iconType,
      isInstance: true
    });
  }

  function renderPods(_ref4) {
    var record = _ref4.record;
    var dataSource = record.toData();
    return /*#__PURE__*/React.createElement(PodStatus, {
      dataSource: dataSource
    });
  }

  return /*#__PURE__*/React.createElement("div", {
    className: "".concat(prefixCls, "-instance-table")
  }, /*#__PURE__*/React.createElement(Modals, null), /*#__PURE__*/React.createElement(ResourceListTitle, {
    type: "instances"
  }), /*#__PURE__*/React.createElement(_Table, {
    dataSet: istListDs,
    border: false,
    queryBar: "bar"
  }, /*#__PURE__*/React.createElement(Column, {
    name: "code",
    renderer: renderName,
    sortable: true
  }), /*#__PURE__*/React.createElement(Column, {
    name: "versionName",
    renderer: renderVersion
  }), /*#__PURE__*/React.createElement(Column, {
    name: "appServiceName",
    renderer: renderAppName,
    sortable: true
  }), /*#__PURE__*/React.createElement(Column, {
    renderer: renderPods,
    width: "1rem",
    header: formatMessage({
      id: "".concat(intlPrefix, ".instance.pod.status")
    })
  })));
});
export default Content;