// @ts-nocheck
import * as React from "react";
import WebViewApi from "./web-view-api";
import { useSiteSettings } from "../../providers/site";

class MyMainApi {
  send = undefined;

  setSend(send: any) {
    this.send = send;
  }

  onload = () => {};

  welcome = (message: any) => {
    const send: any = this.send;
    if (send) send("welcome", [message], false);
  };

  howOldAreYou = () =>
    new Promise((resolve) => {
      resolve(3);
    });
}

function EmbedPannels({ channelSlug }: any) {
  const { slug } = useSiteSettings() as any;
  const myMainApi = new MyMainApi();

  return (
    <WebViewApi
      source={{
        uri: `https://sapphire.maestro.io/${slug}/${channelSlug}/?iframe_sdk=iframe&embed=panels-mobile`,
      }}
      apis={[myMainApi]}
      setSend={(send) => {
        myMainApi.setSend(send);
      }}
      onLoadEnd={myMainApi.onload as any}
      onError={(syntheticEvent: { nativeEvent: any }) => {
        const { nativeEvent } = syntheticEvent;
        console.warn("WebView error: ", nativeEvent);
      }}
      // enable the listener to log all messages
      // listener={(message) => {
      //   console.log(message);
      // }}
    />
  );
}

export default EmbedPannels;
