import React from 'react';
import String from 'string';
import PropTypes from 'prop-types';
import { DEFAULT_TRUNCATED_LENGHT } from '../../constants/general';

/**
 * @description propTypes for InnerHtmlStripTags
 * @type {Object}
 */
const propTypes = {
  html: PropTypes.string.isRequired,
  truncateTo: PropTypes.number,
};

/**
 * @description default props for InnerHtmlStripTags
 * @type {Object}
 */
const defaultProps = {
  truncateTo: DEFAULT_TRUNCATED_LENGHT,
};

/**
 * @function InnerHtmlStripTags
 * @param {String} html html string
 * @param {Number} [truncateTo] truncate length
 * @returns {XML}
 */
function InnerHtmlStripTags({ html, truncateTo }) {
  const stripedHtml = String(html)
    .trim()
    .replaceAll('&nbsp;',' ')
    .stripTags()
    .s;

  const truncatedHtml = String(stripedHtml)
    .truncate(truncateTo).s;

  return <span> {truncatedHtml}</span>;
}

InnerHtmlStripTags.propTypes = propTypes;
InnerHtmlStripTags.defaultProps = defaultProps;

export default InnerHtmlStripTags;

@@ -734,16 +734,17 @@
 &nbsp;',
+ 
 ' ')%0A   
@@ -858,11 +858,44 @@
 span
-%3E %7B
+ dangerouslySetInnerHTML=%7B%7B __html: 
 trun
@@ -907,15 +907,13 @@
 Html
-%7D%3C/span
+ %7D%7D /
 %3E;%0A%7D

put striped HTML to the dangerouslySetInnerHTML