Ahmad140 commited on
Commit
32a5464
·
verified ·
1 Parent(s): cb07eec

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +377 -38
index.html CHANGED
@@ -7,8 +7,64 @@
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 all existing CSS – same as before – I'm omitting for brevity, but keep your current styles) */
11
- /* Ensure the media upload panel is styled */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  .media-panel { background: #f0f2f5; border-radius: 16px; padding: 12px; margin: 10px 0; display: none; }
13
  .media-panel textarea { width: 100%; padding: 8px; border-radius: 12px; border: 1px solid #ccc; }
14
  .media-panel input[type="file"] { margin: 8px 0; }
@@ -16,8 +72,56 @@
16
  </style>
17
  </head>
18
  <body>
19
- <!-- Your existing HTML structure (chat icon, modal, invoice column) – keep exactly the same -->
20
- <!-- Only the <script> section changes; I provide the full script below. -->
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
  <script>
23
  // ---------- Session ----------
@@ -37,10 +141,7 @@
37
  "Contact number"
38
  ];
39
 
40
- // ---------- Store Project ID from bot confirmation ----------
41
  let storedProjectId = localStorage.getItem(`project_id_${sessionId}`) || null;
42
-
43
- // ---------- Invoice State ----------
44
  let invoiceItems = [];
45
  let nextId = 1;
46
 
@@ -105,46 +206,35 @@
105
  return true;
106
  }
107
 
108
- // ---------- Auto-add services from bot messages (including YES/NO answers) ----------
109
  function autoAddFromBotMessage(text) {
110
- // Extract Project ID
111
  const match = text.match(/Project ID:\s*`([A-Z0-9\-]+)`/i);
112
  if (match) {
113
  storedProjectId = match[1];
114
  localStorage.setItem(`project_id_${sessionId}`, storedProjectId);
115
  }
116
-
117
  const lower = text.toLowerCase();
118
- // Domain
119
  if (lower.includes("domain: yes") || (lower.includes("need a domain") && lower.includes("yes"))) {
120
  addInvoiceItem("Domain Registration", "PKR 5,000", "domain");
121
  }
122
- // Pages (detect "Pages: X")
123
  const pagesMatch = lower.match(/pages:\s*(\d+)/);
124
  if (pagesMatch) {
125
  const pages = parseInt(pagesMatch[1]);
126
- // Base pages are 5; extra pages cost
127
- if (pages !== 5) {
128
- const extraPages = Math.max(0, pages - 5);
129
- if (extraPages > 0) {
130
- const extraCost = extraPages * 5000;
131
- addInvoiceItem(`${extraPages} extra page(s)`, `PKR ${extraCost.toLocaleString()}`, "pages");
132
- }
133
  }
134
  }
135
- // E-commerce
136
  if (lower.includes("e‑commerce: yes") || (lower.includes("need e‑commerce") && lower.includes("yes"))) {
137
  addInvoiceItem("E‑commerce Functionality", "PKR 50,000", "ecommerce");
138
  }
139
- // Chatbot
140
  if (lower.includes("chatbot: yes") || (lower.includes("ai chatbot") && lower.includes("yes"))) {
141
  addInvoiceItem("AI Chatbot", "PKR 30,000", "chatbot");
142
  }
143
- // SEO
144
  if (lower.includes("seo: yes") || (lower.includes("seo optimization") && lower.includes("yes"))) {
145
  addInvoiceItem("SEO Optimization", "PKR 25,000", "seo");
146
  }
147
- // Extra features from "✅ Added **something**"
148
  const addedMatch = text.match(/✅ Added \*\*([^*]+)\*\*/i);
149
  if (addedMatch) {
150
  const feature = addedMatch[1].toLowerCase();
@@ -169,12 +259,8 @@
169
  }
170
  }
171
 
172
- // ---------- Media Upload Handling ----------
173
  let mediaPanel = null;
