{"version":3,"file":"index.mjs","names":[],"sources":["../../../../src/composables/useBreadcrumb/index.ts"],"sourcesContent":["import {computed, inject, type MaybeRefOrGetter, toValue, watch} from 'vue'\nimport {breadcrumbGlobalIndexKey, breadcrumbRegistryKey} from '../../utils/keys'\n\nexport const useBreadcrumb = (\n  /**\n   * When set it will utilize a separate instance of breadcrumb\n   */\n  id: MaybeRefOrGetter<string | null> = breadcrumbGlobalIndexKey\n) => {\n  const parentData = inject(breadcrumbRegistryKey, null)\n\n  const resolvedId = computed(() => {\n    const v = toValue(id)\n    if (!v) return breadcrumbGlobalIndexKey\n    return v\n  })\n\n  watch(\n    resolvedId,\n    (newValue) => {\n      if (!newValue || !parentData) return\n      parentData.items.value = {\n        ...parentData.items.value,\n        [newValue]: parentData.items.value[newValue] || [],\n      }\n    },\n    {immediate: true}\n  )\n\n  const items = computed({\n    get: () => parentData?.items.value[resolvedId.value] || [],\n    set(value) {\n      if (!parentData) return\n      parentData.items.value[resolvedId.value] = value\n    },\n  })\n\n  return {\n    items,\n    reset() {\n      if (!parentData) return\n      parentData.reset(resolvedId.value || undefined)\n    },\n  }\n}\n"],"mappings":";;;AAGA,IAAa,iBAIX,KAAsC,6BACnC;CACH,MAAM,aAAa,OAAO,uBAAuB,KAAK;CAEtD,MAAM,aAAa,eAAe;EAChC,MAAM,IAAI,QAAQ,GAAG;AACrB,MAAI,CAAC,EAAG,QAAO;AACf,SAAO;GACP;AAEF,OACE,aACC,aAAa;AACZ,MAAI,CAAC,YAAY,CAAC,WAAY;AAC9B,aAAW,MAAM,QAAQ;GACvB,GAAG,WAAW,MAAM;IACnB,WAAW,WAAW,MAAM,MAAM,aAAa,EAAE;GACnD;IAEH,EAAC,WAAW,MAAK,CAClB;AAUD,QAAO;EACL,OATY,SAAS;GACrB,WAAW,YAAY,MAAM,MAAM,WAAW,UAAU,EAAE;GAC1D,IAAI,OAAO;AACT,QAAI,CAAC,WAAY;AACjB,eAAW,MAAM,MAAM,WAAW,SAAS;;GAE9C,CAAC;EAIA,QAAQ;AACN,OAAI,CAAC,WAAY;AACjB,cAAW,MAAM,WAAW,SAAS,KAAA,EAAU;;EAElD"}