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

const app = express();

app.use(express.urlencoded({ extended: true }));

// Set up Pug as the view engine
app.set('view engine', 'pug');
app.set('views', path.join(__dirname, 'views'));

// Serve static files
app.use(express.static(path.join(__dirname, 'public')));

// Home route
app.get('/', (_, res) => {
  res.render('index', {
    title: 'Freshyo - Delivering Freshness',
    year: new Date().getFullYear()
  });
});

// Privacy Policy route
app.get('/privacy-policy', (_, res) => {
  res.render('policy', {
    title: 'Freshyo - Privacy Policy',
    year: new Date().getFullYear()
  });
});

// Delete Account route
app.get('/delete-account', (_, res) => {
  res.render('delete', {
    title: 'Freshyo - Delete Account',
    year: new Date().getFullYear()
  });
});

// Handle Delete Account submission
app.post('/delete-account', (req, res) => {
  const { mobile } = req.body;
  console.log(`Received deletion request for: ${mobile}`);
  
  res.render('success', {
    title: 'Freshyo - Request Submitted',
    year: new Date().getFullYear()
  });
});

// QR-based download route
app.get('/qr-based-download', (_, res) => {
  res.render('qr-download', {
    title: 'Freshyo - Download App',
    year: new Date().getFullYear()
  });
});

const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
  console.log(`✨ Freshyo FRESH info site running at http://localhost:${PORT}`);
});