'use strict';

exports.__esModule = true;

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

var _propTypes2 = _interopRequireDefault(_propTypes);

var _Button = require('../../atoms/buttons/Button');

var _Button2 = _interopRequireDefault(_Button);

var _ColoredHeading = require('../../atoms/headings/ColoredHeading');

var _ColoredHeading2 = _interopRequireDefault(_ColoredHeading);

var _DateRange = require('../../forms/DateRange');

var _DateRange2 = _interopRequireDefault(_DateRange);

var _OrgSelector = require('../../forms/OrgSelector');

var _OrgSelector2 = _interopRequireDefault(_OrgSelector);

var _SelectBox = require('../../forms/SelectBox');

var _SelectBox2 = _interopRequireDefault(_SelectBox);

var _InputTextTypeAhead = require('../../forms/InputTextTypeAhead');

var _InputTextTypeAhead2 = _interopRequireDefault(_InputTextTypeAhead);

require('./style.css');

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

var PressFilters = function PressFilters(props) {
  var action = props.action,
      coloredHeading = props.coloredHeading,
      topic = props.topic,
      orgSelector = props.orgSelector,
      pressType = props.pressType,
      dateRange = props.dateRange,
      submitButton = props.submitButton,
      clearButton = props.clearButton;

  var handleClear = function handleClear() {
    if (typeof props.clearButton.onClearCallback === 'function') {
      props.clearButton.onClearCallback();
    }
  };
  var selectBoxProps = pressType.selectBox;
  var typeAheadProps = pressType.typeAhead;
  return _react2.default.createElement(
    'section',
    { className: 'ma__press-filters' },
    _react2.default.createElement(
      'div',
      { className: 'ma__press-filters__container' },
      _react2.default.createElement(
        'header',
        { className: 'ma__press-filters__heading' },
        _react2.default.createElement(_ColoredHeading2.default, coloredHeading)
      ),
      _react2.default.createElement(
        'form',
        { className: 'ma__press-filters__form js-press-filters', action: action },
        _react2.default.createElement(
          'div',
          { className: 'ma__press-filters__organizations' },
          _react2.default.createElement(_OrgSelector2.default, orgSelector)
        ),
        topic && _react2.default.createElement(
          'div',
          { className: 'ma__press-filters__topic' },
          _react2.default.createElement(_SelectBox2.default, topic)
        ),
        _react2.default.createElement(
          'div',
          { className: 'ma__press-filters__type' },
          selectBoxProps && _react2.default.createElement(_SelectBox2.default, selectBoxProps),
          typeAheadProps && _react2.default.createElement(_InputTextTypeAhead2.default, typeAheadProps)
        ),
        _react2.default.createElement(
          'div',
          { className: 'ma__press-filters__date' },
          _react2.default.createElement(_DateRange2.default, dateRange)
        ),
        _react2.default.createElement(
          'div',
          { className: 'ma__press-filters__button' },
          _react2.default.createElement(_Button2.default, submitButton)
        ),
        clearButton && _react2.default.createElement(
          'button',
          { type: 'button', 'aria-label': clearButton.info, className: 'ma__press-filters__clear js-press-filters-clear', onClick: function onClick() {
              return handleClear();
            } },
          clearButton.text
        )
      )
    )
  );
};

// import child components


PressFilters.propTypes = process.env.NODE_ENV !== "production" ? {
  /** The form action  */
  action: _propTypes2.default.string,
  /** @atoms/headings/ColoredHeading */
  coloredHeading: _propTypes2.default.shape(_ColoredHeading2.default.PropTypes),
  /** @forms/SelectBox */
  topic: _propTypes2.default.shape(_SelectBox2.default.PropTypes),
  /** @forms/SelectBox or /** @forms/InputTextTypeAhead  */
  pressType: _propTypes2.default.oneOf([_propTypes2.default.shape({ selectBox: _SelectBox2.default.propTypes }), _propTypes2.default.shape({ typeAhead: _InputTextTypeAhead2.default.propTypes })]),
  /** @molecules/OrgSelector */
  orgSelector: _propTypes2.default.shape(_OrgSelector2.default.PropTypes).isRequired,
  /** @molecules/DateRange */
  dateRange: _propTypes2.default.shape(_DateRange2.default.PropTypes).isRequired,
  /** @forms/Button */
  submitButton: _propTypes2.default.shape(_Button2.default.PropTypes).isRequired,
  /** Clear all button at the bottom of the filter */
  clearButton: _propTypes2.default.shape({
    text: _propTypes2.default.string,
    info: _propTypes2.default.string,
    onClearCallback: _propTypes2.default.func
  })
} : {};

PressFilters.defaultProps = {
  action: '#',
  coloredHeading: _ColoredHeading2.default.defaultProps
};

exports.default = PressFilters;
module.exports = exports['default'];