Spaces:
Paused
Paused
Update index.html
Browse files- index.html +389 -145
index.html
CHANGED
|
@@ -3,10 +3,11 @@
|
|
| 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; }
|
| 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; }
|
|
@@ -35,7 +36,8 @@
|
|
| 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
|
|
|
|
| 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,9 +55,8 @@
|
|
| 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 |
-
.
|
| 57 |
-
.
|
| 58 |
-
.quick-msg-chip:hover { background: #d1d4db; transform: translateY(-1px); }
|
| 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); }
|
|
@@ -65,10 +66,6 @@
|
|
| 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 |
-
.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; }
|
| 69 |
-
.modal-content { background: #1e1e28; border-radius: 20px; padding: 20px; width: 350px; color: white; }
|
| 70 |
-
.modal-content input { width: 100%; margin: 10px 0; padding: 8px; border-radius: 8px; border: none; }
|
| 71 |
-
.flex-row { display: flex; gap: 10px; justify-content: flex-end; margin-top: 15px; }
|
| 72 |
</style>
|
| 73 |
</head>
|
| 74 |
<body>
|
|
@@ -84,7 +81,7 @@
|
|
| 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
|
| 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,45 +98,30 @@
|
|
| 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>
|
| 108 |
-
<div class="quick-msg-chip" id="customInvoiceChip">➕ Add Custom Service</div>
|
| 109 |
-
<div class="quick-msg-chip" data-msg="Help">❓ Help</div>
|
| 110 |
-
</div>
|
| 111 |
<div class="chat-input-area">
|
| 112 |
-
<input type="text" id="userInput" placeholder="Ask
|
| 113 |
<button id="sendBtn"><i class="fas fa-paper-plane"></i></button>
|
| 114 |
</div>
|
| 115 |
</div>
|
| 116 |
<div class="invoice-column" id="invoiceColumn">
|
| 117 |
<div class="invoice-title">
|
| 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">
|
| 122 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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>
|
| 137 |
-
<button id="addCustomBtn" class="btn" style="background:#25D366;">Add to Invoice</button>
|
| 138 |
-
</div>
|
| 139 |
-
</div>
|
| 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,19 +129,37 @@
|
|
| 147 |
}
|
| 148 |
const API_URL = "/api/chat";
|
| 149 |
const DEFAULT_QUESTIONS = [
|
| 150 |
-
"Basic website price and timeline?",
|
| 151 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
];
|
| 153 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
let invoiceItems = [];
|
| 155 |
let nextId = 1;
|
| 156 |
-
let storedProjectId = localStorage.getItem(`project_id_${sessionId}`) || null;
|
| 157 |
|
| 158 |
function parsePrice(priceStr) {
|
| 159 |
let match = priceStr.match(/(\d[\d,]+)/);
|
| 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,73 +168,135 @@
|
|
| 168 |
totalSpan.innerText = 'PKR 0';
|
| 169 |
return;
|
| 170 |
}
|
| 171 |
-
let html = ''
|
|
|
|
| 172 |
invoiceItems.forEach(item => {
|
| 173 |
-
|
| 174 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
});
|
| 176 |
container.innerHTML = html;
|
| 177 |
totalSpan.innerText = `PKR ${total.toLocaleString()}`;
|
| 178 |
-
document.querySelectorAll('.remove-item').forEach(el =>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 179 |
}
|
| 180 |
-
|
| 181 |
-
function
|
| 182 |
-
|
| 183 |
-
invoiceItems.push({ id: nextId++, name, price, serviceKey: key || name, timelineDays });
|
| 184 |
updateInvoiceDisplay();
|
| 185 |
-
return true;
|
| 186 |
}
|
| 187 |
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 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 |
-
|
| 210 |
-
if (
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 211 |
}
|
|
|
|
|
|
|
| 212 |
function generateFinalReport() {
|
| 213 |
-
if (
|
|
|
|
|
|
|
|
|
|
| 214 |
let report = "📋 **Final Project Report**\n\n**Selected Services:**\n";
|
| 215 |
-
let totalPrice = 0
|
|
|
|
| 216 |
invoiceItems.forEach(item => {
|
| 217 |
-
|
|
|
|
| 218 |
report += `- ${item.name}: ${item.price}\n`;
|
| 219 |
-
if (item.timelineDays) {
|
|
|
|
|
|
|
|
|
|
| 220 |
});
|
| 221 |
-
report += `\n**💰 Total Cost:** PKR ${totalPrice.toLocaleString()}`;
|
| 222 |
-
if (
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 226 |
}
|
|
|
|
|
|
|
| 227 |
function downloadReport() {
|
| 228 |
-
if (
|
| 229 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 230 |
let totalPrice = 0;
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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,114 +310,296 @@
|
|
| 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 |
-
|
| 254 |
-
|
| 255 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 256 |
if (pagesMatch) {
|
| 257 |
-
|
| 258 |
if (pages !== currentPages) {
|
| 259 |
currentPages = pages;
|
| 260 |
-
invoiceItems = invoiceItems.filter(
|
| 261 |
-
|
| 262 |
-
if (
|
|
|
|
|
|
|
|
|
|
| 263 |
}
|
| 264 |
}
|
| 265 |
-
|
| 266 |
-
if (lower.includes("
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 274 |
}
|
| 275 |
}
|
| 276 |
|
| 277 |
-
// Live
|
| 278 |
-
const widgetContent = document.getElementById('widgetContent')
|
| 279 |
-
const
|
|
|
|
|
|
|
|
|
|
| 280 |
let widgetOpen = false;
|
| 281 |
-
toggleIcon.
|
| 282 |
-
|
| 283 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 284 |
|
| 285 |
-
|
| 286 |
-
|
|
|
|
| 287 |
if (sender === 'user') {
|
| 288 |
-
|
| 289 |
-
|
|
|
|
|
|
|
|
|
|
| 290 |
return;
|
| 291 |
}
|
| 292 |
-
|
| 293 |
-
|
|
|
|
|
|
|
|
|
|
| 294 |
wrapper.appendChild(msgDiv);
|
|
|
|
|
|
|
| 295 |
autoAddFromBotMessage(text);
|
| 296 |
-
|
| 297 |
-
let
|
| 298 |
-
if (
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 302 |
}
|
| 303 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 304 |
}
|
| 305 |
|
| 306 |
-
// UI
|
| 307 |
-
const chatIcon = document.getElementById('chatIcon')
|
| 308 |
-
const
|
| 309 |
-
const
|
| 310 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 311 |
|
| 312 |
-
const invoiceColumn = document.getElementById('invoiceColumn')
|
|
|
|
| 313 |
const toggleInvoiceBtn = document.getElementById('toggleInvoiceBtn');
|
| 314 |
let invoiceHidden = false;
|
| 315 |
-
toggleInvoiceBtn.
|
| 316 |
if (invoiceHidden) {
|
| 317 |
-
invoiceColumn.classList.remove('hidden');
|
|
|
|
|
|
|
| 318 |
} else {
|
| 319 |
-
invoiceColumn.classList.add('hidden');
|
|
|
|
|
|
|
| 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 |
-
|
| 330 |
-
|
| 331 |
-
|
|
|
|
|
|
|
| 332 |
});
|
| 333 |
}
|
|
|
|
| 334 |
let typingDiv = null;
|
| 335 |
-
function showTyping() {
|
| 336 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 337 |
|
| 338 |
async function sendMessage() {
|
| 339 |
-
|
| 340 |
if (!msg) return;
|
| 341 |
if (questionsContainer) questionsContainer.style.display = 'none';
|
| 342 |
-
|
| 343 |
userInput.value = '';
|
| 344 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 345 |
showTyping();
|
| 346 |
try {
|
| 347 |
-
|
| 348 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 349 |
hideTyping();
|
| 350 |
-
|
| 351 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 352 |
}
|
| 353 |
|
| 354 |
-
chatIcon.onclick = () => {
|
|
|
|
|
|
|
|
|
|
| 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>
|
|
|
|
| 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 |
+
/* (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; }
|
|
|
|
| 36 |
.empty-invoice { color: #888; font-size: 0.75rem; text-align: center; padding: 20px; }
|
| 37 |
.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; }
|
| 38 |
.download-report-btn { background: #2a6d4c; margin-top: 4px; }
|
| 39 |
+
.final-report-btn:hover { background: #128C7E; transform: scale(1.02); }
|
| 40 |
+
.download-report-btn:hover { background: #1e5a3e; transform: scale(1.02); }
|
| 41 |
.chat-messages { flex: 1; padding: 12px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
|
| 42 |
.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; }
|
| 43 |
@keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }
|
|
|
|
| 55 |
.toggle-widget { cursor: pointer; margin-left: 8px; }
|
| 56 |
.widget-content { padding: 10px; display: none; background: #fef9e6; font-size: 0.7rem; }
|
| 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 |
.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 |
<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 |
</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>
|
| 112 |
+
</div>
|
| 113 |
+
<div class="invoice-total" id="invoiceTotal">
|
| 114 |
+
<span>Subtotal:</span>
|
| 115 |
+
<span id="totalAmount">PKR 0</span>
|
| 116 |
+
</div>
|
| 117 |
<button class="final-report-btn" id="finalReportBtn"><i class="fas fa-file-alt"></i> Generate Final Report</button>
|
| 118 |
<button class="download-report-btn" id="downloadReportBtn"><i class="fas fa-download"></i> Download Report</button>
|
| 119 |
</div>
|
| 120 |
</div>
|
| 121 |
</div>
|
| 122 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
<script>
|
| 124 |
+
// ---------- Session ----------
|
| 125 |
let sessionId = localStorage.getItem('chat_session_id');
|
| 126 |
if (!sessionId) {
|
| 127 |
sessionId = 'user_' + Date.now() + '_' + Math.random().toString(36).substr(2, 8);
|
|
|
|
| 129 |
}
|
| 130 |
const API_URL = "/api/chat";
|
| 131 |
const DEFAULT_QUESTIONS = [
|
| 132 |
+
"Basic website price and timeline?",
|
| 133 |
+
"Standard package details",
|
| 134 |
+
"Premium package details",
|
| 135 |
+
"Extra: live chat cost increase?",
|
| 136 |
+
"Add e-commerce to my quote",
|
| 137 |
+
"I want to build a website",
|
| 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,]+)/);
|
| 150 |
if (match) return parseInt(match[0].replace(/,/g, ''));
|
| 151 |
return 0;
|
| 152 |
}
|
| 153 |
+
|
| 154 |
+
function parseTimelineDays(timelineStr) {
|
| 155 |
+
if (!timelineStr) return 0;
|
| 156 |
+
let match = timelineStr.match(/(\d+)\s*-\s*(\d+)\s*days?/);
|
| 157 |
+
if (match) return parseInt(match[2]);
|
| 158 |
+
match = timelineStr.match(/(\d+)\s*days?/);
|
| 159 |
+
if (match) return parseInt(match[1]);
|
| 160 |
+
return 0;
|
| 161 |
+
}
|
| 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 = '';
|
| 172 |
+
let total = 0;
|
| 173 |
invoiceItems.forEach(item => {
|
| 174 |
+
const priceNum = parsePrice(item.price);
|
| 175 |
+
total += priceNum;
|
| 176 |
+
html += `
|
| 177 |
+
<div class="invoice-item" data-id="${item.id}">
|
| 178 |
+
<div class="invoice-item-name">${item.name}</div>
|
| 179 |
+
<div style="display: flex; align-items: center; gap: 12px;">
|
| 180 |
+
<span class="invoice-item-price">${item.price}</span>
|
| 181 |
+
<span class="remove-item" data-id="${item.id}"><i class="fas fa-times-circle"></i></span>
|
| 182 |
+
</div>
|
| 183 |
+
</div>
|
| 184 |
+
`;
|
| 185 |
});
|
| 186 |
container.innerHTML = html;
|
| 187 |
totalSpan.innerText = `PKR ${total.toLocaleString()}`;
|
| 188 |
+
document.querySelectorAll('.remove-item').forEach(el => {
|
| 189 |
+
el.addEventListener('click', (e) => {
|
| 190 |
+
const id = parseInt(el.dataset.id);
|
| 191 |
+
removeInvoiceItem(id);
|
| 192 |
+
});
|
| 193 |
+
});
|
| 194 |
}
|
| 195 |
+
|
| 196 |
+
function removeInvoiceItem(id) {
|
| 197 |
+
invoiceItems = invoiceItems.filter(item => item.id !== id);
|
|
|
|
| 198 |
updateInvoiceDisplay();
|
|
|
|
| 199 |
}
|
| 200 |
|
| 201 |
+
function addInvoiceItem(serviceName, priceStr, serviceKey = null, timelineDays = null) {
|
| 202 |
+
if (serviceKey && invoiceItems.some(item => item.serviceKey === serviceKey)) return false;
|
| 203 |
+
const newItem = { id: nextId++, name: serviceName, price: priceStr, serviceKey: serviceKey || serviceName, timelineDays: timelineDays };
|
| 204 |
+
invoiceItems.push(newItem);
|
| 205 |
+
updateInvoiceDisplay();
|
| 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 |
+
|
| 220 |
+
// ---------- Generate Final Report (in chat) ----------
|
| 221 |
function generateFinalReport() {
|
| 222 |
+
if (invoiceItems.length === 0) {
|
| 223 |
+
addMessageWithConfirm("❌ You haven't added any services yet. Please confirm some packages or features first.", 'bot');
|
| 224 |
+
return;
|
| 225 |
+
}
|
| 226 |
let report = "📋 **Final Project Report**\n\n**Selected Services:**\n";
|
| 227 |
+
let totalPrice = 0;
|
| 228 |
+
let totalTimelineDays = 0;
|
| 229 |
invoiceItems.forEach(item => {
|
| 230 |
+
const priceNum = parsePrice(item.price);
|
| 231 |
+
totalPrice += priceNum;
|
| 232 |
report += `- ${item.name}: ${item.price}\n`;
|
| 233 |
+
if (item.timelineDays) {
|
| 234 |
+
totalTimelineDays += item.timelineDays;
|
| 235 |
+
report += ` (timeline: ${item.timelineDays} days)\n`;
|
| 236 |
+
}
|
| 237 |
});
|
| 238 |
+
report += `\n**💰 Total Estimated Cost:** PKR ${totalPrice.toLocaleString()}`;
|
| 239 |
+
if (totalTimelineDays > 0) {
|
| 240 |
+
report += `\n**⏱️ Total Estimated Timeline:** ${totalTimelineDays} working days (cumulative)`;
|
| 241 |
+
report += `\n> Note: Some tasks can run in parallel, so actual timeline may be less. We will provide a detailed schedule after confirmation.`;
|
| 242 |
+
} else {
|
| 243 |
+
report += `\n**⏱️ Timeline:** Please contact for detailed timeline based on selected services.`;
|
| 244 |
+
}
|
| 245 |
+
if (storedProjectId) {
|
| 246 |
+
report += `\n\n📌 **Project ID:** \`${storedProjectId}\`\n🔍 **Check status:** Type \`status ${storedProjectId}\` anytime.`;
|
| 247 |
+
} else {
|
| 248 |
+
report += `\n\n✅ After final confirmation, you will receive a Project ID to track your request.`;
|
| 249 |
+
}
|
| 250 |
+
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.`;
|
| 251 |
+
addMessageWithConfirm(report, 'bot');
|
| 252 |
}
|
| 253 |
+
|
| 254 |
+
// ---------- Download Report (as .txt file) ----------
|
| 255 |
function downloadReport() {
|
| 256 |
+
if (invoiceItems.length === 0) {
|
| 257 |
+
alert("No services selected. Please add items to your quote first.");
|
| 258 |
+
return;
|
| 259 |
+
}
|
| 260 |
+
let content = "ELITE VISUALS – QUOTE REPORT\n";
|
| 261 |
+
content += "==========================\n\n";
|
| 262 |
+
content += `Date: ${new Date().toLocaleString()}\n`;
|
| 263 |
+
content += `Session ID: ${sessionId}\n\n`;
|
| 264 |
+
content += "Selected Services:\n";
|
| 265 |
+
content += "-----------------\n";
|
| 266 |
let totalPrice = 0;
|
| 267 |
+
let totalDays = 0;
|
| 268 |
+
invoiceItems.forEach(item => {
|
| 269 |
+
const priceNum = parsePrice(item.price);
|
| 270 |
+
totalPrice += priceNum;
|
| 271 |
+
content += `• ${item.name}: ${item.price}\n`;
|
| 272 |
+
if (item.timelineDays) {
|
| 273 |
+
totalDays += item.timelineDays;
|
| 274 |
+
content += ` (est. timeline: ${item.timelineDays} days)\n`;
|
| 275 |
+
}
|
| 276 |
+
});
|
| 277 |
+
content += "\n-----------------\n";
|
| 278 |
+
content += `TOTAL COST: PKR ${totalPrice.toLocaleString()}\n`;
|
| 279 |
+
if (totalDays > 0) content += `CUMULATIVE TIMELINE: ${totalDays} working days\n`;
|
| 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";
|
| 288 |
+
const blob = new Blob([content], { type: "text/plain" });
|
| 289 |
+
const url = URL.createObjectURL(blob);
|
| 290 |
+
const a = document.createElement("a");
|
| 291 |
+
a.href = url;
|
| 292 |
+
a.download = `quote_${new Date().toISOString().slice(0,19).replace(/:/g, "-")}.txt`;
|
| 293 |
+
document.body.appendChild(a);
|
| 294 |
+
a.click();
|
| 295 |
+
document.body.removeChild(a);
|
| 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" },
|
|
|
|
| 310 |
"custom backend": { name: "Custom Backend", price: "PKR 100,000", key: "custom_backend" }
|
| 311 |
};
|
| 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]);
|
| 327 |
if (pages !== currentPages) {
|
| 328 |
currentPages = pages;
|
| 329 |
+
invoiceItems = invoiceItems.filter(item => item.serviceKey !== "pages");
|
| 330 |
+
const extraPages = Math.max(0, pages - 5);
|
| 331 |
+
if (extraPages > 0) {
|
| 332 |
+
const extraCost = extraPages * 5000;
|
| 333 |
+
addInvoiceItem(`${extraPages} extra page(s)`, `PKR ${extraCost.toLocaleString()}`, "pages");
|
| 334 |
+
}
|
| 335 |
}
|
| 336 |
}
|
| 337 |
+
// E-commerce
|
| 338 |
+
if (lower.includes("e‑commerce: yes") || (lower.includes("need e‑commerce") && lower.includes("yes"))) {
|
| 339 |
+
addInvoiceItem("E‑commerce Functionality", "PKR 50,000", "ecommerce");
|
| 340 |
+
}
|
| 341 |
+
// Chatbot
|
| 342 |
+
if (lower.includes("chatbot: yes") || (lower.includes("ai chatbot") && lower.includes("yes"))) {
|
| 343 |
+
addInvoiceItem("AI Chatbot", "PKR 30,000", "chatbot");
|
| 344 |
+
}
|
| 345 |
+
// SEO
|
| 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();
|
| 361 |
+
for (const [key, svc] of Object.entries(serviceMap)) {
|
| 362 |
+
if (feature.includes(key) || key.includes(feature)) {
|
| 363 |
+
addInvoiceItem(svc.name, svc.price, svc.key);
|
| 364 |
+
break;
|
| 365 |
+
}
|
| 366 |
+
}
|
| 367 |
+
}
|
| 368 |
+
const genericAdded = text.match(/✅ Added (.+?)\./i);
|
| 369 |
+
if (genericAdded && !addedMatch) {
|
| 370 |
+
const feature = genericAdded[1].toLowerCase();
|
| 371 |
+
for (const [key, svc] of Object.entries(serviceMap)) {
|
| 372 |
+
if (feature.includes(key) || key.includes(feature)) {
|
| 373 |
+
addInvoiceItem(svc.name, svc.price, svc.key);
|
| 374 |
+
break;
|
| 375 |
+
}
|
| 376 |
+
}
|
| 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');
|
| 384 |
+
const unhideWidgetBtn = document.getElementById('unhideWidgetBtn');
|
| 385 |
+
const liveWidget = document.getElementById('liveWidget');
|
| 386 |
let widgetOpen = false;
|
| 387 |
+
toggleIcon.addEventListener('click', (e) => {
|
| 388 |
+
e.stopPropagation();
|
| 389 |
+
if (widgetOpen) {
|
| 390 |
+
widgetContent.classList.remove('show');
|
| 391 |
+
toggleIcon.classList.remove('fa-chevron-up');
|
| 392 |
+
toggleIcon.classList.add('fa-chevron-down');
|
| 393 |
+
} else {
|
| 394 |
+
widgetContent.classList.add('show');
|
| 395 |
+
toggleIcon.classList.remove('fa-chevron-down');
|
| 396 |
+
toggleIcon.classList.add('fa-chevron-up');
|
| 397 |
+
}
|
| 398 |
+
widgetOpen = !widgetOpen;
|
| 399 |
+
});
|
| 400 |
+
hideWidgetBtn.addEventListener('click', () => {
|
| 401 |
+
liveWidget.style.display = 'none';
|
| 402 |
+
hideWidgetBtn.style.display = 'none';
|
| 403 |
+
unhideWidgetBtn.style.display = 'inline-flex';
|
| 404 |
+
});
|
| 405 |
+
unhideWidgetBtn.addEventListener('click', () => {
|
| 406 |
+
liveWidget.style.display = 'block';
|
| 407 |
+
hideWidgetBtn.style.display = 'inline-flex';
|
| 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') {
|
| 449 |
+
const div = document.createElement('div');
|
| 450 |
+
div.className = 'message user-msg';
|
| 451 |
+
div.innerText = text;
|
| 452 |
+
chatMessagesDiv.appendChild(div);
|
| 453 |
+
chatMessagesDiv.scrollTop = chatMessagesDiv.scrollHeight;
|
| 454 |
return;
|
| 455 |
}
|
| 456 |
+
const wrapper = document.createElement('div');
|
| 457 |
+
wrapper.className = 'bot-message-wrapper';
|
| 458 |
+
const msgDiv = document.createElement('div');
|
| 459 |
+
msgDiv.className = 'message bot-msg';
|
| 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) {
|
| 486 |
+
const confirmBtn = document.createElement('button');
|
| 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';
|
| 495 |
+
};
|
| 496 |
+
wrapper.appendChild(confirmBtn);
|
| 497 |
+
}
|
| 498 |
+
chatMessagesDiv.appendChild(wrapper);
|
| 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');
|
| 506 |
+
const sendBtn = document.getElementById('sendBtn');
|
| 507 |
+
const userInput = document.getElementById('userInput');
|
| 508 |
+
const chatMessagesDiv = document.getElementById('chatMessages');
|
| 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');
|
| 517 |
const toggleInvoiceBtn = document.getElementById('toggleInvoiceBtn');
|
| 518 |
let invoiceHidden = false;
|
| 519 |
+
toggleInvoiceBtn.addEventListener('click', () => {
|
| 520 |
if (invoiceHidden) {
|
| 521 |
+
invoiceColumn.classList.remove('hidden');
|
| 522 |
+
chatColumn.classList.remove('expanded');
|
| 523 |
+
toggleInvoiceBtn.innerHTML = '<i class="fas fa-eye-slash"></i>';
|
| 524 |
} else {
|
| 525 |
+
invoiceColumn.classList.add('hidden');
|
| 526 |
+
chatColumn.classList.add('expanded');
|
| 527 |
+
toggleInvoiceBtn.innerHTML = '<i class="fas fa-eye"></i>';
|
| 528 |
}
|
| 529 |
invoiceHidden = !invoiceHidden;
|
| 530 |
+
});
|
|
|
|
|
|
|
| 531 |
|
| 532 |
function renderQuestionBubbles() {
|
| 533 |
questionsContainer.innerHTML = '';
|
| 534 |
DEFAULT_QUESTIONS.forEach(q => {
|
| 535 |
+
const bubble = document.createElement('div');
|
| 536 |
+
bubble.className = 'question-bubble';
|
| 537 |
+
bubble.innerText = q;
|
| 538 |
+
bubble.onclick = () => { userInput.value = q; sendMessage(); };
|
| 539 |
+
questionsContainer.appendChild(bubble);
|
| 540 |
});
|
| 541 |
}
|
| 542 |
+
|
| 543 |
let typingDiv = null;
|
| 544 |
+
function showTyping() {
|
| 545 |
+
if (typingDiv) return;
|
| 546 |
+
typingDiv = document.createElement('div');
|
| 547 |
+
typingDiv.className = 'typing-indicator';
|
| 548 |
+
typingDiv.innerHTML = '<span></span><span></span><span></span>';
|
| 549 |
+
chatMessagesDiv.appendChild(typingDiv);
|
| 550 |
+
chatMessagesDiv.scrollTop = chatMessagesDiv.scrollHeight;
|
| 551 |
+
}
|
| 552 |
+
function hideTyping() {
|
| 553 |
+
if (typingDiv) { typingDiv.remove(); typingDiv = null; }
|
| 554 |
+
}
|
| 555 |
|
| 556 |
async function sendMessage() {
|
| 557 |
+
const msg = userInput.value.trim();
|
| 558 |
if (!msg) return;
|
| 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, {
|
| 571 |
+
method: 'POST',
|
| 572 |
+
headers: { 'Content-Type': 'application/json' },
|
| 573 |
+
body: JSON.stringify({ message: msg, session_id: sessionId })
|
| 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 |
|
| 594 |
+
chatIcon.onclick = () => {
|
| 595 |
+
chatModal.style.display = 'flex';
|
| 596 |
+
if (questionsContainer.children.length === 0) renderQuestionBubbles();
|
| 597 |
+
};
|
| 598 |
closeChat.onclick = () => chatModal.style.display = 'none';
|
| 599 |
sendBtn.onclick = sendMessage;
|
| 600 |
+
userInput.addEventListener('keypress', (e) => { if (e.key === 'Enter') sendMessage(); });
|
| 601 |
renderQuestionBubbles();
|
| 602 |
+
updateWidget(null);
|
| 603 |
</script>
|
| 604 |
</body>
|
| 605 |
</html>
|