Update chat.js
Browse files
chat.js
CHANGED
@@ -66,7 +66,7 @@ function processUserMessage(message) {
|
|
66 |
if (state.step === 'area') {
|
67 |
const area = parseFloat(message);
|
68 |
if (isNaN(area) || area <= 0) {
|
69 |
-
return addMessage('bot', 'Please enter a valid positive number for area (e.g., 100).');
|
70 |
}
|
71 |
state.area = area;
|
72 |
state.step = 'tileLength';
|
@@ -74,7 +74,7 @@ function processUserMessage(message) {
|
|
74 |
} else if (state.step === 'tileLength') {
|
75 |
const length = parseFloat(message);
|
76 |
if (isNaN(length) || length <= 0) {
|
77 |
-
return addMessage('bot', 'Please enter a valid positive number for tile length.');
|
78 |
}
|
79 |
state.tileLength = length;
|
80 |
state.step = 'tileWidth';
|
@@ -82,7 +82,7 @@ function processUserMessage(message) {
|
|
82 |
} else if (state.step === 'tileWidth') {
|
83 |
const width = parseFloat(message);
|
84 |
if (isNaN(width) || width <= 0) {
|
85 |
-
return addMessage('bot', 'Please enter a valid positive number for tile width.');
|
86 |
}
|
87 |
state.tileWidth = width;
|
88 |
calculateTiles();
|
@@ -93,8 +93,26 @@ function processUserMessage(message) {
|
|
93 |
function calculateTiles() {
|
94 |
const { tileLength, tileWidth, area, tileType } = state;
|
95 |
const tileArea = tileLength * tileWidth;
|
96 |
-
|
97 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
|
99 |
chatArea.insertAdjacentHTML('beforeend', `
|
100 |
<div class="bot-message bg-gray-100 rounded-lg p-4 mb-3">
|
|
|
66 |
if (state.step === 'area') {
|
67 |
const area = parseFloat(message);
|
68 |
if (isNaN(area) || area <= 0) {
|
69 |
+
return addMessage('bot', '❗ Please enter a valid positive number for area (e.g., 100).');
|
70 |
}
|
71 |
state.area = area;
|
72 |
state.step = 'tileLength';
|
|
|
74 |
} else if (state.step === 'tileLength') {
|
75 |
const length = parseFloat(message);
|
76 |
if (isNaN(length) || length <= 0) {
|
77 |
+
return addMessage('bot', '❗ Please enter a valid positive number for tile length.');
|
78 |
}
|
79 |
state.tileLength = length;
|
80 |
state.step = 'tileWidth';
|
|
|
82 |
} else if (state.step === 'tileWidth') {
|
83 |
const width = parseFloat(message);
|
84 |
if (isNaN(width) || width <= 0) {
|
85 |
+
return addMessage('bot', '❗ Please enter a valid positive number for tile width.');
|
86 |
}
|
87 |
state.tileWidth = width;
|
88 |
calculateTiles();
|
|
|
93 |
function calculateTiles() {
|
94 |
const { tileLength, tileWidth, area, tileType } = state;
|
95 |
const tileArea = tileLength * tileWidth;
|
96 |
+
|
97 |
+
if (tileArea <= 0) {
|
98 |
+
return addMessage('bot', `❗ Invalid tile dimensions. Length × width must be greater than 0.`);
|
99 |
+
}
|
100 |
+
|
101 |
+
if (tileArea >= area) {
|
102 |
+
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.`);
|
103 |
+
}
|
104 |
+
|
105 |
+
if (tileArea > 50) {
|
106 |
+
addMessage('bot', `🔎 That’s quite a large tile (${tileArea} sq.ft). Double-check your input or continue if it's correct.`);
|
107 |
+
}
|
108 |
+
|
109 |
+
const aspectRatio = Math.max(tileLength / tileWidth, tileWidth / tileLength);
|
110 |
+
if (aspectRatio > 10) {
|
111 |
+
addMessage('bot', `📐 This tile has a very high aspect ratio (${aspectRatio.toFixed(1)}:1). Make sure that's intentional.`);
|
112 |
+
}
|
113 |
+
|
114 |
+
const numTiles = Math.ceil((area / tileArea) * 1.1); // add 10% buffer
|
115 |
+
const numBoxes = Math.ceil(numTiles / 10); // assume 10 tiles/box
|
116 |
|
117 |
chatArea.insertAdjacentHTML('beforeend', `
|
118 |
<div class="bot-message bg-gray-100 rounded-lg p-4 mb-3">
|