import {
  TEMPLATE_REGISTRY,
  TEMPLATE_METADATA
} from "@nextsparkjs/registries/template-registry";
class TemplateService {
  /**
   * Check if an app path has a template override
   *
   * @param appPath - App path to check (e.g., 'app/(public)/page.tsx')
   * @returns True if template override exists
   *
   * @example
   * ```typescript
   * if (TemplateService.hasOverride('app/(public)/page.tsx')) {
   *   // Template exists, use override
   * }
   * ```
   */
  static hasOverride(appPath) {
    return appPath in TEMPLATE_REGISTRY;
  }
  /**
   * Get template component for app path
   * Returns the highest priority template component
   *
   * @param appPath - App path to get component for
   * @returns Template component or null if not found
   *
   * @example
   * ```typescript
   * const Component = TemplateService.getComponent('app/(public)/page.tsx')
   * if (Component) {
   *   return <Component {...props} />
   * }
   * ```
   */
  static getComponent(appPath) {
    const entry = TEMPLATE_REGISTRY[appPath];
    return (entry == null ? void 0 : entry.component) || null;
  }
  /**
   * Get full template entry for app path
   *
   * @param appPath - App path to get entry for
   * @returns Template registry entry or null if not found
   *
   * @example
   * ```typescript
   * const entry = TemplateService.getEntry('app/(public)/page.tsx')
   * if (entry) {
   *   console.log(entry.template.themeName) // 'default'
   * }
   * ```
   */
  static getEntry(appPath) {
    return TEMPLATE_REGISTRY[appPath] || null;
  }
  /**
   * Get all app paths that have template overrides
   *
   * @returns Array of app paths with overrides
   *
   * @example
   * ```typescript
   * const paths = TemplateService.getOverriddenPaths()
   * // ['app/(public)/page.tsx', 'app/(public)/layout.tsx', ...]
   * ```
   */
  static getOverriddenPaths() {
    return Object.keys(TEMPLATE_REGISTRY);
  }
  /**
   * Get templates by template type
   *
   * @param templateType - Template type (e.g., 'page', 'layout', 'error')
   * @returns Array of template entries matching the type
   *
   * @example
   * ```typescript
   * const pages = TemplateService.getByType('page')
   * const layouts = TemplateService.getByType('layout')
   * ```
   */
  static getByType(templateType) {
    return Object.values(TEMPLATE_REGISTRY).filter((entry) => entry.template.templateType === templateType);
  }
  /**
   * Get templates by theme name
   *
   * @param themeName - Theme name (e.g., 'default')
   * @returns Array of template entries for the theme
   *
   * @example
   * ```typescript
   * const defaultTemplates = TemplateService.getByTheme('default')
   * ```
   */
  static getByTheme(themeName) {
    const results = [];
    Object.values(TEMPLATE_REGISTRY).forEach((entry) => {
      if (entry.template.themeName === themeName) {
        results.push(entry);
      }
      entry.alternatives.forEach((alt) => {
        if (alt.themeName === themeName) {
          results.push({
            appPath: entry.appPath,
            component: null,
            // Would need dynamic import
            template: alt,
            alternatives: []
          });
        }
      });
    });
    return results;
  }
  /**
   * Resolve template for a given app path
   * Returns theme template if available, null if should use original app file
   *
   * @param appPath - App path to resolve
   * @returns Resolution result with hasOverride flag and template details
   *
   * @example
   * ```typescript
   * const result = TemplateService.resolve('app/(public)/page.tsx')
   * if (result.hasOverride) {
   *   return result.component
   * }
   * // Use original app file
   * ```
   */
  static resolve(appPath) {
    const entry = this.getEntry(appPath);
    if (entry) {
      return {
        hasOverride: true,
        component: entry.component,
        template: entry.template,
        originalPath: appPath
      };
    }
    return {
      hasOverride: false,
      originalPath: appPath
    };
  }
  /**
   * Get all template entries
   *
   * @returns Array of all template entries
   */
  static getAll() {
    return Object.values(TEMPLATE_REGISTRY);
  }
  /**
   * Get template count
   *
   * @returns Total number of templates
   */
  static getCount() {
    return TEMPLATE_METADATA.totalTemplates;
  }
  /**
   * Get available template types
   *
   * @returns Array of template types (e.g., ['page', 'layout'])
   */
  static getTypes() {
    return TEMPLATE_METADATA.templateTypes;
  }
  /**
   * Get registry metadata
   *
   * @returns Template registry metadata
   */
  static getMetadata() {
    return TEMPLATE_METADATA;
  }
}
export {
  TemplateService
};
