Ahmad140 commited on
Commit
0507f71
·
verified ·
1 Parent(s): 8da0e8b

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +100 -90
index.html CHANGED
@@ -7,7 +7,6 @@
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
- /* (Keep your existing CSS exactly as before – unchanged) */
11
  * { margin: 0; padding: 0; box-sizing: border-box; }
12
  body { background: linear-gradient(135deg, #f5f7fa 0%, #e9eef5 100%); font-family: 'Inter', sans-serif; height: 100vh; overflow: hidden; }
13
  .chat-icon { position: fixed; bottom: 28px; right: 28px; width: 64px; height: 64px; background: linear-gradient(145deg, #25D366, #128C7E); border-radius: 50%; display: flex; align-items: center; justify-content: center; cursor: pointer; box-shadow: 0 10px 25px rgba(0,0,0,0.2); animation: pulse 1.8s infinite; z-index: 1000; }
@@ -57,6 +56,9 @@
57
  .widget-content.show { display: block; }
58
  .info-row { margin: 4px 0; }
59
  .info-label { font-weight: 700; color: #075E54; }
 
 
 
60
  .questions-container { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px; }
61
  .question-bubble { background: #e4e6eb; padding: 4px 10px; border-radius: 16px; font-size: 0.7rem; cursor: pointer; transition: 0.2s; }
62
  .question-bubble:hover { background: #d1d4db; transform: translateY(-1px); }
@@ -66,6 +68,10 @@
66
  .chat-input-area { display: flex; padding: 10px; background: white; border-top: 1px solid #ddd; gap: 8px; }
67
  .chat-input-area input { flex: 1; padding: 8px 12px; border: 1px solid #ccc; border-radius: 30px; outline: none; font-size: 0.8rem; }
68
  .chat-input-area button { background: #25D366; border: none; width: 36px; height: 36px; border-radius: 50%; color: white; cursor: pointer; }
 
 
 
 
69
  </style>
70
  </head>
71
  <body>
@@ -81,7 +87,7 @@
81
  <div class="chat-invoice-container" id="chatInvoiceContainer">
82
  <div class="chat-column" id="chatColumn">
83
  <div class="chat-messages" id="chatMessages">
84
- <div class="message bot-msg">✨ Assalam-o-Alaikum! I can help you with website packages, extra features, and **step-by-step project building**. To start a new project, simply say: **"I want to build a website"** – I'll ask you all the requirements and then generate a proposal, project ID, and total invoice. You can also ask about packages or use the confirm buttons below.</div>
85
  <div class="live-widget" id="liveWidget">
86
  <div class="widget-header">
87
  <span><i class="fas fa-chart-line"></i> 📊 Live Quote</span>
@@ -98,14 +104,22 @@
98
  </div>
99
  <div id="defaultQuestionsContainer" class="questions-container"></div>
100
  </div>
 
 
 
 
 
 
 
101
  <div class="chat-input-area">
102
- <input type="text" id="userInput" placeholder="Ask about price, timeline, confirm Basic, add SEO, or say 'I want to build a website'...">
103
  <button id="sendBtn"><i class="fas fa-paper-plane"></i></button>
104
  </div>
105
  </div>
106
  <div class="invoice-column" id="invoiceColumn">
107
  <div class="invoice-title">
108
  <span>🧾 Your Quote</span>
 
109
  </div>
110
  <div class="invoice-items" id="invoiceItems">
111
  <div class="empty-invoice">✨ No services selected yet.<br>Ask or confirm a package to add.</div>
@@ -120,6 +134,19 @@
120
  </div>
121
  </div>
122
 
 
 
 
 
 
 
 
 
 
 
 
 
 
123
  <script>
124
  // ---------- Session ----------
125
  let sessionId = localStorage.getItem('chat_session_id');
@@ -138,12 +165,10 @@
138
  "Contact number"
139
  ];
140
 
141
- // ---------- Store Project ID from bot confirmation ----------
142
- let storedProjectId = localStorage.getItem(`project_id_${sessionId}`) || null;
143
-
144
  // ---------- Invoice State ----------
145
  let invoiceItems = [];
146
  let nextId = 1;
 
147
 
148
  function parsePrice(priceStr) {
149
  let match = priceStr.match(/(\d[\d,]+)/);
@@ -206,14 +231,41 @@
206
  return true;
207
  }
208
 
209
- // ---------- Extract and store Project ID from bot message ----------
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
210
  function extractAndStoreProjectId(text) {
211
  const match = text.match(/Project ID:\s*`([A-Z0-9\-]+)`/i);
212
  if (match) {
213
- const pid = match[1];
214
- storedProjectId = pid;
215
- localStorage.setItem(`project_id_${sessionId}`, pid);
216
- console.log("Project ID stored:", pid);
217
  }
218
  }
219
 
@@ -280,8 +332,6 @@
280
  if (storedProjectId) {
281
  content += `\n📌 PROJECT ID: ${storedProjectId}\n`;
282
  content += `🔍 To check status, type in chat: status ${storedProjectId}\n`;
283
- } else {
284
- content += `\n✅ After final confirmation, you will receive a Project ID to track your request.\n`;
285
  }
286
  content += "\nThis is an estimate. Final quote may vary.\n";
287
  content += "Contact: hello@elitevisuals.com | +92 300 1234567\n";
@@ -296,7 +346,7 @@
296
  URL.revokeObjectURL(url);
297
  }
298
 
299
- // ---------- Auto-add services from bot messages ----------
300
  const serviceMap = {
301
  "domain": { name: "Domain Registration", price: "PKR 5,000", key: "domain" },
302
  "e-commerce": { name: "E‑commerce Functionality", price: "PKR 50,000", key: "ecommerce" },
@@ -312,15 +362,13 @@
312
  let currentPages = 5;
313
 
314
  function autoAddFromBotMessage(text) {
315
- // Also check for project ID
316
  extractAndStoreProjectId(text);
317
-
318
  const lower = text.toLowerCase();
319
  // Domain
320
  if (lower.includes("domain: yes") || (lower.includes("need a domain") && lower.includes("yes"))) {
321
  addInvoiceItem("Domain Registration", "PKR 5,000", "domain");
322
  }
323
- // Pages (detect after user enters number)
324
  const pagesMatch = lower.match(/pages:\s*(\d+)/);
325
  if (pagesMatch) {
326
  const pages = parseInt(pagesMatch[1]);
@@ -346,15 +394,15 @@
346
  if (lower.includes("seo: yes") || (lower.includes("seo optimization") && lower.includes("yes"))) {
347
  addInvoiceItem("SEO Optimization", "PKR 25,000", "seo");
348
  }
349
- // Inventory management
350
  if (lower.includes("inventory management: yes") || (lower.includes("inventory management") && lower.includes("yes"))) {
351
  addInvoiceItem("Inventory Management", "PKR 30,000", "inventory");
352
  }
353
- // Database integration
354
  if (lower.includes("database integration: yes") || (lower.includes("database integration") && lower.includes("yes"))) {
355
  addInvoiceItem("Database Integration", "PKR 40,000", "database");
356
  }
357
- // Extra features from "✅ Added **something**" pattern
358
  const addedMatch = text.match(/✅ Added \*\*([^*]+)\*\*/i);
359
  if (addedMatch) {
360
  const feature = addedMatch[1].toLowerCase();
@@ -365,6 +413,7 @@
365
  }
366
  }
367
  }
 
368
  const genericAdded = text.match(/✅ Added (.+?)\./i);
369
  if (genericAdded && !addedMatch) {
370
  const feature = genericAdded[1].toLowerCase();
@@ -377,7 +426,7 @@
377
  }
378
  }
379
 
380
- // ---------- Live Widget (unchanged) ----------
381
  const widgetContent = document.getElementById('widgetContent');
382
  const toggleIcon = document.getElementById('toggleIcon');
383
  const hideWidgetBtn = document.getElementById('hideWidgetBtn');
@@ -408,41 +457,11 @@
408
  unhideWidgetBtn.style.display = 'none';
409
  });
410
  function updateWidget(data) {
411
- const widgetEmptyMsg = document.getElementById('widgetEmptyMsg');
412
- const widgetDetailsDiv = document.getElementById('widgetDetails');
413
- if (!data || Object.keys(data).length === 0) {
414
- widgetEmptyMsg.style.display = 'block';
415
- widgetDetailsDiv.style.display = 'none';
416
- return;
417
- }
418
- let html = '';
419
- if (data.package) {
420
- html += `<div class="info-row"><span class="info-label">📦 Package:</span> ${data.package}</div>`;
421
- if (data.price) html += `<div class="info-row"><span class="info-label">💰 Price:</span> ${data.price}</div>`;
422
- if (data.timeline) html += `<div class="info-row"><span class="info-label">⏱️ Timeline:</span> ${data.timeline}</div>`;
423
- if (data.features && data.features.length) {
424
- html += `<div class="info-row"><span class="info-label">✅ Includes:</span><ul>${data.features.map(f => `<li>${f}</li>`).join('')}</ul></div>`;
425
- }
426
- window._lastWidgetTimeline = data.timeline;
427
- } else if (data.extra_feature) {
428
- html += `<div class="info-row"><span class="info-label">✨ Extra:</span> ${data.extra_feature}</div>`;
429
- if (data.extra_cost) html += `<div class="info-row"><span class="info-label">💰 Additional Cost:</span> ${data.extra_cost}</div>`;
430
- if (data.extra_timeline) html += `<div class="info-row"><span class="info-label">⏱️ Timeline Increase:</span> ${data.extra_timeline}</div>`;
431
- window._lastWidgetTimeline = data.extra_timeline;
432
- } else if (data.service) {
433
- html += `<div class="info-row"><span class="info-label">🛠️ Service:</span> ${data.service}</div>`;
434
- if (data.price) html += `<div class="info-row"><span class="info-label">💰 Price:</span> ${data.price}</div>`;
435
- if (data.timeline) html += `<div class="info-row"><span class="info-label">⏱️ Timeline:</span> ${data.timeline}</div>`;
436
- window._lastWidgetTimeline = data.timeline;
437
- } else {
438
- html = `<div class="info-row">ℹ️ Ask about a package or feature.</div>`;
439
- }
440
- widgetDetailsDiv.innerHTML = html;
441
- widgetEmptyMsg.style.display = 'none';
442
- widgetDetailsDiv.style.display = 'block';
443
  }
444
 
445
- // ---------- Message with Confirm Button ----------
446
  function addMessageWithConfirm(text, sender, widgetData = null) {
447
  const chatMessagesDiv = document.getElementById('chatMessages');
448
  if (sender === 'user') {
@@ -460,26 +479,30 @@
460
  msgDiv.innerText = text;
461
  wrapper.appendChild(msgDiv);
462
 
463
- // Auto-add services from bot message (and capture project ID)
464
  autoAddFromBotMessage(text);
465
 
 
466
  let serviceName = null, servicePrice = null, serviceKey = null, timelineStr = null;
467
- if (widgetData) {
468
- if (widgetData.package) {
469
- serviceName = `${widgetData.package} Website Package`;
470
- servicePrice = widgetData.price;
471
- serviceKey = `pkg_${widgetData.package}`;
472
- timelineStr = widgetData.timeline;
473
- } else if (widgetData.service) {
474
- serviceName = widgetData.service;
475
- servicePrice = widgetData.price;
476
- serviceKey = `svc_${widgetData.service}`;
477
- timelineStr = widgetData.timeline;
478
- } else if (widgetData.extra_feature) {
479
- serviceName = `Extra: ${widgetData.extra_feature}`;
480
- servicePrice = widgetData.extra_cost;
481
- serviceKey = `extra_${widgetData.extra_feature}`;
482
- timelineStr = widgetData.extra_timeline;
 
 
 
483
  }
484
  }
485
  if (serviceName && servicePrice) {
@@ -487,8 +510,7 @@
487
  confirmBtn.className = 'confirm-btn';
488
  confirmBtn.innerHTML = '<i class="fas fa-check-circle"></i> Confirm & Add to Quote';
489
  confirmBtn.onclick = () => {
490
- const timelineDays = timelineStr ? parseTimelineDays(timelineStr) : null;
491
- addInvoiceItem(serviceName, servicePrice, serviceKey, timelineDays);
492
  confirmBtn.disabled = true;
493
  confirmBtn.style.opacity = '0.6';
494
  confirmBtn.innerText = '✓ Added';
@@ -499,7 +521,7 @@
499
  chatMessagesDiv.scrollTop = chatMessagesDiv.scrollHeight;
500
  }
501
 
502
- // ---------- UI Event Listeners ----------
503
  const chatIcon = document.getElementById('chatIcon');
504
  const chatModal = document.getElementById('chatModal');
505
  const closeChat = document.getElementById('closeChat');
@@ -509,8 +531,8 @@
509
  const questionsContainer = document.getElementById('defaultQuestionsContainer');
510
  const finalReportBtn = document.getElementById('finalReportBtn');
511
  const downloadReportBtn = document.getElementById('downloadReportBtn');
512
- finalReportBtn.addEventListener('click', () => generateFinalReport());
513
- downloadReportBtn.addEventListener('click', () => downloadReport());
514
 
515
  const invoiceColumn = document.getElementById('invoiceColumn');
516
  const chatColumn = document.getElementById('chatColumn');
@@ -559,12 +581,10 @@
559
  if (questionsContainer) questionsContainer.style.display = 'none';
560
  addMessageWithConfirm(msg, 'user');
561
  userInput.value = '';
562
-
563
  if (msg.toLowerCase().includes('final report') || msg.toLowerCase().includes('summary') || msg.toLowerCase().includes('total quote')) {
564
  generateFinalReport();
565
  return;
566
  }
567
-
568
  showTyping();
569
  try {
570
  const res = await fetch(API_URL, {
@@ -574,20 +594,10 @@
574
  });
575
  const data = await res.json();
576
  hideTyping();
577
- const widgetData = data.widget || null;
578
- addMessageWithConfirm(data.reply, 'bot', widgetData);
579
- if (widgetData) {
580
- updateWidget(widgetData);
581
- if (!widgetOpen) {
582
- widgetContent.classList.add('show');
583
- toggleIcon.classList.remove('fa-chevron-down');
584
- toggleIcon.classList.add('fa-chevron-up');
585
- widgetOpen = true;
586
- }
587
- }
588
  } catch (err) {
589
  hideTyping();
590
- addMessageWithConfirm("❌ Server error. Try again.", 'bot');
591
  }
592
  }
593
 
 
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; }
12
  .chat-icon { position: fixed; bottom: 28px; right: 28px; width: 64px; height: 64px; background: linear-gradient(145deg, #25D366, #128C7E); border-radius: 50%; display: flex; align-items: center; justify-content: center; cursor: pointer; box-shadow: 0 10px 25px rgba(0,0,0,0.2); animation: pulse 1.8s infinite; z-index: 1000; }
 
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); }
62
  .questions-container { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px; }
63
  .question-bubble { background: #e4e6eb; padding: 4px 10px; border-radius: 16px; font-size: 0.7rem; cursor: pointer; transition: 0.2s; }
64
  .question-bubble:hover { background: #d1d4db; transform: translateY(-1px); }
 
68
  .chat-input-area { display: flex; padding: 10px; background: white; border-top: 1px solid #ddd; gap: 8px; }
69
  .chat-input-area input { flex: 1; padding: 8px 12px; border: 1px solid #ccc; border-radius: 30px; outline: none; font-size: 0.8rem; }
70
  .chat-input-area button { background: #25D366; border: none; width: 36px; height: 36px; border-radius: 50%; color: white; cursor: pointer; }
71
+ .modal { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.7); justify-content: center; align-items: center; z-index: 2000; }
72
+ .modal-content { background: #1e1e28; border-radius: 20px; padding: 20px; width: 350px; color: white; }
73
+ .modal-content input { width: 100%; margin: 10px 0; padding: 8px; border-radius: 8px; border: none; }
74
+ .flex-row { display: flex; gap: 10px; justify-content: flex-end; margin-top: 15px; }
75
  </style>
76
  </head>
77
  <body>
 
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
  </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>
111
+ <div class="quick-msg-chip" id="customInvoiceChip">➕ Add Custom Service</div>
112
+ <div class="quick-msg-chip" data-msg="Help">❓ Help</div>
113
+ </div>
114
  <div class="chat-input-area">
115
+ <input type="text" id="userInput" placeholder="Ask me anything or start a project...">
116
  <button id="sendBtn"><i class="fas fa-paper-plane"></i></button>
117
  </div>
118
  </div>
119
  <div class="invoice-column" id="invoiceColumn">
120
  <div class="invoice-title">
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>
 
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>
145
+ <button id="addCustomBtn" class="btn" style="background:#25D366;">Add to Invoice</button>
146
+ </div>
147
+ </div>
148
+ </div>
149
+
150
  <script>
151
  // ---------- Session ----------
152
  let sessionId = localStorage.getItem('chat_session_id');
 
165
  "Contact number"
166
  ];
167
 
 
 
 
168
  // ---------- Invoice State ----------
169
  let invoiceItems = [];
170
  let nextId = 1;
171
+ let storedProjectId = localStorage.getItem(`project_id_${sessionId}`) || null;
172
 
173
  function parsePrice(priceStr) {
174
  let match = priceStr.match(/(\d[\d,]+)/);
 
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
 
 
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";
 
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" },
 
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]);
 
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();
 
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();
 
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');
 
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') {
 
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) {
 
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';
 
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');
 
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');
 
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, {
 
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