diff --git a/public/assets/js/api.js b/public/assets/js/api.js index 19bd972..779a3da 100644 --- a/public/assets/js/api.js +++ b/public/assets/js/api.js @@ -1,7 +1,7 @@ /** * مُصادَق — API Client with JWT Auth & Refresh Flow */ -const API = { +window.API = { baseUrl: '/Application/public/api.php', accessToken: localStorage.getItem('access_token'), diff --git a/public/shell.php b/public/shell.php index 63f015e..8b34f2b 100644 --- a/public/shell.php +++ b/public/shell.php @@ -231,13 +231,13 @@ const errorEl = document.getElementById('login-error'); try { - const result = await API.post('/auth/login', { email, password }); + const result = await window.API.post('/auth/login', { email, password }); if (result.success) { localStorage.setItem('access_token', result.data.access_token); if (result.data.refresh_token) { localStorage.setItem('refresh_token', result.data.refresh_token); } - API.accessToken = result.data.access_token; + window.API.accessToken = result.data.access_token; navigate(); } } catch (err) { @@ -250,6 +250,25 @@ } } + // ── AI Query Handler ───────────────────────────────────── + document.getElementById('ai-query').addEventListener('keydown', async (e) => { + if (e.key === 'Enter') { + const query = e.target.value; + const answerEl = document.getElementById('ai-answer'); + if (!query) return; + + answerEl.textContent = 'جاري التحليل...'; + e.target.value = ''; + + try { + const res = await window.API.post('/ai/query', { query }); + answerEl.textContent = res.data.answer; + } catch (err) { + answerEl.textContent = 'عذراً، حدث خطأ أثناء معالجة طلبك.'; + } + } + }); + // ── Start the app ──────────────────────────────────────── navigate();