38 lines
1.4 KiB
JavaScript
38 lines
1.4 KiB
JavaScript
const appRouter = () => ({
|
|
isLoggedIn: !!localStorage.getItem('access_token'),
|
|
pageHtml: 'جاري التحميل...',
|
|
async init() {
|
|
console.log('App Initialized');
|
|
await this.navigate(window.location.pathname);
|
|
window.onpopstate = () => this.navigate(window.location.pathname);
|
|
},
|
|
async navigate(path) {
|
|
console.log('Navigating to:', path);
|
|
const isLogin = path.includes('login');
|
|
|
|
if (!this.isLoggedIn && !isLogin) {
|
|
this.pageHtml = await this.loadPage('login');
|
|
} else if (isLogin) {
|
|
this.pageHtml = await this.loadPage('login');
|
|
} else {
|
|
this.pageHtml = await this.loadPage('dashboard');
|
|
}
|
|
},
|
|
initCharts() {
|
|
const ctx = document.getElementById('invoiceChart')?.getContext('2d');
|
|
},
|
|
async loadPage(page) {
|
|
if (page === 'dashboard') {
|
|
return `<div></div>`;
|
|
}
|
|
if (page === 'login') return `
|
|
<div class="flex flex-col items-center justify-center min-h-[60vh]">
|
|
<div class="w-full max-w-md p-8 glass rounded-3xl glow border-white/10">
|
|
<h2 class="text-3xl font-bold mb-2 text-center">مرحباً بك مجدداً</h2>
|
|
</div>
|
|
</div>
|
|
`;
|
|
return '<div>الصفحة قيد الإنشاء</div>';
|
|
}
|
|
});
|