174
- let mediaTextarea = null;
175
- let mediaFileInput = null;
176
- let mediaImagePreview = null;
177
-
178
  function createMediaPanel() {
179
  if (mediaPanel) return;
180
  const chatArea = document.getElementById('chatMessages');
@@ -190,9 +276,9 @@
190
  `;
191
  chatArea.appendChild(panel);
192
  mediaPanel = panel;
193
- mediaTextarea = document.getElementById('mediaText');
194
- mediaFileInput = document.getElementById('mediaImage');
195
- mediaImagePreview = document.getElementById('mediaPreview');
196
  const submitBtn = document.getElementById('mediaSubmitBtn');
197
  mediaFileInput.onchange = () => {
198
  const file = mediaFileInput.files[0];
@@ -226,7 +312,6 @@
226
  });
227
  const data = await res.json();
228
  if (data.status === 'ok') {
229
- // Send "DONE" to move to next step
230
  userInput.value = "DONE";
231
  sendMessage();
232
  mediaPanel.style.display = 'none';
@@ -244,14 +329,268 @@
244
  mediaPanel.style.display = 'block';
245
  }
246
 
247
- // ---------- Other chat functions (addMessage, sendMessage, etc.) ----------
248
- // We'll reuse the existing functions from your current index.html, but modify the addMessageWithConfirm to handle MEDIA_REQUEST
249
- // For brevity, I'll include the minimal changes – but you should replace your entire <script> with the one below.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
250
 
251
- // I'll provide the complete script below; it includes all previous functions plus media handling and auto-add.
252
- // (Due to length, I'll continue directly.)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
253
 
254
- // For the sake of completion, I will provide the full script block as a single piece.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
255
  </script>
256
  </body>
257
  </html>
 
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; }
13
+ @keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(37,211,102,0.5); } 70% { box-shadow: 0 0 0 15px rgba(37,211,102,0); } 100% { box-shadow: 0 0 0 0 rgba(37,211,102,0); } }
14
+ .chat-icon:hover { transform: scale(1.08); background: #20b859; }
15
+ .chat-icon i { font-size: 32px; color: white; }
16
+ .chat-modal { position: fixed; bottom: 100px; right: 28px; width: 580px; height: 680px; 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; }
17
+ @keyframes slideUpFade { from { opacity: 0; transform: translateY(30px); } to { opacity: 1; transform: translateY(0); } }
18
+ .chat-header { background: linear-gradient(135deg, #075E54, #0b3b32); color: white; padding: 12px 18px; display: flex; justify-content: space-between; align-items: center; }
19
+ .header-buttons { display: flex; gap: 10px; align-items: center; }
20
+ .header-btn { background: rgba(255,255,255,0.2); border: none; width: 32px; height: 32px; border-radius: 50%; cursor: pointer; color: white; transition: 0.2s; display: inline-flex; align-items: center; justify-content: center; }
21
+ .header-btn:hover { transform: scale(1.05); background: rgba(255,255,255,0.4); }
22
+ .chat-invoice-container { display: flex; flex: 1; overflow: hidden; transition: all 0.3s ease; }
23
+ .chat-column { flex: 1.5; display: flex; flex-direction: column; background: #f0f2f5; transition: all 0.3s ease; }
24
+ .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; }
25
+ .invoice-column.hidden { display: none; width: 0; padding: 0; }
26
+ .chat-column.expanded { flex: 1; }
27
+ .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; }
28
+ .invoice-items { flex: 1; overflow-y: auto; max-height: 280px; }
29
+ .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); }
30
+ .invoice-item-name { font-weight: 500; font-size: 0.8rem; }
31
+ .invoice-item-price { font-size: 0.8rem; color: #2d6a4f; font-weight: 600; }
32
+ .remove-item { color: #e63946; cursor: pointer; font-size: 14px; transition: 0.2s; }
33
+ .remove-item:hover { transform: scale(1.1); }
34
+ .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; }
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); } }
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
+ .bot-message-wrapper { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; max-width: 85%; margin-right: auto; }
46
+ .bot-message-wrapper .message { margin: 0; max-width: 100%; }
47
+ .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; }
48
+ .confirm-btn:hover { background: #128C7E; transform: scale(1.02); }
49
+ .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); }
50
+ .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; }
51
+ .widget-controls { display: flex; gap: 10px; }
52
+ .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; }
53
+ .widget-controls button:hover { background: rgba(255,255,255,0.4); }
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
+ .questions-container { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px; }
60
+ .question-bubble { background: #e4e6eb; padding: 4px 10px; border-radius: 16px; font-size: 0.7rem; cursor: pointer; transition: 0.2s; }
61
+ .question-bubble:hover { background: #d1d4db; transform: translateY(-1px); }
62
+ .typing-indicator { background: white; padding: 6px 12px; border-radius: 20px; display: inline-flex; gap: 4px; width: fit-content; }
63
+ .typing-indicator span { width: 6px; height: 6px; background: #888; border-radius: 50%; animation: wave 1.2s infinite; }
64
+ @keyframes wave { 0%,60%,100% { transform: translateY(0); } 30% { transform: translateY(-4px); } }
65
+ .chat-input-area { display: flex; padding: 10px; background: white; border-top: 1px solid #ddd; gap: 8px; }
66
+ .chat-input-area input { flex: 1; padding: 8px 12px; border: 1px solid #ccc; border-radius: 30px; outline: none; font-size: 0.8rem; }
67
+ .chat-input-area button { background: #25D366; border: none; width: 36px; height: 36px; border-radius: 50%; color: white; cursor: pointer; }
68
  .media-panel { background: #f0f2f5; border-radius: 16px; padding: 12px; margin: 10px 0; display: none; }
69
  .media-panel textarea { width: 100%; padding: 8px; border-radius: 12px; border: 1px solid #ccc; }
70
  .media-panel input[type="file"] { margin: 8px 0; }
 
72
  </style>
73
  </head>
74
  <body>
75
+ <div class="chat-icon" id="chatIcon"><i class="fas fa-comment-dots"></i></div>
76
+ <div class="chat-modal" id="chatModal">
77
+ <div class="chat-header">
78
+ <h3><i class="fas fa-robot"></i> Elite Visuals AI</h3>
79
+ <div class="header-buttons">
80
+ <button class="header-btn" id="toggleInvoiceBtn" title="Toggle Invoice Panel"><i class="fas fa-eye-slash"></i></button>
81
+ <button class="header-btn" id="closeChat"><i class="fas fa-times"></i></button>
82
+ </div>
83
+ </div>
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 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>
88
+ <div class="live-widget" id="liveWidget">
89
+ <div class="widget-header">
90
+ <span><i class="fas fa-chart-line"></i> 📊 Live Quote</span>
91
+ <div class="widget-controls">
92
+ <button id="hideWidgetBtn"><i class="fas fa-eye-slash"></i> Hide</button>
93
+ <button id="unhideWidgetBtn" style="display: none;"><i class="fas fa-eye"></i> Show</button>
94
+ <i class="fas fa-chevron-down toggle-widget" id="toggleIcon"></i>
95
+ </div>
96
+ </div>
97
+ <div class="widget-content" id="widgetContent">
98
+ <p id="widgetEmptyMsg">💡 Ask about a package/feature to see details.</p>
99
+ <div id="widgetDetails" style="display: none;"></div>
100
+ </div>
101
+ </div>
102
+ <div id="defaultQuestionsContainer" class="questions-container"></div>
103
+ </div>
104
+ <div class="chat-input-area">
105
+ <input type="text" id="userInput" placeholder="Ask about price, timeline, confirm Basic, add SEO, or say 'I want to build a website'...">
106
+ <button id="sendBtn"><i class="fas fa-paper-plane"></i></button>
107
+ </div>
108
+ </div>
109
+ <div class="invoice-column" id="invoiceColumn">
110
+ <div class="invoice-title">
111
+ <span>🧾 Your Quote</span>
112
+ </div>
113
+ <div class="invoice-items" id="invoiceItems">
114
+ <div class="empty-invoice">✨ No services selected yet.<br>Ask or confirm a package to add.</div>
115
+ </div>
116
+ <div class="invoice-total" id="invoiceTotal">
117
+ <span>Subtotal:</span>
118
+ <span id="totalAmount">PKR 0</span>
119
+ </div>
120
+ <button class="final-report-btn" id="finalReportBtn"><i class="fas fa-file-alt"></i> Generate Final Report</button>
121
+ <button class="download-report-btn" id="downloadReportBtn"><i class="fas fa-download"></i> Download Report</button>
122
+ </div>
123
+ </div>
124
+ </div>
125
 
126
  <script>
127
  // ---------- Session ----------
 
141
  "Contact number"
142
  ];
143
 
 
144
  let storedProjectId = localStorage.getItem(`project_id_${sessionId}`) || null;
 
 
145
  let invoiceItems = [];
146
  let nextId = 1;
147
 
 
206
  return true;
207
  }
208
 
209
+ // Auto-add from bot messages (YES/NO, pages, extra features)
210
  function autoAddFromBotMessage(text) {
 
211
  const match = text.match(/Project ID:\s*`([A-Z0-9\-]+)`/i);
212
  if (match) {
213
  storedProjectId = match[1];
214
  localStorage.setItem(`project_id_${sessionId}`, storedProjectId);
215
  }
 
216
  const lower = text.toLowerCase();
 
217
  if (lower.includes("domain: yes") || (lower.includes("need a domain") && lower.includes("yes"))) {
218
  addInvoiceItem("Domain Registration", "PKR 5,000", "domain");
219
  }
 
220
  const pagesMatch = lower.match(/pages:\s*(\d+)/);
221
  if (pagesMatch) {
222
  const pages = parseInt(pagesMatch[1]);
223
+ const extraPages = Math.max(0, pages - 5);
224
+ if (extraPages > 0) {
225
+ const extraCost = extraPages * 5000;
226
+ addInvoiceItem(`${extraPages} extra page(s)`, `PKR ${extraCost.toLocaleString()}`, "pages");
 
 
 
227
  }
228
  }
 
229
  if (lower.includes("e‑commerce: yes") || (lower.includes("need e‑commerce") && lower.includes("yes"))) {
230
  addInvoiceItem("E‑commerce Functionality", "PKR 50,000", "ecommerce");
231
  }
 
232
  if (lower.includes("chatbot: yes") || (lower.includes("ai chatbot") && lower.includes("yes"))) {
233
  addInvoiceItem("AI Chatbot", "PKR 30,000", "chatbot");
234
  }
 
235
  if (lower.includes("seo: yes") || (lower.includes("seo optimization") && lower.includes("yes"))) {
236
  addInvoiceItem("SEO Optimization", "PKR 25,000", "seo");
237
  }
 
238
  const addedMatch = text.match(/✅ Added \*\*([^*]+)\*\*/i);
239
  if (addedMatch) {
240
  const feature = addedMatch[1].toLowerCase();
 
259
  }
260
  }
261
 
262
+ // ---------- Media Upload ----------
263
  let mediaPanel = null;
 
 
 
 
264
  function createMediaPanel() {
265
  if (mediaPanel) return;
266
  const chatArea = document.getElementById('chatMessages');
 
276
  `;
277
  chatArea.appendChild(panel);
278
  mediaPanel = panel;
279
+ const mediaTextarea = document.getElementById('mediaText');
280
+ const mediaFileInput = document.getElementById('mediaImage');
281
+ const mediaImagePreview = document.getElementById('mediaPreview');
282
  const submitBtn = document.getElementById('mediaSubmitBtn');
283
  mediaFileInput.onchange = () => {
284
  const file = mediaFileInput.files[0];
 
312
  });
