File size: 25,885 Bytes
b2363b3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
<!DOCTYPE html>
<html lang="pt-BR" class="dark">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>geoForms Studio - Builder</title>
    <link rel="icon" type="image/x-icon" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%234f46e5' stroke-width='2'><path d='M21 10c0 7-9 13-9 13s-9-6-9-13a9 9 0 0 1 18 0z'/><circle cx='12' cy='10' r='3'/></svg>">
    <script src="https://cdn.tailwindcss.com"></script>
    <script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
    <script src="https://unpkg.com/feather-icons"></script>
    <link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
    <script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet.draw/1.0.4/leaflet.draw.css" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet.draw/1.0.4/leaflet.draw.js"></script>
    <script>
        tailwind.config = {
            darkMode: 'class',
            theme: {
                extend: {
                    colors: {
                        primary: {
                            50: '#eef2ff',
                            100: '#e0e7ff',
                            500: '#6366f1',
                            600: '#4f46e5',
                            700: '#4338ca',
                            900: '#312e81'
                        },
                        secondary: {
                            50: '#ecfdf5',
                            100: '#d1fae5',
                            500: '#10b981',
                            600: '#059669',
                            700: '#047857'
                        }
                    }
                }
            }
        }
    </script>
    <link rel="stylesheet" href="style.css">
