import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _objectSpread from "@babel/runtime/helpers/objectSpread";

/**
 * Web Section Component
 *
 */
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import { isTrue, registerElement, validateDOMAttributes, processChildren } from '../../shared/component-helper';
const renderProps = {
  render_content: null
};
export const propTypes = {
  style: PropTypes.string,
  style_type: PropTypes.string,
  spacing: PropTypes.string,
  class: PropTypes.string,

  /** React props */
  className: PropTypes.string,
  children: PropTypes.oneOfType([PropTypes.string, PropTypes.func, PropTypes.node]),
  // Web Component props
  render_content: PropTypes.func
};
export const defaultProps = _objectSpread({
  style: null,
  style_type: 'mint-green-12',
  class: null,

  /** React props */
  className: null,
  children: null
}, renderProps);
export default class Section extends PureComponent {
  static enableWebComponent() {
    registerElement(Section.tagName, Section, defaultProps);
  }

  static getContent(props) {
    if (props.text) return props.text;
    if (typeof props.render_content === 'function') props.render_content(props);
    return processChildren(props);
  }

  render() {
    const _this$props = this.props,
          {
      style,
      style_type,
      spacing,
      className,
      class: _className
    } = _this$props,
          attributes = _objectWithoutProperties(_this$props, ["style", "style_type", "spacing", "className", "class"]);

    const content = Section.getContent(this.props);

    const params = _objectSpread({
      className: classnames('dnb-section', "dnb-section--".concat(typeof style === 'string' ? style : style_type), (isTrue(spacing) || spacing) && "dnb-section--spacing".concat(!/true|false/.test(String(spacing)) ? '-' + spacing : ''), className, _className)
    }, attributes); // also used for code markup simulation


    validateDOMAttributes(this.props, params);
    return React.createElement("section", params, content);
  }

}

_defineProperty(Section, "tagName", 'dnb-section');

_defineProperty(Section, "defaultProps", defaultProps);

Section.propTypes = process.env.NODE_ENV !== "production" ? propTypes : {};