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

/**
 * Web ViewTitle Component
 *
 */
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import { registerElement, validateDOMAttributes, processChildren } from '../../shared/component-helper'; // import './style/dnb-view-title.css' // no good solution to import the style here

const renderProps = {// render_content: null
};
export const propTypes = {
  text: PropTypes.string,
  tag: PropTypes.string,
  class: PropTypes.string,

  /** React props */
  className: PropTypes.string,
  children: PropTypes.oneOfType([PropTypes.string, PropTypes.node, PropTypes.func]) // Web Component props
  // render_content: PropTypes.func

};
export const defaultProps = _objectSpread({
  text: null,
  tag: 'h1',
  class: null,

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

  static getText(props) {
    if (typeof props.text === 'string') {
      return props.text;
    }

    return processChildren(props);
  }

  render() {
    const {
      tag: Component,
      className,
      class: _className
    } = this.props;
    const text = ViewTitle.getText(this.props);
    const params = {
      className: classnames('dnb-view-title', className, _className) // also used for code markup simulation

    };
    validateDOMAttributes(this.props, params);
    return React.createElement(Component, params, text);
  }

}

_defineProperty(ViewTitle, "tagName", 'dnb-view-title');

_defineProperty(ViewTitle, "defaultProps", defaultProps);

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