import { initEditor } from "@/modules/editor";
import { isPc } from "@queenjs/utils";
import { defineComponent } from "vue";

export default defineComponent(() => {
  const editor = initEditor();
  const params = new URLSearchParams(location.href.split("?")[1]);
  const id = params.get("id");

  editor.actions.switchMode("preview");

  if (id) {
    editor.actions.initDesign(id);
    editor.controls.wxCtrl.setup(window.location.href);

    editor.actions.on("initDesign:success", () => {
      const data = editor.store.designData;
      document.title = data.title;
      const shareData = {
        title: data.title,
        link: location.href,
        imgUrl: data.thumbnail || "",
        desc: data.desc,
      };
      editor.controls.wxCtrl.setShareData(shareData);
      editor.controls.wxCtrl.setShare(shareData);
    });
  }

  return () => (
    <div class="flex items-center justify-center h-100vh bg-gray-100">
      <div class={isPc() ? `h-668px scrollbar` : `h-full`}>
        <editor.components.Preview />
      </div>
    </div>
  );
});
