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
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Lead Registration</title>
    <style>

        /* CSS Reset & Base */

        * { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; }

        body {

            background: linear-gradient(135deg, #a1c4fd 0%, #c2e9fb 100%);

            display: flex;

            justify-content: center;

            align-items: center;

            min-height: 100vh;

            padding: 20px;

        }



        /* Card Container */

        .card {

            display: flex;

            background: white;

            border-radius: 15px;

            box-shadow: 0 10px 30px rgba(0,0,0,0.2);

            overflow: hidden;

            width: 1000px;

            max-width: 100%;

            min-height: 600px;

        }



        /* Left Panel (White) */

        .left-panel {

            flex: 1;

            padding: 50px;

            background: #fff;

        }



        /* Right Panel (Blue) */

        .right-panel {

            flex: 1;

            padding: 50px;

            background: #4d4dff;

            color: white;

        }



        /* Headings */

        h2 { margin-bottom: 30px; font-weight: 600; font-size: 1.5rem; }

        .left-panel h2 { color: #3b4d81; }

        .right-panel h2 { color: white; }



        /* Form Grid System */

        .form-row {

            display: flex;

            gap: 20px;

            margin-bottom: 25px;

        }

        .form-group { 

            flex: 1;

            position: relative;

        }

        

        /* Inputs - General Styling */

        input, select {

            width: 100%;

            padding: 12px 0 8px 0;

            border: none;

            outline: none;

            font-size: 0.95rem;

            transition: 0.3s;

            background: transparent;

        }



        /* Left Panel Input Styling (Light) */

        .left-panel input, .left-panel select {

            border-bottom: 2px solid #ddd;

            color: #333;

        }

        .left-panel input::placeholder { 

            color: #999;

            opacity: 1;

        }

        .left-panel input:focus, .left-panel select:focus { 

            border-bottom-color: #4d4dff; 

        }

        .left-panel select {

            cursor: pointer;

            appearance: none;

            background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23666' d='M6 9L1 4h10z'/%3E%3C/svg%3E");

            background-repeat: no-repeat;

            background-position: right center;

        }

        .left-panel select option {

            color: #333;

            background: white;

        }



        /* Right Panel Input Styling (Dark/Blue) */

        .right-panel input, .right-panel select {

            border-bottom: 2px solid rgba(255,255,255,0.4);

            color: white;

        }

        .right-panel input::placeholder { 

            color: rgba(255,255,255,0.7);

            opacity: 1;

        }

        .right-panel select {

            cursor: pointer;

            appearance: none;

            background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23ffffff' d='M6 9L1 4h10z'/%3E%3C/svg%3E");

            background-repeat: no-repeat;

            background-position: right center;

        }

        .right-panel select option {

            color: #333;

            background: #4d4dff;

        }

        .right-panel input:focus, .right-panel select:focus { 

            border-bottom-color: white; 

        }



        /* Checkbox */

        .checkbox-group {

            display: flex;

            align-items: center;

            font-size: 0.85rem;

            margin-top: 20px;

            margin-bottom: 30px;

            color: rgba(255,255,255,0.9);

        }

        .checkbox-group input { 

            width: auto; 

            margin-right: 10px;

            cursor: pointer;

        }

        .checkbox-group label {

            cursor: pointer;

        }



        /* Button */

        .btn-submit {

            background: white;

            color: #4d4dff;

            border: none;

            padding: 12px 30px;

            border-radius: 25px;

            font-weight: bold;

            cursor: pointer;

            font-size: 1rem;

            transition: all 0.2s;

        }

        .btn-submit:hover { 

            transform: scale(1.05);

            box-shadow: 0 4px 15px rgba(255,255,255,0.3);

        }

        .btn-submit:disabled { 

            opacity: 0.6; 

            cursor: not-allowed;

            transform: scale(1);

        }



        /* Alert Messages */

        .alert {

            padding: 15px 20px;

            margin-bottom: 25px;

            border-radius: 8px;

            display: none; /* Hidden by default */

            font-size: 0.9rem;

            animation: slideIn 0.3s ease-out;

        }

        .alert.success { 

            background: #d4edda; 

            color: #155724; 

            border-left: 4px solid #28a745;

        }

        .alert.error { 

            background: #f8d7da; 

            color: #721c24; 

            border-left: 4px solid #dc3545;

        }

        .alert.show { 

            display: block; /* Visible when class 'show' is added */

        }



        @keyframes slideIn {

            from {

                opacity: 0;

                transform: translateY(-10px);

            }

            to {

                opacity: 1;

                transform: translateY(0);

            }

        }



        /* Responsive Mobile */

        @media (max-width: 768px) {

            .card { flex-direction: column; }

            .left-panel, .right-panel { padding: 30px; }

            .form-row { flex-direction: column; gap: 15px; }

        }

    </style>
</head>
<body>

    <!-- Link to Dashboard for Hugging Face Space -->
    <div style="position: absolute; top: 20px; right: 20px; z-index: 100;">
        <a href="/" style="background: white; padding: 10px 20px; border-radius: 20px; text-decoration: none; font-weight: bold; color: #4d4dff; box-shadow: 0 2px 10px rgba(0,0,0,0.1); font-size: 0.9rem;">View CRM Dashboard &rarr;</a>
    </div>

    <div class="card">
        <!-- Left Side: General Info -->
        <div class="left-panel">
            <h2>General Information</h2>
            
            <!-- Alert Box for Success/Error -->
            <div id="alertBox" class="alert"></div>
            
            <form id="leadForm">
                <div class="form-row">
                    <div class="form-group">
                        <input type="text" name="first_name" placeholder="First Name *" required>
                    </div>
                    <div class="form-group">
                        <input type="text" name="last_name" placeholder="Last Name *" required>
                    </div>
                </div>

                <div class="form-row">
                    <div class="form-group">
                        <input type="email" name="email" placeholder="Email Address *" required>
                    </div>
                </div>

                <div class="form-row">
                    <div class="form-group">
                        <select name="source" required>
                            <option value="" disabled selected>How did you hear about us? *</option>
                            <option value="Google Ads">Google Ads</option>
                            <option value="Facebook">Facebook</option>
                            <option value="LinkedIn">LinkedIn</option>
                            <option value="Twitter">Twitter</option>
                            <option value="Referral">Referral</option>
                            <option value="Direct">Direct</option>
                            <option value="Other">Other</option>
                        </select>
                    </div>
                </div>

                <div class="form-row">
                    <div class="form-group">
                        <input type="text" name="company" placeholder="Company Name (Optional)">
                    </div>
                </div>

                <div class="form-row">
                    <div class="form-group">
                        <select name="position">
                            <option value="" disabled selected>Position (Optional)</option>
                            <option value="Developer">Developer</option>
                            <option value="Manager">Manager</option>
                            <option value="Director">Director</option>
                            <option value="Executive">Executive</option>
                            <option value="Other">Other</option>
                        </select>
                    </div>
                </div>
        </div>

        <!-- Right Side: Contact Details -->
        <div class="right-panel">
            <h2>Additional Information</h2>

                <div class="form-row">
                    <div class="form-group">
                        <select name="city" required>
                            <option value="" disabled selected>City *</option>
                            <option value="Dhaka">Dhaka</option>
                            <option value="Chittagong">Chittagong</option>
                            <option value="Winnipeg">Winnipeg</option>
                            <option value="Toronto">Toronto</option>
                            <option value="Vancouver">Vancouver</option>
                            <option value="Montreal">Montreal</option>
                            <option value="Calgary">Calgary</option>
                            <option value="New York">New York</option>
                            <option value="Los Angeles">Los Angeles</option>
                            <option value="Chicago">Chicago</option>
                            <option value="Other">Other</option>
                        </select>
                    </div>
                </div>

                <div class="form-row">
                    <div class="form-group">
                        <select name="budget" required>
                            <option value="" disabled selected>Budget Range *</option>
                            <option value="1000">Under $1,000</option>
                            <option value="5000">$1,000 - $5,000</option>
                            <option value="10000">$5,000 - $10,000</option>
                            <option value="25000">$10,000 - $25,000</option>
                            <option value="50000">$25,000 - $50,000</option>
                            <option value="100000">$50,000+</option>
                        </select>
                    </div>
                </div>

                <div class="form-row">
                    <div class="form-group">
                        <input type="tel" name="phone" placeholder="Phone Number (Optional)">
                    </div>
                </div>

                <div class="form-row">
                    <div class="form-group">
                        <input type="text" name="address" placeholder="Street Address (Optional)">
                    </div>
                </div>

                <div class="form-row">
                    <div class="form-group">
                        <input type="text" name="zip_code" placeholder="Zip/Postal Code (Optional)">
                    </div>
                </div>

                <div class="checkbox-group">
                    <input type="checkbox" id="terms" required>
                    <label for="terms">I accept the Terms and Conditions *</label>
                </div>

                <button type="button" class="btn-submit" onclick="submitData()">Submit Lead</button>
            </form>
        </div>
    </div>

    <!-- JavaScript Handling Submission and Alerts -->
    <script>

        async function submitData() {

            const form = document.getElementById('leadForm');

            const alertBox = document.getElementById('alertBox');

            

            // 1. Reset Alert State (Important for re-submission)

            alertBox.className = 'alert'; 

            alertBox.style.display = 'none';

            

            // 2. Client-side Validation

            if (!form.checkValidity()) {

                showAlert("Please fill in all required fields marked with *", "error");

                form.reportValidity();

                return;

            }



            // 3. Gather Form Data

            const formData = new FormData(form);

            const data = Object.fromEntries(formData.entries());



            // 4. UI Feedback (Disable Button)

            const btn = document.querySelector('.btn-submit');

            const originalText = btn.innerText;

            btn.innerText = "Submitting...";

            btn.disabled = true;



            try {

                // 5. Send POST Request

                const response = await fetch('/submit', {

                    method: 'POST',

                    headers: { 'Content-Type': 'application/json' },

                    body: JSON.stringify(data)

                });



                const result = await response.json();



                if (response.ok) {

                    // --- SUCCESS ---

                    const successMsg = result.message || "✅ Success! Lead submitted successfully.";

                    showAlert(successMsg, "success");

                    

                    // Reset form fields

                    form.reset();

                } else {

                    // --- SERVER/n8n ERROR ---

                    const errorMsg = result.error?.reason || result.message || "❌ Submission failed";

                    showAlert(`Error: ${errorMsg}`, "error");

                }

            } catch (error) {

                // --- NETWORK ERROR ---

                showAlert(`❌ Connection Error: ${error.message}`, "error");

            } finally {

                // 6. Reset Button State

                btn.innerText = originalText;

                btn.disabled = false;

            }

        }



        function showAlert(message, type) {

            const alertBox = document.getElementById('alertBox');

            

            // Set message text

            alertBox.textContent = message;

            

            // Apply CSS classes (This triggers the visible styling)

            alertBox.className = `alert ${type} show`;

            

            // Ensure element is visible (Overrides any inline 'display: none')

            alertBox.style.display = 'block';

            

            // Scroll user to the message

            alertBox.scrollIntoView({ behavior: 'smooth', block: 'nearest' });

            

            // Auto-hide success messages after 7 seconds

            if (type === 'success') {

                setTimeout(() => {

                    alertBox.style.display = 'none'; // Clean hide

                    alertBox.className = 'alert';

                }, 7000);

            }

        }



        // Allow submitting via Enter key

        document.getElementById('leadForm').addEventListener('keypress', function(e) {

            if (e.key === 'Enter' && e.target.tagName !== 'TEXTAREA') {

                e.preventDefault();

                submitData();

            }

        });

    </script>
</body>
</html>