// lib/traitRegistry.ts
var traits = /* @__PURE__ */ new Map();
var listeners = /* @__PURE__ */ new Set();
function notifyListeners() {
  listeners.forEach((listener) => listener());
}
function registerTrait(info) {
  traits.set(info.id, info);
  notifyListeners();
}
function updateTraitState(id, newState) {
  const trait = traits.get(id);
  if (trait) {
    trait.currentState = newState;
    trait.transitionCount++;
    notifyListeners();
  }
}
function updateGuardResult(traitId, guardName, result) {
  const trait = traits.get(traitId);
  if (trait) {
    const guard = trait.guards.find((g) => g.name === guardName);
    if (guard) {
      guard.lastResult = result;
      notifyListeners();
    }
  }
}
function unregisterTrait(id) {
  traits.delete(id);
  notifyListeners();
}
function getAllTraits() {
  return Array.from(traits.values());
}
function getTrait(id) {
  return traits.get(id);
}
function subscribeToTraitChanges(listener) {
  listeners.add(listener);
  return () => listeners.delete(listener);
}
function clearTraits() {
  traits.clear();
  notifyListeners();
}

export { clearTraits, getAllTraits, getTrait, registerTrait, subscribeToTraitChanges, unregisterTrait, updateGuardResult, updateTraitState };
