import { BLOCK_REGISTRY } from "@nextsparkjs/registries/block-registry";
class BlockService {
  /**
   * Get all registered blocks
   *
   * @returns Array of all block configurations
   *
   * @example
   * ```typescript
   * const blocks = BlockService.getAll()
   * // Returns all 16 blocks from the registry
   * ```
   */
  static getAll() {
    return Object.values(BLOCK_REGISTRY);
  }
  /**
   * Get block by slug
   *
   * @param slug - Unique block identifier
   * @returns Block configuration or undefined if not found
   *
   * @example
   * ```typescript
   * const heroBlock = BlockService.get('hero')
   * if (heroBlock) {
   *   console.log(heroBlock.name) // "Hero Section"
   * }
   * ```
   */
  static get(slug) {
    return BLOCK_REGISTRY[slug];
  }
  /**
   * Get blocks by category
   *
   * @param category - Block category to filter by
   * @returns Array of blocks in the specified category
   *
   * @example
   * ```typescript
   * const heroBlocks = BlockService.getByCategory('hero')
   * // Returns all hero blocks (4 blocks)
   * ```
   */
  static getByCategory(category) {
    return Object.values(BLOCK_REGISTRY).filter((block) => block.category === category);
  }
  /**
   * Check if block exists
   *
   * @param slug - Block slug to check
   * @returns True if block exists in registry
   *
   * @example
   * ```typescript
   * if (BlockService.has('hero')) {
   *   // Block exists, safe to use
   * }
   * ```
   */
  static has(slug) {
    return slug in BLOCK_REGISTRY;
  }
  /**
   * Get blocks that are allowed in patterns
   * Filters out blocks with allowInPatterns: false
   *
   * @returns Array of blocks allowed in patterns
   *
   * @example
   * ```typescript
   * const patternsBlocks = BlockService.getForPatterns()
   * // Returns all blocks except pattern references
   * ```
   */
  static getForPatterns() {
    return Object.values(BLOCK_REGISTRY).filter(
      (block) => block.allowInPatterns !== false
    );
  }
  /**
   * Get blocks for a specific entity scope, respecting pattern context
   *
   * @param entitySlug - Entity slug (e.g., 'pages', 'posts', 'patterns')
   * @returns Filtered blocks array
   *
   * @example
   * ```typescript
   * // Get blocks for pages
   * const pageBlocks = BlockService.getForScope('pages')
   *
   * // Get blocks for patterns (excludes blocks with allowInPatterns: false)
   * const patternBlocks = BlockService.getForScope('patterns')
   * ```
   */
  static getForScope(entitySlug) {
    const effectiveScope = entitySlug === "patterns" ? "pages" : entitySlug;
    const scopeFiltered = Object.values(BLOCK_REGISTRY).filter(
      (block) => {
        var _a, _b;
        return ((_a = block.scope) == null ? void 0 : _a.includes(effectiveScope)) || ((_b = block.scope) == null ? void 0 : _b.includes("*"));
      }
    );
    if (entitySlug === "patterns") {
      return scopeFiltered.filter((block) => block.allowInPatterns !== false);
    }
    return scopeFiltered;
  }
}
export {
  BlockService
};
