import React from 'react';
import PropTypes from 'prop-types';
import ShowToggle from 'shared/components/tooltip/show_toggle';
import MessageTooltip from 'shared/components/tooltip/message_tooltip';
import 'shared/components/tooltip/message_tooltip.scss';

const PaymentSummaryRow = ({
  sub_label,
  currency,
  value,
  container_class,
  label_class,
  negative,
  title,
  onClick,
  message_text
}) => {
  function renderSubLabel() {
    if (sub_label) {
      return (
        <span className="lbl-info" onClick={onClick}>
          {sub_label}
        </span>
      );
    } else if (message_text) {
      return (
        <ShowToggle key={title}>
          {({show, onShow, onHide}) => (
            <MessageTooltip
              key={title}
              show_trunkshow_message={show}
              onShowTrunkshowMessage={onShow}
              onHideTrunkshowMessage={onHide}
              message_text={message_text}
              show_link={false}
            />
          )}
        </ShowToggle>
      );
    } else {
      return false;
    }
  }

  if (value) {
    return (
      <div
        className={'order-summary-wrap-v2 column row ' + container_class}
        data-automation={title}
      >
        <label className={'pull-left ' + label_class}>
          {title}
          {renderSubLabel()}
        </label>
        <div className={'pull-right ' + label_class}>
          {negative && <span> - </span>}
          {currency}
          {value}
        </div>
      </div>
    );
  } else {
    return false;
  }
};

PaymentSummaryRow.propTypes = {
  sub_label: PropTypes.string,
  currency: PropTypes.string,
  value: PropTypes.string,
  container_class: PropTypes.string,
  label_class: PropTypes.string,
  negative: PropTypes.string,
  title: PropTypes.string,
  onClick: PropTypes.func,
  message_text: PropTypes.string
};

export default PaymentSummaryRow;
