'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

var _Popover = require('@material-ui/core/Popover');

var _Popover2 = _interopRequireDefault(_Popover);

var _List = require('@material-ui/core/List');

var _List2 = _interopRequireDefault(_List);

var _ListItem = require('@material-ui/core/ListItem');

var _ListItem2 = _interopRequireDefault(_ListItem);

var _ListItemText = require('@material-ui/core/ListItemText');

var _ListItemText2 = _interopRequireDefault(_ListItemText);

var _ListItemSecondaryAction = require('@material-ui/core/ListItemSecondaryAction');

var _ListItemSecondaryAction2 = _interopRequireDefault(_ListItemSecondaryAction);

var _Switch = require('@material-ui/core/Switch');

var _Switch2 = _interopRequireDefault(_Switch);

var _Button = require('@material-ui/core/Button');

var _Button2 = _interopRequireDefault(_Button);

var _styles = require('@material-ui/core/styles');

var _FormattedFieldname = require('../Shared/FormattedFieldname');

var _FormattedFieldname2 = _interopRequireDefault(_FormattedFieldname);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var styles = function styles(theme) {
  return {
    actions: {
      margin: theme.spacing.unit + 'px ' + theme.spacing.unit / 2 + 'px'
    },
    button: {
      margin: '0 ' + theme.spacing.unit / 2 + 'px'
    },
    fieldname: {
      maxWidth: 250,
      textOverflow: 'ellipsis',
      overflow: 'hidden',
      whiteSpace: 'nowrap',
      direction: 'rtl'
    }
  };
};

var HiddenFieldsMenu = function HiddenFieldsMenu(_ref) {
  var anchorEl = _ref.anchorEl,
      open = _ref.open,
      onRequestClose = _ref.onRequestClose,
      onShowAll = _ref.onShowAll,
      onHideAll = _ref.onHideAll,
      fields = _ref.fields,
      onToggle = _ref.onToggle,
      classes = _ref.classes;
  return _react2.default.createElement(
    _Popover2.default,
    {
      id: 'hidden-fields-menu',
      anchorEl: anchorEl,
      anchorOrigin: {
        vertical: 'bottom',
        horizontal: 'left'
      },
      open: open,
      onClose: onRequestClose,
      PaperProps: {
        style: {
          maxHeight: '50vh',
          minWidth: 200,
          maxWidth: '50vw'
        }
      }
    },
    _react2.default.createElement(
      'div',
      { className: classes.actions },
      _react2.default.createElement(
        _Button2.default,
        { dense: true, onClick: onShowAll, className: classes.button },
        'Show All'
      ),
      _react2.default.createElement(
        _Button2.default,
        { dense: true, onClick: onHideAll, className: classes.button },
        'Hide All'
      )
    ),
    _react2.default.createElement(
      _List2.default,
      { dense: true },
      fields.map(function (field) {
        return _react2.default.createElement(
          _ListItem2.default,
          { key: field.key, button: false },
          _react2.default.createElement(_ListItemText2.default, { className: classes.fieldname, primary: _react2.default.createElement(_FormattedFieldname2.default, { fieldname: field.key }) }),
          _react2.default.createElement(
            _ListItemSecondaryAction2.default,
            null,
            _react2.default.createElement(_Switch2.default, {
              onClick: function onClick() {
                return onToggle(field.key);
              },
              checked: !field.hidden
            })
          )
        );
      })
    )
  );
};

HiddenFieldsMenu.propTypes = {
  classes: _propTypes2.default.object.isRequired,
  anchorEl: _propTypes2.default.node,
  open: _propTypes2.default.bool.isRequired,
  onRequestClose: _propTypes2.default.func.isRequired,
  onShowAll: _propTypes2.default.func.isRequired,
  onHideAll: _propTypes2.default.func.isRequired,
  fields: _propTypes2.default.arrayOf(_propTypes2.default.shape({
    key: _propTypes2.default.string.isRequired,
    hidden: _propTypes2.default.bool
  })),
  onToggle: _propTypes2.default.func.isRequired
};

exports.default = (0, _styles.withStyles)(styles)(HiddenFieldsMenu);
//# sourceMappingURL=HiddenFieldsMenu.js.map