import { DesignComp } from "@/modules/editor/objects/DesignTemp/DesignComp";
import { CompUI } from "..";

const cacheCompMap = new Map<string, DesignComp>();

export function addCacheToMap(obj: Record<string, DesignComp>) {
  cacheCompMap.forEach((comp) => {
    obj[comp.id] = comp;
  });
  cacheCompMap.clear();
}

export function createCompId(
  compKey: keyof typeof CompUI,
  options?: any
): string {
  const comp = CompUI[compKey].createComp(
    Object.assign(options || {}, { compKey })
  );
  cacheCompMap.set(comp.id, comp);

  return comp.id;
}