</head>
<body class="bg-gray-100 dark:bg-gray-900 h-screen overflow-hidden">
    <script src="components/navbar.js"></script>
    <script src="components/toolbox.js"></script>
    <script src="components/device-preview.js"></script>
    <script src="components/properties-panel.js"></script>
    
    <geo-navbar></geo-navbar>
    
    <div class="flex h-[calc(100vh-64px)]">
        <!-- Toolbox Sidebar -->
        <geo-toolbox></geo-toolbox>
        
        <!-- Center Canvas -->
        <div class="flex-1 flex flex-col relative bg-gray-200 dark:bg-gray-800">
            <!-- Device Toolbar -->
            <div class="bg-white dark:bg-gray-700 border-b border-gray-200 dark:border-gray-600 p-3 flex justify-center gap-4 shadow-sm">
                <button onclick="setDevice('mobile')" class="device-btn active p-2 rounded-lg hover:bg-gray-100 dark:hover:bg-gray-600 transition-colors" data-device="mobile">
                    <i data-feather="smartphone" class="w-5 h-5 text-gray-600 dark:text-gray-300"></i>
                </button>
                <button onclick="setDevice('tablet')" class="device-btn p-2 rounded-lg hover:bg-gray-100 dark:hover:bg-gray-600 transition-colors" data-device="tablet">
                    <i data-feather="tablet" class="w-5 h-5 text-gray-600 dark:text-gray-300"></i>
                </button>
                <button onclick="setDevice('desktop')" class="device-btn p-2 rounded-lg hover:bg-gray-100 dark:hover:bg-gray-600 transition-colors" data-device="desktop">
                    <i data-feather="monitor" class="w-5 h-5 text-gray-600 dark:text-gray-300"></i>
                </button>
                <div class="w-px h-6 bg-gray-300 dark:bg-gray-500 mx-2"></div>
                <button onclick="toggleTheme()" class="p-2 rounded-lg hover:bg-gray-100 dark:hover:bg-gray-600 transition-colors">
                    <i data-feather="sun" class="w-5 h-5 text-gray-600 dark:text-gray-300 hidden dark:block"></i>
                    <i data-feather="moon" class="w-5 h-5 text-gray-600 dark:text-gray-300 block dark:hidden"></i>
                </button>
                <button onclick="exportForm()" class="p-2 rounded-lg hover:bg-gray-100 dark:hover:bg-gray-600 transition-colors text-primary-600">
                    <i data-feather="download" class="w-5 h-5"></i>
                </button>
            </div>
            
            <!-- Canvas Area -->
            <div class="flex-1 overflow-auto p-8 flex justify-center items-start" id="canvasArea">
                <geo-device-preview id="devicePreview"></geo-device-preview>
            </div>
        </div>
        
        <!-- Properties Panel -->
        <geo-properties-panel></geo-properties-panel>
    </div>
    <script src="script.js"></script>
    <script>
        feather.replace();
        
        // Initialize builder with real functionality
        let currentForm = {
            id: null,
            name: '',
            description: '',
            fields: [],
            theme: 'dark'
        };
        let selectedFieldIndex = null;

        function initBuilder() {
            const urlParams = new URLSearchParams(window.location.search);
            const formId = urlParams.get('form');
            
            if (!formId) {
                window.location.href = 'index.html';
                return;
            }

            // Load form data
            const forms = JSON.parse(localStorage.getItem('geoforms_list') || '[]');
            const form = forms.find(f => f.id === formId);
            
            if (!form) {
                window.location.href = 'index.html';
                return;
            }

            currentForm = {
                ...form,
                fields: JSON.parse(localStorage.getItem(`geoform_${formId}`) || '[]')
            };

            // Update device preview
            const preview = document.getElementById('devicePreview');
            if (preview) {
                preview.setFormTitle(currentForm.name, currentForm.description || 'Preencha os dados abaixo');
                currentForm.fields.forEach(field => preview.addField(field));
            }

            // Listen for field events
            preview?.addEventListener('fieldSelected', (e) => {
                selectedFieldIndex = currentForm.fields.findIndex(f => f.id === e.detail.fieldId);
                updatePropertiesPanel(e.detail);
            });

            preview?.addEventListener('fieldUpdated', (e) => {
                const index = currentForm.fields.findIndex(f => f.id === e.detail.field.id);
                if (index !== -1) {
                    currentForm.fields[index][e.detail.property] = e.detail.value;
                    saveForm();
                }
            });

            preview?.addEventListener('fieldDeleted', (e) => {
                const index = currentForm.fields.findIndex(f => f.id === e.detail.field.id);
                if (index !== -1) {
                    currentForm.fields.splice(index, 1);
                    saveForm();
                    // Refresh preview
                    preview.shadowRoot.getElementById('formContent').innerHTML = '';
                    if (currentForm.fields.length === 0) {
                        preview.shadowRoot.getElementById('formContent').innerHTML = \`
                            <div class="empty-state">
                                <svg class="empty-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1">
                                    <rect x="3" y="3" width="18" height="18" rx="2" ry="2"/>
                                    <line x1="12" y1="8" x2="12" y2="16"/>
                                    <line x1="8" y1="12" x2="16" y2="12"/>
                                </svg>
                                <p>Arraste ferramentas da caixa ao lado</p>
                            </div>
                        \`;
                    } else {
                        currentForm.fields.forEach(field => preview.addField(field));
                    }
                }
            });
        }

        function updatePropertiesPanel(fieldData) {
            const panel = document.querySelector('geo-properties-panel');
            if (panel) {
                panel.showFieldProperties(fieldData);
            }
        }

        function saveForm() {
            localStorage.setItem(`geoform_${currentForm.id}`, JSON.stringify(currentForm.fields));
            
            const forms = JSON.parse(localStorage.getItem('geoforms_list') || '[]');
            const index = forms.findIndex(f => f.id === currentForm.id);
            if (index !== -1) {
                forms[index].fields = currentForm.fields;
                forms[index].updatedAt = new Date().toISOString();
                localStorage.setItem('geoforms_list', JSON.stringify(forms));
            }
        }

        function setDevice(device) {
            const preview = document.getElementById('devicePreview');
            if (preview) {
                preview.setAttribute('device-type', device);
            }
            
            document.querySelectorAll('.device-btn').forEach(btn => {
                btn.classList.toggle('active', btn.dataset.device === device);
            });
        }

        function exportForm() {
            const exportData = {
                metadata: {
                    id: currentForm.id,
                    name: currentForm.name,
                    description: currentForm.description,
                    createdAt: currentForm.createdAt,
                    updatedAt: new Date().toISOString()
                },
                schema: currentForm.fields,
                config: {
                    theme: currentForm.theme,
                    version: '2.0.0'
                }
            };

            // Create comprehensive export package
            const jsonContent = JSON.stringify(exportData, null, 2);
            const htmlContent = generateStandaloneHTML(exportData);
            
            // Create manifest with all files
            const manifest = {
                name: currentForm.name,
                generatedAt: new Date().toISOString(),
                files: {
                    'form-config.json': jsonContent,
                    'form-mobile.html': htmlContent,
                    'form-preview.html': generatePreviewHTML(exportData),
                    'README.txt': \`FormForge GeoStudio Export
=============================
Formulário: \${currentForm.name}
Gerado em: \${new Date().toLocaleString('pt-BR')}

ARQUIVOS:
- form-config.json: Configuração do formulário
- form-mobile.html: Versão mobile standalone
- form-preview.html: Preview do formulário

INSTRUÇÕES:
1. Abra form-mobile.html em um navegador mobile
2. Ou importe form-config.json no FormForge GeoStudio
\`
                }
            };

            // Download as JSON package
            const blob = new Blob([JSON.stringify(manifest, null, 2)], { type: 'application/json' });
            const url = URL.createObjectURL(blob);
            const a = document.createElement('a');
            a.href = url;
            a.download = \`\${currentForm.name.replace(/\\s+/g, '_')}_FormForge_Package.json\`;
            document.body.appendChild(a);
            a.click();
            document.body.removeChild(a);
            URL.revokeObjectURL(url);

            alert('📦 Pacote exportado com sucesso!\\n\\nO arquivo JSON contém:\\n✓ Configuração do formulário\\n✓ HTML mobile standalone\\n✓ Preview HTML\\n✓ Instruções de uso');
        }

        function generateStandaloneHTML(data) {
            return \`<!DOCTYPE html>
<html lang="pt-BR">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="mobile-web-app-capable" content="yes">
    <title>\${data.metadata.name}</title>
    <link rel="manifest" href="data:application/json;base64,\${btoa(JSON.stringify({name: data.metadata.name, start_url: '.', display: 'standalone', background_color: '#4f46e5'}))}">
    <style>
        * { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
        body { 
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; 
            margin: 0; 
            padding: 0; 
            background: #f3f4f6; 
            -webkit-font-smoothing: antialiased;
        }
        .header { 
            background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%); 
            color: white; 
            padding: 1.25rem; 
            position: sticky; 
            top: 0; 
            z-index: 100;
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
        }
        .header h1 { margin: 0 0 0.25rem 0; font-size: 1.25rem; font-weight: 700; }
        .header p { margin: 0; font-size: 0.875rem; opacity: 0.9; }
        .form { padding: 1rem; max-width: 600px; margin: 0 auto; padding-bottom: 6rem; }
        .field { 
            margin-bottom: 1rem; 
            background: white; 
            padding: 1rem; 
            border-radius: 12px; 
            box-shadow: 0 1px 3px rgba(0,0,0,0.08);
        }
        .field-label { 
            display: block; 
            font-size: 0.875rem; 
            font-weight: 600; 
            color: #374151; 
            margin-bottom: 0.5rem; 
        }
        .field-required { color: #ef4444; margin-left: 0.25rem; }
        .field-input { 
            width: 100%; 
            padding: 0.75rem; 
            border: 1px solid #d1d5db; 
            border-radius: 8px; 
            font-size: 16px; 
            background: #f9fafb;
            transition: all 0.2s;
        }
        .field-input:focus { 
            outline: none; 
            border-color: #4f46e5; 
            box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
        }
        .field-select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3E%3Cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3E%3C/svg%3E"); background-position: right 0.5rem center; background-repeat: no-repeat; background-size: 1.5em 1.5em; padding-right: 2.5rem; }
        .photo-upload { 
            border: 2px dashed #d1d5db; 
            border-radius: 8px; 
            padding: 2rem; 
            text-align: center; 
            color: #6b7280; 
            cursor: pointer;
            transition: all 0.2s;
        }
        .photo-upload:active { background: #f3f4f6; border-color: #4f46e5; }
        .map-container { 
            height: 200px; 
            border-radius: 8px; 
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            display: flex; 
            align-items: center; 
            justify-content: center; 
            color: white; 
            font-size: 0.875rem;
        }
        .signature-pad { 
            height: 120px; 
            border: 2px dashed #d1d5db; 
            border-radius: 8px; 
            display: flex; 
            align-items: center; 
            justify-content: center; 
            color: #9ca3af; 
            font-size: 0.875rem;
        }
        .submit-btn { 
            position: fixed; 
            bottom: 0; 
            left: 0; 
            right: 0; 
            padding: 1rem; 
            background: white; 
            border-top: 1px solid #e5e7eb;
            max-width: 600px;
            margin: 0 auto;
        }
        .submit-btn button { 
            width: 100%; 
            padding: 1rem; 
            background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%); 
            color: white; 
            border: none; 
            border-radius: 12px; 
            font-size: 1rem; 
            font-weight: 600;
            cursor: pointer;
            box-shadow: 0 4px 6px -1px rgba(79, 70, 229, 0.3);
        }
        .submit-btn button:active { transform: translateY(1px); }
        .textarea-field { min-height: 100px; resize: vertical; }
        
        /* Success animation */
        @keyframes successPulse {
            0% { transform: scale(1); }
            50% { transform: scale(1.05); }
            100% { transform: scale(1); }
        }
        .success-animation {
            animation: successPulse 0.5s ease;
        }
    </style>
</head>
<body>
    <div class="header">
        <h1>${data.metadata.name}</h1>
        ${data.metadata.description ? `<p>${data.metadata.description}</p>` : ''}
    </div>
    
    <form class="form" id="geoForm" onsubmit="handleSubmit(event)">
        ${data.schema.map(field => {
            const required = field.required ? '<span class="field-required">*</span>' : '';
            const inputName = \`field_\${field.id}\`;
            
            switch(field.type) {
                case 'text':
                    return \`<div class="field">
                        <label class="field-label">\${field.label}\${required}</label>
                        <input type="text" name="\${inputName}" class="field-input" placeholder="\${field.placeholder || ''}" \${field.required ? 'required' : ''}>
                    </div>\`;
                    
                case 'textarea':
                    return \`<div class="field">
                        <label class="field-label">\${field.label}\${required}</label>
                        <textarea name="\${inputName}" class="field-input textarea-field" rows="4" placeholder="\${field.placeholder || ''}" \${field.required ? 'required' : ''}></textarea>
                    </div>\`;
                    
                case 'number':
                    return \`<div class="field">
                        <label class="field-label">\${field.label}\${required}</label>
                        <input type="number" name="\${inputName}" class="field-input" \${field.required ? 'required' : ''}>
                    </div>\`;
                    
                case 'select':
                    const options = (field.options || 'Opção 1, Opção 2').split(',').map(o => o.trim());
                    return \`<div class="field">
                        <label class="field-label">\${field.label}\${required}</label>
                        <select name="\${inputName}" class="field-input field-select" \${field.required ? 'required' : ''}>
                            <option value="">Selecione...</option>
                            \${options.map(o => \`<option value="\${o}">\${o}</option>\`).join('')}
                        </select>
                    </div>\`;
                    
                case 'date':
                    return \`<div class="field">
                        <label class="field-label">\${field.label}\${required}</label>
                        <input type="date" name="\${inputName}" class="field-input" \${field.required ? 'required' : ''}>
                    </div>\`;
                    
                case 'photo':
                    return \`<div class="field">
                        <label class="field-label">\${field.label}\${required}</label>
                        <div class="photo-upload" onclick="capturePhoto('\${inputName}')" id="photo_\${inputName}">
                            <svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" style="margin: 0 auto 0.5rem;">
                                <rect x="3" y="3" width="18" height="18" rx="2" ry="2"/>
                                <circle cx="8.5" cy="8.5" r="1.5"/>
                                <polyline points="21 15 16 10 5 21"/>
                            </svg>
                            <div>Toque para capturar foto</div>
                            <input type="file" name="\${inputName}" id="input_\${inputName}" accept="image/*" capture="environment" style="display: none;" \${field.required ? 'required' : ''}>
                        </div>
                    </div>\`;
                    
                case 'map':
                    const geoType = field.geometryType || 'point';
                    const geoLabel = geoType === 'point' ? '📍 Ponto' : geoType === 'line' ? '📏 Linha' : '⬡ Polígono';
                    return \`<div class="field">
                        <label class="field-label">\${field.label}\${required}</label>
                        <div class="map-container" id="map_\${inputName}">
                            <div>
                                <div style="font-size: 2rem; margin-bottom: 0.5rem;">🗺️</div>
                                <div>Mapa - \${geoLabel}</div>
                                <div style="font-size: 0.75rem; margin-top: 0.5rem; opacity: 0.8;">
                                    Toque para abrir mapa interativo
                                </div>
                            </div>
                        </div>
                        <input type="hidden" name="\${inputName}" id="input_\${inputName}" \${field.required ? 'required' : ''}>
                    </div>\`;
                    
                case 'signature':
                    return \`<div class="field">
                        <label class="field-label">\${field.label}\${required}</label>
                        <div class="signature-pad" onclick="openSignature('\${inputName}')" id="sig_\${inputName}">
                            ✍️ Toque para assinar
                        </div>
                        <input type="hidden" name="\${inputName}" id="input_\${inputName}" \${field.required ? 'required' : ''}>
                    </div>\`;
                    
                default:
                    return \`<div class="field">
                        <label class="field-label">\${field.label}\${required}</label>
                        <input type="text" name="\${inputName}" class="field-input" \${field.required ? 'required' : ''}>
                    </div>\`;
            }
        }).join('')}
        
        <div class="submit-btn">
            <button type="submit">
                ✅ Enviar Dados
            </button>
        </div>
    </form>

    <script>
        // Photo capture
        function capturePhoto(fieldName) {
            const input = document.getElementById('input_' + fieldName);
            const container = document.getElementById('photo_' + fieldName);
            
            input.onchange = function(e) {
                const file = e.target.files[0];
                if (file) {
                    const reader = new FileReader();
                    reader.onload = function(evt) {
                        container.innerHTML = \`<img src="\${evt.target.result}" style="max-width: 100%; border-radius: 8px;">\`;
                    };
                    reader.readAsDataURL(file);
                }
            };
            
            input.click();
        }
        
        // Map capture (simplified - would use actual map in production)
        function openMap(fieldName, geometryType) {
            // In production, this would open an interactive map
            const coords = prompt('Digite as coordenadas (lat,lng):', '-23.5505,-46.6333');
            if (coords) {
                document.getElementById('input_' + fieldName).value = coords;
                document.getElementById('map_' + fieldName).style.background = 'linear-gradient(135deg, #10b981 0%, #059669 100%)';
            }
        }
        
        // Signature capture
        function openSignature(fieldName) {
            // In production, this would open a signature pad
            const confirmed = confirm('Simular assinatura capturada?');
            if (confirmed) {
                document.getElementById('input_' + fieldName).value = 'signature_' + Date.now();
                document.getElementById('sig_' + fieldName).innerHTML = '✅ Assinatura capturada';
                document.getElementById('sig_' + fieldName).style.background = '#d1fae5';
                document.getElementById('sig_' + fieldName).style.color = '#065f46';
            }
        }
        
        // Form submission
        function handleSubmit(e) {
            e.preventDefault();
            
            const formData = new FormData(e.target);
            const data = Object.fromEntries(formData.entries());
            
            // Show success animation
            const btn = e.target.querySelector('button[type="submit"]');
            btn.classList.add('success-animation');
            btn.innerHTML = '✅ Enviado com sucesso!';
            btn.style.background = 'linear-gradient(135deg, #10b981 0%, #059669 100%)';
            
            console.log('Form data:', data);
            
            setTimeout(() => {
                alert('✅ Formulário enviado com sucesso!\\n\\nDados coletados:\\n' + JSON.stringify(data, null, 2));
                btn.classList.remove('success-animation');
                btn.innerHTML = '✅ Enviar Dados';
                btn.style.background = '';
                e.target.reset();
            }, 500);
        }
        
        // Initialize map clicks
        document.querySelectorAll('[id^="map_"]').forEach(map => {
            const fieldName = map.id.replace('map_', '');
            const field = ${JSON.stringify(data.schema)}.find(f => 'field_' + f.id === fieldName);
            map.addEventListener('click', () => openMap(fieldName, field?.geometryType || 'point'));
        });
    <\/script>
</body>
</html>\`;
        }

        function generatePreviewHTML(data) {
            return generateStandaloneHTML(data).replace('form-mobile.html', '#');
        }

        // Initialize on load
        initBuilder();
    </script>
</body>
</html>