import { useEditor } from "@/modules/editor";
import { clipboard } from "@/utils";
import { useAuth } from "@queenjs-modules/auth";
import { useQRCode } from "@vueuse/integrations/useQRCode";
import { Button } from "ant-design-vue";
import { defineComponent } from "vue";

export const ShareBox = defineComponent({
  setup() {
    const { store } = useEditor();
    const auth = useAuth();
    const userInfo: any = auth.store.userInfo;
    const isSys = userInfo.roles?.includes("system") ? true : false;
    let shareLink =
      location.origin +
      "/share.html?id=" +
      store.designData._id +
      "&isSys=" +
      isSys;
    // if (location.host == "www.infish.cn") {
    //   shareLink =
    //     location.origin +
    //     "/projects/queenshowv1/share.html?id=" +
    //     store.designData._id;
    // }

    const qrUrl = useQRCode(shareLink);

    return () => (
      <div class="p-20px bg-dark-500 text-center">
        <img src={qrUrl.value} />
        <div class="mb-20px"></div>
        <Button onClick={() => clipboard.copy(shareLink)}>复制链接</Button>
      </div>
    );
  },
});
