File size: 10,757 Bytes
198828b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
import React, { useState } from 'react';
import { Brain, AlertTriangle, AlertCircle, CheckCircle, ChevronDown, ChevronRight, Info } from 'lucide-react';
import { Badge } from './ui/badge';
import { Button } from './ui/button';
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from './ui/collapsible';
import { Tooltip, TooltipContent, TooltipTrigger } from './ui/tooltip';

interface ReviewItem {
  id: string;
  title: string;
  schedule: string;
  status: 'urgent' | 'review' | 'stable';
  weight: number;
  lastReviewed: string;
  memoryRetention: number;
  previousQuestion: string;
}

export function SmartReview() {
  // Initialize with the first item of W-4 (red zone) expanded by default
  const [expandedItems, setExpandedItems] = useState<string[]>(['w4-1']);
  const [selectedCategory, setSelectedCategory] = useState<string>('W-4'); // Default to red zone

  const reviewData = [
    { 
      label: 'W-4', 
      percentage: 35, 
      color: 'bg-red-500', 
      textColor: 'text-red-500', 
      icon: AlertTriangle, 
      description: 'Higher forgetting risk',
      items: [
        {
          id: 'w4-1',
          title: 'Main Concept of Lab 3',
          schedule: 'T+7',
          status: 'urgent' as const,
          weight: 35,
          lastReviewed: '7 days ago',
          memoryRetention: 25,
          previousQuestion: 'I\'ve read the instructions for Lab 3, but what is the main concept we\'re supposed to be learning here?'
        }
      ]
    },
    { 
      label: 'W-2', 
      percentage: 20, 
      color: 'bg-orange-500', 
      textColor: 'text-orange-500', 
      icon: AlertCircle, 
      description: 'Medium forgetting risk',
      items: [
        {
          id: 'w2-1',
          title: 'Effective Prompt Engineering',
          schedule: 'T+14',
          status: 'review' as const,
          weight: 20,
          lastReviewed: '3 days ago',
          memoryRetention: 60,
          previousQuestion: 'I understand what prompt engineering is, but what specifically makes a prompt effective versus ineffective?'
        }
      ]
    },
    { 
      label: 'W-1', 
      percentage: 12, 
      color: 'bg-green-500', 
      textColor: 'text-green-500', 
      icon: CheckCircle, 
      description: 'Recently learned',
      items: [
        {
          id: 'w1-1',
          title: 'Objective LLM Evaluation',
          schedule: 'T+7',
          status: 'stable' as const,
          weight: 12,
          lastReviewed: '1 day ago',
          memoryRetention: 90,
          previousQuestion: 'How can we objectively evaluate an LLM\'s performance when the output quality seems so subjective?'
        }
      ]
    },
  ];

  const totalPercentage = reviewData.reduce((sum, item) => sum + item.percentage, 0);
  const selectedData = reviewData.find(item => item.label === selectedCategory);

  const toggleItem = (itemId: string) => {
    setExpandedItems(prev => 
      prev.includes(itemId) 
        ? prev.filter(id => id !== itemId)
        : [...prev, itemId]
    );
  };

  // When category changes, automatically expand the first item of that category
  const handleCategoryChange = (categoryLabel: string) => {
    setSelectedCategory(categoryLabel);
    const categoryData = reviewData.find(item => item.label === categoryLabel);
    if (categoryData && categoryData.items.length > 0) {
      // Expand only the first item of the selected category
      setExpandedItems([categoryData.items[0].id]);
    }
  };

  const getStatusBadge = (status: 'urgent' | 'review' | 'stable') => {
    const configs = {
      urgent: { label: '🔥 URGENT', className: 'bg-red-500 text-white hover:bg-red-600' },
      review: { label: '⚠️ REVIEW', className: 'bg-orange-500 text-white hover:bg-orange-600' },
      stable: { label: '✓ STABLE', className: 'bg-green-500 text-white hover:bg-green-600' },
    };
    return configs[status];
  };

  const getButtonColorClass = (colorClass: string) => {
    // Extract color from bg-red-500, bg-orange-500, bg-green-500
    if (colorClass.includes('red')) {
      return 'bg-red-500 hover:bg-red-600';
    } else if (colorClass.includes('orange')) {
      return 'bg-orange-500 hover:bg-orange-600';
    } else if (colorClass.includes('green')) {
      return 'bg-green-500 hover:bg-green-600';
    }
    return 'bg-red-500 hover:bg-red-600'; // default
  };

  return (
    <div className="space-y-4">
      <div className="flex flex-col gap-1">
        <div className="flex items-center gap-2">
          <Brain className="h-5 w-5 text-red-500" />
          <h3>Current Review Distribution</h3>
          <Tooltip>
            <TooltipTrigger asChild>
              <button className="text-muted-foreground hover:text-foreground transition-colors">
                <Info className="h-3 w-3" />
              </button>
            </TooltipTrigger>
            <TooltipContent side="right" className="p-2" style={{ maxWidth: '170px', whiteSpace: 'normal', wordBreak: 'break-word' }}>
              <p className="text-[10px] leading-relaxed text-left" style={{ whiteSpace: 'normal' }}>
                Based on the forgetting curve, Clare has selected topics you might be forgetting from your learning history and interaction patterns. Higher weights indicate higher forgetting risk.
              </p>
            </TooltipContent>
          </Tooltip>
        </div>
        <div className="text-xs text-muted-foreground ml-7">(T+7 Schedule)</div>
      </div>

      {/* Combined Progress Bar - Clickable */}
      <div className="space-y-2">
        <div className="text-xs text-muted-foreground">Overall Distribution</div>
        <div className="flex items-center gap-3">
          {reviewData.map((item) => (
            <button
              key={item.label}
              className={`flex flex-col gap-1.5 pt-2 px-1 pb-0 rounded-lg transition-all duration-200 hover:brightness-110 focus:outline-none cursor-pointer ${
                selectedCategory === item.label ? 'bg-muted/80' : 'bg-transparent hover:bg-muted/40'
              }`}
              onClick={() => handleCategoryChange(item.label)}
              title={`Click to view ${item.label} items`}
              style={{ flex: item.percentage }}
            >
              <div className="flex items-center gap-1 justify-center whitespace-nowrap">
                <span className="text-[10px]">{item.label}:</span>
                <span className={`text-[10px] font-medium ${item.textColor}`}>{item.percentage}%</span>
              </div>
              <div className={`h-2 ${item.color} rounded-full mb-2`} />
            </button>
          ))}
        </div>
      </div>

      {/* Selected Category Progress Bar with Expandable Items */}
      {selectedData && (
        <div className="space-y-2">
          <div className="flex items-center justify-between">
            <div className="flex items-center gap-2">
              <selectedData.icon className={`h-4 w-4 ${selectedData.textColor}`} />
              <span className="text-sm">{selectedData.label}:</span>
              <span className={`text-sm font-medium ${selectedData.textColor}`}>{selectedData.percentage}%</span>
            </div>
          </div>
          <div className="h-2 bg-muted rounded-full overflow-hidden">
            <div 
              className={`h-full ${selectedData.color} transition-all duration-500`}
              style={{ width: `${(selectedData.percentage / totalPercentage) * 100}%` }}
            />
          </div>
          
          {/* Expandable Review Items */}
          <div className="space-y-2">
            {selectedData.items.map((reviewItem) => (
              <Collapsible
                key={reviewItem.id}
                open={expandedItems.includes(reviewItem.id)}
                onOpenChange={() => toggleItem(reviewItem.id)}
              >
                <CollapsibleTrigger asChild>
                  <Button
                    variant="ghost"
                    className="w-full justify-between text-left h-auto p-2 hover:bg-muted/50"
                  >
                    <span className="text-sm">Review: {reviewItem.title}</span>
                    {expandedItems.includes(reviewItem.id) ? (
                      <ChevronDown className="h-4 w-4 flex-shrink-0" />
                    ) : (
                      <ChevronRight className="h-4 w-4 flex-shrink-0" />
                    )}
                  </Button>
                </CollapsibleTrigger>
                <CollapsibleContent>
                  <div className="p-3 space-y-3 pl-4" style={{ borderLeft: '0.5px solid', borderColor: `var(--${selectedData.color.replace('bg-', '')})` }}>
                    <div className="flex items-center gap-2 flex-wrap">
                      <Badge variant="outline" className="text-xs">
                        {reviewItem.schedule}
                      </Badge>
                      <Badge className={`text-xs ${getStatusBadge(reviewItem.status).className}`}>
                        {getStatusBadge(reviewItem.status).label}
                      </Badge>
                      <span className="text-xs text-muted-foreground">
                        Weight: {reviewItem.weight}% | Last: {reviewItem.lastReviewed}
                      </span>
                    </div>

                    <div className="space-y-1">
                      <div className="flex justify-between items-center">
                        <span className="text-xs text-muted-foreground">Memory Retention</span>
                        <span className="text-xs font-medium">{reviewItem.memoryRetention}%</span>
                      </div>
                      <div className="h-2 bg-muted rounded-full overflow-hidden">
                        <div
                          className={`h-full ${selectedData.color} transition-all duration-500`}
                          style={{ width: `${reviewItem.memoryRetention}%` }}
                        />
                      </div>
                    </div>

                    <div className="space-y-1">
                      <p className="text-xs text-muted-foreground">You previously asked:</p>
                      <p className="text-xs bg-muted/50 p-2 rounded italic">
                        "{reviewItem.previousQuestion}"
                      </p>
                    </div>

                    <Button 
                      className={`w-full ${getButtonColorClass(selectedData.color)} text-white`}
                      size="sm"
                    >
                      Review this topic
                    </Button>
                  </div>
                </CollapsibleContent>
              </Collapsible>
            ))}
          </div>
        </div>
      )}

    </div>
  );
}