{"version":3,"file":"index.mjs","sources":["../../../../src/composables/useBreadcrumb/index.ts"],"sourcesContent":["import {computed, inject, type MaybeRefOrGetter, toValue, watch} from 'vue'\nimport {breadcrumbGlobalIndexKey, breadcrumbPluginKey} 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(breadcrumbPluginKey)\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"],"names":[],"mappings":";;AAGa,MAAA,gBAAgB,CAI3B,KAAsC,6BACnC;AACG,QAAA,aAAa,OAAO,mBAAmB;AAEvC,QAAA,aAAa,SAAS,MAAM;AAC1B,UAAA,IAAI,QAAQ,EAAE;AAChB,QAAA,CAAC,EAAU,QAAA;AACR,WAAA;AAAA,EAAA,CACR;AAED;AAAA,IACE;AAAA,IACA,CAAC,aAAa;AACR,UAAA,CAAC,YAAY,CAAC,WAAY;AAC9B,iBAAW,MAAM,QAAQ;AAAA,QACvB,GAAG,WAAW,MAAM;AAAA,QACpB,CAAC,QAAQ,GAAG,WAAW,MAAM,MAAM,QAAQ,KAAK,CAAA;AAAA,MAClD;AAAA,IACF;AAAA,IACA,EAAC,WAAW,KAAI;AAAA,EAClB;AAEA,QAAM,QAAQ,SAAS;AAAA,IACrB,KAAK,OAAM,yCAAY,MAAM,MAAM,WAAW,WAAU,CAAC;AAAA,IACzD,IAAI,OAAO;AACT,UAAI,CAAC,WAAY;AACjB,iBAAW,MAAM,MAAM,WAAW,KAAK,IAAI;AAAA,IAAA;AAAA,EAC7C,CACD;AAEM,SAAA;AAAA,IACL;AAAA,IACA,QAAQ;AACN,UAAI,CAAC,WAAY;AACN,iBAAA,MAAM,WAAW,SAAS,MAAS;AAAA,IAAA;AAAA,EAElD;AACF;"}