import { createElement } from 'react';
import { createRoot } from 'react-dom/client';
import App from './App';

class PDFReaderPanel extends TemplateElement {
  dataListener?: ViewListener.ViewListener;

  constructor() {
    super();
  }

  connectedCallback() {
    super.connectedCallback();

    this.dataListener = RegisterViewListener('JS_LISTENER_COMM_BUS');

    const container = document.getElementById('react');
    if (container) {
      const root = createRoot(container);
      root.render(createElement(App, { dataListener: this.dataListener }));
    }
  }

  disconnectedCallback() {
    super.disconnectedCallback();
  }
}

window.customElements.define('pdf-reader-panel', PDFReaderPanel);
checkAutoload();
