|
| 1 | +import React, { useState } from 'react' |
| 2 | +import { motion } from 'framer-motion' |
| 3 | + |
| 4 | +interface Props { |
| 5 | + isOpen: boolean |
| 6 | + onClose: () => void |
| 7 | + onConfirm: (depth: number) => void |
| 8 | + initialDepth?: number |
| 9 | +} |
| 10 | + |
| 11 | +export const AnalysisConfigModal: React.FC<Props> = ({ |
| 12 | + isOpen, |
| 13 | + onClose, |
| 14 | + onConfirm, |
| 15 | + initialDepth = 15, |
| 16 | +}) => { |
| 17 | + const [selectedDepth, setSelectedDepth] = useState(initialDepth) |
| 18 | + |
| 19 | + const depthOptions = [ |
| 20 | + { |
| 21 | + value: 12, |
| 22 | + label: 'Fast (d12)', |
| 23 | + description: 'Quick surface-level analysis', |
| 24 | + }, |
| 25 | + { |
| 26 | + value: 15, |
| 27 | + label: 'Balanced (d15)', |
| 28 | + description: 'Deeper analysis with good speed', |
| 29 | + }, |
| 30 | + { |
| 31 | + value: 18, |
| 32 | + label: 'Deep (d18)', |
| 33 | + description: 'Thorough analysis with slower speed', |
| 34 | + }, |
| 35 | + ] |
| 36 | + |
| 37 | + const handleConfirm = () => { |
| 38 | + onConfirm(selectedDepth) |
| 39 | + onClose() |
| 40 | + } |
| 41 | + |
| 42 | + if (!isOpen) return null |
| 43 | + |
| 44 | + return ( |
| 45 | + <motion.div |
| 46 | + className="absolute left-0 top-0 z-20 flex h-screen w-screen flex-col items-center justify-center bg-black/70 px-4 backdrop-blur-sm md:px-0" |
| 47 | + initial={{ opacity: 0 }} |
| 48 | + animate={{ opacity: 1 }} |
| 49 | + exit={{ opacity: 0 }} |
| 50 | + transition={{ duration: 0.2 }} |
| 51 | + data-testid="analysis-config-modal" |
| 52 | + onClick={(e) => { |
| 53 | + if (e.target === e.currentTarget) onClose() |
| 54 | + }} |
| 55 | + > |
| 56 | + <motion.div |
| 57 | + className="flex w-full flex-col gap-4 rounded-md border border-white/10 bg-background-1 p-5 md:w-[min(500px,40vw)] md:p-6" |
| 58 | + initial={{ y: 20, opacity: 0 }} |
| 59 | + animate={{ y: 0, opacity: 1 }} |
| 60 | + exit={{ y: 20, opacity: 0 }} |
| 61 | + transition={{ duration: 0.3 }} |
| 62 | + onClick={(e) => e.stopPropagation()} |
| 63 | + > |
| 64 | + <div className="flex items-center gap-2"> |
| 65 | + <span className="material-symbols-outlined text-2xl text-human-3"> |
| 66 | + network_intelligence |
| 67 | + </span> |
| 68 | + <h2 className="text-xl font-semibold">Analyze Entire Game</h2> |
| 69 | + </div> |
| 70 | + |
| 71 | + <div className="flex flex-col gap-3"> |
| 72 | + <p className="text-sm text-primary/80"> |
| 73 | + Choose the Stockfish analysis depth for all positions in the game: |
| 74 | + </p> |
| 75 | + |
| 76 | + <div className="flex flex-col gap-2"> |
| 77 | + {depthOptions.map((option) => ( |
| 78 | + <label |
| 79 | + key={option.value} |
| 80 | + className={`flex cursor-pointer items-center gap-3 rounded border p-3 transition duration-200 ${ |
| 81 | + selectedDepth === option.value |
| 82 | + ? 'border-human-4 bg-human-4/10' |
| 83 | + : 'border-white/10 hover:border-white/20 hover:bg-white/5' |
| 84 | + }`} |
| 85 | + htmlFor={`depth-${option.value}`} |
| 86 | + aria-label={`Select ${option.label}`} |
| 87 | + > |
| 88 | + <input |
| 89 | + type="radio" |
| 90 | + name="depth" |
| 91 | + id={`depth-${option.value}`} |
| 92 | + value={option.value} |
| 93 | + checked={selectedDepth === option.value} |
| 94 | + onChange={(e) => setSelectedDepth(Number(e.target.value))} |
| 95 | + className="h-4 w-4 text-human-4" |
| 96 | + /> |
| 97 | + <div className="flex flex-col gap-0.5"> |
| 98 | + <span className="text-sm font-medium">{option.label}</span> |
| 99 | + <span className="text-xs text-secondary"> |
| 100 | + {option.description} |
| 101 | + </span> |
| 102 | + </div> |
| 103 | + </label> |
| 104 | + ))} |
| 105 | + </div> |
| 106 | + |
| 107 | + <div className="mt-2 flex items-start gap-2 rounded bg-background-2/60 p-3"> |
| 108 | + <span className="material-symbols-outlined !text-base text-secondary"> |
| 109 | + info |
| 110 | + </span> |
| 111 | + <p className="text-xs text-secondary"> |
| 112 | + Higher depths provide more accurate analysis but take longer to |
| 113 | + complete. You can cancel the analysis at any time. Currently, |
| 114 | + analysis only persists until you close the tab, but we are working |
| 115 | + on a persistent analysis feature! |
| 116 | + </p> |
| 117 | + </div> |
| 118 | + </div> |
| 119 | + |
| 120 | + <div className="flex justify-end gap-2 pt-2"> |
| 121 | + <button |
| 122 | + onClick={onClose} |
| 123 | + className="flex h-9 items-center gap-1 rounded bg-background-2 px-4 text-sm transition duration-200 hover:bg-background-3" |
| 124 | + > |
| 125 | + Cancel |
| 126 | + </button> |
| 127 | + <button |
| 128 | + onClick={handleConfirm} |
| 129 | + className="flex h-9 items-center gap-1 rounded bg-human-4 px-4 text-sm font-medium text-white transition duration-200 hover:bg-human-4/90" |
| 130 | + > |
| 131 | + <span className="material-symbols-outlined text-sm"> |
| 132 | + play_arrow |
| 133 | + </span> |
| 134 | + Start Analysis |
| 135 | + </button> |
| 136 | + </div> |
| 137 | + </motion.div> |
| 138 | + </motion.div> |
| 139 | + ) |
| 140 | +} |
0 commit comments