/**
 * Registers lightweight descriptors for built-in modules.
 *
 * Implementations self-register after their loader resolves. Keeping this file
 * renderer-neutral means the shell can expose every tool without downloading
 * its UI or engine-specific dependencies up front.
 */
import { registerModule, type AsukaModuleDefinition } from './core/modules';
import { getI18n } from './core/i18n';

const lazyBuiltins: AsukaModuleDefinition[] = [
  { id: 'views', label: 'Views', icon: 'views', displayMode: 'floating', supportedEngines: ['fabric', '3d'], loader: () => import('./components/modules/ViewsModule') },
  { id: 'layers', label: 'Layers', icon: 'layers', supportedEngines: ['fabric', '3d'], requiredCapabilities: ['objects'], loader: () => import('./components/modules/LayersModule') },
  { id: 'history', label: 'History', icon: 'reset', displayMode: 'floating', supportedEngines: ['fabric', '3d'], loader: () => import('./components/modules/HistoryModule') },
  { id: 'zoom', label: 'Zoom', icon: 'zoom', displayMode: 'floating', supportedEngines: ['fabric', '3d'], loader: () => import('./components/modules/ZoomModule') },

  { id: 'image', label: 'Images', icon: 'images', displayMode: 'floating', supportedEngines: ['fabric', '3d'], requiredCapabilities: ['addImage'], loader: () => import('./components/modules/ImageModule') },
  { id: 'image-upload', label: 'Upload', icon: 'upload', displayMode: 'floating', supportedEngines: ['fabric', '3d'], requiredCapabilities: ['addImage'], loader: () => import('./components/modules/UploadImageModule') },
  { id: 'image-qrcode', label: getI18n().t('modules.qrcode-image'), icon: 'qr-code', displayMode: 'floating', supportedEngines: ['fabric', '3d'], requiredCapabilities: ['addImage'], loader: () => import('./components/modules/QRCodeImageModule') },
  { id: 'image-ai-text-to-image', label: 'AI image', icon: 'ai-image', displayMode: 'floating', licenseFeature: 'aiCredits', supportedEngines: ['fabric', '3d'], requiredCapabilities: ['addImage'], loader: () => import('./components/modules/AiTextToImageModule') },
  { id: 'image-pixabay', label: 'Pixabay', icon: 'pixabay', displayMode: 'floating', licenseFeature: 'pixabay', supportedEngines: ['fabric', '3d'], requiredCapabilities: ['addImage'], loader: () => import('./components/modules/PixabayImageModule') },
  { id: 'image-pexels', label: 'Pexels', icon: 'pexels', displayMode: 'floating', licenseFeature: 'pexels', supportedEngines: ['fabric', '3d'], requiredCapabilities: ['addImage'], loader: () => import('./components/modules/PexelsImageModule') },
  { id: 'image-facebook', label: 'Facebook', icon: 'facebook', displayMode: 'floating', licenseFeature: 'facebookImages', supportedEngines: ['fabric', '3d'], requiredCapabilities: ['addImage'], loader: () => import('./components/modules/FacebookImageModule') },
  { id: 'text', label: 'Text', icon: 'text', displayMode: 'floating', supportedEngines: ['fabric', '3d'], requiredCapabilities: ['addText'], loader: () => import('./components/modules/TextCreateModule') },
  { id: 'designs', label: 'Designs', icon: 'brush', displayMode: 'floating', keepMounted: true, supportedEngines: ['fabric', '3d'], requiredCapabilities: ['addDesign'], loader: () => import('./components/modules/DesignsModule') },
  { id: 'colors', label: 'Colors', icon: 'color', displayMode: 'floating', supportedEngines: ['fabric', '3d'], requiredCapabilities: ['color'], loader: () => import('./components/modules/ColorsModule') },
  { id: 'transform', label: 'Transform', icon: 'transform', displayMode: 'floating', keepMounted: true, supportedEngines: ['fabric', '3d'], requiredCapabilities: ['transform'], loader: () => import('./components/modules/TransformModule') },

  { id: 'font-family', label: 'Font family', icon: 'font-case', displayMode: 'floating', keepMounted: true, supportedEngines: ['fabric', '3d'], requiredCapabilities: ['objects'], loader: () => import('./components/modules/FontFamilyModule') },
  { id: 'text-formatting', label: 'Text', icon: 'formatting', displayMode: 'floating', supportedEngines: ['fabric', '3d'], requiredCapabilities: ['objects'], loader: () => import('./components/modules/TextFormattingModule') },
  { id: 'text-curve', label: 'Curved text', icon: 'curve-text', displayMode: 'floating', supportedEngines: ['fabric'], requiredCapabilities: ['canvas2d'], loader: () => import('./components/modules/TextCurveModule') },
  { id: 'shapes', label: 'Shapes', icon: 'customize', displayMode: 'floating', supportedEngines: ['fabric'], requiredCapabilities: ['canvas2d'], loader: () => import('./components/modules/ShapesModule') },
  { id: 'magnifier', label: 'Magnifier', icon: 'magnifying-glass', displayMode: 'floating', supportedEngines: ['fabric'], requiredCapabilities: ['canvas2d'], loader: () => import('./components/modules/MagnifierActionModule') },
  { id: 'ruler', label: 'Ruler', icon: 'ruler', displayMode: 'floating', supportedEngines: ['fabric'], requiredCapabilities: ['canvas2d'], loader: () => import('./components/modules/RulerActionModule') },

  { id: 'elements', label: 'Elements', icon: 'puzzle', displayMode: 'floating', keepMounted: true, supportedEngines: ['fabric', '3d'], requiredCapabilities: ['addElement'], loader: () => import('./components/modules/ElementsModule') },
  { id: 'element-editor', label: 'Element editor', icon: 'element-editor', displayMode: 'modal', keepMounted: true, supportedEngines: ['fabric', '3d'], requiredCapabilities: ['addElement'], loader: () => import('./components/modules/ElementEditorModule') },
  { id: 'element-variation-picker', label: 'Variations', icon: 'variations', displayMode: 'floating', supportedEngines: ['fabric', '3d'], loader: () => import('./components/modules/ElementVariationPickerModule') },
  { id: 'camera', label: 'Camera', icon: 'camera', displayMode: 'floating', keepMounted: true, supportedEngines: ['3d'], requiredCapabilities: ['scene3d'], loader: () => import('./components/modules/CameraModule') },

  { id: 'download', label: 'Download', icon: 'download', displayMode: 'floating', keepMounted: true, supportedEngines: ['fabric', '3d'], requiredCapabilities: ['exportPng'], loader: () => import('./components/modules/DownloadModule') },
  { id: 'state', label: 'State', icon: 'state', displayMode: 'floating', group: 'dev', supportedEngines: ['fabric', '3d'], loader: () => import('./components/modules/StateModule') },
  { id: 'license', label: 'License', icon: 'license', displayMode: 'floating', keepMounted: true, supportedEngines: ['fabric', '3d'], loader: () => import('./components/modules/LicenseModule') },

];

let registered = false;

export function registerBuiltinModules(): void {
  if (registered) return;
  registered = true;
  lazyBuiltins.forEach((definition) => registerModule({ ...definition, isAvailable: true }));
}
