import "choerodon-ui/lib/icon/style";
import _Icon from "choerodon-ui/lib/icon";

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, { useState } from 'react';
import { observer } from 'mobx-react-lite';
import { FormattedMessage } from 'react-intl';
import NetworkForm from "../../../deploy/NetworkForm";
import DomainForm from "../../../deploy/DomainForm";
import { StoreProvider as DeployStoreProvider } from "../../../deploy/stores";
import { StoreProvider, useDeployStore } from "../../../../stores";
import "../../../deploy/index.less";
var ResourceSetting = observer(function (_ref) {
  var _ref$prefixCls = _ref.prefixCls,
      prefixCls = _ref$prefixCls === void 0 ? 'c7ncd-deploy' : _ref$prefixCls,
      _ref$intlPrefix = _ref.intlPrefix,
      intlPrefix = _ref$intlPrefix === void 0 ? 'c7ncd.deploy' : _ref$intlPrefix,
      style = _ref.style,
      networkRef = _ref.networkRef,
      domainRef = _ref.domainRef,
      envId = _ref.envId;

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

  var _useState3 = useState(false),
      _useState4 = _slicedToArray(_useState3, 2),
      netIsExpand = _useState4[0],
      setNetIsExpand = _useState4[1];

  var _useState5 = useState(false),
      _useState6 = _slicedToArray(_useState5, 2),
      ingressIsExpand = _useState6[0],
      setIngressIsExpand = _useState6[1];

  function handleExpand(Operating) {
    Operating(function (pre) {
      return !pre;
    });
  }

  return /*#__PURE__*/React.createElement("div", {
    className: "c7ncd-deploy-manual-deploy",
    style: style || undefined
  }, /*#__PURE__*/React.createElement("div", {
    className: "".concat(prefixCls, "-resource-config")
  }, /*#__PURE__*/React.createElement("div", {
    role: "none",
    className: "".concat(prefixCls, "-resource-config-title"),
    onClick: function onClick() {
      return handleExpand(setResourceIsExpand);
    }
  }, /*#__PURE__*/React.createElement(FormattedMessage, {
    id: "".concat(intlPrefix, ".resource")
  }), /*#__PURE__*/React.createElement(_Icon, {
    type: resourceIsExpand ? 'expand_less' : 'expand_more',
    className: "".concat(prefixCls, "-resource-config-icon")
  })), /*#__PURE__*/React.createElement("div", {
    className: resourceIsExpand ? '' : "".concat(prefixCls, "-resource-display")
  }, /*#__PURE__*/React.createElement("div", {
    role: "none",
    className: "".concat(prefixCls, "-resource-config-network"),
    onClick: function onClick() {
      return handleExpand(setNetIsExpand);
    }
  }, /*#__PURE__*/React.createElement(_Icon, {
    type: netIsExpand ? 'expand_less' : 'expand_more',
    className: "".concat(prefixCls, "-resource-config-network-icon")
  }), /*#__PURE__*/React.createElement(FormattedMessage, {
    id: "".concat(intlPrefix, ".network")
  })), /*#__PURE__*/React.createElement("div", {
    className: netIsExpand ? "".concat(prefixCls, "-resource-content") : "".concat(prefixCls, "-resource-display")
  }, /*#__PURE__*/React.createElement(NetworkForm, {
    cRef: networkRef,
    envId: envId
  })), /*#__PURE__*/React.createElement("div", {
    role: "none",
    className: "".concat(prefixCls, "-resource-config-network"),
    onClick: function onClick() {
      return handleExpand(setIngressIsExpand);
    }
  }, /*#__PURE__*/React.createElement(_Icon, {
    type: ingressIsExpand ? 'expand_less' : 'expand_more',
    className: "".concat(prefixCls, "-resource-config-network-icon")
  }), /*#__PURE__*/React.createElement(FormattedMessage, {
    id: "".concat(intlPrefix, ".ingress")
  })), /*#__PURE__*/React.createElement("div", {
    className: ingressIsExpand ? "".concat(prefixCls, "-resource-content") : "".concat(prefixCls, "-resource-display")
  }, /*#__PURE__*/React.createElement(DomainForm, {
    envId: envId,
    cRef: domainRef
  })))));
});
var Content = observer(function () {
  var _useDeployStore = useDeployStore(),
      deployStore = _useDeployStore.deployStore,
      style = _useDeployStore.style,
      networkRef = _useDeployStore.networkRef,
      domainRef = _useDeployStore.domainRef,
      envId = _useDeployStore.envId;

  return /*#__PURE__*/React.createElement(DeployStoreProvider, {
    deployStore: deployStore
  }, /*#__PURE__*/React.createElement(ResourceSetting, {
    style: style,
    networkRef: networkRef,
    domainRef: domainRef,
    envId: envId
  }));
});
export default observer(function (props) {
  return /*#__PURE__*/React.createElement(StoreProvider, props, /*#__PURE__*/React.createElement(Content, null));
});