313
  const data = await res.json();
314
  if (data.status === 'ok') {
 
315
  userInput.value = "DONE";
316
  sendMessage();
317
  mediaPanel.style.display = 'none';
 
329
  mediaPanel.style.display = 'block';
330
  }
331
 
332
+ // ---------- Message Functions ----------
333
+ function addMessageWithConfirm(text, sender, widgetData = null) {
334
+ const chatMessagesDiv = document.getElementById('chatMessages');
335
+ if (sender === 'user') {
336
+ const div = document.createElement('div');
337
+ div.className = 'message user-msg';
338
+ div.innerText = text;
339
+ chatMessagesDiv.appendChild(div);
340
+ chatMessagesDiv.scrollTop = chatMessagesDiv.scrollHeight;
341
+ return;
342
+ }
343
+ const wrapper = document.createElement('div');
344
+ wrapper.className = 'bot-message-wrapper';
345
+ const msgDiv = document.createElement('div');
346
+ msgDiv.className = 'message bot-msg';
347
+ msgDiv.innerText = text;
348
+ wrapper.appendChild(msgDiv);
349
+
350
+ // Check for media request
351
+ if (text.startsWith("MEDIA_REQUEST|")) {
352
+ const cleanMsg = text.replace("MEDIA_REQUEST|", "");
353
+ msgDiv.innerText = cleanMsg;
354
+ showMediaPanel();
355
+ } else {
356
+ autoAddFromBotMessage(text);
357
+ }
358
+
359
+ let serviceName = null, servicePrice = null, serviceKey = null, timelineStr = null;
360
+ if (widgetData) {
361
+ if (widgetData.package) {
362
+ serviceName = `${widgetData.package} Website Package`;
363
+ servicePrice = widgetData.price;
364
+ serviceKey = `pkg_${widgetData.package}`;
365
+ timelineStr = widgetData.timeline;
366
+ } else if (widgetData.service) {
367
+ serviceName = widgetData.service;
368
+ servicePrice = widgetData.price;
369
+ serviceKey = `svc_${widgetData.service}`;
370
+ timelineStr = widgetData.timeline;
371
+ } else if (widgetData.extra_feature) {
372
+ serviceName = `Extra: ${widgetData.extra_feature}`;
373
+ servicePrice = widgetData.extra_cost;
374
+ serviceKey = `extra_${widgetData.extra_feature}`;
375
+ timelineStr = widgetData.extra_timeline;
376
+ }
377
+ }
378
+ if (serviceName && servicePrice) {
379
+ const confirmBtn = document.createElement('button');
380
+ confirmBtn.className = 'confirm-btn';
381
+ confirmBtn.innerHTML = '<i class="fas fa-check-circle"></i> Confirm & Add to Quote';
382
+ confirmBtn.onclick = () => {
383
+ const timelineDays = timelineStr ? parseTimelineDays(timelineStr) : null;
384
+ addInvoiceItem(serviceName, servicePrice, serviceKey, timelineDays);
385
+ confirmBtn.disabled = true;
386
+ confirmBtn.style.opacity = '0.6';
387
+ confirmBtn.innerText = '✓ Added';
388
+ };
389
+ wrapper.appendChild(confirmBtn);
390
+ }
391
+ chatMessagesDiv.appendChild(wrapper);
392
+ chatMessagesDiv.scrollTop = chatMessagesDiv.scrollHeight;
393
+ }
394
+
395
+ function addMessage(text, sender) {
396
+ const div = document.createElement('div');
397
+ div.className = `message ${sender === 'user' ? 'user-msg' : 'bot-msg'}`;
398
+ div.innerText = text;
399
+ document.getElementById('chatMessages').appendChild(div);
400
+ chatMessagesDiv.scrollTop = chatMessagesDiv.scrollHeight;
401
+ }
402
+
403
+ // ---------- History Loading ----------
404
+ let historyLoaded = false;
405
+ async function loadChatHistory() {
406
+ try {
407
+ const res = await fetch(`/api/history?session_id=${sessionId}`);
408
+ const data = await res.json();
409
+ if (data.messages && data.messages.length) {
410
+ const chatMessagesDiv = document.getElementById('chatMessages');
411
+ const children = Array.from(chatMessagesDiv.children);
412
+ let welcomeIndex = -1;
413
+ for (let i = 0; i < children.length; i++) {
414
+ const child = children[i];
415
+ if (child.classList && child.classList.contains('message') &&
416
+ child.classList.contains('bot-msg') &&
417
+ child.innerText.includes("Assalam-o-Alaikum")) {
418
+ welcomeIndex = i;
419
+ break;
420
+ }
421
+ }
422
+ for (let i = children.length - 1; i >= 0; i--) {
423
+ if (i !== welcomeIndex) {
424
+ children[i].remove();
425
+ }
426
+ }
427
+ for (let msg of data.messages) {
428
+ if (msg.role === 'user') {
429
+ addMessage(msg.content, 'user');
430
+ } else if (msg.role === 'assistant') {
431
+ addMessage(msg.content, 'bot');
432
+ }
433
+ }
434
+ }
435
+ } catch (err) {
436
+ console.error("History load error", err);
437
+ }
438
+ }
439
+
440
+ // ---------- UI Event Listeners ----------
441
+ const chatIcon = document.getElementById('chatIcon');
442
+ const chatModal = document.getElementById('chatModal');
443
+ const closeChat = document.getElementById('closeChat');
444
+ const sendBtn = document.getElementById('sendBtn');
445
+ const userInput = document.getElementById('userInput');
446
+ const chatMessagesDiv = document.getElementById('chatMessages');
447
+ const questionsContainer = document.getElementById('defaultQuestionsContainer');
448
+ const finalReportBtn = document.getElementById('finalReportBtn');
449
+ const downloadReportBtn = document.getElementById('downloadReportBtn');
450
+ finalReportBtn.onclick = () => {
451
+ if (invoiceItems.length === 0) {
452
+ addMessageWithConfirm("❌ No services added yet.", 'bot');
453
+ return;
454
+ }
455
+ let report = "📋 **Final Project Report**\n\n**Selected Services:**\n";
456
+ let totalPrice = 0, totalDays = 0;
457
+ invoiceItems.forEach(item => {
458
+ totalPrice += parsePrice(item.price);
459
+ report += `- ${item.name}: ${item.price}\n`;
460
+ if (item.timelineDays) totalDays += item.timelineDays;
461
+ });
462
+ report += `\n💰 Total: PKR ${totalPrice.toLocaleString()}`;
463
+ if (totalDays) report += `\n⏱️ Timeline: ${totalDays} days`;
464
+ if (storedProjectId) report += `\n\n📌 Project ID: ${storedProjectId}`;
465
+ addMessageWithConfirm(report, 'bot');
466
+ };
467
+ downloadReportBtn.onclick = () => {
468
+ if (invoiceItems.length === 0) { alert("No services selected."); return; }
469
+ let content = "ELITE VISUALS – QUOTE REPORT\n\nDate: "+new Date().toLocaleString()+"\n\nServices:\n";
470
+ let total = 0;
471
+ invoiceItems.forEach(item => {
472
+ total += parsePrice(item.price);
473
+ content += `• ${item.name}: ${item.price}\n`;
474
+ });
475
+ content += `\nTOTAL: PKR ${total.toLocaleString()}`;
476
+ if (storedProjectId) content += `\n\nProject ID: ${storedProjectId}`;
477
+ const blob = new Blob([content], {type:"text/plain"});
478
+ const a = document.createElement('a');
479
+ a.href = URL.createObjectURL(blob);
480
+ a.download = `quote_${Date.now()}.txt`;
481
+ a.click();
482
+ URL.revokeObjectURL(a.href);
483
+ };
484
 
