import { useEditor } from "@/modules/editor";
import { CompObject } from "@/modules/editor/controllers/SelectCtrl/compObj";
import { onMounted, ref, inject, provide, compile } from "vue";

export function useCompRef(compId: string) {
  const compRef = ref();
  const { store, helper, compObjsMap } = useEditor();

  const parentId = compId !== "root" ? (inject("compParentId") as string) : "";
  provide("compParentId", compId);
  store.setCompPid(compId, parentId);

  onMounted(() => {
    const comp = helper.findComp(compId);
    if (comp) {
      Object.defineProperties(comp, {
        $el: {
          value: compRef.value,
          configurable: true,
        },
      });
    }
  });
  return compRef;
}
