import { ast } from "../ast.js";
import { RESERVED_WORDS, tryOrLog } from "./_shared.js";
export const viewChecks = (services) => {
  const index = services.shared.workspace.IndexManager;
  return tryOrLog((el, accept) => {
    if (!el.name) {
      return;
    }
    if (RESERVED_WORDS.includes(el.name)) {
      accept("error", `Reserved word: ${el.name}`, {
        node: el,
        property: "name"
      });
    }
    const anotherViews = index.allElements(ast.LikeC4View).filter((n) => n.name === el.name).limit(2).count();
    if (anotherViews > 1) {
      accept("error", `Duplicate view '${el.name}'`, {
        node: el,
        property: "name"
      });
    }
  });
};
