import styles from '../ContentPreview.module.css';

// Updated to handle both previewUrl and previewContent

interface TextRendererProps {
  previewUrl?: string;
  previewContent?: string;
  fileName: string;
  mimeType?: string;
  onError: () => void;
}

export function TextRenderer({ previewUrl, previewContent, fileName, mimeType, onError }: TextRendererProps) {
  // If we have previewContent directly, display it as text
  if (previewContent && !previewUrl) {
    return (
      <div className={styles.textContainer}>
        <div className={styles.textHeader}>
          <span className={styles.textTitle}>Text Preview</span>
        </div>
        <pre className={styles.textPreview}>
          <code className={styles.textCode}>
            {previewContent}
          </code>
        </pre>
      </div>
    );
  }

  // Otherwise, use iframe with previewUrl
  return (
    <iframe
      src={previewUrl}
      className={styles.previewIframe}
      title={`Preview of ${fileName}`}
      data-mime-type={mimeType}
      onError={onError}
      style={{ background: 'white !important' }}
    />
  );
}

