Ahmad140 commited on
Commit
7bc0028
·
verified ·
1 Parent(s): 907d787

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +107 -361
index.html CHANGED
@@ -3,9 +3,9 @@
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
6
- <title>Elite Visuals AI – Smart Invoice & Final Report</title>
7
- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
8
  <link href="https://fonts.googleapis.com/css2?family=Inter:opsz,wght@14..32,300;400;500;600;700&display=swap" rel="stylesheet">
 
9
  <style>
10
  * { margin: 0; padding: 0; box-sizing: border-box; }
11
  body { background: linear-gradient(135deg, #f5f7fa 0%, #e9eef5 100%); font-family: 'Inter', sans-serif; height: 100vh; overflow: hidden; }
@@ -35,8 +35,7 @@
35
  .empty-invoice { color: #888; font-size: 0.75rem; text-align: center; padding: 20px; }
36
  .final-report-btn, .download-report-btn { background: #25D366; color: white; border: none; border-radius: 25px; padding: 8px 12px; font-size: 0.75rem; font-weight: 600; cursor: pointer; transition: 0.2s; width: 100%; margin-top: 8px; }
37
  .download-report-btn { background: #2a6d4c; margin-top: 4px; }
38
- .final-report-btn:hover { background: #128C7E; transform: scale(1.02); }
39
- .download-report-btn:hover { background: #1e5a3e; transform: scale(1.02); }
40
  .chat-messages { flex: 1; padding: 12px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
41
  .message { max-width: 85%; padding: 8px 12px; border-radius: 18px; font-size: 0.8rem; line-height: 1.4; white-space: pre-line; animation: fadeIn 0.2s; }
42
  @keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }
@@ -54,8 +53,6 @@
54
  .toggle-widget { cursor: pointer; margin-left: 8px; }
55
  .widget-content { padding: 10px; display: none; background: #fef9e6; font-size: 0.7rem; }
56
  .widget-content.show { display: block; }
57
- .info-row { margin: 4px 0; }
58
- .info-label { font-weight: 700; color: #075E54; }
59
  .quick-messages { display: flex; gap: 8px; overflow-x: auto; padding: 8px; background: #f0f2f5; border-top: 1px solid #ddd; }
60
  .quick-msg-chip { background: #e4e6eb; color: #1f2a3e; padding: 6px 12px; border-radius: 30px; font-size: 0.7rem; font-weight: 500; cursor: pointer; white-space: nowrap; transition: 0.2s; }
61
  .quick-msg-chip:hover { background: #d1d4db; transform: translateY(-1px); }
@@ -87,7 +84,7 @@
87
  <div class="chat-invoice-container" id="chatInvoiceContainer">
88
  <div class="chat-column" id="chatColumn">
89
  <div class="chat-messages" id="chatMessages">
90
- <div class="message bot-msg">✨ Assalam-o-Alaikum! I can help with website design, e‑commerce, SEO, and more. To start a new project, simply say: <strong>"I want to build a website"</strong> – I'll ask for all requirements and generate a proposal with a Project ID. You can also ask about packages or use the buttons below.</div>
91
  <div class="live-widget" id="liveWidget">
92
  <div class="widget-header">
93
  <span><i class="fas fa-chart-line"></i> 📊 Live Quote</span>
@@ -104,7 +101,7 @@
104
  </div>
105
  <div id="defaultQuestionsContainer" class="questions-container"></div>
106
  </div>
107
- <div class="quick-messages" id="quickMessages">
108
  <div class="quick-msg-chip" data-msg="Show packages">📦 Show Packages</div>
109
  <div class="quick-msg-chip" data-msg="Contact number">📞 Contact</div>
110
  <div class="quick-msg-chip" data-msg="I want to build a website">🚀 Start Project</div>
@@ -121,24 +118,19 @@
121
  <span>🧾 Your Quote</span>
122
  <button id="addCustomServiceBtn" style="background: none; border: none; color: #075E54; font-size: 1.2rem; cursor: pointer;" title="Add custom service"><i class="fas fa-plus-circle"></i></button>
123
  </div>
124
- <div class="invoice-items" id="invoiceItems">
125
- <div class="empty-invoice">✨ No services selected yet.<br>Ask or confirm a package to add.</div>
126
- </div>
127
- <div class="invoice-total" id="invoiceTotal">
128
- <span>Subtotal:</span>
129
- <span id="totalAmount">PKR 0</span>
130
- </div>
131
  <button class="final-report-btn" id="finalReportBtn"><i class="fas fa-file-alt"></i> Generate Final Report</button>
132
  <button class="download-report-btn" id="downloadReportBtn"><i class="fas fa-download"></i> Download Report</button>
133
  </div>
134
  </div>
135
  </div>
136
 
137
- <!-- Modal for adding custom service -->
138
  <div id="customServiceModal" class="modal">
139
  <div class="modal-content">
140
  <h3>Add Custom Service</h3>
141
- <input type="text" id="customServiceName" placeholder="Service name (e.g., SEO Audit)">
142
  <input type="text" id="customServicePrice" placeholder="Price (e.g., PKR 25,000)">
143
  <div class="flex-row">
144
  <button id="cancelCustomBtn" class="btn-warning" style="background:#ffc107; color:#333;">Cancel</button>
@@ -148,7 +140,6 @@
148
  </div>
149
 
150
  <script>
151
- // ---------- Session ----------
152
  let sessionId = localStorage.getItem('chat_session_id');
153
  if (!sessionId) {
154
  sessionId = 'user_' + Date.now() + '_' + Math.random().toString(36).substr(2, 8);
@@ -156,16 +147,10 @@
156
  }
157
  const API_URL = "/api/chat";
158
  const DEFAULT_QUESTIONS = [
159
- "Basic website price and timeline?",
160
- "Standard package details",
161
- "Premium package details",
162
- "Extra: live chat cost increase?",
163
- "Add e-commerce to my quote",
164
- "I want to build a website",
165
- "Contact number"
166
  ];
167
 
168
- // ---------- Invoice State ----------
169
  let invoiceItems = [];
170
  let nextId = 1;
171
  let storedProjectId = localStorage.getItem(`project_id_${sessionId}`) || null;
@@ -175,16 +160,6 @@
175
  if (match) return parseInt(match[0].replace(/,/g, ''));
176
  return 0;
177
  }
178
-
179
- function parseTimelineDays(timelineStr) {
180
- if (!timelineStr) return 0;
181
- let match = timelineStr.match(/(\d+)\s*-\s*(\d+)\s*days?/);
182
- if (match) return parseInt(match[2]);
183
- match = timelineStr.match(/(\d+)\s*days?/);
184
- if (match) return parseInt(match[1]);
185
- return 0;
186
- }
187
-
188
  function updateInvoiceDisplay() {
189
  const container = document.getElementById('invoiceItems');
190
  const totalSpan = document.getElementById('totalAmount');
@@ -193,160 +168,73 @@
193
  totalSpan.innerText = 'PKR 0';
194
  return;
195
  }
196
- let html = '';
197
- let total = 0;
198
  invoiceItems.forEach(item => {
199
- const priceNum = parsePrice(item.price);
200
- total += priceNum;
201
- html += `
202
- <div class="invoice-item" data-id="${item.id}">
203
- <div class="invoice-item-name">${item.name}</div>
204
- <div style="display: flex; align-items: center; gap: 12px;">
205
- <span class="invoice-item-price">${item.price}</span>
206
- <span class="remove-item" data-id="${item.id}"><i class="fas fa-times-circle"></i></span>
207
- </div>
208
- </div>
209
- `;
210
  });
211
  container.innerHTML = html;
212
  totalSpan.innerText = `PKR ${total.toLocaleString()}`;
213
- document.querySelectorAll('.remove-item').forEach(el => {
214
- el.addEventListener('click', (e) => {
215
- const id = parseInt(el.dataset.id);
216
- removeInvoiceItem(id);
217
- });
218
- });
219
- }
220
-
221
- function removeInvoiceItem(id) {
222
- invoiceItems = invoiceItems.filter(item => item.id !== id);
223
- updateInvoiceDisplay();
224
  }
225
-
226
- function addInvoiceItem(serviceName, priceStr, serviceKey = null, timelineDays = null) {
227
- if (serviceKey && invoiceItems.some(item => item.serviceKey === serviceKey)) return false;
228
- const newItem = { id: nextId++, name: serviceName, price: priceStr, serviceKey: serviceKey || serviceName, timelineDays: timelineDays };
229
- invoiceItems.push(newItem);
230
  updateInvoiceDisplay();
231
  return true;
232
  }
233
 
234
- // ---------- Custom Service Modal ----------
235
  const modal = document.getElementById('customServiceModal');
236
- const addCustomBtnHeader = document.getElementById('addCustomServiceBtn');
237
- const customInvoiceChip = document.getElementById('customInvoiceChip');
238
- function openModal() { modal.style.display = 'flex'; }
239
- addCustomBtnHeader.onclick = openModal;
240
- customInvoiceChip.onclick = openModal;
241
  document.getElementById('cancelCustomBtn').onclick = () => modal.style.display = 'none';
242
  document.getElementById('addCustomBtn').onclick = () => {
243
- const name = document.getElementById('customServiceName').value.trim();
244
- const price = document.getElementById('customServicePrice').value.trim();
245
- if (!name || !price) {
246
- alert("Please enter both service name and price.");
247
- return;
248
- }
249
  addInvoiceItem(name, price, `custom_${Date.now()}`);
250
  modal.style.display = 'none';
251
  document.getElementById('customServiceName').value = '';
252
  document.getElementById('customServicePrice').value = '';
253
  };
254
 
255
- // ---------- Quick Messages ----------
256
- document.querySelectorAll('.quick-msg-chip[data-msg]').forEach(chip => {
257
- chip.addEventListener('click', () => {
258
- userInput.value = chip.getAttribute('data-msg');
259
- sendMessage();
260
- });
261
- });
262
 
263
- // ---------- Extract Project ID from bot confirmation ----------
264
  function extractAndStoreProjectId(text) {
265
- const match = text.match(/Project ID:\s*`([A-Z0-9\-]+)`/i);
266
- if (match) {
267
- storedProjectId = match[1];
268
- localStorage.setItem(`project_id_${sessionId}`, storedProjectId);
269
- }
270
  }
271
-
272
- // ---------- Generate Final Report (in chat) ----------
273
  function generateFinalReport() {
274
- if (invoiceItems.length === 0) {
275
- addMessageWithConfirm("❌ You haven't added any services yet. Please confirm some packages or features first.", 'bot');
276
- return;
277
- }
278
  let report = "📋 **Final Project Report**\n\n**Selected Services:**\n";
279
- let totalPrice = 0;
280
- let totalTimelineDays = 0;
281
  invoiceItems.forEach(item => {
282
- const priceNum = parsePrice(item.price);
283
- totalPrice += priceNum;
284
  report += `- ${item.name}: ${item.price}\n`;
285
- if (item.timelineDays) {
286
- totalTimelineDays += item.timelineDays;
287
- report += ` (timeline: ${item.timelineDays} days)\n`;
288
- }
289
  });
290
- report += `\n**💰 Total Estimated Cost:** PKR ${totalPrice.toLocaleString()}`;
291
- if (totalTimelineDays > 0) {
292
- report += `\n**⏱️ Total Estimated Timeline:** ${totalTimelineDays} working days (cumulative)`;
293
- report += `\n> Note: Some tasks can run in parallel, so actual timeline may be less. We will provide a detailed schedule after confirmation.`;
294
- } else {
295
- report += `\n**⏱️ Timeline:** Please contact for detailed timeline based on selected services.`;
296
- }
297
- if (storedProjectId) {
298
- report += `\n\n📌 **Project ID:** \`${storedProjectId}\`\n🔍 **Check status:** Type \`status ${storedProjectId}\` anytime.`;
299
- } else {
300
- report += `\n\n✅ After final confirmation, you will receive a Project ID to track your request.`;
301
- }
302
- report += `\n\n✅ This is a preliminary quote. For final confirmation and payment, please share your contact details or email us at hello@elitevisuals.com.`;
303
- addMessageWithConfirm(report, 'bot');
304
  }
305
-
306
- // ---------- Download Report (as .txt file) ----------
307
  function downloadReport() {
308
- if (invoiceItems.length === 0) {
309
- alert("No services selected. Please add items to your quote first.");
310
- return;
311
- }
312
- let content = "ELITE VISUALS – QUOTE REPORT\n";
313
- content += "==========================\n\n";
314
- content += `Date: ${new Date().toLocaleString()}\n`;
315
- content += `Session ID: ${sessionId}\n\n`;
316
- content += "Selected Services:\n";
317
- content += "-----------------\n";
318
  let totalPrice = 0;
319
- let totalDays = 0;
320
- invoiceItems.forEach(item => {
321
- const priceNum = parsePrice(item.price);
322
- totalPrice += priceNum;
323
- content += `• ${item.name}: ${item.price}\n`;
324
- if (item.timelineDays) {
325
- totalDays += item.timelineDays;
326
- content += ` (est. timeline: ${item.timelineDays} days)\n`;
327
- }
328
- });
329
- content += "\n-----------------\n";
330
- content += `TOTAL COST: PKR ${totalPrice.toLocaleString()}\n`;
331
- if (totalDays > 0) content += `CUMULATIVE TIMELINE: ${totalDays} working days\n`;
332
- if (storedProjectId) {
333
- content += `\n📌 PROJECT ID: ${storedProjectId}\n`;
334
- content += `🔍 To check status, type in chat: status ${storedProjectId}\n`;
335
- }
336
- content += "\nThis is an estimate. Final quote may vary.\n";
337
- content += "Contact: hello@elitevisuals.com | +92 300 1234567\n";
338
- const blob = new Blob([content], { type: "text/plain" });
339
- const url = URL.createObjectURL(blob);
340
- const a = document.createElement("a");
341
- a.href = url;
342
- a.download = `quote_${new Date().toISOString().slice(0,19).replace(/:/g, "-")}.txt`;
343
- document.body.appendChild(a);
344
- a.click();
345
- document.body.removeChild(a);
346
- URL.revokeObjectURL(url);
347
  }
348
 
349
- // ---------- Auto-add services from bot messages (matching the step builder outputs) ----------
350
  const serviceMap = {
351
  "domain": { name: "Domain Registration", price: "PKR 5,000", key: "domain" },
352
  "e-commerce": { name: "E‑commerce Functionality", price: "PKR 50,000", key: "ecommerce" },
@@ -360,256 +248,114 @@
360
  "custom backend": { name: "Custom Backend", price: "PKR 100,000", key: "custom_backend" }
361
  };
362
  let currentPages = 5;
363
-
364
  function autoAddFromBotMessage(text) {
365
  extractAndStoreProjectId(text);
366
- const lower = text.toLowerCase();
367
- // Domain
368
- if (lower.includes("domain: yes") || (lower.includes("need a domain") && lower.includes("yes"))) {
369
- addInvoiceItem("Domain Registration", "PKR 5,000", "domain");
370
- }
371
- // Pages
372
- const pagesMatch = lower.match(/pages:\s*(\d+)/);
373
  if (pagesMatch) {
374
- const pages = parseInt(pagesMatch[1]);
375
  if (pages !== currentPages) {
376
  currentPages = pages;
377
- invoiceItems = invoiceItems.filter(item => item.serviceKey !== "pages");
378
- const extraPages = Math.max(0, pages - 5);
379
- if (extraPages > 0) {
380
- const extraCost = extraPages * 5000;
381
- addInvoiceItem(`${extraPages} extra page(s)`, `PKR ${extraCost.toLocaleString()}`, "pages");
382
- }
383
  }
384
  }
385
- // E-commerce
386
- if (lower.includes("e‑commerce: yes") || (lower.includes("need e‑commerce") && lower.includes("yes"))) {
387
- addInvoiceItem("E��commerce Functionality", "PKR 50,000", "ecommerce");
388
- }
389
- // Chatbot
390
- if (lower.includes("chatbot: yes") || (lower.includes("ai chatbot") && lower.includes("yes"))) {
391
- addInvoiceItem("AI Chatbot", "PKR 30,000", "chatbot");
392
- }
393
- // SEO
394
- if (lower.includes("seo: yes") || (lower.includes("seo optimization") && lower.includes("yes"))) {
395
- addInvoiceItem("SEO Optimization", "PKR 25,000", "seo");
396
- }
397
- // Inventory
398
- if (lower.includes("inventory management: yes") || (lower.includes("inventory management") && lower.includes("yes"))) {
399
- addInvoiceItem("Inventory Management", "PKR 30,000", "inventory");
400
- }
401
- // Database
402
- if (lower.includes("database integration: yes") || (lower.includes("database integration") && lower.includes("yes"))) {
403
- addInvoiceItem("Database Integration", "PKR 40,000", "database");
404
- }
405
- // Extra features from "✅ Added **something**"
406
- const addedMatch = text.match(/✅ Added \*\*([^*]+)\*\*/i);
407
- if (addedMatch) {
408
- const feature = addedMatch[1].toLowerCase();
409
- for (const [key, svc] of Object.entries(serviceMap)) {
410
- if (feature.includes(key) || key.includes(feature)) {
411
- addInvoiceItem(svc.name, svc.price, svc.key);
412
- break;
413
- }
414
- }
415
- }
416
- // Also handle "✅ Added something." pattern
417
- const genericAdded = text.match(/✅ Added (.+?)\./i);
418
- if (genericAdded && !addedMatch) {
419
- const feature = genericAdded[1].toLowerCase();
420
- for (const [key, svc] of Object.entries(serviceMap)) {
421
- if (feature.includes(key) || key.includes(feature)) {
422
- addInvoiceItem(svc.name, svc.price, svc.key);
423
- break;
424
- }
425
- }
426
  }
427
  }
428
 
429
- // ---------- Live Widget (optional, kept for compatibility) ----------
430
- const widgetContent = document.getElementById('widgetContent');
431
- const toggleIcon = document.getElementById('toggleIcon');
432
- const hideWidgetBtn = document.getElementById('hideWidgetBtn');
433
- const unhideWidgetBtn = document.getElementById('unhideWidgetBtn');
434
- const liveWidget = document.getElementById('liveWidget');
435
  let widgetOpen = false;
436
- toggleIcon.addEventListener('click', (e) => {
437
- e.stopPropagation();
438
- if (widgetOpen) {
439
- widgetContent.classList.remove('show');
440
- toggleIcon.classList.remove('fa-chevron-up');
441
- toggleIcon.classList.add('fa-chevron-down');
442
- } else {
443
- widgetContent.classList.add('show');
444
- toggleIcon.classList.remove('fa-chevron-down');
445
- toggleIcon.classList.add('fa-chevron-up');
446
- }
447
- widgetOpen = !widgetOpen;
448
- });
449
- hideWidgetBtn.addEventListener('click', () => {
450
- liveWidget.style.display = 'none';
451
- hideWidgetBtn.style.display = 'none';
452
- unhideWidgetBtn.style.display = 'inline-flex';
453
- });
454
- unhideWidgetBtn.addEventListener('click', () => {
455
- liveWidget.style.display = 'block';
456
- hideWidgetBtn.style.display = 'inline-flex';
457
- unhideWidgetBtn.style.display = 'none';
458
- });
459
- function updateWidget(data) {
460
- // This function can be kept but is not strictly needed because backend no longer sends 'widget'.
461
- // We'll keep it inert.
462
- }
463
 
464
- // ---------- Message display with Confirm buttons ----------
465
- function addMessageWithConfirm(text, sender, widgetData = null) {
466
- const chatMessagesDiv = document.getElementById('chatMessages');
467
  if (sender === 'user') {
468
- const div = document.createElement('div');
469
- div.className = 'message user-msg';
470
- div.innerText = text;
471
- chatMessagesDiv.appendChild(div);
472
- chatMessagesDiv.scrollTop = chatMessagesDiv.scrollHeight;
473
  return;
474
  }
475
- const wrapper = document.createElement('div');
476
- wrapper.className = 'bot-message-wrapper';
477
- const msgDiv = document.createElement('div');
478
- msgDiv.className = 'message bot-msg';
479
- msgDiv.innerText = text;
480
  wrapper.appendChild(msgDiv);
481
-
482
- // Auto-add from bot message
483
  autoAddFromBotMessage(text);
484
-
485
- // Check if this message contains a package or extra feature that can be confirmed
486
- let serviceName = null, servicePrice = null, serviceKey = null, timelineStr = null;
487
- // Try to extract from package patterns
488
- const pkgMatch = text.match(/\*\*([^*]+)\*\* – PKR ([\d,]+)/);
489
  if (pkgMatch) {
490
- serviceName = pkgMatch[1] + " Package";
491
- servicePrice = `PKR ${pkgMatch[2]}`;
492
- serviceKey = `pkg_${pkgMatch[1].toLowerCase().replace(/ /g, '_')}`;
493
- } else {
494
- // extra feature pattern
495
- const extraMatch = text.match(/✅ Added \*\*([^*]+)\*\*\./i);
496
- if (extraMatch) {
497
- const feature = extraMatch[1].toLowerCase();
498
- for (const [key, svc] of Object.entries(serviceMap)) {
499
- if (feature.includes(key) || key.includes(feature)) {
500
- serviceName = svc.name;
501
- servicePrice = svc.price;
502
- serviceKey = svc.key;
503
- break;
504
- }
505
- }
506
- }
507
- }
508
- if (serviceName && servicePrice) {
509
- const confirmBtn = document.createElement('button');
510
- confirmBtn.className = 'confirm-btn';
511
- confirmBtn.innerHTML = '<i class="fas fa-check-circle"></i> Confirm & Add to Quote';
512
- confirmBtn.onclick = () => {
513
- addInvoiceItem(serviceName, servicePrice, serviceKey);
514
- confirmBtn.disabled = true;
515
- confirmBtn.style.opacity = '0.6';
516
- confirmBtn.innerText = '✓ Added';
517
- };
518
- wrapper.appendChild(confirmBtn);
519
  }
520
- chatMessagesDiv.appendChild(wrapper);
521
- chatMessagesDiv.scrollTop = chatMessagesDiv.scrollHeight;
522
  }
523
 
524
- // ---------- Main UI ----------
525
- const chatIcon = document.getElementById('chatIcon');
526
- const chatModal = document.getElementById('chatModal');
527
- const closeChat = document.getElementById('closeChat');
528
- const sendBtn = document.getElementById('sendBtn');
529
- const userInput = document.getElementById('userInput');
530
- const chatMessagesDiv = document.getElementById('chatMessages');
531
- const questionsContainer = document.getElementById('defaultQuestionsContainer');
532
- const finalReportBtn = document.getElementById('finalReportBtn');
533
- const downloadReportBtn = document.getElementById('downloadReportBtn');
534
- finalReportBtn.addEventListener('click', generateFinalReport);
535
- downloadReportBtn.addEventListener('click', downloadReport);
536
 
537
- const invoiceColumn = document.getElementById('invoiceColumn');
538
- const chatColumn = document.getElementById('chatColumn');
539
  const toggleInvoiceBtn = document.getElementById('toggleInvoiceBtn');
540
  let invoiceHidden = false;
541
- toggleInvoiceBtn.addEventListener('click', () => {
542
  if (invoiceHidden) {
543
- invoiceColumn.classList.remove('hidden');
544
- chatColumn.classList.remove('expanded');
545
- toggleInvoiceBtn.innerHTML = '<i class="fas fa-eye-slash"></i>';
546
  } else {
547
- invoiceColumn.classList.add('hidden');
548
- chatColumn.classList.add('expanded');
549
- toggleInvoiceBtn.innerHTML = '<i class="fas fa-eye"></i>';
550
  }
551
  invoiceHidden = !invoiceHidden;
552
- });
 
 
553
 
554
  function renderQuestionBubbles() {
555
  questionsContainer.innerHTML = '';
556
  DEFAULT_QUESTIONS.forEach(q => {
557
- const bubble = document.createElement('div');
558
- bubble.className = 'question-bubble';
559
- bubble.innerText = q;
560
- bubble.onclick = () => { userInput.value = q; sendMessage(); };
561
- questionsContainer.appendChild(bubble);
562
  });
563
  }
564
-
565
  let typingDiv = null;
566
- function showTyping() {
567
- if (typingDiv) return;
568
- typingDiv = document.createElement('div');
569
- typingDiv.className = 'typing-indicator';
570
- typingDiv.innerHTML = '<span></span><span></span><span></span>';
571
- chatMessagesDiv.appendChild(typingDiv);
572
- chatMessagesDiv.scrollTop = chatMessagesDiv.scrollHeight;
573
- }
574
- function hideTyping() {
575
- if (typingDiv) { typingDiv.remove(); typingDiv = null; }
576
- }
577
 
578
  async function sendMessage() {
579
- const msg = userInput.value.trim();
580
  if (!msg) return;
581
  if (questionsContainer) questionsContainer.style.display = 'none';
582
- addMessageWithConfirm(msg, 'user');
583
  userInput.value = '';
584
- if (msg.toLowerCase().includes('final report') || msg.toLowerCase().includes('summary') || msg.toLowerCase().includes('total quote')) {
585
- generateFinalReport();
586
- return;
587
- }
588
  showTyping();
589
  try {
590
- const res = await fetch(API_URL, {
591
- method: 'POST',
592
- headers: { 'Content-Type': 'application/json' },
593
- body: JSON.stringify({ message: msg, session_id: sessionId })
594
- });
595
- const data = await res.json();
596
  hideTyping();
597
- addMessageWithConfirm(data.reply, 'bot', data.widget);
598
- } catch (err) {
599
- hideTyping();
600
- addMessageWithConfirm("❌ Server error. Please try again later.", 'bot');
601
- }
602
  }
603
 
604
- chatIcon.onclick = () => {
605
- chatModal.style.display = 'flex';
606
- if (questionsContainer.children.length === 0) renderQuestionBubbles();
607
- };
608
  closeChat.onclick = () => chatModal.style.display = 'none';
609
  sendBtn.onclick = sendMessage;
610
- userInput.addEventListener('keypress', (e) => { if (e.key === 'Enter') sendMessage(); });
611
  renderQuestionBubbles();
612
- updateWidget(null);
613
  </script>
614
  </body>
615
  </html>
 
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
6
+ <title>Elite Visuals AI – Smart Invoice</title>
 
7
  <link href="https://fonts.googleapis.com/css2?family=Inter:opsz,wght@14..32,300;400;500;600;700&display=swap" rel="stylesheet">
8
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
9
  <style>
10
  * { margin: 0; padding: 0; box-sizing: border-box; }
11
  body { background: linear-gradient(135deg, #f5f7fa 0%, #e9eef5 100%); font-family: 'Inter', sans-serif; height: 100vh; overflow: hidden; }
 
35
  .empty-invoice { color: #888; font-size: 0.75rem; text-align: center; padding: 20px; }
36
  .final-report-btn, .download-report-btn { background: #25D366; color: white; border: none; border-radius: 25px; padding: 8px 12px; font-size: 0.75rem; font-weight: 600; cursor: pointer; transition: 0.2s; width: 100%; margin-top: 8px; }
37
  .download-report-btn { background: #2a6d4c; margin-top: 4px; }
38
+ .final-report-btn:hover, .download-report-btn:hover { background: #128C7E; transform: scale(1.02); }
 
39
  .chat-messages { flex: 1; padding: 12px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
40
  .message { max-width: 85%; padding: 8px 12px; border-radius: 18px; font-size: 0.8rem; line-height: 1.4; white-space: pre-line; animation: fadeIn 0.2s; }
41
  @keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }
 
53
  .toggle-widget { cursor: pointer; margin-left: 8px; }
54
  .widget-content { padding: 10px; display: none; background: #fef9e6; font-size: 0.7rem; }
55
  .widget-content.show { display: block; }
 
 
56
  .quick-messages { display: flex; gap: 8px; overflow-x: auto; padding: 8px; background: #f0f2f5; border-top: 1px solid #ddd; }
57
  .quick-msg-chip { background: #e4e6eb; color: #1f2a3e; padding: 6px 12px; border-radius: 30px; font-size: 0.7rem; font-weight: 500; cursor: pointer; white-space: nowrap; transition: 0.2s; }
58
  .quick-msg-chip:hover { background: #d1d4db; transform: translateY(-1px); }
 
84
  <div class="chat-invoice-container" id="chatInvoiceContainer">
85
  <div class="chat-column" id="chatColumn">
86
  <div class="chat-messages" id="chatMessages">
87
+ <div class="message bot-msg">✨ Assalam-o-Alaikum! I can help with websites, e‑commerce, SEO, and more. To start a project, say: <strong>"I want to build a website"</strong></div>
88
  <div class="live-widget" id="liveWidget">
89
  <div class="widget-header">
90
  <span><i class="fas fa-chart-line"></i> 📊 Live Quote</span>
 
101
  </div>
102
  <div id="defaultQuestionsContainer" class="questions-container"></div>
103
  </div>
104
+ <div class="quick-messages">
105
  <div class="quick-msg-chip" data-msg="Show packages">📦 Show Packages</div>
106
  <div class="quick-msg-chip" data-msg="Contact number">📞 Contact</div>
107
  <div class="quick-msg-chip" data-msg="I want to build a website">🚀 Start Project</div>
 
118
  <span>🧾 Your Quote</span>
119
  <button id="addCustomServiceBtn" style="background: none; border: none; color: #075E54; font-size: 1.2rem; cursor: pointer;" title="Add custom service"><i class="fas fa-plus-circle"></i></button>
120
  </div>
121
+ <div class="invoice-items" id="invoiceItems"><div class="empty-invoice">✨ No services selected yet.<br>Ask or confirm a package to add.</div></div>
122
+ <div class="invoice-total"><span>Subtotal:</span><span id="totalAmount">PKR 0</span></div>
 
 
 
 
 
123
  <button class="final-report-btn" id="finalReportBtn"><i class="fas fa-file-alt"></i> Generate Final Report</button>
124
  <button class="download-report-btn" id="downloadReportBtn"><i class="fas fa-download"></i> Download Report</button>
125
  </div>
126
  </div>
127
  </div>
128
 
129
+ <!-- Modal for custom service -->
130
  <div id="customServiceModal" class="modal">
131
  <div class="modal-content">
132
  <h3>Add Custom Service</h3>
133
+ <input type="text" id="customServiceName" placeholder="Service name">
134
  <input type="text" id="customServicePrice" placeholder="Price (e.g., PKR 25,000)">
135
  <div class="flex-row">
136
  <button id="cancelCustomBtn" class="btn-warning" style="background:#ffc107; color:#333;">Cancel</button>
 
140
  </div>
141
 
142
  <script>
 
143
  let sessionId = localStorage.getItem('chat_session_id');
144
  if (!sessionId) {
145
  sessionId = 'user_' + Date.now() + '_' + Math.random().toString(36).substr(2, 8);
 
147
  }
148
  const API_URL = "/api/chat";
149
  const DEFAULT_QUESTIONS = [
150
+ "Basic website price and timeline?","Standard package details","Premium package details",
151
+ "Extra: live chat cost increase?","Add e-commerce to my quote","I want to build a website","Contact number"
 
 
 
 
 
152
  ];
153
 
 
154
  let invoiceItems = [];
155
  let nextId = 1;
156
  let storedProjectId = localStorage.getItem(`project_id_${sessionId}`) || null;
 
160
  if (match) return parseInt(match[0].replace(/,/g, ''));
161
  return 0;
162
  }
 
 
 
 
 
 
 
 
 
 
163
  function updateInvoiceDisplay() {
164
  const container = document.getElementById('invoiceItems');
165
  const totalSpan = document.getElementById('totalAmount');
 
168
  totalSpan.innerText = 'PKR 0';
169
  return;
170
  }
171
+ let html = '', total = 0;
 
172
  invoiceItems.forEach(item => {
173
+ total += parsePrice(item.price);
174
+ html += `<div class="invoice-item" data-id="${item.id}"><div class="invoice-item-name">${item.name}</div><div style="display:flex; gap:12px;"><span class="invoice-item-price">${item.price}</span><span class="remove-item" data-id="${item.id}"><i class="fas fa-times-circle"></i></span></div></div>`;
 
 
 
 
 
 
 
 
 
175
  });
176
  container.innerHTML = html;
177
  totalSpan.innerText = `PKR ${total.toLocaleString()}`;
178
+ document.querySelectorAll('.remove-item').forEach(el => el.addEventListener('click', (e) => removeInvoiceItem(parseInt(el.dataset.id))));
 
 
 
 
 
 
 
 
 
 
179
  }
180
+ function removeInvoiceItem(id) { invoiceItems = invoiceItems.filter(i => i.id !== id); updateInvoiceDisplay(); }
181
+ function addInvoiceItem(name, price, key = null, timelineDays = null) {
182
+ if (key && invoiceItems.some(i => i.serviceKey === key)) return false;
183
+ invoiceItems.push({ id: nextId++, name, price, serviceKey: key || name, timelineDays });
 
184
  updateInvoiceDisplay();
185
  return true;
186
  }
187
 
188
+ // Custom service modal
189
  const modal = document.getElementById('customServiceModal');
190
+ document.getElementById('addCustomServiceBtn').onclick = () => modal.style.display = 'flex';
191
+ document.getElementById('customInvoiceChip').onclick = () => modal.style.display = 'flex';
 
 
 
192
  document.getElementById('cancelCustomBtn').onclick = () => modal.style.display = 'none';
193
  document.getElementById('addCustomBtn').onclick = () => {
194
+ let name = document.getElementById('customServiceName').value.trim();
195
+ let price = document.getElementById('customServicePrice').value.trim();
196
+ if (!name || !price) { alert("Enter both fields"); return; }
 
 
 
197
  addInvoiceItem(name, price, `custom_${Date.now()}`);
198
  modal.style.display = 'none';
199
  document.getElementById('customServiceName').value = '';
200
  document.getElementById('customServicePrice').value = '';
201
  };
202
 
203
+ document.querySelectorAll('.quick-msg-chip[data-msg]').forEach(chip => chip.addEventListener('click', () => {
204
+ userInput.value = chip.getAttribute('data-msg');
205
+ sendMessage();
206
+ }));
 
 
 
207
 
 
208
  function extractAndStoreProjectId(text) {
209
+ let m = text.match(/Project ID:\s*`([A-Z0-9\-]+)`/i);
210
+ if (m) { storedProjectId = m[1]; localStorage.setItem(`project_id_${sessionId}`, storedProjectId); }
 
 
 
211
  }
 
 
212
  function generateFinalReport() {
213
+ if (!invoiceItems.length) { addMessage("❌ No services yet.", 'bot'); return; }
 
 
 
214
  let report = "📋 **Final Project Report**\n\n**Selected Services:**\n";
215
+ let totalPrice = 0, totalDays = 0;
 
216
  invoiceItems.forEach(item => {
217
+ totalPrice += parsePrice(item.price);
 
218
  report += `- ${item.name}: ${item.price}\n`;
219
+ if (item.timelineDays) { totalDays += item.timelineDays; report += ` (timeline: ${item.timelineDays} days)\n`; }
 
 
 
220
  });
221
+ report += `\n**💰 Total Cost:** PKR ${totalPrice.toLocaleString()}`;
222
+ if (totalDays) report += `\n**⏱️ Timeline:** ${totalDays} working days (cumulative)`;
223
+ if (storedProjectId) report += `\n\n📌 **Project ID:** \`${storedProjectId}\`\n🔍 Check status: \`status ${storedProjectId}\``;
224
+ report += `\n\n✅ Final quote – contact us to confirm.`;
225
+ addMessage(report, 'bot');
 
 
 
 
 
 
 
 
 
226
  }
 
 
227
  function downloadReport() {
228
+ if (!invoiceItems.length) { alert("No services selected."); return; }
229
+ let content = "ELITE VISUALS – QUOTE REPORT\n\nDate: "+new Date().toLocaleString()+"\nSession: "+sessionId+"\n\nServices:\n";
 
 
 
 
 
 
 
 
230
  let totalPrice = 0;
231
+ invoiceItems.forEach(item => { totalPrice += parsePrice(item.price); content += `• ${item.name}: ${item.price}\n`; });
232
+ content += `\nTOTAL: PKR ${totalPrice.toLocaleString()}`;
233
+ if (storedProjectId) content += `\n\nProject ID: ${storedProjectId}\nCheck status: status ${storedProjectId}`;
234
+ const blob = new Blob([content], {type:"text/plain"}), a = document.createElement('a');
235
+ a.href = URL.createObjectURL(blob); a.download = `quote_${Date.now()}.txt`; a.click(); URL.revokeObjectURL(a.href);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
236
  }
237
 
 
238
  const serviceMap = {
239
  "domain": { name: "Domain Registration", price: "PKR 5,000", key: "domain" },
240
  "e-commerce": { name: "E‑commerce Functionality", price: "PKR 50,000", key: "ecommerce" },
 
248
  "custom backend": { name: "Custom Backend", price: "PKR 100,000", key: "custom_backend" }
249
  };
250
  let currentPages = 5;
 
251
  function autoAddFromBotMessage(text) {
252
  extractAndStoreProjectId(text);
253
+ let lower = text.toLowerCase();
254
+ if (lower.includes("domain: yes")) addInvoiceItem("Domain Registration", "PKR 5,000", "domain");
255
+ let pagesMatch = lower.match(/pages:\s*(\d+)/);
 
 
 
 
256
  if (pagesMatch) {
257
+ let pages = parseInt(pagesMatch[1]);
258
  if (pages !== currentPages) {
259
  currentPages = pages;
260
+ invoiceItems = invoiceItems.filter(i => i.serviceKey !== "pages");
261
+ let extra = Math.max(0, pages-5);
262
+ if (extra) addInvoiceItem(`${extra} extra page(s)`, `PKR ${extra*5000}`, "pages");
 
 
 
263
  }
264
  }
265
+ if (lower.includes("e‑commerce: yes")) addInvoiceItem("E‑commerce Functionality", "PKR 50,000", "ecommerce");
266
+ if (lower.includes("chatbot: yes")) addInvoiceItem("AI Chatbot", "PKR 30,000", "chatbot");
267
+ if (lower.includes("seo: yes")) addInvoiceItem("SEO Optimization", "PKR 25,000", "seo");
268
+ if (lower.includes("inventory management: yes")) addInvoiceItem("Inventory Management", "PKR 30,000", "inventory");
269
+ if (lower.includes("database integration: yes")) addInvoiceItem("Database Integration", "PKR 40,000", "database");
270
+ let added = text.match(/✅ Added \*\*([^*]+)\*\*/i);
271
+ if (added) {
272
+ let feat = added[1].toLowerCase();
273
+ for (let [k, svc] of Object.entries(serviceMap)) if (feat.includes(k)) addInvoiceItem(svc.name, svc.price, svc.key);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
274
  }
275
  }
276
 
277
+ // Live widget (simplified – keep existing but no data from backend)
278
+ const widgetContent = document.getElementById('widgetContent'), toggleIcon = document.getElementById('toggleIcon');
279
+ const hideWidgetBtn = document.getElementById('hideWidgetBtn'), unhideWidgetBtn = document.getElementById('unhideWidgetBtn'), liveWidget = document.getElementById('liveWidget');
 
 
 
280
  let widgetOpen = false;
281
+ toggleIcon.onclick = (e) => { e.stopPropagation(); widgetOpen ? (widgetContent.classList.remove('show'), toggleIcon.classList.replace('fa-chevron-up','fa-chevron-down')) : (widgetContent.classList.add('show'), toggleIcon.classList.replace('fa-chevron-down','fa-chevron-up')); widgetOpen = !widgetOpen; };
282
+ hideWidgetBtn.onclick = () => { liveWidget.style.display = 'none'; hideWidgetBtn.style.display = 'none'; unhideWidgetBtn.style.display = 'inline-flex'; };
283
+ unhideWidgetBtn.onclick = () => { liveWidget.style.display = 'block'; hideWidgetBtn.style.display = 'inline-flex'; unhideWidgetBtn.style.display = 'none'; };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
284
 
285
+ function addMessage(text, sender, confirmData=null) {
286
+ let container = document.getElementById('chatMessages');
 
287
  if (sender === 'user') {
288
+ let div = document.createElement('div'); div.className = 'message user-msg'; div.innerText = text;
289
+ container.appendChild(div); container.scrollTop = container.scrollHeight;
 
 
 
290
  return;
291
  }
292
+ let wrapper = document.createElement('div'); wrapper.className = 'bot-message-wrapper';
293
+ let msgDiv = document.createElement('div'); msgDiv.className = 'message bot-msg'; msgDiv.innerText = text;
 
 
 
294
  wrapper.appendChild(msgDiv);
 
 
295
  autoAddFromBotMessage(text);
296
+ // also try to add a confirm button if a package or extra is mentioned
297
+ let pkgMatch = text.match(/\*\*([^*]+)\*\* – PKR ([\d,]+)/);
 
 
 
298
  if (pkgMatch) {
299
+ let btn = document.createElement('button'); btn.className = 'confirm-btn'; btn.innerHTML = '<i class="fas fa-check-circle"></i> Confirm & Add to Quote';
300
+ btn.onclick = () => { addInvoiceItem(pkgMatch[1]+" Package", `PKR ${pkgMatch[2]}`, `pkg_${pkgMatch[1]}`); btn.disabled = true; btn.innerText = '✓ Added'; };
301
+ wrapper.appendChild(btn);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
302
  }
303
+ container.appendChild(wrapper); container.scrollTop = container.scrollHeight;
 
304
  }
305
 
306
+ // UI listeners
307
+ const chatIcon = document.getElementById('chatIcon'), chatModal = document.getElementById('chatModal'), closeChat = document.getElementById('closeChat');
308
+ const sendBtn = document.getElementById('sendBtn'), userInput = document.getElementById('userInput'), chatMessagesDiv = document.getElementById('chatMessages');
309
+ const questionsContainer = document.getElementById('defaultQuestionsContainer'), finalReportBtn = document.getElementById('finalReportBtn'), downloadReportBtn = document.getElementById('downloadReportBtn');
310
+ finalReportBtn.onclick = generateFinalReport; downloadReportBtn.onclick = downloadReport;
 
 
 
 
 
 
 
311
 
312
+ const invoiceColumn = document.getElementById('invoiceColumn'), chatColumn = document.getElementById('chatColumn');
 
313
  const toggleInvoiceBtn = document.getElementById('toggleInvoiceBtn');
314
  let invoiceHidden = false;
315
+ toggleInvoiceBtn.onclick = () => {
316
  if (invoiceHidden) {
317
+ invoiceColumn.classList.remove('hidden'); chatColumn.classList.remove('expanded'); toggleInvoiceBtn.innerHTML = '<i class="fas fa-eye-slash"></i>';
 
 
318
  } else {
319
+ invoiceColumn.classList.add('hidden'); chatColumn.classList.add('expanded'); toggleInvoiceBtn.innerHTML = '<i class="fas fa-eye"></i>';
 
 
320
  }
321
  invoiceHidden = !invoiceHidden;
322
+ };
323
+ // Ensure invoice visible initially
324
+ invoiceColumn.classList.remove('hidden'); chatColumn.classList.remove('expanded'); toggleInvoiceBtn.innerHTML = '<i class="fas fa-eye-slash"></i>';
325
 
326
  function renderQuestionBubbles() {
327
  questionsContainer.innerHTML = '';
328
  DEFAULT_QUESTIONS.forEach(q => {
329
+ let b = document.createElement('div'); b.className = 'question-bubble'; b.innerText = q;
330
+ b.onclick = () => { userInput.value = q; sendMessage(); };
331
+ questionsContainer.appendChild(b);
 
 
332
  });
333
  }
 
334
  let typingDiv = null;
335
+ function showTyping() { if (typingDiv) return; typingDiv = document.createElement('div'); typingDiv.className = 'typing-indicator'; typingDiv.innerHTML = '<span></span><span></span><span></span>'; chatMessagesDiv.appendChild(typingDiv); chatMessagesDiv.scrollTop = chatMessagesDiv.scrollHeight; }
336
+ function hideTyping() { if (typingDiv) { typingDiv.remove(); typingDiv = null; } }
 
 
 
 
 
 
 
 
 
337
 
338
  async function sendMessage() {
339
+ let msg = userInput.value.trim();
340
  if (!msg) return;
341
  if (questionsContainer) questionsContainer.style.display = 'none';
342
+ addMessage(msg, 'user');
343
  userInput.value = '';
344
+ if (msg.toLowerCase().includes('final report')) { generateFinalReport(); return; }
 
 
 
345
  showTyping();
346
  try {
347
+ let res = await fetch(API_URL, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ message: msg, session_id: sessionId }) });
348
+ let data = await res.json();
 
 
 
 
349
  hideTyping();
350
+ addMessage(data.reply, 'bot');
351
+ } catch(e) { hideTyping(); addMessage("❌ Server error. Try again.", 'bot'); }
 
 
 
352
  }
353
 
354
+ chatIcon.onclick = () => { chatModal.style.display = 'flex'; if (questionsContainer.children.length === 0) renderQuestionBubbles(); };
 
 
 
355
  closeChat.onclick = () => chatModal.style.display = 'none';
356
  sendBtn.onclick = sendMessage;
357
+ userInput.addEventListener('keypress', e => { if (e.key === 'Enter') sendMessage(); });
358
  renderQuestionBubbles();
 
359
  </script>
360
  </body>
361
  </html>