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 _inherits from "@babel/runtime/helpers/inherits";
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
import _defineProperty from "@babel/runtime/helpers/defineProperty";

var _dec, _class, _class2, _temp;

import React from 'react';
import PropTypes from 'prop-types';
import { style } from 'typestyle';
import { Button, withTheme } from '@material-ui/core';
import { KeyboardBackspace, Fullscreen, FullscreenExit, Layers, LayersClear } from '@material-ui/icons';
import SelectTab from './SelectTab';

var getCn = function getCn(props) {
  return {
    icon: style({
      color: props.theme.typography.button.color
    }),
    button: style({
      marginRight: props.theme.spacing.unit,
      minWidth: 40 // 縦長にはならないように

    })
  };
};

var MenuBar = (_dec = withTheme(), _dec(_class = (_temp = _class2 =
/*#__PURE__*/
function (_React$Component) {
  _inherits(MenuBar, _React$Component);

  function MenuBar() {
    var _getPrototypeOf2;

    var _this;

    _classCallCheck(this, MenuBar);

    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    _this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(MenuBar)).call.apply(_getPrototypeOf2, [this].concat(args)));

    _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "toggleLineWidget", function () {
      var showLineWidget = _this.props.showLineWidget;

      _this.props.setShowLineWidget(!showLineWidget);
    });

    _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "handleBack", function () {
      _this.props.runApp();

      _this.props.globalEvent.emit('message.editor', {
        data: {
          value: _this.props.filePathToBack
        }
      });
    });

    _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "toggleExpandingEditorCard", function () {
      _this.props.setExpandingEditorCard(!_this.props.isExpandingEditorCard);
    });

    return _this;
  }

  _createClass(MenuBar, [{
    key: "render",
    value: function render() {
      var dcn = getCn(this.props);
      var _this$props = this.props,
          filePath = _this$props.filePath,
          filePathToBack = _this$props.filePathToBack,
          isExpandingEditorCard = _this$props.isExpandingEditorCard;
      var showBackButton = filePath !== filePathToBack;
      return React.createElement(React.Fragment, null, React.createElement(Button, {
        variant: "outlined",
        size: "small",
        disabled: !this.props.hasHistory,
        onClick: this.props.handleUndo,
        className: dcn.button
      }, React.createElement(KeyboardBackspace, null), this.props.localization.editorCard.undo), React.createElement(Button, {
        variant: "outlined",
        size: "small",
        className: dcn.button,
        onClick: this.toggleLineWidget
      }, this.props.showLineWidget ? React.createElement(Layers, {
        className: dcn.icon,
        fontSize: "small"
      }) : React.createElement(LayersClear, {
        fontSize: "small"
      })), React.createElement(Button, {
        variant: isExpandingEditorCard ? 'contained' : 'outlined',
        color: "primary",
        size: "small",
        className: dcn.button,
        onClick: this.toggleExpandingEditorCard
      }, isExpandingEditorCard ? React.createElement(FullscreenExit, null) : React.createElement(Fullscreen, null)), showBackButton ? null : React.createElement(SelectTab, {
        filePath: filePath,
        tabs: this.props.tabs,
        globalEvent: this.props.globalEvent,
        localization: this.props.localization,
        className: dcn.button
      }));
    }
  }]);

  return MenuBar;
}(React.Component), _defineProperty(_class2, "propTypes", {
  theme: PropTypes.object.isRequired,
  localization: PropTypes.object.isRequired,
  handleUndo: PropTypes.func.isRequired,
  runApp: PropTypes.func.isRequired,
  hasHistory: PropTypes.bool.isRequired,
  tabs: PropTypes.array.isRequired,
  filePath: PropTypes.string.isRequired,
  showLineWidget: PropTypes.bool.isRequired,
  setShowLineWidget: PropTypes.func.isRequired,
  label: PropTypes.string.isRequired,
  filePathToBack: PropTypes.string.isRequired,
  globalEvent: PropTypes.object.isRequired,
  isExpandingEditorCard: PropTypes.bool.isRequired,
  setExpandingEditorCard: PropTypes.func.isRequired
}), _temp)) || _class);
export { MenuBar as default };