File size: 2,132 Bytes
65d68f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { Sparkles } from "lucide-react";
import { DocumentSelect } from "@/components/forms/DocumentSelect";
import { EmptyState } from "@/components/states/EmptyState";
import { ErrorState } from "@/components/states/ErrorState";
import { LoadingSpinner } from "@/components/states/LoadingSpinner";
import type { ApiDocument } from "@/lib/api/types";
import Link from "next/link";

type GeneratePanelProps = {
  documents: ApiDocument[];
  selectedDocumentId: string;
  onDocumentChange: (documentId: string) => void;
  isLoadingDocuments: boolean;
  documentError: string | null;
  isGenerating: boolean;
  buttonLabel: string;
  onGenerate: () => void;
};

export function GeneratePanel({
  documents,
  selectedDocumentId,
  onDocumentChange,
  isLoadingDocuments,
  documentError,
  isGenerating,
  buttonLabel,
  onGenerate,
}: GeneratePanelProps) {
  if (isLoadingDocuments) return <LoadingSpinner label="Loading your study sources\u2026" />;
  if (documentError) return <ErrorState title="Could not load sources" message="We couldn't reach your study sources. Try again or add new notes." action={<Link href="/upload" className="btn-primary !h-9 !text-[13px]">Add source</Link>} />;
  if (documents.length === 0) return <EmptyState title="No sources yet" description="Add notes or question papers to generate study outputs." action={<Link href="/upload" className="btn-primary !h-9 !text-[13px]">Add source</Link>} />;

  return (
    <section className="grid gap-3 lg:grid-cols-[1fr_200px]">
      <DocumentSelect documents={documents} selectedDocumentId={selectedDocumentId} onChange={onDocumentChange} />
      <button
        type="button"
        onClick={onGenerate}
        disabled={isGenerating || !selectedDocumentId}
        className="btn-primary !h-full min-h-[72px] disabled:cursor-not-allowed disabled:opacity-40"
      >
        {isGenerating ? (
          <span className="size-4 animate-spin rounded-full border-2 border-white/30 border-t-white" />
        ) : (
          <Sparkles className="size-4" />
        )}
        {isGenerating ? "Generating" : buttonLabel}
      </button>
    </section>
  );
}