|
| 1 | +import { motion } from 'framer-motion' |
| 2 | +import type React from 'react' |
| 3 | +import Modal from '../../../../../components/modal' |
| 4 | +import type { PomodoroSettings } from '../types' |
| 5 | + |
| 6 | +interface SettingInputProps { |
| 7 | + label: string |
| 8 | + value: number |
| 9 | + onChange: (value: number) => void |
| 10 | + max: number |
| 11 | + getInputStyle: () => string |
| 12 | + theme: string |
| 13 | +} |
| 14 | + |
| 15 | +const SettingInput: React.FC<SettingInputProps> = ({ |
| 16 | + label, |
| 17 | + value, |
| 18 | + onChange, |
| 19 | + max, |
| 20 | + getInputStyle, |
| 21 | + theme, |
| 22 | +}) => { |
| 23 | + return ( |
| 24 | + <div className="flex items-center justify-between"> |
| 25 | + <label |
| 26 | + className={`text-xs ${theme === 'light' ? 'text-gray-600' : 'text-gray-300'}`} |
| 27 | + > |
| 28 | + {label} |
| 29 | + </label> |
| 30 | + <input |
| 31 | + type="number" |
| 32 | + min="1" |
| 33 | + max={max} |
| 34 | + value={value} |
| 35 | + onChange={(e) => { |
| 36 | + const value = Number.parseInt(e.target.value) |
| 37 | + if (value > 0 && value <= max) { |
| 38 | + onChange(value) |
| 39 | + } |
| 40 | + }} |
| 41 | + className={`w-16 px-2 py-1 text-sm rounded border transition-colors ${getInputStyle()} ${theme === 'light' ? 'text-gray-700' : 'text-gray-200'}`} |
| 42 | + /> |
| 43 | + </div> |
| 44 | + ) |
| 45 | +} |
| 46 | + |
| 47 | +interface PomodoroSettingsPanelProps { |
| 48 | + isOpen: boolean |
| 49 | + onClose: () => void |
| 50 | + settings: PomodoroSettings |
| 51 | + onUpdateSettings: (newSettings: PomodoroSettings) => void |
| 52 | + onReset: () => void |
| 53 | + getTextStyle: () => string |
| 54 | + getInputStyle: () => string |
| 55 | + theme: string |
| 56 | +} |
| 57 | + |
| 58 | +export const PomodoroSettingsPanel: React.FC<PomodoroSettingsPanelProps> = ({ |
| 59 | + isOpen, |
| 60 | + onClose, |
| 61 | + settings, |
| 62 | + onUpdateSettings, |
| 63 | + onReset, |
| 64 | + getTextStyle, |
| 65 | + getInputStyle, |
| 66 | + theme, |
| 67 | +}) => { |
| 68 | + const handleSettingChange = (key: keyof PomodoroSettings, value: number) => { |
| 69 | + onUpdateSettings({ |
| 70 | + ...settings, |
| 71 | + [key]: value, |
| 72 | + }) |
| 73 | + } |
| 74 | + |
| 75 | + const handleSaveAndClose = () => { |
| 76 | + onClose() |
| 77 | + onReset() |
| 78 | + } |
| 79 | + |
| 80 | + return ( |
| 81 | + <Modal |
| 82 | + isOpen={isOpen} |
| 83 | + onClose={onClose} |
| 84 | + closeOnBackdropClick={false} |
| 85 | + title="تنظیمات تایمر پومودورو" |
| 86 | + direction="rtl" |
| 87 | + > |
| 88 | + <motion.div |
| 89 | + initial={{ opacity: 0, height: 0 }} |
| 90 | + animate={{ opacity: 1, height: 'auto' }} |
| 91 | + exit={{ opacity: 0, height: 0 }} |
| 92 | + transition={{ duration: 0.3 }} |
| 93 | + className="mt-6 overflow-hidden" |
| 94 | + > |
| 95 | + <div className={'p-4 rounded-xl'}> |
| 96 | + <h4 className={`text-sm font-medium mb-3 ${getTextStyle()}`}> |
| 97 | + تنظیمات زمان (دقیقه) |
| 98 | + </h4> |
| 99 | + |
| 100 | + <div className="space-y-3"> |
| 101 | + <SettingInput |
| 102 | + label="زمان کار:" |
| 103 | + value={settings.workTime} |
| 104 | + onChange={(value) => { |
| 105 | + handleSettingChange('workTime', value) |
| 106 | + }} |
| 107 | + max={60} |
| 108 | + getInputStyle={getInputStyle} |
| 109 | + theme={theme} |
| 110 | + /> |
| 111 | + |
| 112 | + <SettingInput |
| 113 | + label="استراحت کوتاه:" |
| 114 | + value={settings.shortBreakTime} |
| 115 | + onChange={(value) => { |
| 116 | + handleSettingChange('shortBreakTime', value) |
| 117 | + }} |
| 118 | + max={30} |
| 119 | + getInputStyle={getInputStyle} |
| 120 | + theme={theme} |
| 121 | + /> |
| 122 | + |
| 123 | + <SettingInput |
| 124 | + label="استراحت بلند:" |
| 125 | + value={settings.longBreakTime} |
| 126 | + onChange={(value) => { |
| 127 | + handleSettingChange('longBreakTime', value) |
| 128 | + }} |
| 129 | + max={60} |
| 130 | + getInputStyle={getInputStyle} |
| 131 | + theme={theme} |
| 132 | + /> |
| 133 | + |
| 134 | + <SettingInput |
| 135 | + label="تعداد دوره قبل از استراحت بلند:" |
| 136 | + value={settings.cyclesBeforeLongBreak} |
| 137 | + onChange={(value) => { |
| 138 | + handleSettingChange('cyclesBeforeLongBreak', value) |
| 139 | + }} |
| 140 | + max={10} |
| 141 | + getInputStyle={getInputStyle} |
| 142 | + theme={theme} |
| 143 | + /> |
| 144 | + |
| 145 | + <div className="text-center"> |
| 146 | + <button |
| 147 | + onClick={handleSaveAndClose} |
| 148 | + className={`px-4 py-1 text-sm font-medium rounded-md transition-colors ${ |
| 149 | + theme === 'light' |
| 150 | + ? 'bg-blue-500 text-white hover:bg-blue-600' |
| 151 | + : 'bg-blue-600 text-gray-200 hover:bg-blue-700' |
| 152 | + }`} |
| 153 | + > |
| 154 | + ذخیره و بستن |
| 155 | + </button> |
| 156 | + </div> |
| 157 | + </div> |
| 158 | + </div> |
| 159 | + </motion.div> |
| 160 | + </Modal> |
| 161 | + ) |
| 162 | +} |
0 commit comments