const express = require('express');
const path = require('path');
const app = express();

app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, 'views'));

// Static files served first — before admin router so /css/main.css etc. always resolve
app.use(express.static(path.join(__dirname, 'public')));
app.use(express.urlencoded({ extended: true, limit: '20mb' }));
app.use(express.json({ limit: '20mb' }));

// Admin app mounted after static
const adminApp = require('../admin/server');
app.use('/', adminApp);

app.get('/', (req, res) => res.render('index', { page: 'home' }));
app.get('/our-programs', (req, res) => res.render('programs', { page: 'programs' }));
app.get('/meet-your-mentors', (req, res) => res.render('mentors', { page: 'mentors' }));
app.get('/sustainability-promise', (req, res) => res.render('sustainability', { page: 'sustainability' }));
app.get('/resources', (req, res) => res.render('resources', { page: 'resources' }));
app.get('/contact-us', (req, res) => res.render('contact', { page: 'contact' }));

app.post('/contact', (req, res) => {
  res.json({ success: true, message: 'Message received. We will be in touch soon.' });
});

const PORT = process.env.PORT || 3000;
app.listen(PORT, () => console.log(`Ecobe Academy running on http://localhost:${PORT}`));

module.exports = app;
