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";
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { style } from 'typestyle';
import Dialog from '@material-ui/core/Dialog';
import DialogTitle from '@material-ui/core/DialogTitle';
import DialogContent from '@material-ui/core/DialogContent';
import DialogActions from '@material-ui/core/DialogActions';
import Table from '@material-ui/core/Table';
import TableBody from '@material-ui/core/TableBody';
import TableRow from '@material-ui/core/TableRow';
import TableCell from '@material-ui/core/TableCell';
import TextField from '@material-ui/core/TextField';
import { Confirm, Abort } from './Buttons';
var cn = {
  root: style({
    fontSize: 16
  }),
  left: style({
    textAlign: 'right'
  })
};

var RenameDialog =
/*#__PURE__*/
function (_Component) {
  _inherits(RenameDialog, _Component);

  function RenameDialog() {
    var _getPrototypeOf2;

    var _this;

    _classCallCheck(this, RenameDialog);

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

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

    _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "state", {
      changed: false,
      name: _this.props.content.name,
      type: _this.props.content.type
    });

    _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "confirm", function () {
      var _this$props = _this.props,
          onRequestClose = _this$props.onRequestClose,
          resolve = _this$props.resolve;
      var _this$state = _this.state,
          changed = _this$state.changed,
          name = _this$state.name,
          type = _this$state.type;
      resolve(changed ? {
        name: name,
        type: type
      } : {});
      onRequestClose();
    });

    _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "handleNameChange", function (event, name) {
      _this.setState({
        changed: true,
        name: name
      });
    });

    _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "handleTypeChange", function (event, type) {
      _this.setState({
        changed: true,
        type: type
      });
    });

    return _this;
  }

  _createClass(RenameDialog, [{
    key: "render",
    value: function render() {
      var onRequestClose = this.props.onRequestClose;
      var _this$state2 = this.state,
          changed = _this$state2.changed,
          name = _this$state2.name,
          type = _this$state2.type;
      return React.createElement(Dialog, {
        open: true,
        className: cn.root,
        onClose: onRequestClose
      }, React.createElement(DialogTitle, null, "File Preference"), React.createElement(DialogContent, null, React.createElement(Table, null, React.createElement(TableBody, null, React.createElement(TableRow, null, React.createElement(TableCell, {
        className: cn.left
      }, "Name"), React.createElement(TableCell, null, React.createElement(TextField, {
        id: "name",
        defaultValue: name,
        onChange: this.handleNameChange
      }))), React.createElement(TableRow, null, React.createElement(TableCell, {
        className: cn.left
      }, "Type"), React.createElement(TableCell, null, React.createElement(TextField, {
        id: "type",
        defaultValue: type,
        onChange: this.handleTypeChange
      })))))), React.createElement(DialogActions, null, React.createElement(Abort, {
        onClick: onRequestClose
      }, "Cancel"), React.createElement(Confirm, {
        disabled: !changed,
        onClick: this.confirm
      }, "Save")));
    }
  }]);

  return RenameDialog;
}(Component);

_defineProperty(RenameDialog, "propTypes", {
  resolve: PropTypes.func.isRequired,
  onRequestClose: PropTypes.func.isRequired,
  content: PropTypes.any
});

export { RenameDialog as default };