import { inject, type InjectionKey, type Ref } from "vue";

export type HierarchyOption = {
  id: string | number;
  label: string;
  slug?: string | null;
};

export type HierarchyContext = {
  parentField: string;
  parentSlugPrefix: Ref<string>;
  setParentOption: (option: HierarchyOption) => void;
  clearParentOption: () => void;
};

export const hierarchyContextKey: InjectionKey<HierarchyContext> =
  Symbol("hierarchyContext");

export function useHierarchyContext(): HierarchyContext | null {
  return inject(hierarchyContextKey, null);
}
