/**
 * WooNooW Addon TypeScript Definitions
 * 
 * Type definitions for addon developers using the WooNooW API
 * 
 * @package WooNooW
 * @version 1.0.0
 */

import type { ComponentType } from 'react';

declare global {
  interface Window {
    /**
     * WooNooW API exposed to addon developers
     */
    WooNooW: {
      React: typeof import('react');
      ReactDOM: typeof import('react-dom/client');
      
      hooks: {
        useQuery: any;
        useMutation: any;
        useQueryClient: any;
        useModules: () => {
          isEnabled: (moduleId: string) => boolean;
          modules: string[];
        };
        useModuleSettings: (moduleId: string) => {
          settings: Record<string, any>;
          isLoading: boolean;
          updateSettings: {
            mutate: (settings: Record<string, any>) => void;
            isPending: boolean;
          };
          saveSetting: (key: string, value: any) => void;
        };
      };
      
      components: {
        Button: ComponentType<any>;
        Input: ComponentType<any>;
        Label: ComponentType<any>;
        Textarea: ComponentType<any>;
        Switch: ComponentType<any>;
        Select: ComponentType<any>;
        SelectContent: ComponentType<any>;
        SelectItem: ComponentType<any>;
        SelectTrigger: ComponentType<any>;
        SelectValue: ComponentType<any>;
        Checkbox: ComponentType<any>;
        Badge: ComponentType<any>;
        Card: ComponentType<any>;
        CardContent: ComponentType<any>;
        CardDescription: ComponentType<any>;
        CardFooter: ComponentType<any>;
        CardHeader: ComponentType<any>;
        CardTitle: ComponentType<any>;
        SettingsLayout: ComponentType<{
          title: string;
          description?: string;
          isLoading?: boolean;
          children: React.ReactNode;
        }>;
        SettingsCard: ComponentType<{
          title: string;
          description?: string;
          children: React.ReactNode;
        }>;
        SettingsSection: ComponentType<any>;
        SchemaForm: ComponentType<{
          schema: FormSchema;
          initialValues?: Record<string, any>;
          onSubmit: (values: Record<string, any>) => void | Promise<void>;
          isSubmitting?: boolean;
          submitLabel?: string;
          errors?: Record<string, string>;
        }>;
        SchemaField: ComponentType<any>;
      };
      
      icons: {
        Settings: ComponentType<any>;
        Save: ComponentType<any>;
        Trash2: ComponentType<any>;
        Edit: ComponentType<any>;
        Plus: ComponentType<any>;
        X: ComponentType<any>;
        Check: ComponentType<any>;
        AlertCircle: ComponentType<any>;
        Info: ComponentType<any>;
        Loader2: ComponentType<any>;
        ChevronDown: ComponentType<any>;
        ChevronUp: ComponentType<any>;
        ChevronLeft: ComponentType<any>;
        ChevronRight: ComponentType<any>;
      };
      
      utils: {
        api: {
          get: (endpoint: string) => Promise<any>;
          post: (endpoint: string, data?: any) => Promise<any>;
          put: (endpoint: string, data?: any) => Promise<any>;
          delete: (endpoint: string) => Promise<any>;
        };
        toast: {
          success: (message: string) => void;
          error: (message: string) => void;
          info: (message: string) => void;
          warning: (message: string) => void;
        };
        __: (text: string, domain?: string) => string;
      };
    };
  }
}

/**
 * Form Schema Types
 */
export type FieldType = 'text' | 'textarea' | 'email' | 'url' | 'number' | 'toggle' | 'checkbox' | 'select';

export interface FieldSchema {
  type: FieldType;
  label: string;
  description?: string;
  placeholder?: string;
  required?: boolean;
  default?: any;
  options?: Record<string, string>;
  min?: number;
  max?: number;
}

export type FormSchema = Record<string, FieldSchema>;

/**
 * Module Registration
 */
export interface ModuleRegistration {
  id: string;
  name: string;
  description: string;
  version: string;
  author: string;
  category: 'marketing' | 'customers' | 'products' | 'shipping' | 'payments' | 'analytics' | 'other';
  icon: string;
  features: string[];
  has_settings?: boolean;
  settings_component?: string;
  spa_bundle?: string;
}

/**
 * Settings Schema Registration
 */
export interface SettingsSchemaRegistration {
  [moduleId: string]: FormSchema;
}

export {};
