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 EnvDetail from "../../../../../../components/env-detail";
import { useResourceStore } from "../../../../stores";
import { useREStore } from "../stores";
var REModals = observer(function () {
  var modalStyle = useMemo(function () {
    return {
      width: 380
    };
  }, []);

  var _useResourceStore = useResourceStore(),
      intlPrefix = _useResourceStore.intlPrefix,
      prefixCls = _useResourceStore.prefixCls,
      formatMessage = _useResourceStore.intl.formatMessage,
      treeDs = _useResourceStore.treeDs;

  var _useREStore = useREStore(),
      baseInfoDs = _useREStore.baseInfoDs,
      resourceCountDs = _useREStore.resourceCountDs,
      gitopsLogDs = _useREStore.gitopsLogDs,
      gitopsSyncDs = _useREStore.gitopsSyncDs;

  function refresh() {
    baseInfoDs.query();
    resourceCountDs.query();
    treeDs.query();
    gitopsSyncDs.query();
    gitopsLogDs.query();
  }

  function linkToConfig() {
    var record = baseInfoDs.current;
    var url = record && record.get('gitlabUrl');
    url && window.open(url);
  }

  function openEnvDetail() {
    _Modal.open({
      key: _Modal.key(),
      title: formatMessage({
        id: "".concat(intlPrefix, ".modal.env-detail")
      }),
      children: /*#__PURE__*/React.createElement(EnvDetail, {
        record: baseInfoDs.current
      }),
      drawer: true,
      style: modalStyle,
      okCancel: false,
      okText: formatMessage({
        id: 'close'
      })
    });
  }

  function getButtons() {
    return [{
      name: formatMessage({
        id: "".concat(intlPrefix, ".modal.env-detail")
      }),
      icon: 'find_in_page-o',
      handler: openEnvDetail,
      display: true
    }, {
      name: formatMessage({
        id: "".concat(intlPrefix, ".environment.config-lab")
      }),
      icon: 'account_balance',
      handler: linkToConfig,
      display: true
    }, {
      icon: 'refresh',
      handler: refresh,
      display: true
    }];
  }

  return /*#__PURE__*/React.createElement(HeaderButtons, {
    items: getButtons(),
    showClassName: true
  });
});
export default REModals;