import React, { useState } from 'react';
import { AiValidationDialogs } from './components/AiValidationDialogs';
import { Product } from '../../../../types/products';
import { 
  AiValidationProgress, 
  AiValidationDetails, 
  CurrentPrompt as AiValidationCurrentPrompt 
} from './hooks/useAiValidation';

const ValidationStepNew: React.FC = () => {
  const [aiValidationProgress, setAiValidationProgress] = useState<AiValidationProgress>({
    isOpen: false,
    status: 'idle',
    step: 0
  });
  
  const [aiValidationDetails, setAiValidationDetails] = useState<AiValidationDetails>({
    changes: [],
    warnings: [],
    changeDetails: [],
    isOpen: false
  });
  
  const [currentPrompt, setCurrentPrompt] = useState<AiValidationCurrentPrompt>({
    isOpen: false,
    prompt: '',
    isLoading: true,
  });
  
  // Track reversion state (for internal use)
  const [reversionState, setReversionState] = useState<Record<string, boolean>>({});
  
  const [fieldData] = useState<Product[]>([]);

  // eslint-disable-next-line @typescript-eslint/no-unused-vars

  const revertAiChange = (productIndex: number, fieldKey: string) => {
    const key = `${productIndex}-${fieldKey}`;
    setReversionState(prev => ({
      ...prev,
      [key]: true
    }));
  };

  const isChangeReverted = (productIndex: number, fieldKey: string): boolean => {
    const key = `${productIndex}-${fieldKey}`;
    return !!reversionState[key];
  };

  const getFieldDisplayValueWithHighlight = (
    _fieldKey: string,
    originalValue: any,
    correctedValue: any
  ) => {
    return {
      originalHtml: String(originalValue),
      correctedHtml: String(correctedValue)
    };
  };

  return (
    <div>
      <AiValidationDialogs
        aiValidationProgress={aiValidationProgress}
        aiValidationDetails={aiValidationDetails}
        currentPrompt={currentPrompt}
        setAiValidationProgress={setAiValidationProgress}
        setAiValidationDetails={setAiValidationDetails}
        setCurrentPrompt={setCurrentPrompt}
        revertAiChange={revertAiChange}
        isChangeReverted={isChangeReverted}
        getFieldDisplayValueWithHighlight={getFieldDisplayValueWithHighlight}
        fields={fieldData}
        debugData={currentPrompt.debugData}
      />
    </div>
  );
};

export default ValidationStepNew; 