function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import cx from 'classnames';
import Expandable from './Expandable';

class NarrativePanel extends Component {
  constructor() {
    super();

    _defineProperty(this, "toggleOpen", () => {
      this.setState(prevState => ({
        open: !prevState.open
      }));
    });

    this.state = {
      open: false
    };
  }

  render() {
    const {
      props: {
        title,
        children
      },
      state,
      toggleOpen
    } = this;
    return /*#__PURE__*/React.createElement("div", {
      className: cx('narrative-panel', {
        'narrative-panel--open': state.open
      })
    }, /*#__PURE__*/React.createElement("div", {
      className: "narrative-panel__heading",
      role: "button",
      tabIndex: 0,
      onClick: toggleOpen
    }, title), /*#__PURE__*/React.createElement(Expandable, {
      className: "narrative-panel__options",
      open: state.open
    }, /*#__PURE__*/React.createElement("div", {
      className: "narrative-panel__options-content"
    }, children)));
  }

}

NarrativePanel.propTypes = {
  title: PropTypes.string.isRequired,
  children: PropTypes.any
};
NarrativePanel.defaultProps = {
  children: null
};
export default NarrativePanel;