import React from 'react';
import _ from 'lodash';
import "./index.less";
/**
 * 传入一个数组，返回这个数组的每一项组成的段落
 * @param arr 遍历的数组
 * @param valueKey p标签中文本 在数组元素中的key 不传直接取数组的元素
 */

function generateManyP(arr, valueKey) {
  return _.map(arr, function (value, key) {
    return /*#__PURE__*/React.createElement("p", {
      className: "",
      key: key
    }, valueKey ? value[valueKey] : value);
  });
}

export default function (_ref) {
  var intlPrefix = _ref.intlPrefix,
      record = _ref.record,
      prefixCls = _ref.prefixCls,
      formatMessage = _ref.formatMessage;
  var updater = record && record.get('lastUpdaterName');

  if (!updater) {
    if (record && record.get('creatorDate') === record.get('lastUpdateDate')) {
      updater = '-';
    } else {
      updater = 'GitOps';
    }
  }

  var instanceCode = '-';

  if (record && record.get('target') && record.get('target').instances && record.get('target').instances.length !== 0) {
    instanceCode = generateManyP(record.get('target').instances, 'code');
  }

  var externalIps = '-';

  if (record && record.get('config') && record.get('config').externalIps) {
    externalIps = generateManyP(record.get('config').externalIps);
  }

  return /*#__PURE__*/React.createElement("div", {
    className: "".concat(prefixCls, "-net")
  }, /*#__PURE__*/React.createElement("p", {
    className: "".concat(prefixCls, "-net-title")
  }, "\u8BE6\u60C5"), /*#__PURE__*/React.createElement("ul", {
    className: "".concat(prefixCls, "-application-detail-modal")
  }, /*#__PURE__*/React.createElement("li", {
    className: "detail-item"
  }, /*#__PURE__*/React.createElement("div", {
    className: "detail-item-one-to-many"
  }, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("span", {
    className: "detail-item-text"
  }, formatMessage({
    id: 'instance'
  }))), /*#__PURE__*/React.createElement("div", null, instanceCode))), /*#__PURE__*/React.createElement("li", {
    className: "detail-item"
  }, /*#__PURE__*/React.createElement("span", {
    className: "detail-item-text"
  }, formatMessage({
    id: "".concat(intlPrefix, ".application.net.configType")
  })), /*#__PURE__*/React.createElement("span", null, record && record.get('type') || '-')), /*#__PURE__*/React.createElement("li", {
    className: "detail-item"
  }, /*#__PURE__*/React.createElement("div", {
    className: "detail-item-one-to-many"
  }, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("span", {
    className: "detail-item-text"
  }, formatMessage({
    id: "".concat(intlPrefix, ".application.net.ip")
  }))), /*#__PURE__*/React.createElement("div", null, externalIps))), /*#__PURE__*/React.createElement("li", {
    className: "detail-item"
  }, /*#__PURE__*/React.createElement("span", {
    className: "detail-item-text"
  }, formatMessage({
    id: "".concat(intlPrefix, ".net.selecter")
  })), /*#__PURE__*/React.createElement("span", {
    className: "detail-item-more-text"
  }, record && record.get('target') && record.get('target').labels && _.map(record.get('target').labels, function (value, key) {
    return "".concat(key, "=").concat(value);
  }).join(' ,') || '-')), /*#__PURE__*/React.createElement("li", {
    className: "detail-item"
  }, /*#__PURE__*/React.createElement("span", {
    className: "detail-item-text"
  }, formatMessage({
    id: "".concat(intlPrefix, ".net.dns")
  })), /*#__PURE__*/React.createElement("span", {
    className: "detail-item-more-text"
  }, record && record.get('dns') || '-')), /*#__PURE__*/React.createElement("li", {
    className: "detail-item"
  }, /*#__PURE__*/React.createElement("span", {
    className: "detail-item-text"
  }, formatMessage({
    id: 'createDate'
  })), /*#__PURE__*/React.createElement("span", null, record && record.get('creationDate') || '-')), /*#__PURE__*/React.createElement("li", {
    className: "detail-item"
  }, /*#__PURE__*/React.createElement("span", {
    className: "detail-item-text"
  }, formatMessage({
    id: 'creator'
  })), /*#__PURE__*/React.createElement("span", null, record && record.get('creatorName') || 'GitOps')), /*#__PURE__*/React.createElement("li", {
    className: "detail-item"
  }, /*#__PURE__*/React.createElement("span", {
    className: "detail-item-text"
  }, formatMessage({
    id: 'updateDate'
  })), /*#__PURE__*/React.createElement("span", null, record && record.get('lastUpdateDate') || '-')), /*#__PURE__*/React.createElement("li", {
    className: "detail-item"
  }, /*#__PURE__*/React.createElement("span", {
    className: "detail-item-text"
  }, formatMessage({
    id: 'updater'
  })), /*#__PURE__*/React.createElement("span", null, updater))), /*#__PURE__*/React.createElement("div", {
    className: "net-hr"
  }), /*#__PURE__*/React.createElement("p", {
    className: "".concat(prefixCls, "-net-title")
  }, "\u6807\u7B7E"), record && record.get('labels') ? _.map(record.get('labels'), function (value, key) {
    return /*#__PURE__*/React.createElement("div", {
      key: key,
      className: "".concat(prefixCls, "-application-label")
    }, /*#__PURE__*/React.createElement("span", null, key), value);
  }) : /*#__PURE__*/React.createElement("span", {
    className: "detail-item-text"
  }, formatMessage({
    id: "".concat(intlPrefix, ".no.label")
  })));
}