import s from "../../../_virtual/cjs.js";
class h {
  constructor() {
    this.registeredBlocks = {}, this.groupOrder = [], this.breakpoints = {};
  }
  /**
   * Register multiple blocks at once
   * @param blocks - Array of block configurations to register
   */
  registerBlocks(e) {
    return e.forEach((r) => {
      this.registerBlock(r);
    }), this;
  }
  /**
   * Register a single block configuration
   * @param block - Block configuration to register
   * @throws Error if the block type is already registered
   */
  registerBlock(e) {
    if (this.registeredBlocks[e.type])
      throw new Error(`Block type "${e.type}" already registered`);
    return this.registeredBlocks[e.type] = e, this;
  }
  getRegisteredBlocks() {
    return this.registeredBlocks;
  }
  /**
   * Get all registered blocks
   * @returns Object containing all registered blocks
   */
  getBlocks() {
    return Object.values(this.registeredBlocks);
  }
  /**
   * Get a block by its type
   * @param type - The type of the block to retrieve
   * @returns The block configuration if found, otherwise undefined
   */
  getBlock(e) {
    if (!this.registeredBlocks[e])
      throw new Error(`Block type "${e}" is not registered`);
    return this.registeredBlocks[e];
  }
  /**
   * Get blocks by their group
   * @param group - The group to filter blocks by
   * @returns Array of blocks that belong to the specified group
   */
  getBlocksByGroup(e) {
    return Object.values(this.registeredBlocks).filter((r) => r.group === e);
  }
  /**
   * Get all registered block types
   * @returns Array of block type strings
   */
  getBlockTypes() {
    return Object.keys(this.registeredBlocks);
  }
  /**
   * Get all registered groups
   * @returns Array of group configurations
   */
  setGroupsOrder(e) {
    return this.groupOrder = e, this;
  }
  /**
   * Get the order of registered groups
   * @returns Array of block groups in the order they were registered
   */
  getGroupsOrder() {
    return this.groupOrder;
  }
  /**
   * Get the order index of a specific group
   * @param group - The group to find the order index for
   * @returns The index of the group in the registered order, or -1 if not found
   */
  getGroupOrder(e) {
    return this.groupOrder.indexOf(e);
  }
  /**
   * Get all registered breakpoints
   * @returns Object containing all registered breakpoints
   */
  registerBreakpoints(e) {
    return e.forEach((r) => {
      this.registerBreakpoint(r);
    }), this;
  }
  /**
   * Register a single breakpoint configuration
   * @param breakpoint - The breakpoint configuration to register
   * @throws Error if the breakpoint key is already registered
   */
  registerBreakpoint(e) {
    if (this.breakpoints[e.key])
      throw new Error(`Breakpoint "${e.key}" is already registered`);
    return this.breakpoints[e.key] = e, this;
  }
  /**
   * Get a specific breakpoint by its key
   * @param key - The key of the breakpoint to retrieve
   * @returns The breakpoint configuration if found, otherwise undefined
   */
  getBreakpoint(e) {
    if (!this.breakpoints[e])
      throw new Error(`Breakpoint "${e}" is not registered`);
    return this.breakpoints[e];
  }
  /**
   * Get all registered breakpoints
   * @returns Array of all registered breakpoint configurations
   */
  getBreakpoints() {
    return Object.values(this.breakpoints);
  }
  /**
   * Get a media query string for a specific breakpoint
   * @param key - The key of the breakpoint to generate the media query for
   * @returns Media query string for the specified breakpoint
   */
  getMediaQuery(e) {
    const r = this.getBreakpoint(e);
    return `@media (max-width: ${r.maxWidth}px) and (min-width: ${r.minWidth}px)`;
  }
  /**
   * Merge custom configuration with existing configuration
   * @param config - Custom builder configuration to merge
   * @returns The BuilderRegistry instance for method chaining
   */
  mergeConfig(e) {
    return e.blocks && e.blocks.length > 0 && e.blocks.forEach((r) => {
      const t = this.registeredBlocks[r.type];
      t ? this.registeredBlocks[r.type] = s(t, r) : this.registerBlock(r);
    }), e.groups && e.groups.length > 0 && this.setGroupsOrder(e.groups), e.breakpoints && e.breakpoints.length > 0 && e.breakpoints.forEach((r) => {
      const t = this.breakpoints[r.key];
      t ? this.breakpoints[r.key] = s(t, r) : this.registerBreakpoint(r);
    }), this;
  }
}
export {
  h as BuilderRegistry
};
//# sourceMappingURL=registry.js.map
