-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsights.html
More file actions
411 lines (381 loc) · 13.6 KB
/
insights.html
File metadata and controls
411 lines (381 loc) · 13.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
<!DOCTYPE html>
<html>
<head>
<!-- Optimized Favicon links matching your generated files -->
<!-- Standard favicon sizes for browser tabs -->
<link
rel="icon"
type="image/png"
sizes="16x16"
href="images/favicon-16x16.png"
/>
<link
rel="icon"
type="image/png"
sizes="32x32"
href="images/favicon-32x32.png"
/>
<!-- Apple touch icon for iOS home screen -->
<link
rel="apple-touch-icon"
sizes="180x180"
href="images/apple-touch-icon.png"
/>
<!-- Fallback ICO for older browsers -->
<link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon" />
<link rel="icon" href="images/favicon.ico" type="image/x-icon" />
<!-- Web App Manifest -->
<link rel="manifest" href="images/site.webmanifest" />
<!-- Optional: Microsoft tile color -->
<meta name="msapplication-TileColor" content="#da532c" />
<meta name="theme-color" content="#ffffff" />
<title>AI Insights</title>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=Bebas+Neue&family=Inter:wght@400;500;700&display=swap"
rel="stylesheet"
/>
<link rel="stylesheet" href="output.css" />
<script src="https://cdn.tailwindcss.com"></script>
<style>
/* Add the transition styles from menued.html */
html,
body {
transition: background-color 0.3s ease, color 0.3s ease;
}
/* Color transitions */
.bg-white,
.bg-gray-50,
.bg-gray-100,
.bg-gray-200,
.dark\:bg-slate-800,
.dark\:bg-slate-700,
.dark\:bg-slate-900,
.text-gray-700,
.dark\:text-yellow-400,
.text-gray-600,
.dark\:text-gray-300,
.text-white,
.dark\:text-gray-200,
.text-gray-800,
.dark\:text-white {
transition: background-color 0.3s ease, color 0.3s ease;
}
/* Border transitions */
.border-gray-200,
.dark\:border-slate-600,
.border-gray-300,
.dark\:border-slate-700 {
transition: border-color 0.3s ease;
}
/* Respect reduced motion preference */
@media (prefers-reduced-motion: reduce) {
* {
transition: none !important;
animation: none !important;
}
}
</style>
<script>
// Immediately set the correct theme to prevent flash
(function () {
const storedTheme = localStorage.getItem("color-theme");
const systemDark = window.matchMedia(
"(prefers-color-scheme: dark)"
).matches;
if (storedTheme === "dark" || (!storedTheme && systemDark)) {
document.documentElement.classList.add("dark");
}
})();
tailwind.config = {
darkMode: "class",
theme: {
extend: {
fontFamily: {
bebas: ['"Bebas Neue"', "sans-serif"],
inter: ['"Inter"', "sans-serif"],
},
colors: {
primary: {
yellow: "#FFC107",
"yellow-dark": "#FFB300",
},
dark: {
bg: "#1a1a2e",
"bg-secondary": "#16213e",
"bg-card": "#0f172a",
text: "#e8e8e8",
"text-secondary": "#cbd5e0",
},
},
transitionProperty: {
colors: "background-color, border-color, color, fill, stroke",
},
},
},
};
</script>
</head>
<body
class="dark:bg-slate-900 min-h-screen p-5 transition-colors duration-300"
>
<header class="mb-8 flex justify-between items-center">
<div>
<h1
class="font-bebas tracking-wider text-4xl text-yellow-500 dark:text-yellow-400 font-bold mb-2"
>
Order AI Insights
</h1>
<p class="text-gray-400 dark:text-gray-300">
AI-powered analysis of your business data
</p>
</div>
<div class="flex items-center">
<button
id="darkModeToggle"
class="theme-toggle p-2 rounded-full bg-gray-200 dark:bg-gray-700 cursor-pointer transition-all duration-300 hover:bg-gray-300 dark:hover:bg-gray-600 hover:scale-110 hover:shadow-lg"
>
<svg
id="sunIcon"
xmlns="http://www.w3.org/2000/svg"
class="w-6 h-6 text-yellow-500 dark:hidden transition-colors duration-300"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
stroke-width="2"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M12 3v1m0 16v1m9-9h-1M4 12H3m15.364 6.364l-.707-.707M6.343 6.343l-.707-.707m12.728 0l-.707.707M6.343 17.657l-.707.707M16 12a4 4 0 11-8 0 4 4 0 018 0z"
/>
</svg>
<svg
id="moonIcon"
xmlns="http://www.w3.org/2000/svg"
class="w-6 h-6 text-yellow-400 hidden dark:block transition-colors duration-300"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
stroke-width="2"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M20.354 15.354A9 9 0 018.646 3.646 9.003 9.003 0 0012 21a9.003 9.003 0 008.354-5.646z"
/>
</svg>
</button>
<img
src="/images/logo.png"
alt="AI Insights Logo"
class="h-32 w-32 ml-4"
/>
</div>
</header>
<nav class="mb-6">
<ul class="flex space-x-4">
<li>
<a
href="/orders"
class="font-bebas tracking-wider text-yellow-500 dark:text-yellow-400 font-bold text-2xl relative group"
>
View Orders
<span
class="absolute bottom-0 left-0 w-0 h-0.5 bg-current transition-all duration-300 group-hover:w-full"
></span>
</a>
</li>
<li>
<a
href="/menued"
class="font-bebas tracking-wider text-yellow-500 dark:text-yellow-400 font-bold text-2xl relative group"
>
Menu
<span
class="absolute bottom-0 left-0 w-0 h-0.5 bg-current transition-all duration-300 group-hover:w-full"
></span>
</a>
</li>
<li>
<a
href="/inventory"
class="font-bebas tracking-wider text-yellow-500 dark:text-yellow-400 font-bold text-2xl relative group"
>
Inventory
<span
class="absolute bottom-0 left-0 w-0 h-0.5 bg-current transition-all duration-300 group-hover:w-full"
></span>
</a>
</li>
</ul>
</nav>
<div class="flex flex-col space-y-4">
<button
onclick="fetchInsights()"
class="bg-yellow-500 dark:bg-blue-600 text-gray-900 dark:text-white font-bebas tracking-wider text-xl px-6 py-3 rounded-xl shadow-lg hover:shadow-xl transform hover:-translate-y-1 transition-all duration-300 flex items-center justify-center w-48 relative overflow-hidden"
>
<svg
class="w-6 h-6 mr-3 transform transition hover:rotate-6 hover:scale-110"
fill="none"
stroke="currentColor"
viewBox="0 0 24 24"
xmlns="http://www.w3.org/2000/svg"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M13 10V3L4 14h7v7l9-11h-7z"
></path>
</svg>
<span>Generate Insights</span>
</button>
<div id="loading" class="hidden text-gray-400 dark:text-gray-300">
Analyzing your order data...
</div>
</div>
<div id="insights-container" class="mt-8 hidden">
<div
class="bg-white dark:bg-slate-800 border border-gray-300 dark:border-slate-600 rounded-lg p-6 transition-colors duration-300"
>
<div
id="insights"
class="text-gray-700 dark:text-gray-300 whitespace-pre-line markdown transition-colors duration-300"
></div>
</div>
</div>
<script>
// Theme toggle functionality
document.addEventListener("DOMContentLoaded", function () {
const darkModeToggle = document.getElementById("darkModeToggle");
// Function to set theme with transition
function setTheme(isDark) {
// Start transition
document.documentElement.classList.add("transition-colors");
document.documentElement.classList.add("duration-300");
if (isDark) {
document.documentElement.classList.add("dark");
localStorage.setItem("color-theme", "dark");
} else {
document.documentElement.classList.remove("dark");
localStorage.setItem("color-theme", "light");
}
// Remove transition classes after animation completes
setTimeout(() => {
document.documentElement.classList.remove("transition-colors");
document.documentElement.classList.remove("duration-300");
}, 300);
}
// Check for saved theme preference or use system preference
if (
localStorage.getItem("color-theme") === "dark" ||
(!("color-theme" in localStorage) &&
window.matchMedia("(prefers-color-scheme: dark)").matches)
) {
setTheme(true);
} else {
setTheme(false);
}
// Dark mode toggle click event
darkModeToggle.addEventListener("click", function () {
const isDark = !document.documentElement.classList.contains("dark");
setTheme(isDark);
});
});
// Simple markdown parser for formatting insights
function parseMarkdown(markdown) {
if (!markdown) return "";
// Replace headers
let html = markdown
.replace(/^# (.*$)/gm, '<h1 class="text-2xl font-bold my-3">$1</h1>')
.replace(
/^## (.*$)/gm,
'<h2 class="text-xl font-semibold my-2">$1</h2>'
)
.replace(
/^### (.*$)/gm,
'<h3 class="text-lg font-medium my-2">$1</h3>'
)
// Replace lists
.replace(/^\- (.*$)/gm, '<li class="ml-4"> $1</li>')
// Replace paragraphs
.split("\n\n")
.join('</p><p class="my-2">');
return '<p class="my-2">' + html + "</p>";
}
function fetchInsights() {
// Show loading state
document.getElementById("loading").classList.remove("hidden");
document.getElementById("insights-container").classList.add("hidden");
fetch("/api/order-insights")
.then((res) => {
if (!res.ok) {
throw new Error("Server error: " + res.status);
}
return res.json();
})
.then((data) => {
// Hide loading state
document.getElementById("loading").classList.add("hidden");
// Show insights container
document
.getElementById("insights-container")
.classList.remove("hidden");
// Format and display insights with markdown parsing
document.getElementById("insights").innerHTML = parseMarkdown(
data.insights
);
})
.catch((err) => {
console.error(err);
document.getElementById("loading").classList.add("hidden");
document
.getElementById("insights-container")
.classList.remove("hidden");
document.getElementById("insights").innerHTML =
'<div class="text-red-500">Failed to fetch insights. Please try again later.</div>';
});
}
</script>
<script>
// Periodically check server-side authentication status.
// This catches session expiry or logout from other tabs/windows.
// Adjusted frequency to 30 seconds to reduce unnecessary network traffic.
setInterval(() => {
fetch("/check-auth")
.then((res) => {
if (res.status === 401) {
// Session has expired or user logged out from server
window.location.href = "/login";
}
// If status is 200, the session is active and 'rolling: true' on server
// means its expiration timer is automatically reset.
})
.catch((error) => {
console.error("Error checking authentication:", error);
// Optionally, redirect to login on network error if deemed appropriate
// window.location.href = '/login';
});
}, 30000); // Checks every 30 seconds
// Initial check on page load:
// This is the most important check to ensure the user is authenticated when the page first loads.
// Removed all sessionStorage and onpageshow logic as it interfered with server-side session management.
fetch("/check-auth")
.then((res) => {
if (res.status === 401) {
// Session expired or not authenticated on initial load
window.location.href = "/login";
}
// If status is 200, no action needed, user is authenticated by the server.
})
.catch((error) => {
console.error("Error on initial authentication check:", error);
// Handle network errors or server unavailability gracefully.
// Redirecting to login is a common fallback for critical auth errors.
window.location.href = "/login";
});
</script>
</body>
</html>