import { fk as htmlReactParser, P as PropTypes } from './index.esm2.js';
import { useRef, useEffect } from 'react';
import { jsx } from 'react/jsx-runtime';
import '@qubejs/core';
import 'react-dom';
import 'react-html-parser';
import 'react-router-dom';

const HTML = ({
  className: _className = '',
  value: _value = '',
  html: _html = '',
  onAction
}) => {
  const container = useRef();
  const handleClick = e => {
    var _targetToCheck$getAtt;
    let targetToCheck = e.target;
    while (targetToCheck.getAttribute('data-html-root') !== 'root' && targetToCheck && !targetToCheck.getAttribute('href')) {
      targetToCheck = targetToCheck.parentElement;
    }
    if (targetToCheck && (targetToCheck.getAttribute('data-action-type') || ((_targetToCheck$getAtt = targetToCheck.getAttribute('href')) == null ? void 0 : _targetToCheck$getAtt.indexOf('download-doc')) > -1)) {
      var _targetToCheck$getAtt2;
      e.stopPropagation();
      e.preventDefault();
      let actionType = targetToCheck.getAttribute('data-action-type');
      if (((_targetToCheck$getAtt2 = targetToCheck.getAttribute('href')) == null ? void 0 : _targetToCheck$getAtt2.indexOf('download-doc')) > -1) {
        actionType = 'download-doc';
      }
      let params = {};
      for (var i = 0; i < targetToCheck.attributes.length; i++) {
        params[targetToCheck.attributes[i].name] = targetToCheck.attributes[i].value;
      }
      onAction && onAction({}, Object.assign({
        actionType
      }, params));
    }
  };
  useEffect(() => {
    container.current.addEventListener('click', handleClick, false);
  }, []);
  return /*#__PURE__*/jsx("div", {
    className: `sq-html ${_className}`,
    "data-html-root": "root",
    children: /*#__PURE__*/jsx("div", {
      className: "sq-html__container",
      ref: container,
      children: /*#__PURE__*/jsx("div", {
        className: "sq-html__html",
        children: htmlReactParser(_html || _value)
      })
    })
  });
};
HTML.propTypes = {
  className: PropTypes.string,
  value: PropTypes.any
};

export { HTML as default };
