import "choerodon-ui/lib/dropdown/style";
import _Dropdown from "choerodon-ui/lib/dropdown";
import "choerodon-ui/lib/button/style";
import _Button from "choerodon-ui/lib/button";
import "choerodon-ui/lib/icon/style";
import _Icon from "choerodon-ui/lib/icon";
import "choerodon-ui/lib/menu/style";
import _Menu from "choerodon-ui/lib/menu";
import React, { Component, useMemo } from 'react';
import { FormattedMessage } from 'react-intl';
import { withRouter } from 'react-router-dom';
import { inject } from 'mobx-react';
import _ from 'lodash';
import { developReportList, reportListMap } from "../Home/reportList";
var MenuItem = _Menu.Item;
var ChartSwitch = withRouter(inject('AppState')(function (props) {
  var current = props.current,
      history = props.history,
      search = props.location.search,
      AppState = props.AppState,
      reportType = props.reportType;
  var reportList = useMemo(function () {
    return reportListMap[reportType] || developReportList;
  }, [reportType]);

  var handleClick = function handleClick(e) {
    var nextReport = _.find(reportList, ['key', e.key]);

    if (nextReport) {
      history.push("".concat(nextReport.link).concat(search));
    }
  };

  var menu = /*#__PURE__*/React.createElement(_Menu, {
    onClick: handleClick
  }, _.map(_.filter(reportList, function (item) {
    return item.key !== current;
  }), function (rep) {
    return /*#__PURE__*/React.createElement(MenuItem, {
      key: rep.key
    }, /*#__PURE__*/React.createElement(FormattedMessage, {
      id: "report.".concat(rep.key, ".head")
    }));
  }));
  return /*#__PURE__*/React.createElement(_Dropdown, {
    placement: "bottomCenter",
    trigger: ['click'],
    overlay: menu
  }, /*#__PURE__*/React.createElement(_Button, {
    funcType: "flat"
  }, /*#__PURE__*/React.createElement(FormattedMessage, {
    id: "chart.change"
  }), /*#__PURE__*/React.createElement(_Icon, {
    type: "arrow_drop_down"
  })));
}));
export default ChartSwitch;