class o {
  constructor() {
    this.templates = /* @__PURE__ */ new Map();
  }
  /**
   * Register a template. Normalises `allowedTasks` (the backend's name) →
   * `availableTasks` (FlowForge's canonical name) so consumers can pass
   * either without rewriting.
   */
  register(t) {
    const e = {
      ...t,
      availableTasks: t.availableTasks ?? t.allowedTasks
    };
    return this.templates.set(e.triggerKey, e), this;
  }
  /**
   * Register a list of templates fetched from `GET /api/v1/workflow-template`.
   *
   * The API shape is:
   *   {
   *     key, name, description, allowedTasks, allowedSources,
   *     configuration,            // runtime BPMN — ignored by the canvas
   *     templateUI: {             // ← UI bag, spread onto the template
   *       triggerCategory, icon, tags, category, author, popularity,
   *       source, product, taskLabels, maxTasks, skeletonState, …
   *     }
   *   }
   *
   * Anything in `templateUI` overrides the top-level shorthand where there's
   * an overlap. Bad rows (missing `key`) are skipped with a DEV warning
   * rather than throwing, so one broken template doesn't blank the picker.
   *
   * Returns `this` for chaining and the count of templates registered.
   */
  registerFromApi(t) {
    for (const e of t ?? [])
      e != null && e.key && this.register({
        triggerKey: e.key,
        label: e.name ?? e.key,
        description: e.description,
        availableTasks: e.allowedTasks,
        ...e.templateUI ?? {}
      });
    return this;
  }
  lookup(t) {
    return this.templates.get(t);
  }
  list() {
    return [...this.templates.values()];
  }
  listByCategory(t) {
    return this.list().filter((e) => e.category === t);
  }
  listByTag(t) {
    return this.list().filter((e) => {
      var s;
      return (s = e.tags) == null ? void 0 : s.includes(t);
    });
  }
  search(t) {
    const e = t.toLowerCase();
    return this.list().filter(
      (s) => {
        var r, a, i;
        return s.label.toLowerCase().includes(e) || ((r = s.description) == null ? void 0 : r.toLowerCase().includes(e)) || ((a = s.tags) == null ? void 0 : a.some((l) => l.toLowerCase().includes(e))) || ((i = s.category) == null ? void 0 : i.toLowerCase().includes(e));
      }
    );
  }
  categories() {
    const t = /* @__PURE__ */ new Set();
    return this.list().forEach((e) => {
      e.category && t.add(e.category);
    }), Array.from(t);
  }
  /** Remove every template — useful before re-loading from backend. */
  clear() {
    return this.templates.clear(), this;
  }
}
const c = new o();
export {
  o as TemplateRegistry,
  c as templateRegistry
};
//# sourceMappingURL=templateRegistry.js.map
