Update chat.js
Browse files
chat.js
CHANGED
@@ -47,7 +47,7 @@ function selectTileType(type) {
|
|
47 |
showTyping();
|
48 |
setTimeout(() => {
|
49 |
hideTyping();
|
50 |
-
addMessage('bot',
|
51 |
}, 800);
|
52 |
}
|
53 |
|
@@ -104,7 +104,7 @@ function calculateTiles() {
|
|
104 |
}
|
105 |
|
106 |
if (tileArea > area) {
|
107 |
-
return addMessage('bot',
|
108 |
}
|
109 |
|
110 |
if (tileArea > 20) {
|
@@ -137,9 +137,7 @@ function calculateTiles() {
|
|
137 |
body: JSON.stringify({
|
138 |
tile_type: tileType,
|
139 |
coverage: tileArea,
|
140 |
-
area: area
|
141 |
-
price_range: [3, 10],
|
142 |
-
preferred_sizes: [`${tileLength}x${tileWidth}`]
|
143 |
})
|
144 |
})
|
145 |
.then(res => res.json())
|
@@ -159,31 +157,18 @@ function calculateTiles() {
|
|
159 |
function loadProductRecommendations(products) {
|
160 |
recommendations.innerHTML = '';
|
161 |
products.slice(0, 4).forEach(p => {
|
162 |
-
let ftSize = '';
|
163 |
-
const mmMatch = p.size?.match(/(\d+)\s*[x×X*]\s*(\d+)/);
|
164 |
-
if (mmMatch) {
|
165 |
-
const mmWidth = parseFloat(mmMatch[1]);
|
166 |
-
const mmHeight = parseFloat(mmMatch[2]);
|
167 |
-
const ftWidth = (mmWidth * 0.00328084).toFixed(2);
|
168 |
-
const ftHeight = (mmHeight * 0.00328084).toFixed(2);
|
169 |
-
ftSize = ` (${ftWidth} ft × ${ftHeight} ft)`;
|
170 |
-
}
|
171 |
-
|
172 |
recommendations.insertAdjacentHTML('beforeend', `
|
173 |
<div class="bg-white rounded-lg overflow-hidden shadow-sm border border-gray-100">
|
174 |
-
<div class="h-32 bg-gray-
|
175 |
-
${p.image_url ? `<img src="${p.image_url}" class="h-full object-cover
|
176 |
<svg xmlns="http://www.w3.org/2000/svg" class="h-12 w-12 text-gray-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
177 |
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1" d="M4 6a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2H6a2 2 0 01-2-2V6zM14 6a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2V6zM4 16a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2H6a2 2 0 01-2-2v-2zM14 16a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2v-2z" />
|
178 |
</svg>`}
|
179 |
</div>
|
180 |
<div class="p-3">
|
181 |
<h4 class="font-medium text-gray-800">${p.name || 'Tile Product'}</h4>
|
182 |
-
<p class="text-sm text-gray-600 mt-1"
|
183 |
-
<p class="text-
|
184 |
-
<a href="${p.url || '#'}" target="_blank" rel="noopener noreferrer">
|
185 |
-
<button class="mt-2 w-full bg-indigo-600 text-white py-1 rounded text-sm hover:bg-indigo-700 transition">View Product</button>
|
186 |
-
</a>
|
187 |
</div>
|
188 |
</div>
|
189 |
`);
|
|
|
47 |
showTyping();
|
48 |
setTimeout(() => {
|
49 |
hideTyping();
|
50 |
+
addMessage('bot', 'Great! What is the total area to cover (in sq.ft)?');
|
51 |
}, 800);
|
52 |
}
|
53 |
|
|
|
104 |
}
|
105 |
|
106 |
if (tileArea > area) {
|
107 |
+
return addMessage('bot', `⚠ The tile size (${tileLength}×${tileWidth} = ${tileArea} sq.ft) is larger than the total area (${area} sq.ft). Please enter smaller tile dimensions.`);
|
108 |
}
|
109 |
|
110 |
if (tileArea > 20) {
|
|
|
137 |
body: JSON.stringify({
|
138 |
tile_type: tileType,
|
139 |
coverage: tileArea,
|
140 |
+
area: area
|
|
|
|
|
141 |
})
|
142 |
})
|
143 |
.then(res => res.json())
|
|
|
157 |
function loadProductRecommendations(products) {
|
158 |
recommendations.innerHTML = '';
|
159 |
products.slice(0, 4).forEach(p => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
160 |
recommendations.insertAdjacentHTML('beforeend', `
|
161 |
<div class="bg-white rounded-lg overflow-hidden shadow-sm border border-gray-100">
|
162 |
+
<div class="h-32 bg-gray-200 flex items-center justify-center">
|
163 |
+
${p.image_url ? `<img src="${p.image_url}" class="h-full object-cover" alt="${p.name}">` : `
|
164 |
<svg xmlns="http://www.w3.org/2000/svg" class="h-12 w-12 text-gray-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
165 |
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1" d="M4 6a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2H6a2 2 0 01-2-2V6zM14 6a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2V6zM4 16a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2H6a2 2 0 01-2-2v-2zM14 16a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2v-2z" />
|
166 |
</svg>`}
|
167 |
</div>
|
168 |
<div class="p-3">
|
169 |
<h4 class="font-medium text-gray-800">${p.name || 'Tile Product'}</h4>
|
170 |
+
<p class="text-sm text-gray-600 mt-1">${p.price ? `₹${p.price}/box` : 'Price N/A'}</p>
|
171 |
+
<a href="${p.url}" target="_blank" class="mt-2 inline-block text-sm text-indigo-600 underline">View Details</a>
|
|
|
|
|
|
|
172 |
</div>
|
173 |
</div>
|
174 |
`);
|