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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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>SiteBuilder Pro - Create Professional Websites</title>
    <link rel="icon" type="image/x-icon" href="/static/favicon.ico">
    <script src="https://cdn.tailwindcss.com"></script>
    <script src="https://unpkg.com/feather-icons"></script>
    <link href="https://cdn.jsdelivr.net/npm/dragula@3.7.3/dist/dragula.min.css" rel="stylesheet">
    <style>
        .builder-container {
            display: grid;
            grid-template-columns: 250px 1fr 250px;
            height: 100vh;
        }
        .component {
            cursor: move;
            padding: 10px;
            margin: 5px 0;
            background: white;
            border: 1px dashed #ccc;
            border-radius: 4px;
        }
        .component:hover {
            background: #f0f7ff;
            border-color: #3b82f6;
        }
        .canvas {
            background: #f8fafc;
            min-height: 100%;
            padding: 20px;
        }
        .preview-item {
            margin-bottom: 15px;
            position: relative;
        }
        .preview-item:hover {
            outline: 2px dashed #3b82f6;
        }
        .remove-btn {
            position: absolute;
            right: 5px;
            top: 5px;
            background: white;
            border-radius: 50%;
            width: 20px;
            height: 20px;
            display: flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            box-shadow: 0 1px 3px rgba(0,0,0,0.1);
            z-index: 10;
        }
    </style>
