import "choerodon-ui/lib/spin/style";
import _Spin from "@hzero-front-ui/c7n-ui/lib/Spin";
import React, { Fragment } from 'react';
import { FormattedMessage } from 'react-intl';
import { observer } from 'mobx-react-lite';
import map from 'lodash/map';
import { Permission } from '@choerodon/boot';
import ResourceTitle from "../../components/resource-title";
import { useResourceStore } from "../../../stores";
import { useCertDetailStore } from "./stores";
import Modals from "./modals";
import "./index.less";
var Content = observer(function () {
  var _useResourceStore = useResourceStore(),
      prefixCls = _useResourceStore.prefixCls,
      intlPrefix = _useResourceStore.intlPrefix,
      formatMessage = _useResourceStore.intl.formatMessage;

  var _useCertDetailStore = useCertDetailStore(),
      detailDs = _useCertDetailStore.detailDs;

  function getContent() {
    var record = detailDs.current;
    var dnsNames;
    var ingresses;
    var commonName;

    if (record) {
      dnsNames = record.get('DNSNames');
      ingresses = record.get('ingresses');
      commonName = record.get('commonName');
    }

    var dnsNode = dnsNames ? map(dnsNames, function (item) {
      return /*#__PURE__*/React.createElement("li", {
        className: "".concat(prefixCls, "-detail-section-li")
      }, /*#__PURE__*/React.createElement("span", {
        className: "detail-section-li-text"
      }, "DNSNames:\xA0"), /*#__PURE__*/React.createElement("span", null, item));
    }) : /*#__PURE__*/React.createElement("span", {
      style: {
        color: 'rgba(0,0,0,.65)'
      }
    }, formatMessage({
      id: 'nodata'
    }));
    var ingressNode = ingresses && ingresses.length > 0 ? map(ingresses, function (item) {
      return /*#__PURE__*/React.createElement("li", {
        className: "".concat(prefixCls, "-detail-section-li")
      }, /*#__PURE__*/React.createElement("span", null, item));
    }) : /*#__PURE__*/React.createElement("span", {
      style: {
        color: 'rgba(0,0,0,.65)'
      }
    }, formatMessage({
      id: 'nodata'
    }));
    return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
      className: "".concat(prefixCls, "-detail-content-section-title")
    }, /*#__PURE__*/React.createElement(FormattedMessage, {
      id: "".concat(intlPrefix, ".domains")
    })), /*#__PURE__*/React.createElement("div", {
      className: "".concat(prefixCls, "-detail-content-section-name")
    }, /*#__PURE__*/React.createElement("span", null, "CommonName:\xA0"), /*#__PURE__*/React.createElement("span", null, commonName)), /*#__PURE__*/React.createElement("ul", {
      className: "".concat(prefixCls, "-detail-section-ul")
    }, dnsNode)), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
      className: "".concat(prefixCls, "-detail-content-section-title")
    }, /*#__PURE__*/React.createElement(FormattedMessage, {
      id: "".concat(intlPrefix, ".current.domains")
    })), /*#__PURE__*/React.createElement("ul", {
      className: "".concat(prefixCls, "-detail-section-ul")
    }, ingressNode)));
  }

  return /*#__PURE__*/React.createElement(Permission, {
    service: ['choerodon.code.project.deploy.app-deployment.resource.ps.cert-detail']
  }, /*#__PURE__*/React.createElement("div", {
    className: "".concat(prefixCls, "-certificate-detail")
  }, /*#__PURE__*/React.createElement(ResourceTitle, {
    iconType: "class",
    record: detailDs.current,
    statusKey: "commandStatus"
  }), /*#__PURE__*/React.createElement(_Spin, {
    spinning: detailDs.status === 'loading'
  }, getContent()), /*#__PURE__*/React.createElement(Modals, null)));
});
export default Content;