// ═══════════════════════════════════════════════════════════════════════════ // LandveX Finance — Core App // ═══════════════════════════════════════════════════════════════════════════ import { API } from './api.js'; import { Router } from './router.js'; import { Dashboard } from './views/dashboard.js'; import { Accounts } from './views/accounts.js'; import { Journal } from './views/journal.js'; import { Reports } from './views/reports.js'; const app = { api: null, router: null, tenant: 'landvex', async init() { // Dölj loading document.getElementById('loading').style.display = 'none'; // Init API this.api = new API({ baseUrl: '/api/ledger', tenant: this.tenant, getToken: () => localStorage.getItem('lv_token') }); // Testa auth try { await this.api.get('/health'); } catch (e) { if (e.status === 401) { window.location.href = '/login?return=' + encodeURIComponent(window.location.pathname); return; } } // Init router this.router = new Router({ routes: { 'dashboard': () => Dashboard.render(this), 'accounts': () => Accounts.render(this), 'journal': () => Journal.render(this), 'reports': () => Reports.render(this), }, default: 'dashboard' }); // Render app shell this.renderShell(); // Start router this.router.start(); console.log('[LandveX Finance] App initierad'); }, renderShell() { document.getElementById('app').innerHTML = `
LandveX Finance
`; // Tab handlers document.querySelectorAll('[data-route]').forEach(el => { el.addEventListener('click', (e) => { const route = e.currentTarget.dataset.route; this.router.navigate(route); this.updateActiveTab(route); }); }); }, updateActiveTab(route) { document.querySelectorAll('.tab-btn, .nav-item').forEach(el => { el.classList.toggle('active', el.dataset.route === route); }); }, render(content) { document.getElementById('main-content').innerHTML = content; } }; // Start app.init();