Update index.html
Browse files- index.html +205 -68
index.html
CHANGED
|
@@ -2,73 +2,117 @@
|
|
| 2 |
<html lang="en">
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
-
<title>Elite Visuals AI
|
| 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:wght@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 |
-
|
|
|
|
|
|
|
| 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:
|
| 19 |
-
.close-btn { background: rgba(255,255,255,0.2); border: none; width: 32px; height: 32px; border-radius: 50%; cursor: pointer; color: white; }
|
| 20 |
-
.
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
@keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }
|
| 23 |
-
.user-msg { background: #DCF8C6; margin-left: auto; border-bottom-right-radius:
|
| 24 |
-
.bot-msg { background: white; margin-right: auto; border-bottom-left-radius:
|
| 25 |
|
| 26 |
-
/*
|
| 27 |
-
.live-widget { background: white; border-radius:
|
| 28 |
-
.widget-header { background: linear-gradient(135deg, #1e2a3a, #0f172a); color: white; padding:
|
| 29 |
-
.widget-content { padding:
|
| 30 |
.widget-content.show { display: block; }
|
| 31 |
-
.info-row { margin:
|
| 32 |
.info-label { font-weight: 700; color: #075E54; }
|
| 33 |
-
.features-list { margin-left: 20px; margin-top: 5px; }
|
| 34 |
|
| 35 |
-
.questions-container { display: flex; flex-wrap: wrap; gap:
|
| 36 |
-
.question-bubble { background: #e4e6eb; padding:
|
| 37 |
-
.question-bubble:hover { background: #d1d4db; transform: translateY(-
|
| 38 |
-
|
| 39 |
-
.typing-indicator
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
.chat-input-area
|
| 43 |
-
.chat-input-area
|
|
|
|
|
|
|
|
|
|
| 44 |
</style>
|
| 45 |
</head>
|
| 46 |
<body>
|
| 47 |
<div class="chat-icon" id="chatIcon"><i class="fas fa-comment-dots"></i></div>
|
| 48 |
<div class="chat-modal" id="chatModal">
|
| 49 |
-
<div class="chat-header">
|
| 50 |
-
|
| 51 |
-
<
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
</div>
|
| 58 |
-
<div class="
|
| 59 |
-
<
|
| 60 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
</div>
|
| 62 |
</div>
|
| 63 |
-
<div id="defaultQuestionsContainer" class="questions-container"></div>
|
| 64 |
-
</div>
|
| 65 |
-
<div class="chat-input-area">
|
| 66 |
-
<input type="text" id="userInput" placeholder="Ask about price, timeline, extra features...">
|
| 67 |
-
<button id="sendBtn"><i class="fas fa-paper-plane"></i></button>
|
| 68 |
</div>
|
| 69 |
</div>
|
| 70 |
|
| 71 |
<script>
|
|
|
|
| 72 |
let sessionId = localStorage.getItem('chat_session_id');
|
| 73 |
if (!sessionId) {
|
| 74 |
sessionId = 'user_' + Date.now() + '_' + Math.random().toString(36).substr(2, 8);
|
|
@@ -78,34 +122,115 @@
|
|
| 78 |
const DEFAULT_QUESTIONS = [
|
| 79 |
"Basic website price and timeline?",
|
| 80 |
"Standard package details",
|
| 81 |
-
"
|
| 82 |
-
"
|
|
|
|
| 83 |
"Contact number"
|
| 84 |
];
|
| 85 |
|
| 86 |
-
//
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
const widgetContentDiv = document.getElementById('widgetContent');
|
|
|
|
| 95 |
const widgetEmptyMsg = document.getElementById('widgetEmptyMsg');
|
| 96 |
const widgetDetailsDiv = document.getElementById('widgetDetails');
|
| 97 |
let widgetOpen = false;
|
| 98 |
-
const widgetHeader = document.getElementById('widgetHeader');
|
| 99 |
-
const toggleIcon = document.getElementById('toggleIcon');
|
| 100 |
|
| 101 |
widgetHeader.addEventListener('click', () => {
|
| 102 |
-
const content = document.getElementById('widgetContent');
|
| 103 |
if (widgetOpen) {
|
| 104 |
-
|
| 105 |
toggleIcon.classList.remove('fa-chevron-up');
|
| 106 |
toggleIcon.classList.add('fa-chevron-down');
|
| 107 |
} else {
|
| 108 |
-
|
| 109 |
toggleIcon.classList.remove('fa-chevron-down');
|
| 110 |
toggleIcon.classList.add('fa-chevron-up');
|
| 111 |
}
|
|
@@ -113,8 +238,7 @@
|
|
| 113 |
});
|
| 114 |
|
| 115 |
function updateWidget(data) {
|
| 116 |
-
|
| 117 |
-
if (!data || (Object.keys(data).length === 0)) {
|
| 118 |
widgetEmptyMsg.style.display = 'block';
|
| 119 |
widgetDetailsDiv.style.display = 'none';
|
| 120 |
return;
|
|
@@ -125,10 +249,10 @@
|
|
| 125 |
if (data.price) html += `<div class="info-row"><span class="info-label">💰 Price:</span> ${data.price}</div>`;
|
| 126 |
if (data.timeline) html += `<div class="info-row"><span class="info-label">⏱️ Timeline:</span> ${data.timeline}</div>`;
|
| 127 |
if (data.features && data.features.length) {
|
| 128 |
-
html += `<div class="info-row"><span class="info-label">✅ Includes:</span><ul
|
| 129 |
}
|
| 130 |
} else if (data.extra_feature) {
|
| 131 |
-
html += `<div class="info-row"><span class="info-label">✨ Extra
|
| 132 |
if (data.extra_cost) html += `<div class="info-row"><span class="info-label">💰 Additional Cost:</span> ${data.extra_cost}</div>`;
|
| 133 |
if (data.extra_timeline) html += `<div class="info-row"><span class="info-label">⏱️ Timeline Increase:</span> ${data.extra_timeline}</div>`;
|
| 134 |
} else if (data.service) {
|
|
@@ -136,14 +260,22 @@
|
|
| 136 |
if (data.price) html += `<div class="info-row"><span class="info-label">💰 Price:</span> ${data.price}</div>`;
|
| 137 |
if (data.timeline) html += `<div class="info-row"><span class="info-label">⏱️ Timeline:</span> ${data.timeline}</div>`;
|
| 138 |
} else {
|
| 139 |
-
|
| 140 |
-
html = `<div class="info-row">ℹ️ Ask about a specific package or feature for detailed quote.</div>`;
|
| 141 |
}
|
| 142 |
widgetDetailsDiv.innerHTML = html;
|
| 143 |
widgetEmptyMsg.style.display = 'none';
|
| 144 |
widgetDetailsDiv.style.display = 'block';
|
| 145 |
}
|
| 146 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
function renderQuestionBubbles() {
|
| 148 |
questionsContainer.innerHTML = '';
|
| 149 |
DEFAULT_QUESTIONS.forEach(q => {
|
|
@@ -192,19 +324,21 @@
|
|
| 192 |
const data = await res.json();
|
| 193 |
hideTyping();
|
| 194 |
addMessage(data.reply, 'bot');
|
| 195 |
-
// Update dynamic widget with structured data
|
| 196 |
if (data.widget) {
|
| 197 |
updateWidget(data.widget);
|
| 198 |
-
// Auto-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 199 |
if (!widgetOpen) {
|
| 200 |
-
|
| 201 |
toggleIcon.classList.remove('fa-chevron-down');
|
| 202 |
toggleIcon.classList.add('fa-chevron-up');
|
| 203 |
widgetOpen = true;
|
| 204 |
}
|
| 205 |
-
} else {
|
| 206 |
-
// If no widget data, maybe show a default
|
| 207 |
-
updateWidget(null);
|
| 208 |
}
|
| 209 |
} catch (err) {
|
| 210 |
hideTyping();
|
|
@@ -220,6 +354,9 @@
|
|
| 220 |
sendBtn.onclick = sendMessage;
|
| 221 |
userInput.addEventListener('keypress', (e) => { if (e.key === 'Enter') sendMessage(); });
|
| 222 |
renderQuestionBubbles();
|
|
|
|
|
|
|
|
|
|
| 223 |
</script>
|
| 224 |
</body>
|
| 225 |
</html>
|
|
|
|
| 2 |
<html lang="en">
|
| 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>
|
| 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 |
+
|
| 13 |
+
/* Chat Icon */
|
| 14 |
.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; }
|
| 15 |
@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); } }
|
| 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; }
|
| 35 |
+
.remove-item { color: #e63946; cursor: pointer; font-size: 14px; transition: 0.2s; }
|
| 36 |
+
.remove-item:hover { transform: scale(1.1); }
|
| 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; }
|
| 52 |
.info-label { font-weight: 700; color: #075E54; }
|
|
|
|
| 53 |
|
| 54 |
+
.questions-container { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px; }
|
| 55 |
+
.question-bubble { background: #e4e6eb; padding: 4px 10px; border-radius: 16px; font-size: 0.7rem; cursor: pointer; transition: 0.2s; }
|
| 56 |
+
.question-bubble:hover { background: #d1d4db; transform: translateY(-1px); }
|
| 57 |
+
|
| 58 |
+
.typing-indicator { background: white; padding: 6px 12px; border-radius: 20px; display: inline-flex; gap: 4px; width: fit-content; }
|
| 59 |
+
.typing-indicator span { width: 6px; height: 6px; background: #888; border-radius: 50%; animation: wave 1.2s infinite; }
|
| 60 |
+
@keyframes wave { 0%,60%,100% { transform: translateY(0); } 30% { transform: translateY(-4px); } }
|
| 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>
|
| 69 |
<div class="chat-icon" id="chatIcon"><i class="fas fa-comment-dots"></i></div>
|
| 70 |
<div class="chat-modal" id="chatModal">
|
| 71 |
+
<div class="chat-header">
|
| 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>
|
| 87 |
+
<div id="widgetDetails" style="display: none;"></div>
|
| 88 |
+
</div>
|
| 89 |
+
</div>
|
| 90 |
+
<div id="defaultQuestionsContainer" class="questions-container"></div>
|
| 91 |
</div>
|
| 92 |
+
<div class="chat-input-area">
|
| 93 |
+
<input type="text" id="userInput" placeholder="Ask about price, timeline, confirm Basic, add SEO...">
|
| 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>
|
| 105 |
+
</div>
|
| 106 |
+
<div class="invoice-total" id="invoiceTotal">
|
| 107 |
+
<span>Subtotal:</span>
|
| 108 |
+
<span id="totalAmount">PKR 0</span>
|
| 109 |
</div>
|
| 110 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
</div>
|
| 112 |
</div>
|
| 113 |
|
| 114 |
<script>
|
| 115 |
+
// ---------- Session ----------
|
| 116 |
let sessionId = localStorage.getItem('chat_session_id');
|
| 117 |
if (!sessionId) {
|
| 118 |
sessionId = 'user_' + Date.now() + '_' + Math.random().toString(36).substr(2, 8);
|
|
|
|
| 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;
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
function updateInvoiceDisplay() {
|
| 143 |
+
const container = document.getElementById('invoiceItems');
|
| 144 |
+
const totalSpan = document.getElementById('totalAmount');
|
| 145 |
+
if (invoiceItems.length === 0) {
|
| 146 |
+
container.innerHTML = '<div class="empty-invoice">✨ No services selected yet.<br>Ask or confirm a package to add.</div>';
|
| 147 |
+
totalSpan.innerText = 'PKR 0';
|
| 148 |
+
return;
|
| 149 |
+
}
|
| 150 |
+
let html = '';
|
| 151 |
+
let total = 0;
|
| 152 |
+
invoiceItems.forEach(item => {
|
| 153 |
+
const priceNum = parsePrice(item.price);
|
| 154 |
+
total += priceNum;
|
| 155 |
+
html += `
|
| 156 |
+
<div class="invoice-item" data-id="${item.id}">
|
| 157 |
+
<div class="invoice-item-name">${item.name}</div>
|
| 158 |
+
<div style="display: flex; align-items: center; gap: 12px;">
|
| 159 |
+
<span class="invoice-item-price">${item.price}</span>
|
| 160 |
+
<span class="remove-item" data-id="${item.id}"><i class="fas fa-times-circle"></i></span>
|
| 161 |
+
</div>
|
| 162 |
+
</div>
|
| 163 |
+
`;
|
| 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);
|
| 171 |
+
removeInvoiceItem(id);
|
| 172 |
+
});
|
| 173 |
+
});
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
function removeInvoiceItem(id) {
|
| 177 |
+
invoiceItems = invoiceItems.filter(item => item.id !== id);
|
| 178 |
+
updateInvoiceDisplay();
|
| 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 |
}
|
|
|
|
| 238 |
});
|
| 239 |
|
| 240 |
function updateWidget(data) {
|
| 241 |
+
if (!data || Object.keys(data).length === 0) {
|
|
|
|
| 242 |
widgetEmptyMsg.style.display = 'block';
|
| 243 |
widgetDetailsDiv.style.display = 'none';
|
| 244 |
return;
|
|
|
|
| 249 |
if (data.price) html += `<div class="info-row"><span class="info-label">💰 Price:</span> ${data.price}</div>`;
|
| 250 |
if (data.timeline) html += `<div class="info-row"><span class="info-label">⏱️ Timeline:</span> ${data.timeline}</div>`;
|
| 251 |
if (data.features && data.features.length) {
|
| 252 |
+
html += `<div class="info-row"><span class="info-label">✅ Includes:</span><ul>${data.features.map(f => `<li>${f}</li>`).join('')}</ul></div>`;
|
| 253 |
}
|
| 254 |
} else if (data.extra_feature) {
|
| 255 |
+
html += `<div class="info-row"><span class="info-label">✨ Extra:</span> ${data.extra_feature}</div>`;
|
| 256 |
if (data.extra_cost) html += `<div class="info-row"><span class="info-label">💰 Additional Cost:</span> ${data.extra_cost}</div>`;
|
| 257 |
if (data.extra_timeline) html += `<div class="info-row"><span class="info-label">⏱️ Timeline Increase:</span> ${data.extra_timeline}</div>`;
|
| 258 |
} else if (data.service) {
|
|
|
|
| 260 |
if (data.price) html += `<div class="info-row"><span class="info-label">💰 Price:</span> ${data.price}</div>`;
|
| 261 |
if (data.timeline) html += `<div class="info-row"><span class="info-label">⏱️ Timeline:</span> ${data.timeline}</div>`;
|
| 262 |
} else {
|
| 263 |
+
html = `<div class="info-row">ℹ️ Ask about a package or feature.</div>`;
|
|
|
|
| 264 |
}
|
| 265 |
widgetDetailsDiv.innerHTML = html;
|
| 266 |
widgetEmptyMsg.style.display = 'none';
|
| 267 |
widgetDetailsDiv.style.display = 'block';
|
| 268 |
}
|
| 269 |
|
| 270 |
+
// ---------- Chat UI ----------
|
| 271 |
+
const chatIcon = document.getElementById('chatIcon');
|
| 272 |
+
const chatModal = document.getElementById('chatModal');
|
| 273 |
+
const closeChat = document.getElementById('closeChat');
|
| 274 |
+
const sendBtn = document.getElementById('sendBtn');
|
| 275 |
+
const userInput = document.getElementById('userInput');
|
| 276 |
+
const chatMessages = document.getElementById('chatMessages');
|
| 277 |
+
const questionsContainer = document.getElementById('defaultQuestionsContainer');
|
| 278 |
+
|
| 279 |
function renderQuestionBubbles() {
|
| 280 |
questionsContainer.innerHTML = '';
|
| 281 |
DEFAULT_QUESTIONS.forEach(q => {
|
|
|
|
| 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;
|
| 341 |
}
|
|
|
|
|
|
|
|
|
|
| 342 |
}
|
| 343 |
} catch (err) {
|
| 344 |
hideTyping();
|
|
|
|
| 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>
|
| 362 |
</html>
|