import { createContext, useContext } from 'react';
import type { FileType } from './file-types';

export type FileViewerContextValue = {
  filePath: string;
  fileName: string;
  root: string;
  fileType: FileType;
  content: string | null;
  loading: boolean;
  error: string | null;
  directContent: boolean;
  ttsLoading: boolean;
  ocrLoading: boolean;
  transcribeLoading: boolean;
  extractAudioLoading: boolean;
  extractLoading: boolean;
  autoPlay: boolean;
  editable: boolean;
  editing: boolean;
  setEditing: (editing: boolean) => void;
  setContent: (content: string) => void;
  handleReadAloud: () => void;
  handleOcr: () => void;
  handleTranscribe: () => void;
  handleExtractAudio: () => void;
  handleExtract: () => void;
  handleDownload: () => void;
  handleSaveResult: (() => void) | null;
  saveResultLoading: boolean;
};

export const FileViewerContext = createContext<FileViewerContextValue | null>(null);

export const useFileViewer = () => {
  const ctx = useContext(FileViewerContext);
  if (!ctx) throw new Error('useFileViewer must be used within FileViewerProvider');
  return ctx;
};
