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

/**
 * Web LineTitle 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-line-title.css' // no good solution to import the style here

const renderProps = {
  render_content: null
};
export const propTypes = {
  content: PropTypes.string,
  modifier: 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({
  content: null,
  modifier: null,
  tag: 'h2',
  class: null,

  /** React props */
  className: null,
  children: null
}, renderProps);

var _ref =
/*#__PURE__*/
React.createElement("span", {
  className: "dnb-line-title__mask",
  "aria-hidden": "true"
});

var _ref2 =
/*#__PURE__*/
React.createElement("span", {
  className: "dnb-line-title__line",
  "aria-hidden": "true"
});

export default class LineTitle extends PureComponent {
  static enableWebComponent() {
    registerElement(LineTitle.tagName, LineTitle, defaultProps);
  }

  static getContent(props) {
    if (typeof props.content === 'string') {
      return props.content;
    } else if (typeof props.render_content === 'function') {
      return props.render_content(props);
    }

    return processChildren(props);
  }

  render() {
    const {
      tag,
      modifier,
      className,
      class: _className
    } = this.props;
    const content = LineTitle.getContent(this.props);
    const params = {
      className: classnames('dnb-line-title', className, _className, modifier ? "dnb-line-title--".concat(modifier) : null) // also used for code markup simulation

    };
    validateDOMAttributes(this.props, params);
    const Tag = "".concat(tag);
    return React.createElement(Tag, params, React.createElement("span", {
      className: "dnb-line-title__title dnb-typo-light"
    }, _ref, React.createElement("span", {
      className: "dnb-line-title__text"
    }, content)), _ref2);
  }

}

_defineProperty(LineTitle, "tagName", 'dnb-line-title');

_defineProperty(LineTitle, "defaultProps", defaultProps);

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