485
+ const invoiceColumn = document.getElementById('invoiceColumn');
486
+ const chatColumn = document.getElementById('chatColumn');
487
+ const toggleInvoiceBtn = document.getElementById('toggleInvoiceBtn');
488
+ let invoiceHidden = false;
489
+ toggleInvoiceBtn.onclick = () => {
490
+ if (invoiceHidden) {
491
+ invoiceColumn.classList.remove('hidden');
492
+ chatColumn.classList.remove('expanded');
493
+ toggleInvoiceBtn.innerHTML = '<i class="fas fa-eye-slash"></i>';
494
+ } else {
495
+ invoiceColumn.classList.add('hidden');
496
+ chatColumn.classList.add('expanded');
497
+ toggleInvoiceBtn.innerHTML = '<i class="fas fa-eye"></i>';
498
+ }
499
+ invoiceHidden = !invoiceHidden;
500
+ };
501
 
502
+ function renderQuestionBubbles() {
503
+ questionsContainer.innerHTML = '';
504
+ DEFAULT_QUESTIONS.forEach(q => {
505
+ const bubble = document.createElement('div');
506
+ bubble.className = 'question-bubble';
507
+ bubble.innerText = q;
508
+ bubble.onclick = () => { userInput.value = q; sendMessage(); };
509
+ questionsContainer.appendChild(bubble);
510
+ });
511
+ }
512
+
513
+ let typingDiv = null;
514
+ function showTyping() {
515
+ if (typingDiv) return;
516
+ typingDiv = document.createElement('div');
517
+ typingDiv.className = 'typing-indicator';
518
+ typingDiv.innerHTML = '<span></span><span></span><span></span>';
519
+ chatMessagesDiv.appendChild(typingDiv);
520
+ chatMessagesDiv.scrollTop = chatMessagesDiv.scrollHeight;
521
+ }
522
+ function hideTyping() {
523
+ if (typingDiv) { typingDiv.remove(); typingDiv = null; }
524
+ }
525
+
526
+ async function sendMessage() {
527
+ const msg = userInput.value.trim();
528
+ if (!msg) return;
529
+ if (questionsContainer) questionsContainer.style.display = 'none';
530
+ addMessageWithConfirm(msg, 'user');
531
+ userInput.value = '';
532
+ showTyping();
533
+ try {
534
+ const res = await fetch(API_URL, {
535
+ method: 'POST',
536
+ headers: { 'Content-Type': 'application/json' },
537
+ body: JSON.stringify({ message: msg, session_id: sessionId })
538
+ });
539
+ const data = await res.json();
540
+ hideTyping();
541
+ addMessageWithConfirm(data.reply, 'bot', data.widget);
542
+ } catch (err) {
543
+ hideTyping();
544
+ addMessageWithConfirm("❌ Server error. Try again.", 'bot');
545
+ }
546
+ }
547
+
548
+ chatIcon.onclick = async () => {
549
+ chatModal.style.display = 'flex';
550
+ if (questionsContainer.children.length === 0) renderQuestionBubbles();
551
+ if (!historyLoaded) {
552
+ await loadChatHistory();
553
+ historyLoaded = true;
554
+ }
555
+ };
556
+ closeChat.onclick = () => chatModal.style.display = 'none';
557
+ sendBtn.onclick = sendMessage;
558
+ userInput.addEventListener('keypress', (e) => { if (e.key === 'Enter') sendMessage(); });
559
+ renderQuestionBubbles();
560
+
561
+ const widgetContent = document.getElementById('widgetContent');
562
+ const toggleIcon = document.getElementById('toggleIcon');
563
+ const hideWidgetBtn = document.getElementById('hideWidgetBtn');
564
+ const unhideWidgetBtn = document.getElementById('unhideWidgetBtn');
565
+ const liveWidget = document.getElementById('liveWidget');
566
+ let widgetOpen = false;
567
+ toggleIcon.onclick = (e) => {
568
+ e.stopPropagation();
569
+ if (widgetOpen) {
570
+ widgetContent.classList.remove('show');
571
+ toggleIcon.classList.remove('fa-chevron-up');
572
+ toggleIcon.classList.add('fa-chevron-down');
573
+ } else {
574
+ widgetContent.classList.add('show');
575
+ toggleIcon.classList.remove('fa-chevron-down');
576
+ toggleIcon.classList.add('fa-chevron-up');
577
+ }
578
+ widgetOpen = !widgetOpen;
579
+ };
580
+ hideWidgetBtn.onclick = () => {
581
+ liveWidget.style.display = 'none';
582
+ hideWidgetBtn.style.display = 'none';
583
+ unhideWidgetBtn.style.display = 'inline-flex';
584
+ };
585
+ unhideWidgetBtn.onclick = () => {
586
+ liveWidget.style.display = 'block';
587
+ hideWidgetBtn.style.display = 'inline-flex';
588
+ unhideWidgetBtn.style.display = 'none';
589
+ };
590
+ function updateWidget(data) {
591
+ // Not critical for core functionality
592
+ }
593
+ updateWidget(null);
594
  </script>
595
  </body>
596
  </html>