File size: 7,106 Bytes
50a8ea3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import React, { useState } from 'react';
import { analyzeIssueApi, AIAnalysisResponse } from '../services/api';

interface GuidedIntakeModalProps {
  initialCategory?: string;
  selectedCity: string;
  onClose: () => void;
  onLaunchCase: (aiData: AIAnalysisResponse, rawText: string) => void;
}

export const GuidedIntakeModal: React.FC<GuidedIntakeModalProps> = ({

  initialCategory = 'rti',

  selectedCity,

  onClose,

  onLaunchCase,

}) => {
  const [selectedModel, setSelectedModel] = useState<string>(initialCategory);
  const [grievanceText, setGrievanceText] = useState<string>('');
  const [attachedFile, setAttachedFile] = useState<File | null>(null);
  const [loading, setLoading] = useState(false);
  const [error, setError] = useState<string | null>(null);

  const handleProcess = async () => {
    if (!grievanceText.trim() && !attachedFile) return;

    setLoading(true);
    setError(null);
    try {
      const result = await analyzeIssueApi(
        grievanceText || `Document Analysis: ${attachedFile?.name}`,
        selectedCity,
        attachedFile || undefined
      );
      onLaunchCase(result, grievanceText || attachedFile?.name || 'New Filing');
      onClose();
    } catch (err: any) {
      setError(err?.message || 'Processing failed. Please try again.');
    } finally {
      setLoading(false);
    }
  };

  return (
    <div className="fixed inset-0 bg-black/60 backdrop-blur-xs flex items-center justify-center p-4 z-50 animate-in fade-in duration-150">

      <div className="bg-white rounded-2xl max-w-xl w-full p-6 shadow-2xl border border-[#CBD5E1] flex flex-col gap-4">

        {/* Header */}

        <div className="flex justify-between items-center pb-3 border-b border-[#E2E8F0]">

          <div>

            <h3 className="font-headline font-bold text-[18px] text-[#0F172A]">

              Create Legal Notice / RTI

            </h3>

            <p className="text-[12px] text-[#64748B]">Jurisdiction: {selectedCity}</p>

          </div>

          <button

            onClick={onClose}

            className="text-[#64748B] hover:text-[#0F172A] p-1 rounded-lg hover:bg-[#F1F5F9] cursor-pointer"

          >

            <span className="material-symbols-outlined">close</span>

          </button>

        </div>



        {/* Input 1: Model Selector */}

        <div className="flex flex-col gap-1.5">

          <label className="text-[12px] font-bold text-[#475569] uppercase tracking-wider">

            1. Select Model / Framework

          </label>

          <div className="grid grid-cols-3 gap-2">

            {[

              { id: 'rti', label: 'RTI Request', icon: 'description' },

              { id: 'consumer', label: 'Consumer', icon: 'shopping_bag' },

              { id: 'tenancy', label: 'Tenancy / Salary', icon: 'home_work' },

            ].map((m) => (

              <button

                key={m.id}

                type="button"

                onClick={() => setSelectedModel(m.id)}

                className={`p-2.5 rounded-xl border flex flex-col items-center gap-1 text-[12.5px] font-semibold transition-all cursor-pointer ${

                  selectedModel === m.id

                    ? 'border-[#006c4a] bg-[#ECFDF5] text-[#006c4a]'

                    : 'border-[#CBD5E1] text-[#475569] hover:bg-[#F8FAFC]'

                }`}

              >

                <span className="material-symbols-outlined text-[20px]">{m.icon}</span>

                <span>{m.label}</span>

              </button>

            ))}

          </div>

        </div>



        {/* Input 2: Grievance Input */}

        <div className="flex flex-col gap-1.5">

          <label className="text-[12px] font-bold text-[#475569] uppercase tracking-wider">

            2. Describe Your Grievance / Requirements

          </label>

          <textarea

            value={grievanceText}

            onChange={(e) => setGrievanceText(e.target.value)}

            rows={4}

            placeholder="State your problem clearly (e.g., Landlord withheld deposit, road repair expenditure records)..."

            className="w-full p-3 rounded-xl border border-[#CBD5E1] focus:border-[#006c4a] focus:ring-1 focus:ring-[#006c4a] text-[13.5px] text-[#0F172A] outline-none"

          />

        </div>



        {/* Input 3: PDF Attachment */}

        <div className="flex flex-col gap-1.5">

          <label className="text-[12px] font-bold text-[#475569] uppercase tracking-wider">

            3. Attach PDF Document (Optional)

          </label>

          <div className="flex items-center gap-2">

            <input

              type="file"

              id="intakeModalPdf"

              accept=".pdf,application/pdf"

              onChange={(e) => setAttachedFile(e.target.files?.[0] || null)}

              className="hidden"

            />

            <label

              htmlFor="intakeModalPdf"

              className="px-3.5 py-2 bg-[#F8FAFC] hover:bg-[#F1F5F9] border border-[#CBD5E1] rounded-xl text-[12.5px] font-semibold text-[#475569] flex items-center gap-1.5 cursor-pointer"

            >

              <span className="material-symbols-outlined text-[18px] text-[#006c4a]">upload_file</span>

              <span>{attachedFile ? attachedFile.name : 'Select PDF File'}</span>

            </label>

            {attachedFile && (

              <button

                type="button"

                onClick={() => setAttachedFile(null)}

                className="text-[#DC2626] text-[12px] font-semibold hover:underline cursor-pointer"

              >

                Remove

              </button>

            )}

          </div>

        </div>



        {error && (

          <div className="p-2.5 bg-[#FEF2F2] border border-[#FECACA] rounded-lg text-[12px] text-[#991B1B]">

            {error}

          </div>

        )}



        {/* Submit */}

        <div className="flex justify-end gap-2 pt-3 border-t border-[#E2E8F0]">

          <button

            type="button"

            onClick={onClose}

            className="px-4 py-2 text-[13px] font-medium text-[#64748B] hover:bg-[#F1F5F9] rounded-xl cursor-pointer"

          >

            Cancel

          </button>

          <button

            type="button"

            onClick={handleProcess}

            disabled={loading || (!grievanceText.trim() && !attachedFile)}

            className="px-5 py-2 bg-[#006c4a] hover:bg-[#005137] text-white rounded-xl text-[13px] font-bold flex items-center gap-1.5 cursor-pointer disabled:opacity-50"

          >

            {loading ? (

              <>

                <span className="material-symbols-outlined text-[16px] animate-spin">sync</span>

                <span>Generating Draft...</span>

              </>

            ) : (

              <>

                <span>Generate Filing</span>

                <span className="material-symbols-outlined text-[16px]">arrow_forward</span>

              </>

            )}

          </button>

        </div>
      </div>
    </div>
  );
};