import * as React from "react";
import { ComponentTypes } from "../types";
import { PluginProps } from "./types";

export const HTMLPlugin: React.FC<PluginProps> = ({ settings }) => {
  const { html = "" } = settings;
  return (
    <div
      data-testid="WC-HTML-LIVE"
      dangerouslySetInnerHTML={{ __html: html }}
    />
  );
};

export const onComponentRender = (hook, payload, actions) => {
  if (hook.id === "webcomponent" && payload.type === ComponentTypes.HTML) {
    return [HTMLPlugin];
  }
};

export default HTMLPlugin;
