const express = require('express');
const router = express.Router();
const db = require('../db');

// Get page by slug
router.get('/:slug', (req, res) => {
  const { slug } = req.params;
  try {
    const page = db.prepare('SELECT * FROM pages WHERE slug = ? AND is_published = 1').get(slug);
    if (!page) {
      return res.status(404).json({ error: 'ޕޭޖް ނުފެނުނު' });
    }
    res.json(page);
  } catch (err) {
    res.status(500).json({ error: 'ޕޭޖް ހޯދުމުގައި މައްސަލައެއް ދިމާވެއްޖެ' });
  }
});

module.exports = router;
