import "choerodon-ui/pro/lib/modal/style";
import _Modal from "choerodon-ui/pro/lib/modal";
import React, { useMemo } from 'react';
import { observer } from 'mobx-react-lite';
import { HeaderButtons } from '@choerodon/master';
import Detail from "./secret-detail";
import { useResourceStore } from "../../../../stores";
import { useModalStore } from "./stores";
import { useSecretDetailStore } from "../stores";
var modalStyle = {
  width: 380
};

var modalKey1 = _Modal.key();

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

  var _useSecretDetailStore = useSecretDetailStore(),
      detailDs = _useSecretDetailStore.detailDs;

  var _useModalStore = useModalStore(),
      permissions = _useModalStore.permissions;

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

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

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