import axios from 'axios';
import * as cheerio from 'cheerio';
import https from 'https';

async function fetchLakes() {
  const agent = new https.Agent({ rejectUnauthorized: false });
  try {
    const response = await axios.get('https://www.pvl.cz/portal/nadrze/cz/pc/Prehled.aspx', {
      httpsAgent: agent,
      headers: {
        'User-Agent': 'Mozilla/5.0'
      }
    });

    const $ = cheerio.load(response.data);
    const lakes: any[] = [];
    
    // Links to lakes usually look like Mereni.aspx?oid=xxx&id=yyy
    $('a[href^="Mereni.aspx"]').each((i, el) => {
      const href = $(el).attr('href');
      const text = $(el).text().trim();
      if (href && text) {
        lakes.push({ href, text });
      }
    });

    console.log(JSON.stringify(lakes, null, 2));
  } catch (err: any) {
    console.error('Error:', err.message);
  }
}

fetchLakes();
