import _extends from "@babel/runtime/helpers/extends";
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { ChartMonitor } from '@redux-devtools/chart-monitor';
import { selectMonitorWithState } from '../../actions';
export function getPath(obj, inspectedStatePath) {
  const parent = obj.parent;
  if (!parent) return;
  getPath(parent, inspectedStatePath);
  let name = obj.data.name;
  const item = /.+\[(\d+)]/.exec(name);
  if (item) name = item[1];
  inspectedStatePath.push(name);
}
class ChartMonitorWrapper extends Component {
  static update = ChartMonitor.update;
  onClickText = data => {
    const inspectedStatePath = [];
    getPath(data, inspectedStatePath);
    this.props.selectMonitorWithState('InspectorMonitor', {
      inspectedStatePath,
      tabName: 'State',
      subTabName: data.children ? 'Chart' : 'Tree',
      selectedActionId: null,
      startActionId: null,
      inspectedActionPath: []
    });
  };
  render() {
    return (
      /*#__PURE__*/
      // eslint-disable-next-line @typescript-eslint/ban-ts-comment
      // @ts-ignore
      React.createElement(ChartMonitor, _extends({
        defaultIsVisible: true,
        invertTheme: true,
        onClickText: this.onClickText
      }, this.props))
    );
  }
}
const actionCreators = {
  selectMonitorWithState: selectMonitorWithState
};
export default connect(null, actionCreators)(ChartMonitorWrapper);