File size: 10,821 Bytes
763be49
 
0817dc1
763be49
 
 
 
 
 
 
 
 
 
0817dc1
 
763be49
 
 
 
 
 
 
 
0817dc1
 
763be49
 
 
 
 
 
0817dc1
 
 
 
 
 
 
 
 
 
 
 
763be49
 
 
 
 
 
 
 
 
0817dc1
 
763be49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0817dc1
 
763be49
0817dc1
 
 
 
 
 
 
 
 
 
 
 
 
763be49
0817dc1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
763be49
 
 
 
 
0817dc1
763be49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0817dc1
763be49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import React from 'react';
import { CloseIcon, FullscreenEnterIcon, FullscreenExitIcon } from './icons'; // Import fullscreen icons
import { AiImageQuality, AiDimensionsMode } from '../hooks/useAiFeatures';

interface SettingsPanelProps {
  isOpen: boolean;
  onClose: () => void;
  showZoomSlider: boolean;
  onShowZoomSliderChange: (show: boolean) => void;
  aiImageQuality: AiImageQuality;
  onAiImageQualityChange: (quality: AiImageQuality) => void;
  aiApiEndpoint: string;
  onAiApiEndpointChange: (endpoint: string) => void;
  aiDimensionsMode: AiDimensionsMode;
  onAiDimensionsModeChange: (mode: AiDimensionsMode) => void;
  isFullscreenActive: boolean;
  onToggleFullscreen: () => void;
  currentCanvasWidth: number;
  currentCanvasHeight: number;
  onCanvasSizeChange: (width: number, height: number) => void;
}

const CANVAS_SIZE_OPTIONS = [
  { label: '1024 x 1536 px', width: 1024, height: 1536 },
  { label: '1024 x 1024 px', width: 1024, height: 1024 },
  { label: '1200 x 1200 px', width: 1200, height: 1200 },
  { label: '1600 x 1600 px', width: 1600, height: 1600 },
  { label: '2000 x 2000 px', width: 2000, height: 2000 },
  { label: '4000 x 4000 px', width: 4000, height: 4000 },
];

const AI_API_OPTIONS = [
    {
        label: 'Pollinations AI',
        value: 'https://rpfor.deno.dev/proxy?url=https://image.pollinations.ai/prompt/{prompt}?nologo=true&model=gptimage&image={imgurl.url}&quality={quality}{size_params}'
    },
    {
        label: 'Gemini Simple Get',
        value: 'https://geminisimpleget.deno.dev/prompt/{prompt}?image={imgurl.url}'
    }
];


