Spaces:
Sleeping
Sleeping
File size: 26,576 Bytes
5463318 | 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 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 | import React from 'react';
import { motion, AnimatePresence } from 'framer-motion';
import { useGenerate } from '../GenerateContext';
import { Button } from '../../../components/ui/Button';
import { ChevronDown, SlidersHorizontal, BrainCircuit, Activity, LayoutTemplate, Layers, Plus, Minimize2, Check, Trash2 } from 'lucide-react';
import { cn } from '../../../../src/utils/cn';
// Quick Templates Array
const quickTemplates = [
{ id: 'quiz', label: 'Weekly Quiz', icon: Activity, desc: 'Short, recall-focused' },
{ id: 'midterm', label: 'Mid-Term Exam', icon: LayoutTemplate, desc: 'Balanced assessment' },
{ id: 'final', label: 'Final Exam', icon: Layers, desc: 'Comprehensive, analytical' },
{ id: 'competitive', label: 'Competitive', icon: BrainCircuit, desc: 'High difficulty, HOTS' },
{ id: 'revision', label: 'Revision Test', icon: Check, desc: 'Easy, broad coverage' }
];
export const ConfigurePaperStep = () => {
const { configure, setConfigure, setStep } = useGenerate();
const handleTemplateSelect = (templateId) => {
let blooms = { remember: 20, understand: 20, apply: 20, analyze: 15, evaluate: 15, create: 10 };
let diff = 50;
if (templateId === 'quiz') { blooms = { remember: 40, understand: 30, apply: 20, analyze: 10, evaluate: 0, create: 0 }; diff = 30; }
if (templateId === 'midterm') { blooms = { remember: 20, understand: 25, apply: 25, analyze: 15, evaluate: 10, create: 5 }; diff = 50; }
if (templateId === 'final') { blooms = { remember: 10, understand: 20, apply: 25, analyze: 25, evaluate: 15, create: 5 }; diff = 65; }
if (templateId === 'competitive') { blooms = { remember: 5, understand: 10, apply: 20, analyze: 30, evaluate: 25, create: 10 }; diff = 85; }
if (templateId === 'revision') { blooms = { remember: 40, understand: 40, apply: 10, analyze: 10, evaluate: 0, create: 0 }; diff = 25; }
setConfigure(prev => ({ ...prev, quickTemplate: templateId, bloomsDistribution: blooms, difficulty: diff }));
};
return (
<motion.div
initial={{ opacity: 0, x: 20 }} animate={{ opacity: 1, x: 0 }} exit={{ opacity: 0, x: -20 }}
className="w-full flex flex-col bg-white dark:bg-[#111827] shadow-[0_8px_30px_rgb(0,0,0,0.04)] dark:shadow-[0_8px_30px_rgba(0,0,0,0.4)] rounded-2xl border border-slate-100 dark:border-slate-800 p-6 sm:p-8 "
>
<div className="mb-6 flex justify-between items-start">
<div>
<h2 className="text-2xl font-bold text-slate-900 dark:text-white mb-2">Configure Paper Parameters</h2>
<p className="text-slate-500 font-medium tracking-wide">Fine-tune difficulty, structures, and cognitive depth.</p>
</div>
</div>
<div className="space-y-10 pb-12">
{/* A. Quick Templates */}
<section>
<h3 className="text-xs font-bold text-slate-400 uppercase tracking-widest mb-4">Quick Templates</h3>
<div className="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-5 gap-3">
{quickTemplates.map(t => (
<button
key={t.id}
onClick={() => handleTemplateSelect(t.id)}
className={cn(
"flex flex-col items-start p-3 rounded-xl border transition-all text-left group",
configure.quickTemplate === t.id
? "bg-indigo-50 dark:bg-indigo-500/10 border-indigo-400 shadow-sm"
: "bg-slate-50 dark:bg-[#0F172A] border-slate-200 dark:border-slate-700 hover:border-indigo-300 dark:hover:border-indigo-500/50"
)}
>
<div className="flex items-center justify-between w-full mb-2">
<t.icon size={16} className={configure.quickTemplate === t.id ? "text-indigo-600 dark:text-indigo-400" : "text-slate-400"} />
{configure.quickTemplate === t.id && <Check size={14} className="text-indigo-600 dark:text-indigo-400" />}
</div>
<span className={cn("text-sm font-bold truncate w-full", configure.quickTemplate === t.id ? "text-indigo-900 dark:text-indigo-100" : "text-slate-700 dark:text-slate-300")}>{t.label}</span>
<span className="text-[10px] text-slate-500 mt-1 line-clamp-1 truncate w-full">{t.desc}</span>
</button>
))}
</div>
</section>
<div className="h-px bg-slate-200 dark:bg-slate-800" />
{/* B. Question Types */}
<section>
<div className="flex justify-between items-center mb-4">
<h3 className="text-xs font-bold text-slate-400 uppercase tracking-widest">Question Types & Sections</h3>
<Button
variant="ghost"
size="sm"
className="h-8 text-[#4F7CFF]"
onClick={() => {
setConfigure(p => ({
...p,
questionTypes: [
...p.questionTypes,
{ id: `custom-${Date.now()}`, label: 'Custom Section', count: 5, marks: 5, selected: true, topic: '', internalChoices: 0, isCustom: true }
]
}));
}}
>
<Plus size={16} className="mr-1" /> Add Custom Type
</Button>
</div>
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4">
{configure.questionTypes.map((qType, idx) => (
<div key={idx} className={cn("p-4 rounded-xl border flex flex-col gap-3 transition-colors", qType.selected ? "border-[#4F7CFF] bg-[#4F7CFF]/5 shadow-sm" : "border-slate-200 dark:border-slate-700 bg-slate-50 dark:bg-[#0F172A]")}>
<div className="flex items-start justify-between">
<label className="flex items-center gap-2 cursor-pointer flex-1">
<input
type="checkbox"
checked={qType.selected}
onChange={() => {
const newTypes = [...configure.questionTypes];
newTypes[idx].selected = !newTypes[idx].selected;
setConfigure(p => ({ ...p, questionTypes: newTypes }));
}}
className="w-4 h-4 rounded border-slate-300 text-[#4F7CFF] focus:ring-[#4F7CFF] shrink-0"
/>
{qType.isCustom ? (
<input
type="text"
value={qType.label}
onChange={e => {
const newTypes = [...configure.questionTypes];
newTypes[idx].label = e.target.value;
setConfigure(p => ({ ...p, questionTypes: newTypes }));
}}
placeholder="Section Name"
className="bg-transparent border-b border-slate-300 dark:border-slate-600 outline-none text-sm font-bold text-slate-900 dark:text-white px-1 py-0.5 focus:border-[#4F7CFF] transition-colors w-full"
onClick={e => e.preventDefault()}
/>
) : (
<span className="text-sm font-bold text-slate-900 dark:text-white">{qType.label}</span>
)}
</label>
{qType.isCustom && (
<button
className="ml-2 p-1 text-slate-400 hover:text-red-500 hover:bg-slate-200 dark:hover:bg-slate-800 rounded transition-colors"
onClick={(e) => {
e.preventDefault();
const newTypes = [...configure.questionTypes];
newTypes.splice(idx, 1);
setConfigure(p => ({ ...p, questionTypes: newTypes }));
}}
title="Remove Custom Section"
>
<Trash2 size={16} />
</button>
)}
</div>
<div className={cn("flex flex-col gap-3 transition-opacity", qType.selected ? "opacity-100" : "opacity-50 pointer-events-none")}>
<div className="flex items-center gap-3">
<div className="flex-1 space-y-1">
<label className="text-[10px] text-slate-500 uppercase tracking-wider font-bold">Count</label>
<input
type="number" min="0"
value={qType.count}
onChange={e => {
const newTypes = [...configure.questionTypes];
newTypes[idx].count = parseInt(e.target.value) || 0;
setConfigure(p => ({ ...p, questionTypes: newTypes }));
}}
className="w-full bg-white dark:bg-[#111827] border border-slate-200 dark:border-slate-600 rounded p-1.5 text-xs text-slate-900 dark:text-white outline-none focus:border-[#4F7CFF]"
/>
</div>
<div className="flex-1 space-y-1">
<label className="text-[10px] text-slate-500 uppercase tracking-wider font-bold">Marks/Q</label>
<input
type="number" min="0"
value={qType.marks}
onChange={e => {
const newTypes = [...configure.questionTypes];
newTypes[idx].marks = parseInt(e.target.value) || 0;
setConfigure(p => ({ ...p, questionTypes: newTypes }));
}}
className="w-full bg-white dark:bg-[#111827] border border-slate-200 dark:border-slate-600 rounded p-1.5 text-xs text-slate-900 dark:text-white outline-none focus:border-[#4F7CFF]"
/>
</div>
</div>
<div className="space-y-1">
<label className="text-[10px] text-slate-500 uppercase tracking-wider font-bold">Specific Topic Focus (Optional)</label>
<input
type="text"
value={qType.topic || ''}
onChange={e => {
const newTypes = [...configure.questionTypes];
newTypes[idx].topic = e.target.value;
setConfigure(p => ({ ...p, questionTypes: newTypes }));
}}
placeholder="e.g Thermodynamics, Chapter 4..."
title="Leave blank to use all materials uniformly"
className="w-full bg-white dark:bg-[#111827] border border-slate-200 dark:border-slate-600 rounded p-1.5 text-xs text-slate-900 dark:text-white outline-none focus:border-[#4F7CFF]"
/>
</div>
{qType.id !== 'mcq' && (
<div className="space-y-1 mt-1">
<label className="text-[10px] text-slate-500 uppercase tracking-wider font-bold">Internal Choices (OR Options)</label>
<div className="flex items-center gap-2">
<input
type="number" min="0" max={qType.count}
value={qType.internalChoices || 0}
onChange={e => {
const newTypes = [...configure.questionTypes];
// Ensure it doesn't exceed total questions in section
let val = parseInt(e.target.value) || 0;
if (val > newTypes[idx].count) val = newTypes[idx].count;
newTypes[idx].internalChoices = val;
setConfigure(p => ({ ...p, questionTypes: newTypes }));
}}
className="w-16 bg-white dark:bg-[#111827] border border-slate-200 dark:border-slate-600 rounded p-1.5 text-xs text-slate-900 dark:text-white outline-none focus:border-[#4F7CFF]"
/>
<span className="text-[10px] text-slate-400 font-medium">Questions will have an "OR" choice.</span>
</div>
</div>
)}
</div>
</div>
))}
</div>
</section>
<div className="h-px bg-slate-200 dark:bg-slate-800" />
{/* C. Bloom's Taxonomy */}
<section>
<h3 className="text-xs font-bold text-slate-400 uppercase tracking-widest mb-1">Cognitive Level Distribution (Bloom's Taxonomy)</h3>
<p className="text-xs font-medium text-slate-500 mb-6">Control how deeply students interact with the content. High orders (Apply, Analyze) test critical thinking.</p>
<div className="grid grid-cols-2 md:grid-cols-6 gap-2 h-44 items-end">
{Object.entries(configure.bloomsDistribution).map(([level, val], idx) => {
const colors = ['bg-[#ff6b6b]', 'bg-[#feca57]', 'bg-[#1dd1a1]', 'bg-[#54a0ff]', 'bg-[#5f27cd]', 'bg-[#ff9ff3]'];
const verbs = [
'Define, Duplicate, List', 'Classify, Describe, Explain', 'Execute, Implement, Solve',
'Differentiate, Compare', 'Appraise, Argue, Judge', 'Design, Assemble, Construct'
];
return (
<div key={level} className="flex flex-col items-center gap-2 group relative">
<span className="text-[10px] font-bold text-slate-500">{val}%</span>
<div className="w-full relative bg-slate-100 dark:bg-slate-800 rounded-t-lg overflow-hidden h-32 flex items-end group-hover:bg-slate-200 dark:group-hover:bg-slate-700 transition-colors cursor-ns-resize">
<input
type="range" min="0" max="100"
value={val}
onChange={e => {
const newVal = parseInt(e.target.value) || 0;
const diff = newVal - val;
// We want to auto-balance the other values so the sum remains 100
// (or at least handle the distribution smoothly)
let otherKeys = Object.keys(configure.bloomsDistribution).filter(k => k !== level);
let otherSum = otherKeys.reduce((acc, k) => acc + configure.bloomsDistribution[k], 0);
let newDist = { ...configure.bloomsDistribution, [level]: newVal };
if (otherSum > 0 && newVal !== val) {
// Normalize the others
let scale = (100 - newVal) / otherSum;
otherKeys.forEach(k => {
// Distribute proportionally
newDist[k] = Math.round(configure.bloomsDistribution[k] * scale);
});
// Fix any rounding errors to exactly 100
let finalSum = Object.values(newDist).reduce((a, b) => a + b, 0);
if (finalSum !== 100) {
let adjustments = 100 - finalSum;
// Adjust the largest other component to absorb rounding error
let largestOther = otherKeys.sort((a, b) => newDist[b] - newDist[a])[0];
newDist[largestOther] = Math.max(0, newDist[largestOther] + adjustments);
}
}
setConfigure(p => ({ ...p, bloomsDistribution: newDist, quickTemplate: 'Custom' }));
}}
className="absolute top-1/2 left-1/2 opacity-0 cursor-ns-resize appearance-none"
style={{ width: '8rem', height: '4rem', transform: 'translate(-50%, -50%) rotate(-90deg)' }}
/>
<motion.div
className={cn("w-full transition-all group-hover:brightness-110", colors[idx])}
animate={{ height: `${val}%` }}
/>
</div>
<span className="text-[10px] font-bold text-slate-600 dark:text-slate-300 uppercase tracking-wider truncate w-full text-center">{level}</span>
{/* Tooltip */}
<div className="absolute top-1/2 -translate-y-1/2 opacity-0 group-hover:opacity-100 pointer-events-none transition-opacity bg-slate-900 text-white text-[10px] p-2 rounded shadow-xl w-32 left-1/2 -translate-x-1/2 z-20 text-center flex flex-col gap-1">
<span className="font-bold underline capitalize">{level}</span>
<span className="text-slate-300 ">{verbs[idx]}</span>
</div>
</div>
);
})}
</div>
</section>
<div className="h-px bg-slate-200 dark:bg-slate-800" />
{/* D. Difficulty Control */}
<section>
<div className="flex justify-between items-end mb-4">
<div>
<h3 className="text-xs font-bold text-slate-400 uppercase tracking-widest mb-1">Overall Difficulty</h3>
<p className="text-xs font-medium text-slate-500">Dictates semantic complexity & distractors independently of Bloom's level.</p>
</div>
<span className="px-3 py-1 bg-[#4F7CFF] text-white rounded-full text-xs font-black uppercase tracking-widest">
{configure.difficulty < 33 ? 'Easy' : configure.difficulty < 66 ? 'Medium' : 'Hard'} ({configure.difficulty})
</span>
</div>
<div className="relative pt-6 pb-2">
<input
type="range" min="0" max="100"
value={configure.difficulty}
onChange={e => setConfigure(p => ({ ...p, difficulty: parseInt(e.target.value) || 0 }))}
className="w-full h-2 rounded-full appearance-none bg-slate-200 dark:bg-slate-800 outline-none cursor-ew-resize accent-[#4F7CFF]"
/>
<div className="flex justify-between text-[10px] font-bold text-slate-400 uppercase tracking-widest mt-2 px-1">
<span>0</span>
<span>50</span>
<span>100</span>
</div>
</div>
</section>
{/* E. Advanced Settings */}
<section className="border border-slate-200 dark:border-slate-800 rounded-xl overflow-hidden">
<div className="p-4 bg-slate-50 dark:bg-[#0F172A] border-b border-slate-200 dark:border-slate-800 flex justify-between items-center cursor-pointer">
<h3 className="text-sm font-bold text-slate-700 dark:text-slate-300 flex items-center gap-2">
<SlidersHorizontal size={16} /> Advanced AI Settings
</h3>
<ChevronDown size={18} className="text-slate-400" />
</div>
<div className="p-4 grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-y-4 gap-x-6 bg-white dark:bg-[#111827]">
{Object.entries(configure.advancedSettings).map(([key, val]) => (
<label key={key} className="flex items-center justify-between cursor-pointer group">
<span className="text-xs font-bold text-slate-600 dark:text-slate-400 capitalize whitespace-nowrap group-hover:text-[#4F7CFF] transition-colors">
{key.replace(/([A-Z])/g, ' $1').trim()}
</span>
<div className={cn("w-8 h-4 rounded-full flex items-center p-0.5 transition-colors duration-300 shadow-inner", val ? "bg-[#4F7CFF]" : "bg-slate-300 dark:bg-slate-700")}>
<motion.div
layout
className="w-3 h-3 bg-white rounded-full shadow-sm"
animate={{ x: val ? 16 : 0 }}
transition={{ type: "spring", stiffness: 500, damping: 30 }}
/>
</div>
{/* Hidden input to manage actual form state */}
<input
type="checkbox" className="sr-only"
checked={val}
onChange={() => setConfigure(p => ({ ...p, advancedSettings: { ...p.advancedSettings, [key]: !p.advancedSettings[key] } }))}
/>
</label>
))}
</div>
</section>
</div>
<div className="mt-auto pt-6 border-t border-slate-200 dark:border-slate-800 flex justify-between gap-4">
<Button variant="outline" onClick={() => setStep(1)} className="px-6 py-2.5 rounded-xl font-bold border-slate-200 text-slate-600 hover:bg-slate-50">Back</Button>
<Button
onClick={() => setStep(3)}
className="px-8 py-2.5 bg-gradient-to-r from-[#8B5CF6] to-[#4F7CFF] hover:shadow-[0_0_20px_rgba(79,124,255,0.4)] text-white font-bold rounded-xl transition-all shadow-lg hover:scale-[1.02]"
>
Finalize Paper Details
</Button>
</div>
</motion.div>
);
};
|