// src/components/BreadcrumbMenu/breadcrumbStore.ts
import { create } from "zustand";
var useBreadcrumbStore = create((set, get) => ({
  breadcrumbs: {},
  setBreadcrumbs: (namespace, items) => {
    set((state) => ({
      breadcrumbs: {
        ...state.breadcrumbs,
        [namespace]: items
      }
    }));
  },
  addBreadcrumb: (namespace, item) => {
    set((state) => {
      const current = state.breadcrumbs[namespace] || [];
      return {
        breadcrumbs: {
          ...state.breadcrumbs,
          [namespace]: [...current, item]
        }
      };
    });
  },
  updateBreadcrumb: (namespace, itemId, updates) => {
    set((state) => {
      const current = state.breadcrumbs[namespace] || [];
      return {
        breadcrumbs: {
          ...state.breadcrumbs,
          [namespace]: current.map(
            (item) => item.id === itemId ? { ...item, ...updates } : item
          )
        }
      };
    });
  },
  removeBreadcrumbFrom: (namespace, itemId) => {
    set((state) => {
      const current = state.breadcrumbs[namespace] || [];
      const index = current.findIndex((item) => item.id === itemId);
      if (index === -1) return state;
      return {
        breadcrumbs: {
          ...state.breadcrumbs,
          [namespace]: current.slice(0, index)
        }
      };
    });
  },
  sliceBreadcrumbs: (namespace, index) => {
    set((state) => {
      const current = state.breadcrumbs[namespace] || [];
      return {
        breadcrumbs: {
          ...state.breadcrumbs,
          [namespace]: current.slice(0, index + 1)
        }
      };
    });
  },
  clearBreadcrumbs: (namespace) => {
    set((state) => {
      const { [namespace]: _, ...rest } = state.breadcrumbs;
      return {
        breadcrumbs: rest
      };
    });
  },
  getBreadcrumbs: (namespace) => {
    return get().breadcrumbs[namespace] || [];
  }
}));
var useBreadcrumb = (namespace) => {
  const store = useBreadcrumbStore();
  const breadcrumbs = store.breadcrumbs[namespace] || [];
  return {
    breadcrumbs,
    /**
     * Define todos os breadcrumbs de uma vez
     */
    setBreadcrumbs: (items) => {
      store.setBreadcrumbs(namespace, items);
    },
    /**
     * Adiciona um novo breadcrumb ao final
     */
    addBreadcrumb: (item) => {
      store.addBreadcrumb(namespace, item);
    },
    /**
     * Atualiza um breadcrumb existente
     */
    updateBreadcrumb: (itemId, updates) => {
      store.updateBreadcrumb(namespace, itemId, updates);
    },
    /**
     * Remove um breadcrumb e todos os seguintes
     */
    removeBreadcrumbFrom: (itemId) => {
      store.removeBreadcrumbFrom(namespace, itemId);
    },
    /**
     * Mantém apenas os breadcrumbs até o índice especificado (inclusivo)
     */
    sliceBreadcrumbs: (index) => {
      store.sliceBreadcrumbs(namespace, index);
    },
    /**
     * Limpa todos os breadcrumbs
     */
    clearBreadcrumbs: () => {
      store.clearBreadcrumbs(namespace);
    }
  };
};
export {
  useBreadcrumb,
  useBreadcrumbStore
};
//# sourceMappingURL=index.mjs.map