import type { PersonalityQuizWorkflow } from '@/components/personality-quiz/types';
import { PersonalityQuizIntro } from '@/components/personality-quiz/PersonalityQuizIntro';
import { PersonalityQuizQuestionView } from '@/components/personality-quiz/PersonalityQuizQuestionView';
import { PersonalityResultView } from '@/components/personality-quiz/PersonalityResultView';
import { StatePanel } from '@/components/ui/state-panel';

interface PersonalityQuizViewProps {
  readonly workflow: PersonalityQuizWorkflow;
  readonly onViewDirectory: () => void;
  readonly savedDate?: string | null;
  readonly isSaving: boolean;
}

export function PersonalityQuizView({
  workflow,
  onViewDirectory,
  savedDate,
  isSaving,
}: PersonalityQuizViewProps) {
  if (workflow.isContentLoading) {
    return (
      <StatePanel tone="violet" size="lg" alignment="center" loading>
        Loading personality assessment...
      </StatePanel>
    );
  }

  if (workflow.contentError) {
    return (
      <StatePanel tone="red" role="alert">
        Personality assessment content could not be loaded from the backend.
      </StatePanel>
    );
  }

  if (workflow.totalQuestions === 0 || workflow.personalityTypes.length === 0) {
    return (
      <StatePanel tone="slate">
        Personality assessment content is not available yet.
      </StatePanel>
    );
  }

  if (!workflow.started && !workflow.showResult) {
    return <PersonalityQuizIntro workflow={workflow} onViewDirectory={onViewDirectory} />;
  }

  if (workflow.showResult && workflow.result) {
    return (
      <PersonalityResultView
        workflow={workflow}
        onViewDirectory={onViewDirectory}
        savedDate={savedDate}
        isSaving={isSaving}
      />
    );
  }

  return <PersonalityQuizQuestionView workflow={workflow} />;
}