</head>
<body class="bg-gray-100">
    <header class="bg-white shadow-sm">
        <div class="container mx-auto px-4 py-4 flex justify-between items-center">
            <div class="flex items-center space-x-3">
                <div class="w-10 h-10 rounded-lg bg-blue-500 flex items-center justify-center text-white">
                    <i data-feather="globe" class="w-5 h-5"></i>
                </div>
                <h1 class="text-xl font-bold text-gray-800">SiteBuilder Pro</h1>
            </div>
            <div class="flex items-center space-x-4">
                <button id="preview-btn" class="px-4 py-2 bg-gray-200 text-gray-700 rounded-md hover:bg-gray-300">
                    <i data-feather="eye" class="w-4 h-4 mr-2"></i> Preview
                </button>
                <button id="export-btn" class="px-4 py-2 bg-blue-500 text-white rounded-md hover:bg-blue-600">
                    <i data-feather="download" class="w-4 h-4 mr-2"></i> Export
                </button>
                <button id="save-btn" class="px-4 py-2 bg-green-500 text-white rounded-md hover:bg-green-600">
                    <i data-feather="save" class="w-4 h-4 mr-2"></i> Save
                </button>
            </div>
        </div>
    </header>

    <div class="builder-container">
        <!-- Components Panel -->
        <div class="bg-white p-4 border-r overflow-y-auto">
            <h3 class="font-medium text-gray-700 mb-3">Components</h3>
            <div class="space-y-2">
                <div class="component" draggable="true" data-type="header">
                    <div class="flex items-center">
                        <i data-feather="header" class="w-4 h-4 mr-2 text-blue-500"></i>
                        Header
                    </div>
                </div>
                <div class="component" draggable="true" data-type="hero">
                    <div class="flex items-center">
                        <i data-feather="image" class="w-4 h-4 mr-2 text-purple-500"></i>
                        Hero Section
                    </div>
                </div>
                <div class="component" draggable="true" data-type="features">
                    <div class="flex items-center">
                        <i data-feather="grid" class="w-4 h-4 mr-2 text-green-500"></i>
                        Features Grid
                    </div>
                </div>
                <div class="component" draggable="true" data-type="testimonials">
                    <div class="flex items-center">
                        <i data-feather="users" class="w-4 h-4 mr-2 text-yellow-500"></i>
                        Testimonials
                    </div>
                </div>
                <div class="component" draggable="true" data-type="contact">
                    <div class="flex items-center">
                        <i data-feather="mail" class="w-4 h-4 mr-2 text-red-500"></i>
                        Contact Form
                    </div>
                </div>
                <div class="component" draggable="true" data-type="footer">
                    <div class="flex items-center">
                        <i data-feather="footer" class="w-4 h-4 mr-2 text-gray-500"></i>
                        Footer
                    </div>
                </div>
            </div>
        </div>

        <!-- Canvas -->
        <div id="canvas" class="canvas">
            <div id="preview-area"></div>
        </div>

        <!-- Properties Panel -->
        <div class="bg-white p-4 border-l overflow-y-auto">
            <h3 class="font-medium text-gray-700 mb-3">Properties</h3>
            <div id="properties-panel">
                <p class="text-gray-500 text-sm">Select a component to edit its properties</p>
            </div>
        </div>
    </div>

    <!-- Preview Modal -->
    <div id="preview-modal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden">
        <div class="bg-white rounded-lg w-full max-w-6xl h-5/6 overflow-hidden">
            <div class="flex justify-between items-center p-4 border-b">
                <h3 class="text-lg font-medium">Preview</h3>
                <button id="close-preview" class="text-gray-500 hover:text-gray-700">
                    <i data-feather="x" class="w-5 h-5"></i>
                </button>
            </div>
            <div class="h-full overflow-auto p-4">
                <iframe id="preview-iframe" class="w-full h-full border-none"></iframe>
            </div>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/dragula@3.7.3/dist/dragula.min.js"></script>
    <script>
        feather.replace();
        
        // Initialize drag and drop
        dragula([document.getElementById('canvas')], {
            accepts: function(el, target) {
                return target.id === 'canvas';
            }
        });

        // Component templates
        const componentTemplates = {
            header: `
                <header class="bg-white shadow-sm py-4 px-6">
                    <div class="container mx-auto flex justify-between items-center">
                        <div class="flex items-center space-x-3">
                            <div class="w-10 h-10 rounded-lg bg-blue-500 flex items-center justify-center text-white">
                                <i data-feather="globe" class="w-5 h-5"></i>
                            </div>
                            <h2 class="text-xl font-bold">Your Logo</h2>
                        </div>
                        <nav class="hidden md:flex space-x-6">
                            <a href="#" class="text-gray-600 hover:text-blue-500">Home</a>
                            <a href="#" class="text-gray-600 hover:text-blue-500">About</a>
                            <a href="#" class="text-gray-600 hover:text-blue-500">Services</a>
                            <a href="#" class="text-gray-600 hover:text-blue-500">Contact</a>
                        </nav>
                        <button class="md:hidden">
                            <i data-feather="menu" class="w-6 h-6"></i>
                        </button>
                    </div>
                </header>
            `,
            hero: `
                <section class="bg-blue-50 py-16 px-4">
                    <div class="container mx-auto text-center max-w-3xl">
                        <h1 class="text-4xl font-bold text-gray-800 mb-4">Build Beautiful Websites</h1>
                        <p class="text-xl text-gray-600 mb-8">Create professional sites with our drag and drop builder</p>
                        <div class="flex justify-center space-x-4">
                            <button class="px-6 py-3 bg-blue-500 text-white rounded-lg hover:bg-blue-600">Get Started</button>
                            <button class="px-6 py-3 border border-gray-300 text-gray-700 rounded-lg hover:bg-gray-50">Learn More</button>
                        </div>
                    </div>
                </section>
            `,
            features: `
                <section class="py-16 px-4 bg-white">
                    <div class="container mx-auto">
                        <h2 class="text-3xl font-bold text-center text-gray-800 mb-12">Features</h2>
                        <div class="grid grid-cols-1 md:grid-cols-3 gap-8">
                            <div class="bg-gray-50 p-6 rounded-lg">
                                <div class="w-12 h-12 rounded-lg bg-blue-500 flex items-center justify-center text-white mb-4">
                                    <i data-feather="code" class="w-6 h-6"></i>
                                </div>
                                <h3 class="text-xl font-semibold mb-2">Drag & Drop</h3>
                                <p class="text-gray-600">Easily build your site with our intuitive interface</p>
                            </div>
                            <div class="bg-gray-50 p-6 rounded-lg">
                                <div class="w-12 h-12 rounded-lg bg-purple-500 flex items-center justify-center text-white mb-4">
                                    <i data-feather="smartphone" class="w-6 h-6"></i>
                                </div>
                                <h3 class="text-xl font-semibold mb-2">Responsive</h3>
                                <p class="text-gray-600">Your site will look great on all devices</p>
                            </div>
                            <div class="bg-gray-50 p-6 rounded-lg">
                                <div class="w-12 h-12 rounded-lg bg-green-500 flex items-center justify-center text-white mb-4">
                                    <i data-feather="zap" class="w-6 h-6"></i>
                                </div>
                                <h3 class="text-xl font-semibold mb-2">Fast Loading</h3>
                                <p class="text-gray-600">Optimized for performance and speed</p>
                            </div>
                        </div>
                    </div>
                </section>
            `,
            testimonials: `
                <section class="py-16 px-4 bg-gray-50">
                    <div class="container mx-auto max-w-4xl">
                        <h2 class="text-3xl font-bold text-center text-gray-800 mb-12">What Our Customers Say</h2>
                        <div class="grid grid-cols-1 md:grid-cols-2 gap-8">
                            <div class="bg-white p-6 rounded-lg shadow-sm">
                                <div class="flex items-center mb-4">
                                    <div class="w-12 h-12 rounded-full bg-blue-100 flex items-center justify-center text-blue-500 mr-4">
                                        <i data-feather="user" class="w-5 h-5"></i>
                                    </div>
                                    <div>
                                        <h4 class="font-medium">John Smith</h4>
                                        <p class="text-sm text-gray-500">CEO, Company Inc.</p>
                                    </div>
                                </div>
                                <p class="text-gray-600">"This builder saved me so much time and money. Highly recommended!"</p>
                            </div>
                            <div class="bg-white p-6 rounded-lg shadow-sm">
                                <div class="flex items-center mb-4">
                                    <div class="w-12 h-12 rounded-full bg-purple-100 flex items-center justify-center text-purple-500 mr-4">
                                        <i data-feather="user" class="w-5 h-5"></i>
                                    </div>
                                    <div>
                                        <h4 class="font-medium">Sarah Johnson</h4>
                                        <p class="text-sm text-gray-500">Marketing Director</p>
                                    </div>
                                </div>
                                <p class="text-gray-600">"Incredibly easy to use and the results are professional-grade."</p>
                            </div>
                        </div>
                    </div>
                </section>
            `,
            contact: `
                <section class="py-16 px-4 bg-white">
                    <div class="container mx-auto max-w-2xl">
                        <h2 class="text-3xl font-bold text-center text-gray-800 mb-8">Contact Us</h2>
                        <form class="space-y-6">
                            <div>
                                <label class="block text-sm font-medium text-gray-700 mb-1">Name</label>
                                <input type="text" class="w-full px-4 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-blue-500 focus:border-blue-500">
                            </div>
                            <div>
                                <label class="block text-sm font-medium text-gray-700 mb-1">Email</label>
                                <input type="email" class="w-full px-4 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-blue-500 focus:border-blue-500">
                            </div>
                            <div>
                                <label class="block text-sm font-medium text-gray-700 mb-1">Message</label>
                                <textarea rows="4" class="w-full px-4 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-blue-500 focus:border-blue-500"></textarea>
                            </div>
                            <button type="submit" class="w-full py-3 bg-blue-500 text-white rounded-md hover:bg-blue-600">Send Message</button>
                        </form>
                    </div>
                </section>
            `,
            footer: `
                <footer class="bg-gray-800 text-white py-12 px-4">
                    <div class="container mx-auto">
                        <div class="grid grid-cols-1 md:grid-cols-4 gap-8">
                            <div>
                                <h3 class="text-xl font-bold mb-4">SiteBuilder Pro</h3>
                                <p class="text-gray-400">Creating beautiful websites for everyone.</p>
                            </div>
                            <div>
                                <h4 class="font-medium mb-4">Quick Links</h4>
                                <ul class="space-y-2">
                                    <li><a href="#" class="text-gray-400 hover:text-white">Home</a></li>
                                    <li><a href="#" class="text-gray-400 hover:text-white">About</a></li>
                                    <li><a href="#" class="text-gray-400 hover:text-white">Features</a></li>
                                    <li><a href="#" class="text-gray-400 hover:text-white">Pricing</a></li>
                                </ul>
                            </div>
                            <div>
                                <h4 class="font-medium mb-4">Resources</h4>
                                <ul class="space-y-2">
                                    <li><a href="#" class="text-gray-400 hover:text-white">Blog</a></li>
                                    <li><a href="#" class="text-gray-400 hover:text-white">Documentation</a></li>
                                    <li><a href="#" class="text-gray-400 hover:text-white">Support</a></li>
                                </ul>
                            </div>
                            <div>
                                <h4 class="font-medium mb-4">Connect</h4>
                                <div class="flex space-x-4">
                                    <a href="#" class="text-gray-400 hover:text-white"><i data-feather="facebook" class="w-5 h-5"></i></a>
                                    <a href="#" class="text-gray-400 hover:text-white"><i data-feather="twitter" class="w-5 h-5"></i></a>
                                    <a href="#" class="text-gray-400 hover:text-white"><i data-feather="instagram" class="w-5 h-5"></i></a>
                                    <a href="#" class="text-gray-400 hover:text-white"><i data-feather="linkedin" class="w-5 h-5"></i></a>
                                </div>
                            </div>
                        </div>
                        <div class="border-t border-gray-700 mt-8 pt-8 text-center text-gray-400">
                            <p>&copy; 2023 SiteBuilder Pro. All rights reserved.</p>
                        </div>
                    </div>
                </footer>
            `
        };

        // Add components to canvas
        document.querySelectorAll('.component').forEach(component => {
            component.addEventListener('dragstart', function(e) {
                e.dataTransfer.setData('text/plain', this.getAttribute('data-type'));
            });
        });

        const canvas = document.getElementById('canvas');
        const previewArea = document.getElementById('preview-area');

        canvas.addEventListener('dragover', function(e) {
            e.preventDefault();
        });

        canvas.addEventListener('drop', function(e) {
            e.preventDefault();
            const componentType = e.dataTransfer.getData('text/plain');
            if (componentType) {
                const newComponent = document.createElement('div');
                newComponent.className = 'preview-item';
                newComponent.innerHTML = `
                    <div class="remove-btn">
                        <i data-feather="x" class="w-3 h-3"></i>
                    </div>
                    ${componentTemplates[componentType]}
                `;
                previewArea.appendChild(newComponent);
                feather.replace();

                // Add click event to remove button
                newComponent.querySelector('.remove-btn').addEventListener('click', function() {
                    newComponent.remove();
                });
            }
        });

        // Preview functionality
        const previewBtn = document.getElementById('preview-btn');
        const previewModal = document.getElementById('preview-modal');
        const closePreview = document.getElementById('close-preview');
        const previewIframe = document.getElementById('preview-iframe');

        previewBtn.addEventListener('click', function() {
            previewIframe.srcdoc = `
                <!DOCTYPE html>
                <html>
                <head>
                    <script src="https://cdn.tailwindcss.com"></script>
                    <script src="https://unpkg.com/feather-icons"></script>
                    <title>Preview</title>
                </head>
                <body>
                    ${previewArea.innerHTML}
                    <script>feather.replace();</script>
                </body>
                </html>
            `;
            previewModal.classList.remove('hidden');
        });

        closePreview.addEventListener('click', function() {
            previewModal.classList.add('hidden');
        });

        // Export functionality
        document.getElementById('export-btn').addEventListener('click', function() {
            const htmlContent = `
                <!DOCTYPE html>
                <html>
                <head>
                    <meta charset="UTF-8">
                    <meta name="viewport" content="width=device-width, initial-scale=1.0">
                    <title>Your Website</title>
                    <script src="https://cdn.tailwindcss.com"></script>
                    <script src="https://unpkg.com/feather-icons"></script>
                </head>
                <body>
                    ${previewArea.innerHTML}
                    <script>feather.replace();</script>
                </body>
                </html>
            `;

            const blob = new Blob([htmlContent], {type: 'text/html'});
            const url = URL.createObjectURL(blob);
            const a = document.createElement('a');
            a.href = url;
            a.download = 'website.html';
            document.body.appendChild(a);
            a.click();
            document.body.removeChild(a);
            URL.revokeObjectURL(url);
        });

        // Save functionality
        document.getElementById('save-btn').addEventListener('click', function() {
            alert('Website saved successfully! (In a real app, this would save to your account)');
        });
    </script>
</body>
</html>