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

/**
 * Web SummaryTable 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-summary-table.css' // no good solution to import the style here

import Button from '../../components/button/Button';
const renderProps = {
  render_left_content: null,
  render_right_content: null
};
export const propTypes = {
  prev_href: PropTypes.string,
  next_href: PropTypes.string,
  prev_text: PropTypes.string,
  next_text: PropTypes.string,
  prev_title: PropTypes.string,
  next_title: PropTypes.string,
  class: PropTypes.string,

  /** React props */
  className: PropTypes.string,
  children: PropTypes.oneOfType([PropTypes.string, PropTypes.node, PropTypes.func]),
  // Web Component props
  render_left_content: PropTypes.func,
  render_right_content: PropTypes.func
};
export const defaultProps = _objectSpread({
  prev_href: null,
  next_href: null,
  prev_text: 'Back',
  next_text: 'Next',
  prev_title: 'Go back',
  next_title: 'Go next',
  class: null,

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

  static getLeftContent(props) {
    if (typeof props.render_left_content === 'function') {
      return props.render_left_content(props);
    }

    return null;
  }

  static getRightContent(props) {
    if (typeof props.render_right_content === 'function') {
      return props.render_right_content(props);
    }

    return processChildren(props);
  }

  render() {
    const {
      prev_href,
      next_href,
      prev_text,
      next_text,
      prev_title,
      next_title,
      className,
      class: _className
    } = this.props;
    const leftContent = SummaryTable.getLeftContent(this.props);
    const rightContent = SummaryTable.getRightContent(this.props);
    const params = {
      className: "dnb-summary-table ".concat(className || _className || '') // also used for code markup simulation

    };
    validateDOMAttributes(this.props, params);
    return React.createElement("div", params, React.createElement("div", {
      className: "dnb-width-limit"
    }, React.createElement("div", {
      className: "dnb-summary-table__inner"
    }, leftContent && React.createElement("div", {
      className: "dnb-summary-table__left"
    }, leftContent) || React.createElement("div", {
      className: "dnb-summary-table__left"
    }, prev_href && React.createElement("div", {
      className: "dnb-summary-table__item"
    }, React.createElement(Button, {
      type: "button",
      text: prev_text,
      title: prev_title,
      variant: "secondary",
      icon_position: "left",
      icon: "chevron_left",
      href: prev_href
    })), next_href && React.createElement("div", {
      className: "dnb-summary-table__item"
    }, React.createElement(Button, {
      text: next_text,
      title: next_title,
      variant: "primary",
      icon: "chevron_right",
      href: next_href
    }))), rightContent && React.createElement("div", {
      className: "dnb-summary-table__right"
    }, rightContent))));
  }

}

_defineProperty(SummaryTable, "tagName", 'dnb-summary-table');

_defineProperty(SummaryTable, "defaultProps", defaultProps);

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