function ___$insertStyle(css) {
  if (!css) {
    return;
  }
  if (typeof window === 'undefined') {
    return;
  }

  var style = document.createElement('style');

  style.setAttribute('type', 'text/css');
  style.innerHTML = css;
  document.head.appendChild(style);
  return css;
}

import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
import _createClass from '@babel/runtime/helpers/createClass';
import _possibleConstructorReturn from '@babel/runtime/helpers/possibleConstructorReturn';
import _getPrototypeOf from '@babel/runtime/helpers/getPrototypeOf';
import _assertThisInitialized from '@babel/runtime/helpers/assertThisInitialized';
import _inherits from '@babel/runtime/helpers/inherits';
import React from 'react';
import _ from 'lodash';
import shortid from 'shortid';
import withGracefulUnmount from 'react-graceful-unmount';
import store from 'store';
import 'roslib';
import 'amphion';
import 'amphion/src/utils/constants';
import { D as DEFAULT_CONFIG, P as Panels } from './index-93fb9356.js';
import '@babel/runtime/helpers/taggedTemplateLiteral';
import 'styled-components';
import 'react-select';
import 'react-markdown';
import '@babel/runtime/helpers/slicedToArray';
import 'react-rnd';
import 'jsoneditor-react';
import 'jsoneditor-react/es/editor.min.css';
import 'brace';
import 'brace/mode/json';
import 'brace/theme/xcode';

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

var Zethus =
/*#__PURE__*/
function (_React$Component) {
  _inherits(Zethus, _React$Component);

  function Zethus(props) {
    var _this;

    _classCallCheck(this, Zethus);

    _this = _possibleConstructorReturn(this, _getPrototypeOf(Zethus).call(this, props));
    var providedConfig = props.configuration || store.get('zethus_config') || {};
    _this.state = _objectSpread({}, _.merge({}, DEFAULT_CONFIG, providedConfig));
    _this.updateVizOptions = _this.updateVizOptions.bind(_assertThisInitialized(_this));
    _this.updateRosEndpoint = _this.updateRosEndpoint.bind(_assertThisInitialized(_this));
    _this.updateGlobalOptions = _this.updateGlobalOptions.bind(_assertThisInitialized(_this));
    _this.addVisualization = _this.addVisualization.bind(_assertThisInitialized(_this));
    _this.removeVisualization = _this.removeVisualization.bind(_assertThisInitialized(_this));
    _this.toggleVisibility = _this.toggleVisibility.bind(_assertThisInitialized(_this));
    _this.updateConfiguration = _this.updateConfiguration.bind(_assertThisInitialized(_this));
    return _this;
  }

  _createClass(Zethus, [{
    key: "updateConfiguration",
    value: function updateConfiguration(configuration) {
      this.setState(_objectSpread({}, _.merge({}, DEFAULT_CONFIG, configuration)));
    }
  }, {
    key: "updateVizOptions",
    value: function updateVizOptions(key, options) {
      var visualizations = this.state.visualizations;
      this.setState({
        visualizations: _.map(visualizations, function (v) {
          return v.key === key ? _objectSpread({}, v, {}, options) : v;
        })
      });
    }
  }, {
    key: "updateRosEndpoint",
    value: function updateRosEndpoint(endpoint) {
      var ros = this.state.ros;
      this.setState({
        ros: _objectSpread({}, ros, {
          endpoint: endpoint
        })
      });
    }
  }, {
    key: "componentWillUnmount",
    value: function componentWillUnmount() {
      store.set('zethus_config', this.state);
    }
  }, {
    key: "updateGlobalOptions",
    value: function updateGlobalOptions(path, option) {
      var globalOptions = this.state.globalOptions;

      var clonedGlobalOptions = _.cloneDeep(globalOptions);

      _.set(clonedGlobalOptions, path, option);

      this.setState({
        globalOptions: clonedGlobalOptions
      });
    }
  }, {
    key: "removeVisualization",
    value: function removeVisualization(e) {
      var vizId = e.target.dataset.id;
      var visualizations = this.state.visualizations;
      this.setState({
        visualizations: _.filter(visualizations, function (v) {
          return v.key !== vizId;
        })
      });
    }
  }, {
    key: "toggleVisibility",
    value: function toggleVisibility(e) {
      var vizId = e.target.dataset.id;
      var visualizations = this.state.visualizations;
      this.setState({
        visualizations: _.map(visualizations, function (v) {
          return v.key === vizId ? _objectSpread({}, v, {
            visible: !!(_.isBoolean(v.visible) && !v.visible)
          }) : v;
        })
      });
    }
  }, {
    key: "addVisualization",
    value: function addVisualization(vizOptions) {
      var visualizations = this.state.visualizations;
      this.setState({
        visualizations: [].concat(_toConsumableArray(visualizations), [_objectSpread({}, vizOptions, {
          key: shortid.generate()
        })])
      });
    }
  }, {
    key: "render",
    value: function render() {
      return React.createElement(Panels, {
        configuration: this.state,
        addVisualization: this.addVisualization,
        removeVisualization: this.removeVisualization,
        toggleVisibility: this.toggleVisibility,
        updateConfiguration: this.updateConfiguration,
        updateVizOptions: this.updateVizOptions,
        updateRosEndpoint: this.updateRosEndpoint,
        updateGlobalOptions: this.updateGlobalOptions
      });
    }
  }]);

  return Zethus;
}(React.Component);

var zethus = withGracefulUnmount(Zethus);

export default zethus;