const SettingsPanel: React.FC<SettingsPanelProps> = ({
  isOpen,
  onClose,
  showZoomSlider,
  onShowZoomSliderChange,
  aiImageQuality,
  onAiImageQualityChange,
  aiApiEndpoint,
  onAiApiEndpointChange,
  aiDimensionsMode,
  onAiDimensionsModeChange,
  isFullscreenActive,
  onToggleFullscreen,
  currentCanvasWidth,
  currentCanvasHeight,
  onCanvasSizeChange,
}) => {
  if (!isOpen) return null;

  const qualityOptions: { label: string; value: AiImageQuality }[] = [
    { label: 'Low', value: 'low' },
    { label: 'Medium', value: 'medium' },
    { label: 'High (HD)', value: 'hd' },
  ];

  const handleSizeSelection = (event: React.ChangeEvent<HTMLSelectElement>) => {
    const selectedValue = event.target.value;
    const [newWidth, newHeight] = selectedValue.split('x').map(Number);
    if (!isNaN(newWidth) && !isNaN(newHeight)) {
      onCanvasSizeChange(newWidth, newHeight);
    }
  };

  const currentSizeValue = `${currentCanvasWidth}x${currentCanvasHeight}`;

  return (
    <div
      className="fixed inset-0 bg-black bg-opacity-50 backdrop-blur-sm flex justify-center items-center z-[1000] p-4"
      aria-modal="true"
      role="dialog"
      aria-labelledby="settings-panel-title"
    >
      <div className="bg-white rounded-lg shadow-2xl p-6 w-full max-w-md transform transition-all overflow-y-auto max-h-[90vh]">
        <div className="flex justify-between items-center mb-6">
          <h2 id="settings-panel-title" className="text-xl font-semibold text-slate-800">
            Application Settings
          </h2>
          <button
            onClick={onClose}
            className="text-slate-400 hover:text-slate-600 transition-colors"
            aria-label="Close settings panel"
          >
            <CloseIcon className="w-6 h-6" />
          </button>
        </div>

        {/* Interface Settings */}
        <div className="mb-6">
          <h3 className="text-md font-medium text-slate-700 mb-2">Interface</h3>
          <div className="space-y-3">
            {/* Zoom Slider Toggle */}
            <div className="flex items-center justify-between bg-slate-50 p-3 rounded-md border border-slate-200">
              <label htmlFor="showZoomSliderToggle" className="text-sm text-slate-600">
                Show Zoom Slider
              </label>
              <button
                  id="showZoomSliderToggle"
                  role="switch"
                  aria-checked={showZoomSlider}
                  onClick={() => onShowZoomSliderChange(!showZoomSlider)}
                  className={`relative inline-flex items-center h-6 rounded-full w-11 transition-colors duration-200 ease-in-out focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 ${
                  showZoomSlider ? 'bg-blue-600' : 'bg-slate-300'
                  }`}
              >
                  <span className="sr-only">Toggle Zoom Slider Visibility</span>
                  <span
                  className={`inline-block w-4 h-4 transform bg-white rounded-full transition-transform duration-200 ease-in-out ${
                      showZoomSlider ? 'translate-x-6' : 'translate-x-1'
                  }`}
                  />
              </button>
            </div>

            {/* Fullscreen Toggle */}
            <div className="bg-slate-50 p-3 rounded-md border border-slate-200">
                <button
                    onClick={onToggleFullscreen}
                    className="w-full flex items-center justify-center px-4 py-2 text-sm font-medium text-blue-700 bg-blue-100 hover:bg-blue-200 rounded-md focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 transition-colors"
                    aria-label={isFullscreenActive ? 'Exit Fullscreen' : 'Enter Fullscreen'}
                >
                    {isFullscreenActive ? (
                        <FullscreenExitIcon className="w-5 h-5 mr-2" />
                    ) : (
                        <FullscreenEnterIcon className="w-5 h-5 mr-2" />
                    )}
                    {isFullscreenActive ? 'Exit Fullscreen' : 'Enter Fullscreen'}
                </button>
            </div>
          </div>
        </div>

        {/* Canvas Dimensions Settings */}
        <div className="mb-6">
          <h3 className="text-md font-medium text-slate-700 mb-2">Canvas Dimensions</h3>
          <div className="bg-slate-50 p-3 rounded-md border border-slate-200">
            <label htmlFor="canvasSizeSelect" className="block text-sm text-slate-600 mb-1">
              Canvas Size
            </label>
            <select
              id="canvasSizeSelect"
              value={currentSizeValue}
              onChange={handleSizeSelection}
              className="w-full p-2 border border-slate-300 rounded-md focus:ring-1 focus:ring-blue-500 focus:border-blue-500 transition-shadow text-sm"
              aria-describedby="canvas-size-description"
            >
              {CANVAS_SIZE_OPTIONS.map((option) => (
                <option key={`${option.width}x${option.height}`} value={`${option.width}x${option.height}`}>
                  {option.label}
                </option>
              ))}
            </select>
            <p id="canvas-size-description" className="text-xs text-slate-500 mt-1">
              Changing size will clear the current canvas and history.
            </p>
          </div>
        </div>


        {/* AI Image Generation Settings */}
        <div className="mb-6">
          <h3 className="text-md font-medium text-slate-700 mb-2">AI Image Generation</h3>
          
          <div className="bg-slate-50 p-3 rounded-md border border-slate-200 mb-4">
            <label htmlFor="aiApiEndpointSelect" className="block text-sm text-slate-600 mb-1">
              API Endpoint
            </label>
            <select
                id="aiApiEndpointSelect"
                value={aiApiEndpoint}
                onChange={(e) => onAiApiEndpointChange(e.target.value)}
                className="w-full p-2 border border-slate-300 rounded-md focus:ring-1 focus:ring-blue-500 focus:border-blue-500 transition-shadow text-sm"
                aria-describedby="ai-api-description"
            >
                {AI_API_OPTIONS.map((option) => (
                    <option key={option.value} value={option.value}>
                        {option.label}
                    </option>
                ))}
            </select>
            <p id="ai-api-description" className="text-xs text-slate-500 mt-1">
              Select an API for image generation. Placeholders are filled automatically.
            </p>
          </div>
          
          <div className="bg-slate-50 p-3 rounded-md border border-slate-200 mb-4">
            <label htmlFor="aiDimensionsModeSelect" className="block text-sm text-slate-600 mb-1">
                AI Image Dimensions
            </label>
            <select
                id="aiDimensionsModeSelect"
                value={aiDimensionsMode}
                onChange={(e) => onAiDimensionsModeChange(e.target.value as AiDimensionsMode)}
                className="w-full p-2 border border-slate-300 rounded-md focus:ring-1 focus:ring-blue-500 focus:border-blue-500 transition-shadow text-sm"
                aria-describedby="ai-dimensions-description"
            >
                <option value="api_default">API Default (no size)</option>
                <option value="match_canvas">Match Canvas Size</option>
                <option value="fixed_1024">Fixed 1024x1024</option>
            </select>
            <p id="ai-dimensions-description" className="text-xs text-slate-500 mt-1">
                Controls `width` & `height` params for APIs that support them (e.g., Pollinations AI).
            </p>
          </div>

          <div className="bg-slate-50 p-3 rounded-md border border-slate-200">
            <label htmlFor="aiImageQualitySelect" className="block text-sm text-slate-600 mb-1">
              Image Quality
            </label>
            <select
              id="aiImageQualitySelect"
              value={aiImageQuality}
              onChange={(e) => onAiImageQualityChange(e.target.value as AiImageQuality)}
              className="w-full p-2 border border-slate-300 rounded-md focus:ring-1 focus:ring-blue-500 focus:border-blue-500 transition-shadow text-sm"
              aria-describedby="ai-quality-description"
            >
              {qualityOptions.map((option) => (
                <option key={option.value} value={option.value}>
                  {option.label}
                </option>
              ))}
            </select>
            <p id="ai-quality-description" className="text-xs text-slate-500 mt-1">
              Used for APIs that support a 'quality' parameter (e.g., Pollinations AI).
            </p>
          </div>
        </div>

        <div className="flex justify-end gap-3 mt-8">
          <button
            onClick={onClose}
            className="px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700 focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 transition-colors text-sm font-medium"
          >
            Done
          </button>
        </div>
      </div>
    </div>
  );
};

export default SettingsPanel;