/**
 * Generation Config Hook
 */

import { useState, useCallback, useMemo } from 'react';
import { useOptions } from './useOptions';

export interface GenerationConfig {
  model?: string;
  resolution?: string;
  aspectRatio?: string;
  duration?: number;
  count?: number;
  style?: string;
}

export const useGenerationConfig = () => {
  const [config, setConfig] = useState<GenerationConfig>({});

  const updateConfig = useCallback((updates: Partial<GenerationConfig>) => {
    setConfig(prev => ({ ...prev, ...updates }));
  }, []);

  const resetConfig = useCallback(() => {
    setConfig({});
  }, []);

  return {
    config,
    updateConfig,
    resetConfig,
  };
};

// Alias for backward compatibility
export const useVideoGenerationOptions = useGenerationConfig;

// Character options hook - returns structured options data
export function useCharacterOptions() {
  const { options, loading, error } = useOptions();

  const data = useMemo(() => {
    if (!options) return null;

    return {
      genders: {
        options: (options.character_genders?.zh || []).map((value: string) => ({
          label: value,
          value,
        })),
      },
      roles: {
        options: (options.character_roles?.zh || []).map((value: string) => ({
          label: value,
          value,
        })),
      },
      emotions: {
        options: [], // Add when available in OptionsConfig
      },
    };
  }, [options]);

  return { data, loading, error };
}

// Scene options hook - returns structured options data
export function useSceneOptions() {
  const { options, loading, error } = useOptions();

  const data = useMemo(() => {
    if (!options) return null;

    return {
      types: {
        options: [], // Add when available
      },
      times: {
        options: [], // Add when available
      },
    };
  }, [options]);

  return { data, loading, error };
}

// Storyboard options hook - returns structured options data
export function useStoryboardOptions() {
  const { options, loading, error } = useOptions();

  const data = useMemo(() => {
    if (!options) return null;

    return {
      shotTypes: {
        options: (options.shot_types?.zh || []).map((value: string) => ({
          label: value,
          value,
        })),
      },
      cameraMovements: {
        options: (options.camera_movements?.zh || []).map((value: string) => ({
          label: value,
          value,
        })),
      },
    };
  }, [options]);

  return { data, loading, error };
}

// Cinematic options hook - returns structured options data
export function useCinematicOptions() {
  const { loading, error } = useOptions();

  const data = useMemo(() => {
    // TODO: Add cinematic options when available in OptionsConfig
    return {
      cameraAngles: {
        options: [] as { label: string; value: string }[],
      },
      transitions: {
        options: [] as { label: string; value: string }[],
      },
    };
  }, []);

  return { data, loading, error };
}
