Ahmad140 commited on
Commit
e086619
·
verified ·
1 Parent(s): cb11d1c

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +141 -88
index.html CHANGED
@@ -3,7 +3,7 @@
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 Quote & Invoice</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>
@@ -16,19 +16,25 @@
16
  .chat-icon:hover { transform: scale(1.08); background: #20b859; }
17
  .chat-icon i { font-size: 32px; color: white; }
18
 
19
- /* Chat Modal – wider to accommodate invoice */
20
- .chat-modal { position: fixed; bottom: 100px; right: 28px; width: 480px; height: 650px; background: rgba(255,255,255,0.98); border-radius: 28px; box-shadow: 0 25px 50px -12px rgba(0,0,0,0.35); display: none; flex-direction: column; overflow: hidden; z-index: 1001; animation: slideUpFade 0.3s ease-out; }
21
  @keyframes slideUpFade { from { opacity: 0; transform: translateY(30px); } to { opacity: 1; transform: translateY(0); } }
22
  .chat-header { background: linear-gradient(135deg, #075E54, #0b3b32); color: white; padding: 14px 20px; display: flex; justify-content: space-between; align-items: center; }
23
  .close-btn { background: rgba(255,255,255,0.2); border: none; width: 32px; height: 32px; border-radius: 50%; cursor: pointer; color: white; transition: 0.2s; }
24
  .close-btn:hover { transform: rotate(90deg); background: rgba(255,255,255,0.4); }
25
 
26
- /* Two-column layout: Chat + Invoice */
27
- .chat-invoice-container { display: flex; flex: 1; overflow: hidden; }
28
- .chat-column { flex: 1.5; display: flex; flex-direction: column; background: #f0f2f5; }
29
- .invoice-column { flex: 1; background: #fff8f0; border-left: 1px solid #ddd; display: flex; flex-direction: column; overflow-y: auto; padding: 12px; gap: 12px; }
30
- .invoice-title { font-weight: 700; font-size: 1rem; color: #075E54; border-bottom: 2px solid #25D366; padding-bottom: 6px; margin-bottom: 8px; display: flex; justify-content: space-between; }
31
- .invoice-items { flex: 1; overflow-y: auto; max-height: 300px; }
 
 
 
 
 
 
32
  .invoice-item { background: white; border-radius: 12px; padding: 8px 12px; margin-bottom: 8px; display: flex; justify-content: space-between; align-items: center; box-shadow: 0 1px 3px rgba(0,0,0,0.05); }
33
  .invoice-item-name { font-weight: 500; font-size: 0.8rem; }
34
  .invoice-item-price { font-size: 0.8rem; color: #2d6a4f; font-weight: 600; }
@@ -37,15 +43,26 @@
37
  .invoice-total { border-top: 2px dashed #ccc; padding-top: 10px; margin-top: 8px; font-weight: 700; font-size: 0.9rem; display: flex; justify-content: space-between; }
38
  .empty-invoice { color: #888; font-size: 0.75rem; text-align: center; padding: 20px; }
39
 
40
- .chat-messages { flex: 1; padding: 12px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
 
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); } }
43
  .user-msg { background: #DCF8C6; margin-left: auto; border-bottom-right-radius: 4px; }
44
  .bot-msg { background: white; margin-right: auto; border-bottom-left-radius: 4px; box-shadow: 0 1px 2px rgba(0,0,0,0.05); }
45
 
46
- /* Live Widget */
 
 
 
 
 
 
47
  .live-widget { background: white; border-radius: 16px; margin: 8px 8px 0 8px; overflow: hidden; box-shadow: 0 2px 6px rgba(0,0,0,0.05); }
48
- .widget-header { background: linear-gradient(135deg, #1e2a3a, #0f172a); color: white; padding: 8px 12px; display: flex; justify-content: space-between; cursor: pointer; font-size: 0.75rem; font-weight: 600; }
 
 
 
 
49
  .widget-content { padding: 10px; display: none; background: #fef9e6; font-size: 0.7rem; }
50
  .widget-content.show { display: block; }
51
  .info-row { margin: 4px 0; }
@@ -61,8 +78,6 @@
61
  .chat-input-area { display: flex; padding: 10px; background: white; border-top: 1px solid #ddd; gap: 8px; }
62
  .chat-input-area input { flex: 1; padding: 8px 12px; border: 1px solid #ccc; border-radius: 30px; outline: none; font-size: 0.8rem; }
63
  .chat-input-area button { background: #25D366; border: none; width: 36px; height: 36px; border-radius: 50%; color: white; cursor: pointer; }
64
-
65
- .scrollable { overflow-y: auto; }
66
  </style>
67
  </head>
68
  <body>
@@ -72,15 +87,20 @@
72
  <h3><i class="fas fa-robot"></i> Elite Visuals AI</h3>
73
  <button class="close-btn" id="closeChat"><i class="fas fa-times"></i></button>
74
  </div>
75
- <div class="chat-invoice-container">
76
  <!-- Chat Column -->
77
- <div class="chat-column">
78
  <div class="chat-messages" id="chatMessages">
79
- <div class="message bot-msg">✨ Assalam-o-Alaikum! Ask me about website packages, e‑commerce, SEO, or extra features. Your selected services will appear in the invoice panel on the right. You can remove any item with ❌.</div>
80
- <div id="liveWidget" class="live-widget">
81
- <div class="widget-header" id="widgetHeader">
 
82
  <span><i class="fas fa-chart-line"></i> 📊 Live Quote</span>
83
- <i class="fas fa-chevron-down" id="toggleIcon"></i>
 
 
 
 
84
  </div>
85
  <div class="widget-content" id="widgetContent">
86
  <p id="widgetEmptyMsg">💡 Ask about a package/feature to see details.</p>
@@ -94,11 +114,11 @@
94
  <button id="sendBtn"><i class="fas fa-paper-plane"></i></button>
95
  </div>
96
  </div>
97
- <!-- Invoice Column -->
98
- <div class="invoice-column">
99
  <div class="invoice-title">
100
  <span>🧾 Your Quote</span>
101
- <span><i class="fas fa-receipt"></i></span>
102
  </div>
103
  <div class="invoice-items" id="invoiceItems">
104
  <div class="empty-invoice">✨ No services selected yet.<br>Ask or confirm a package to add.</div>
@@ -122,18 +142,17 @@
122
  const DEFAULT_QUESTIONS = [
123
  "Basic website price and timeline?",
124
  "Standard package details",
125
- "Premium website confirm",
126
  "Extra: live chat cost increase?",
127
  "Add e-commerce to my quote",
128
  "Contact number"
129
  ];
130
 
131
  // ---------- Invoice State ----------
132
- let invoiceItems = []; // each item: { id, name, price, serviceKey }
133
  let nextId = 1;
134
 
135
  function parsePrice(priceStr) {
136
- // priceStr like "PKR 50,000" or "PKR 1,20,000" or "Starting PKR 1,50,000"
137
  let match = priceStr.match(/(\d[\d,]+)/);
138
  if (match) return parseInt(match[0].replace(/,/g, ''));
139
  return 0;
@@ -164,7 +183,6 @@
164
  });
165
  container.innerHTML = html;
166
  totalSpan.innerText = `PKR ${total.toLocaleString()}`;
167
- // attach remove event listeners
168
  document.querySelectorAll('.remove-item').forEach(el => {
169
  el.addEventListener('click', (e) => {
170
  const id = parseInt(el.dataset.id);
@@ -179,65 +197,67 @@
179
  }
180
 
181
  function addInvoiceItem(serviceName, priceStr, serviceKey = null) {
182
- // avoid duplicate service key if exists
183
- if (serviceKey && invoiceItems.some(item => item.serviceKey === serviceKey)) {
184
- // do not add duplicate
185
- return false;
186
- }
187
- const newItem = {
188
- id: nextId++,
189
- name: serviceName,
190
- price: priceStr,
191
- serviceKey: serviceKey || serviceName
192
- };
193
  invoiceItems.push(newItem);
194
  updateInvoiceDisplay();
195
  return true;
196
  }
197
 
198
- // Function to auto-add when user confirms or asks for package
199
- function handleAutoAddFromWidget(data) {
200
- if (data && data.package && data.price && data.timeline) {
201
- // Package details
202
- const serviceKey = `pkg_${data.package}`;
203
- if (!invoiceItems.some(i => i.serviceKey === serviceKey)) {
204
- addInvoiceItem(`${data.package} (Website Package)`, data.price, serviceKey);
205
- }
206
- } else if (data && data.service && data.price) {
207
- const serviceKey = `svc_${data.service}`;
208
- if (!invoiceItems.some(i => i.serviceKey === serviceKey)) {
209
- addInvoiceItem(data.service, data.price, serviceKey);
210
- }
211
- } else if (data && data.extra_feature && data.extra_cost) {
212
- const serviceKey = `extra_${data.extra_feature}`;
213
- if (!invoiceItems.some(i => i.serviceKey === serviceKey)) {
214
- addInvoiceItem(`Extra: ${data.extra_feature}`, data.extra_cost, serviceKey);
215
- }
216
  }
217
- }
 
218
 
219
- // ---------- Live Widget Update ----------
220
- const widgetHeader = document.getElementById('widgetHeader');
221
- const widgetContentDiv = document.getElementById('widgetContent');
222
  const toggleIcon = document.getElementById('toggleIcon');
223
- const widgetEmptyMsg = document.getElementById('widgetEmptyMsg');
224
- const widgetDetailsDiv = document.getElementById('widgetDetails');
 
225
  let widgetOpen = false;
226
 
227
- widgetHeader.addEventListener('click', () => {
 
228
  if (widgetOpen) {
229
- widgetContentDiv.classList.remove('show');
230
  toggleIcon.classList.remove('fa-chevron-up');
231
  toggleIcon.classList.add('fa-chevron-down');
232
  } else {
233
- widgetContentDiv.classList.add('show');
234
  toggleIcon.classList.remove('fa-chevron-down');
235
  toggleIcon.classList.add('fa-chevron-up');
236
  }
237
  widgetOpen = !widgetOpen;
238
  });
239
 
 
 
 
 
 
 
 
 
 
 
 
240
  function updateWidget(data) {
 
 
241
  if (!data || Object.keys(data).length === 0) {
242
  widgetEmptyMsg.style.display = 'block';
243
  widgetDetailsDiv.style.display = 'none';
@@ -267,6 +287,55 @@
267
  widgetDetailsDiv.style.display = 'block';
268
  }
269
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
270
  // ---------- Chat UI ----------
271
  const chatIcon = document.getElementById('chatIcon');
272
  const chatModal = document.getElementById('chatModal');
@@ -287,14 +356,6 @@
287
  });
288
  }
289
 
290
- function addMessage(text, sender) {
291
- const div = document.createElement('div');
292
- div.className = `message ${sender === 'user' ? 'user-msg' : 'bot-msg'}`;
293
- div.innerText = text;
294
- chatMessages.appendChild(div);
295
- chatMessages.scrollTop = chatMessages.scrollHeight;
296
- }
297
-
298
  let typingDiv = null;
299
  function showTyping() {
300
  if (typingDiv) return;
@@ -312,7 +373,7 @@
312
  const msg = userInput.value.trim();
313
  if (!msg) return;
314
  if (questionsContainer) questionsContainer.style.display = 'none';
315
- addMessage(msg, 'user');
316
  userInput.value = '';
317
  showTyping();
318
  try {
@@ -323,18 +384,12 @@
323
  });
324
  const data = await res.json();
325
  hideTyping();
326
- addMessage(data.reply, 'bot');
327
- if (data.widget) {
328
- updateWidget(data.widget);
329
- // Auto-add to invoice if user confirmed or requested a package/service
330
- const lowerMsg = msg.toLowerCase();
331
- const isConfirmation = /confirm|add|include|want|i need|book|select|add this|yes/i.test(lowerMsg);
332
- if (isConfirmation || data.widget.package || data.widget.service || data.widget.extra_feature) {
333
- handleAutoAddFromWidget(data.widget);
334
- }
335
- // Expand widget
336
  if (!widgetOpen) {
337
- widgetContentDiv.classList.add('show');
338
  toggleIcon.classList.remove('fa-chevron-down');
339
  toggleIcon.classList.add('fa-chevron-up');
340
  widgetOpen = true;
@@ -342,7 +397,7 @@
342
  }
343
  } catch (err) {
344
  hideTyping();
345
- addMessage("❌ Server error. Try again.", 'bot');
346
  }
347
  }
348
 
@@ -354,8 +409,6 @@
354
  sendBtn.onclick = sendMessage;
355
  userInput.addEventListener('keypress', (e) => { if (e.key === 'Enter') sendMessage(); });
356
  renderQuestionBubbles();
357
-
358
- // Initial widget empty
359
  updateWidget(null);
360
  </script>
361
  </body>
 
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 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>
 
16
  .chat-icon:hover { transform: scale(1.08); background: #20b859; }
17
  .chat-icon i { font-size: 32px; color: white; }
18
 
19
+ /* Chat Modal */
20
+ .chat-modal { position: fixed; bottom: 100px; right: 28px; width: 540px; height: 650px; background: rgba(255,255,255,0.98); border-radius: 28px; box-shadow: 0 25px 50px -12px rgba(0,0,0,0.35); display: none; flex-direction: column; overflow: hidden; z-index: 1001; animation: slideUpFade 0.3s ease-out; }
21
  @keyframes slideUpFade { from { opacity: 0; transform: translateY(30px); } to { opacity: 1; transform: translateY(0); } }
22
  .chat-header { background: linear-gradient(135deg, #075E54, #0b3b32); color: white; padding: 14px 20px; display: flex; justify-content: space-between; align-items: center; }
23
  .close-btn { background: rgba(255,255,255,0.2); border: none; width: 32px; height: 32px; border-radius: 50%; cursor: pointer; color: white; transition: 0.2s; }
24
  .close-btn:hover { transform: rotate(90deg); background: rgba(255,255,255,0.4); }
25
 
26
+ /* Two-column layout */
27
+ .chat-invoice-container { display: flex; flex: 1; overflow: hidden; transition: all 0.3s ease; }
28
+ .chat-column { flex: 1.5; display: flex; flex-direction: column; background: #f0f2f5; transition: all 0.3s ease; }
29
+ .invoice-column { width: 40%; background: #fff8f0; border-left: 1px solid #ddd; display: flex; flex-direction: column; overflow-y: auto; padding: 12px; gap: 12px; transition: all 0.3s ease; }
30
+ .invoice-column.hidden { display: none; width: 0; padding: 0; }
31
+ .chat-column.expanded { flex: 1; }
32
+
33
+ .invoice-title { font-weight: 700; font-size: 1rem; color: #075E54; border-bottom: 2px solid #25D366; padding-bottom: 6px; margin-bottom: 8px; display: flex; justify-content: space-between; align-items: center; }
34
+ .invoice-title button { background: none; border: none; color: #075E54; cursor: pointer; font-size: 1rem; transition: 0.2s; }
35
+ .invoice-title button:hover { transform: scale(1.1); color: #25D366; }
36
+
37
+ .invoice-items { flex: 1; overflow-y: auto; max-height: 350px; }
38
  .invoice-item { background: white; border-radius: 12px; padding: 8px 12px; margin-bottom: 8px; display: flex; justify-content: space-between; align-items: center; box-shadow: 0 1px 3px rgba(0,0,0,0.05); }
39
  .invoice-item-name { font-weight: 500; font-size: 0.8rem; }
40
  .invoice-item-price { font-size: 0.8rem; color: #2d6a4f; font-weight: 600; }
 
43
  .invoice-total { border-top: 2px dashed #ccc; padding-top: 10px; margin-top: 8px; font-weight: 700; font-size: 0.9rem; display: flex; justify-content: space-between; }
44
  .empty-invoice { color: #888; font-size: 0.75rem; text-align: center; padding: 20px; }
45
 
46
+ /* Chat messages */
47
+ .chat-messages { flex: 1; padding: 12px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
48
  .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; }
49
  @keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }
50
  .user-msg { background: #DCF8C6; margin-left: auto; border-bottom-right-radius: 4px; }
51
  .bot-msg { background: white; margin-right: auto; border-bottom-left-radius: 4px; box-shadow: 0 1px 2px rgba(0,0,0,0.05); }
52
 
53
+ /* Bot message with confirm button */
54
+ .bot-message-wrapper { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; max-width: 85%; margin-right: auto; }
55
+ .bot-message-wrapper .message { margin: 0; max-width: 100%; }
56
+ .confirm-btn { background: #25D366; color: white; border: none; border-radius: 20px; padding: 4px 12px; font-size: 0.7rem; cursor: pointer; transition: 0.2s; display: inline-flex; align-items: center; gap: 4px; }
57
+ .confirm-btn:hover { background: #128C7E; transform: scale(1.02); }
58
+
59
+ /* Live Widget with hide/unhide button */
60
  .live-widget { background: white; border-radius: 16px; margin: 8px 8px 0 8px; overflow: hidden; box-shadow: 0 2px 6px rgba(0,0,0,0.05); }
61
+ .widget-header { background: linear-gradient(135deg, #1e2a3a, #0f172a); color: white; padding: 8px 12px; display: flex; justify-content: space-between; align-items: center; font-size: 0.75rem; font-weight: 600; }
62
+ .widget-controls { display: flex; gap: 10px; }
63
+ .widget-controls button { background: rgba(255,255,255,0.2); border: none; color: white; border-radius: 20px; padding: 2px 8px; font-size: 0.7rem; cursor: pointer; transition: 0.2s; }
64
+ .widget-controls button:hover { background: rgba(255,255,255,0.4); }
65
+ .toggle-widget { cursor: pointer; margin-left: 8px; }
66
  .widget-content { padding: 10px; display: none; background: #fef9e6; font-size: 0.7rem; }
67
  .widget-content.show { display: block; }
68
  .info-row { margin: 4px 0; }
 
78
  .chat-input-area { display: flex; padding: 10px; background: white; border-top: 1px solid #ddd; gap: 8px; }
79
  .chat-input-area input { flex: 1; padding: 8px 12px; border: 1px solid #ccc; border-radius: 30px; outline: none; font-size: 0.8rem; }
80
  .chat-input-area button { background: #25D366; border: none; width: 36px; height: 36px; border-radius: 50%; color: white; cursor: pointer; }
 
 
81
  </style>
82
  </head>
83
  <body>
 
87
  <h3><i class="fas fa-robot"></i> Elite Visuals AI</h3>
88
  <button class="close-btn" id="closeChat"><i class="fas fa-times"></i></button>
89
  </div>
90
+ <div class="chat-invoice-container" id="chatInvoiceContainer">
91
  <!-- Chat Column -->
92
+ <div class="chat-column" id="chatColumn">
93
  <div class="chat-messages" id="chatMessages">
94
+ <div class="message bot-msg">✨ Assalam-o-Alaikum! Ask me about website packages, e‑commerce, SEO, or extra features. .</div>
95
+ <!-- Live Widget -->
96
+ <div class="live-widget" id="liveWidget">
97
+ <div class="widget-header">
98
  <span><i class="fas fa-chart-line"></i> 📊 Live Quote</span>
99
+ <div class="widget-controls">
100
+ <button id="hideWidgetBtn"><i class="fas fa-eye-slash"></i> Hide</button>
101
+ <button id="unhideWidgetBtn" style="display: none;"><i class="fas fa-eye"></i> Show</button>
102
+ <i class="fas fa-chevron-down toggle-widget" id="toggleIcon"></i>
103
+ </div>
104
  </div>
105
  <div class="widget-content" id="widgetContent">
106
  <p id="widgetEmptyMsg">💡 Ask about a package/feature to see details.</p>
 
114
  <button id="sendBtn"><i class="fas fa-paper-plane"></i></button>
115
  </div>
116
  </div>
117
+ <!-- Invoice Column (with hide/unhide button) -->
118
+ <div class="invoice-column" id="invoiceColumn">
119
  <div class="invoice-title">
120
  <span>🧾 Your Quote</span>
121
+ <button id="toggleInvoiceBtn" title="Hide/Show Invoice"><i class="fas fa-eye-slash"></i></button>
122
  </div>
123
  <div class="invoice-items" id="invoiceItems">
124
  <div class="empty-invoice">✨ No services selected yet.<br>Ask or confirm a package to add.</div>
 
142
  const DEFAULT_QUESTIONS = [
143
  "Basic website price and timeline?",
144
  "Standard package details",
145
+ "Premium package details",
146
  "Extra: live chat cost increase?",
147
  "Add e-commerce to my quote",
148
  "Contact number"
149
  ];
150
 
151
  // ---------- Invoice State ----------
152
+ let invoiceItems = [];
153
  let nextId = 1;
154
 
155
  function parsePrice(priceStr) {
 
156
  let match = priceStr.match(/(\d[\d,]+)/);
157
  if (match) return parseInt(match[0].replace(/,/g, ''));
158
  return 0;
 
183
  });
184
  container.innerHTML = html;
185
  totalSpan.innerText = `PKR ${total.toLocaleString()}`;
 
186
  document.querySelectorAll('.remove-item').forEach(el => {
187
  el.addEventListener('click', (e) => {
188
  const id = parseInt(el.dataset.id);
 
197
  }
198
 
199
  function addInvoiceItem(serviceName, priceStr, serviceKey = null) {
200
+ if (serviceKey && invoiceItems.some(item => item.serviceKey === serviceKey)) return false;
201
+ const newItem = { id: nextId++, name: serviceName, price: priceStr, serviceKey: serviceKey || serviceName };
 
 
 
 
 
 
 
 
 
202
  invoiceItems.push(newItem);
203
  updateInvoiceDisplay();
204
  return true;
205
  }
206
 
207
+ // ---------- Invoice Hide/Unhide Toggle ----------
208
+ const invoiceColumn = document.getElementById('invoiceColumn');
209
+ const chatColumn = document.getElementById('chatColumn');
210
+ const toggleInvoiceBtn = document.getElementById('toggleInvoiceBtn');
211
+ let invoiceHidden = false;
212
+ toggleInvoiceBtn.addEventListener('click', () => {
213
+ if (invoiceHidden) {
214
+ invoiceColumn.classList.remove('hidden');
215
+ chatColumn.classList.remove('expanded');
216
+ toggleInvoiceBtn.innerHTML = '<i class="fas fa-eye-slash"></i>';
217
+ } else {
218
+ invoiceColumn.classList.add('hidden');
219
+ chatColumn.classList.add('expanded');
220
+ toggleInvoiceBtn.innerHTML = '<i class="fas fa-eye"></i>';
 
 
 
 
221
  }
222
+ invoiceHidden = !invoiceHidden;
223
+ });
224
 
225
+ // ---------- Live Widget (Collapsible + Hide/Unhide) ----------
226
+ const widgetContent = document.getElementById('widgetContent');
 
227
  const toggleIcon = document.getElementById('toggleIcon');
228
+ const hideWidgetBtn = document.getElementById('hideWidgetBtn');
229
+ const unhideWidgetBtn = document.getElementById('unhideWidgetBtn');
230
+ const liveWidget = document.getElementById('liveWidget');
231
  let widgetOpen = false;
232
 
233
+ toggleIcon.addEventListener('click', (e) => {
234
+ e.stopPropagation();
235
  if (widgetOpen) {
236
+ widgetContent.classList.remove('show');
237
  toggleIcon.classList.remove('fa-chevron-up');
238
  toggleIcon.classList.add('fa-chevron-down');
239
  } else {
240
+ widgetContent.classList.add('show');
241
  toggleIcon.classList.remove('fa-chevron-down');
242
  toggleIcon.classList.add('fa-chevron-up');
243
  }
244
  widgetOpen = !widgetOpen;
245
  });
246
 
247
+ hideWidgetBtn.addEventListener('click', () => {
248
+ liveWidget.style.display = 'none';
249
+ hideWidgetBtn.style.display = 'none';
250
+ unhideWidgetBtn.style.display = 'inline-flex';
251
+ });
252
+ unhideWidgetBtn.addEventListener('click', () => {
253
+ liveWidget.style.display = 'block';
254
+ hideWidgetBtn.style.display = 'inline-flex';
255
+ unhideWidgetBtn.style.display = 'none';
256
+ });
257
+
258
  function updateWidget(data) {
259
+ const widgetEmptyMsg = document.getElementById('widgetEmptyMsg');
260
+ const widgetDetailsDiv = document.getElementById('widgetDetails');
261
  if (!data || Object.keys(data).length === 0) {
262
  widgetEmptyMsg.style.display = 'block';
263
  widgetDetailsDiv.style.display = 'none';
 
287
  widgetDetailsDiv.style.display = 'block';
288
  }
289
 
290
+ // ---------- Message with Confirm Button ----------
291
+ function addMessageWithConfirm(text, sender, widgetData = null) {
292
+ if (sender === 'user') {
293
+ const div = document.createElement('div');
294
+ div.className = 'message user-msg';
295
+ div.innerText = text;
296
+ chatMessages.appendChild(div);
297
+ chatMessages.scrollTop = chatMessages.scrollHeight;
298
+ return;
299
+ }
300
+ const wrapper = document.createElement('div');
301
+ wrapper.className = 'bot-message-wrapper';
302
+ const msgDiv = document.createElement('div');
303
+ msgDiv.className = 'message bot-msg';
304
+ msgDiv.innerText = text;
305
+ wrapper.appendChild(msgDiv);
306
+
307
+ let serviceName = null, servicePrice = null, serviceKey = null;
308
+ if (widgetData) {
309
+ if (widgetData.package) {
310
+ serviceName = `${widgetData.package} Website Package`;
311
+ servicePrice = widgetData.price;
312
+ serviceKey = `pkg_${widgetData.package}`;
313
+ } else if (widgetData.service) {
314
+ serviceName = widgetData.service;
315
+ servicePrice = widgetData.price;
316
+ serviceKey = `svc_${widgetData.service}`;
317
+ } else if (widgetData.extra_feature) {
318
+ serviceName = `Extra: ${widgetData.extra_feature}`;
319
+ servicePrice = widgetData.extra_cost;
320
+ serviceKey = `extra_${widgetData.extra_feature}`;
321
+ }
322
+ }
323
+ if (serviceName && servicePrice) {
324
+ const confirmBtn = document.createElement('button');
325
+ confirmBtn.className = 'confirm-btn';
326
+ confirmBtn.innerHTML = '<i class="fas fa-check-circle"></i> Confirm & Add to Quote';
327
+ confirmBtn.onclick = () => {
328
+ addInvoiceItem(serviceName, servicePrice, serviceKey);
329
+ confirmBtn.disabled = true;
330
+ confirmBtn.style.opacity = '0.6';
331
+ confirmBtn.innerText = '✓ Added';
332
+ };
333
+ wrapper.appendChild(confirmBtn);
334
+ }
335
+ chatMessages.appendChild(wrapper);
336
+ chatMessages.scrollTop = chatMessages.scrollHeight;
337
+ }
338
+
339
  // ---------- Chat UI ----------
340
  const chatIcon = document.getElementById('chatIcon');
341
  const chatModal = document.getElementById('chatModal');
 
356
  });
357
  }
358
 
 
 
 
 
 
 
 
 
359
  let typingDiv = null;
360
  function showTyping() {
361
  if (typingDiv) return;
 
373
  const msg = userInput.value.trim();
374
  if (!msg) return;
375
  if (questionsContainer) questionsContainer.style.display = 'none';
376
+ addMessageWithConfirm(msg, 'user');
377
  userInput.value = '';
378
  showTyping();
379
  try {
 
384
  });
385
  const data = await res.json();
386
  hideTyping();
387
+ const widgetData = data.widget || null;
388
+ addMessageWithConfirm(data.reply, 'bot', widgetData);
389
+ if (widgetData) {
390
+ updateWidget(widgetData);
 
 
 
 
 
 
391
  if (!widgetOpen) {
392
+ widgetContent.classList.add('show');
393
  toggleIcon.classList.remove('fa-chevron-down');
394
  toggleIcon.classList.add('fa-chevron-up');
395
  widgetOpen = true;
 
397
  }
398
  } catch (err) {
399
  hideTyping();
400
+ addMessageWithConfirm("❌ Server error. Try again.", 'bot');
401
  }
402
  }
403
 
 
409
  sendBtn.onclick = sendMessage;
410
  userInput.addEventListener('keypress', (e) => { if (e.key === 'Enter') sendMessage(); });
411
  renderQuestionBubbles();
 
 
412
  updateWidget(null);
413
  </script>
414
  </body>