import "choerodon-ui/pro/lib/text-area/style";
import _TextArea from "choerodon-ui/pro/lib/text-area";
import "choerodon-ui/pro/lib/button/style";
import _Button from "choerodon-ui/pro/lib/button";
import "choerodon-ui/pro/lib/form/style";
import _Form from "@hzero-front-ui/c7n-ui/lib/FormPro";
import "choerodon-ui/pro/lib/select/style";
import _Select from "choerodon-ui/pro/lib/select";
import "choerodon-ui/pro/lib/text-field/style";
import _TextField from "choerodon-ui/pro/lib/text-field";
import "choerodon-ui/pro/lib/select-box/style";
import _SelectBox from "choerodon-ui/pro/lib/select-box";
import React, { useMemo } from 'react';
import { observer } from 'mobx-react-lite';
import map from 'lodash/map';
import { useBatchDeployStore } from "./stores";
import Tips from "../../../../components/new-tips";
var Option = _SelectBox.Option;
export default observer(function () {
  var _useBatchDeployStore = useBatchDeployStore(),
      formatMessage = _useBatchDeployStore.intl.formatMessage,
      prefixCls = _useBatchDeployStore.prefixCls,
      batchDeployDs = _useBatchDeployStore.batchDeployDs,
      pathListDs = _useBatchDeployStore.pathListDs,
      domainDs = _useBatchDeployStore.domainDs,
      annotationDs = _useBatchDeployStore.annotationDs;

  var record = domainDs.current;

  function handleAddPath() {
    pathListDs.create();
  }

  function handleRemovePath(removeRecord) {
    pathListDs.remove(removeRecord);
  }

  function handleAddAnnotation() {
    annotationDs.create();
  }

  function handleRemoveAnnotation(annotationRecord) {
    annotationDs.remove(annotationRecord);
  }

  return /*#__PURE__*/React.createElement("div", {
    className: "".concat(prefixCls, "-resource-domain")
  }, /*#__PURE__*/React.createElement(_Form, {
    dataSet: domainDs
  }, /*#__PURE__*/React.createElement(_TextField, {
    name: "name",
    disabled: batchDeployDs.current && !batchDeployDs.current.get('environmentId')
  }), /*#__PURE__*/React.createElement(_SelectBox, {
    name: "isNormal",
    className: "".concat(prefixCls, "-resource-mgt-12")
  }, /*#__PURE__*/React.createElement(Option, {
    value: true
  }, /*#__PURE__*/React.createElement("span", {
    className: "".concat(prefixCls, "-resource-radio")
  }, formatMessage({
    id: 'domain.protocol.normal'
  }))), /*#__PURE__*/React.createElement(Option, {
    value: false
  }, /*#__PURE__*/React.createElement("span", {
    className: "".concat(prefixCls, "-resource-radio")
  }, formatMessage({
    id: 'domain.protocol.secret'
  })))), /*#__PURE__*/React.createElement(_TextField, {
    name: "domain",
    disabled: batchDeployDs.current && !batchDeployDs.current.get('environmentId')
  }), !record.get('isNormal') && /*#__PURE__*/React.createElement(_Select, {
    name: "certId",
    disabled: batchDeployDs.current && !batchDeployDs.current.get('environmentId'),
    searchable: true
  })), map(pathListDs.data, function (pathRecord) {
    return /*#__PURE__*/React.createElement(_Form, {
      record: pathRecord,
      columns: 14,
      key: pathRecord.id
    }, /*#__PURE__*/React.createElement(_TextField, {
      name: "path",
      colSpan: 5,
      disabled: !record.get('domain')
    }), /*#__PURE__*/React.createElement(_TextField, {
      name: "serviceName",
      colSpan: 5,
      disabled: true
    }), /*#__PURE__*/React.createElement(_Select, {
      name: "servicePort",
      disabled: !pathRecord.get('serviceName'),
      colSpan: 3
    }, map(pathRecord.get('ports'), function (port) {
      return /*#__PURE__*/React.createElement(Option, {
        value: port,
        key: port
      }, port);
    })), pathListDs.length > 1 ? /*#__PURE__*/React.createElement(_Button, {
      funcType: "flat",
      icon: "delete",
      className: "".concat(prefixCls, "-resource-delete-btn"),
      onClick: function onClick() {
        return handleRemovePath(pathRecord);
      }
    }) : /*#__PURE__*/React.createElement("span", null));
  }), /*#__PURE__*/React.createElement(_Button, {
    funcType: "flat",
    color: "primary",
    icon: "add",
    onClick: handleAddPath
  }, formatMessage({
    id: 'domain.path.add'
  })), /*#__PURE__*/React.createElement("div", {
    className: "".concat(prefixCls, "-resource-domain-annotation-title")
  }, "Annotations"), map(annotationDs.data, function (annotationRecord) {
    return /*#__PURE__*/React.createElement(_Form, {
      columns: 14,
      record: annotationRecord,
      key: annotationRecord.id,
      className: "".concat(prefixCls, "-resource-domain-annotation")
    }, /*#__PURE__*/React.createElement(_TextField, {
      colSpan: 6,
      name: "key"
    }), /*#__PURE__*/React.createElement("span", {
      className: "".concat(prefixCls, "-resource-domain-annotation-equal")
    }, "="), /*#__PURE__*/React.createElement(_TextArea, {
      colSpan: 6,
      name: "value",
      autoSize: {
        minRows: 1
      },
      resize: "vertical"
    }), annotationDs.length > 1 ? /*#__PURE__*/React.createElement(_Button, {
      funcType: "flat",
      icon: "delete",
      onClick: function onClick() {
        return handleRemoveAnnotation(annotationRecord);
      },
      className: "".concat(prefixCls, "-resource-delete-btn")
    }) : /*#__PURE__*/React.createElement("span", null));
  }), /*#__PURE__*/React.createElement(_Button, {
    funcType: "flat",
    color: "primary",
    icon: "add",
    onClick: handleAddAnnotation
  }, formatMessage({
    id: 'domain.annotation.add'
  })));
});