import "choerodon-ui/lib/button/style";
import _Button from "choerodon-ui/lib/button";
import "choerodon-ui/pro/lib/modal/style";
import _Modal from "choerodon-ui/pro/lib/modal";
import React, { Fragment, useMemo, useCallback, useEffect, useState } from 'react';
import { observer } from 'mobx-react-lite';
import { FormattedMessage } from 'react-intl';
import { HeaderButtons } from '@choerodon/master';
import { useResourceStore } from "../../../../stores";
import { useModalStore } from "./stores";
import { useCustomDetailStore } from "../stores";
import Detail from "./ingress-detail";
var modalStyle = {
  width: '26%'
};

var modalKey1 = _Modal.key();

var CustomModals = observer(function () {
  var _useResourceStore = useResourceStore(),
      intlPrefix = _useResourceStore.intlPrefix,
      prefixCls = _useResourceStore.prefixCls,
      formatMessage = _useResourceStore.intl.formatMessage,
      resourceStore = _useResourceStore.resourceStore,
      treeDs = _useResourceStore.treeDs;

  var _useCustomDetailStore = useCustomDetailStore(),
      detailDs = _useCustomDetailStore.detailDs;

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

  var parentId = resourceStore.getSelectedMenu.parentId;

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

  function openDetail() {
    var detailModal = _Modal.open({
      key: modalKey1,
      title: formatMessage({
        id: "".concat(intlPrefix, ".ingress.detail")
      }),
      children: /*#__PURE__*/React.createElement(Detail, {
        record: detailDs.current,
        intlPrefix: intlPrefix,
        prefixCls: prefixCls,
        formatMessage: formatMessage
      }),
      drawer: true,
      style: modalStyle,
      footer: /*#__PURE__*/React.createElement(_Button, {
        funcType: "raised",
        type: "primary",
        onClick: function onClick() {
          return detailModal.close();
        }
      }, /*#__PURE__*/React.createElement(FormattedMessage, {
        id: "close"
      }))
    });
  }

  var buttons = useMemo(function () {
    return [{
      name: formatMessage({
        id: "".concat(intlPrefix, ".ingress.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 CustomModals;