{"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,IAAI;CAErD,MAAM,aAAa,eAAe;EAChC,MAAM,IAAI,QAAQ,EAAE;EACpB,IAAI,CAAC,GAAG,OAAO;EACf,OAAO;CACT,CAAC;CAED,MACE,aACC,aAAa;EACZ,IAAI,CAAC,YAAY,CAAC,YAAY;EAC9B,WAAW,MAAM,QAAQ;GACvB,GAAG,WAAW,MAAM;IACnB,WAAW,WAAW,MAAM,MAAM,aAAa,CAAC;EACnD;CACF,GACA,EAAC,WAAW,KAAI,CAClB;CAUA,OAAO;EACL,OATY,SAAS;GACrB,WAAW,YAAY,MAAM,MAAM,WAAW,UAAU,CAAC;GACzD,IAAI,OAAO;IACT,IAAI,CAAC,YAAY;IACjB,WAAW,MAAM,MAAM,WAAW,SAAS;GAC7C;EACF,CAGE;EACA,QAAQ;GACN,IAAI,CAAC,YAAY;GACjB,WAAW,MAAM,WAAW,SAAS,KAAA,CAAS;EAChD;CACF;AACF"}