import "choerodon-ui/pro/lib/modal/style";
import _Modal from "choerodon-ui/pro/lib/modal";
import React, { useMemo, useCallback, useEffect } from 'react';
import { observer } from 'mobx-react-lite';
import { HeaderButtons } from '@choerodon/master';
import { useResourceStore } from "../../../../stores";
import { useModalStore } from "./stores";
import { useNetworkDetailStore } from "../stores";
import Detail from "./network-detail";

var modalKey1 = _Modal.key();

var modalStyle = {
  width: 380
};
var ServiceModals = observer(function () {
  var _useResourceStore = useResourceStore(),
      intlPrefix = _useResourceStore.intlPrefix,
      prefixCls = _useResourceStore.prefixCls,
      formatMessage = _useResourceStore.intl.formatMessage,
      resourceStore = _useResourceStore.resourceStore,
      treeDs = _useResourceStore.treeDs;

  var _useNetworkDetailStor = useNetworkDetailStore(),
      baseInfoDs = _useNetworkDetailStor.baseInfoDs;

  var _useModalStore = useModalStore(),
      permissions = _useModalStore.permissions,
      projectId = _useModalStore.AppState.currentMenuType.projectId;

  function openDetail() {
    _Modal.open({
      key: modalKey1,
      title: formatMessage({
        id: "".concat(intlPrefix, ".net.detail")
      }),
      children: /*#__PURE__*/React.createElement(Detail, {
        record: baseInfoDs.current,
        intlPrefix: intlPrefix,
        prefixCls: prefixCls,
        formatMessage: formatMessage
      }),
      drawer: true,
      style: modalStyle,
      okText: formatMessage({
        id: 'close'
      }),
      okCancel: false
    });
  }

  function refresh() {
    treeDs.query();
    baseInfoDs.query();
  }

  var buttons = useMemo(function () {
    return [{
      name: formatMessage({
        id: "".concat(intlPrefix, ".net.detail")
      }),
      icon: 'find_in_page-o',
      handler: openDetail,
      display: true,
      service: permissions
    }, {
      icon: 'refresh',
      handler: refresh,
      display: true
    }];
  }, [formatMessage, intlPrefix, permissions, refresh]);
  return /*#__PURE__*/React.createElement(HeaderButtons, {
    items: buttons,
    showClassName: true
  });
});
export default ServiceModals;