const express = require('express');
const path = require('path');
const app = express();
const families = require('./data/families.json');

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

// API endpoint for family search
app.get('/api/search', (req, res) => {
  const query = req.query.family?.toLowerCase();
  if (!query) {
    return res.json([]);
  }
  const matches = families.filter(fam => fam.family.toLowerCase().includes(query));
  res.json(matches);
});

// Health check endpoint
app.get('/api/health', (req, res) => {
  res.json({ status: 'ok', timestamp: new Date().toISOString() });
});

const port = process.env.PORT || 3000;
app.listen(port, '0.0.0.0', () => {
  console.log(`🗺️  Ora Map Server running at http://localhost:${port}`);
  console.log(`📍 API endpoint: http://localhost:${port}/api/search`);
});
