import React from "react";
import ReactDOM from "react-dom";
import App, { Editor } from "./App";
import registerServiceWorker from "./registerServiceWorker";

const Index = props => (
  <App showAlertComment showAlertReply showAlertFavor showError {...props}>
    <Editor maxUpload={9} autoFocus />
  </App>
);

/**
 * 渲染评论组件
 * @param {object} config 编辑器配置
 *  - {string} id 渲染评论的DOM的 ID
 *  - {number} type 评论的 type
 *  - {string} businessId 评论的 businessId
 */
function renderComment(config) {
  if (!config.id) {
    throw new Error("id is required");
  }
  if (!config.id) {
    throw new Error("type is required");
  }
  if (!config.id) {
    throw new Error("businessId is required");
  }
  const { id, type = 1, businessId = "test" } = config;

  ReactDOM.render(
    <Index type={type} businessId={businessId} />,
    document.getElementById(id)
  );
  // registerServiceWorker();
}

window.renderComment = renderComment;

renderComment({
  id: "root-comment",
  type: 1,
  businessId: "test"
});
