import { onUnmounted } from "vue";
import { emitter } from "@/utils/eventBus";

export const useFlowEvents = () => {
  const listeners = [];

  const onFlowEvent = (type, handler) => {
    emitter.on(type, handler);
    listeners.push([type, handler]);
  };

  onUnmounted(() => {
    listeners.forEach(([type, handler]) => emitter.off(type, handler));
    listeners.length = 0;
  });

  return { onFlowEvent };
};
