function extract({pages}) {
  const business = { values: {}, evidence: {}, activities: [] };
  const clean = (s) => (s || '').replace(/\s+/g, ' ').trim();
  const put = (record, key, value, page) => {
    if (value !== undefined && value !== null && value !== '') {
      record.values[key] = value;
      record.evidence[key] = page.url;
    }
  };
  const date = (month, day, year) => {
    const months = { january: 1, february: 2, march: 3, april: 4, may: 5, june: 6, july: 7, august: 8, september: 9, october: 10, november: 11, december: 12 };
    const n = months[month.toLowerCase()];
    return n ? year + '-' + String(n).padStart(2, '0') + '-' + String(Number(day)).padStart(2, '0') : undefined;
  };
  const findPage = (pattern) => pages.find((p) => pattern.test(p.url) && /summer|camp/i.test(p.text || p.document?.body?.textContent || ''));
  const campPage = findPage(/programs\/camps\/?$/i);
  const home = pages.find((p) => /\/$/.test(p.url));
  const contactPage = campPage || home || pages[0];

  if (home) {
    const title = clean(home.document?.title || '');
    const name = clean(title.split('|')[0]);
    put(business, 'name', name, home);
    put(business, 'website', home.url, home);
    const intro = [...(home.document?.querySelectorAll('section.article p') || [])].map((n) => clean(n.textContent)).find((s) => /Great Work Montessori/i.test(s));
    put(business, 'description', intro, home);
  }
  if (contactPage) {
    const text = clean(contactPage.document?.body?.textContent || contactPage.text);
    const email = text.match(/[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}/i)?.[0];
    put(business, 'contact_email', email, contactPage);
    const address = text.match(/\d+\s+[^\n]+?\s+Wappingers Falls\s*,?\s*New York\s+\d{5}/i)?.[0];
    put(business, 'locations', address ? [{ address: clean(address) }] : undefined, contactPage);
    const social = [...(contactPage.document?.querySelectorAll('a[href]') || [])].map((a) => a.href).filter((h) => /facebook\.com|instagram\.com/i.test(h));
    put(business, 'social_links', social.length ? [...new Set(social)] : undefined, contactPage);
  }

  if (campPage) {
    const body = clean(campPage.document?.body?.textContent || campPage.text);
    const heading = [...(campPage.document?.querySelectorAll('h1,h2') || [])].map((n) => clean(n.textContent)).find((s) => /summer program/i.test(s)) || clean(campPage.document?.title || '').split('|').pop();
    const activity = { values: {}, evidence: {}, sessions: [] };
    put(activity, 'name', heading, campPage);
    put(activity, 'detail_url', campPage.url, campPage);
    const description = [...(campPage.document?.querySelectorAll('section.article p') || [])].map((n) => clean(n.textContent)).find((s) => /summer sessions|summer program/i.test(s));
    put(activity, 'description', description, campPage);
    put(activity, 'category', 'Summer Camps', campPage);
    const ages = body.match(/ages\s+(\d+)\s*[-–]\s*(\d+)/i);
    if (ages) {
      put(activity, 'age_min', Number(ages[1]), campPage);
      put(activity, 'age_max', Number(ages[2]), campPage);
    }
    const tuition = body.match(/tuition\s*:\s*\$([\d,]+)\s+per\s+week/i);
    if (tuition) put(activity, 'price', { amount_cents: Number(tuition[1].replace(/,/g, '')) * 100, currency: 'USD' }, campPage);
    const refund = body.match(/refund policy\s*:\s*([^\n]*?No refunds after\s+[A-Za-z]+\s+\d{1,2},\s+\d{4})/i)?.[1];
    put(activity, 'refund_policy', clean(refund), campPage);

    const year = body.match(/summer program\s+(\d{4})/i)?.[1] || body.match(/dates\s*:\s*[A-Za-z]+\s+\d{1,2}(?:st|nd|rd|th)?\s*[-–]\s*[A-Za-z]+\s+\d{1,2}(?:st|nd|rd|th)?,\s*(\d{4})/i)?.[1];
    const schedule = body.match(/schedule\s*:\s*[^|]*\|\s*(\d{1,2}:\d{2}\s*[AP]M)\s*[-–]\s*(\d{1,2}:\d{2}\s*[AP]M)/i);
    const registration = [...(campPage.document?.querySelectorAll('a[href]') || [])].find((a) => /register here/i.test(clean(a.textContent)))?.href;
    const panels = [...(campPage.document?.querySelectorAll('.panel') || [])];
    for (const panel of panels) {
      const label = clean(panel.querySelector('.panel-title')?.textContent);
      const match = label.match(/([A-Za-z]+)\s+(\d{1,2})\s*[-–]\s*([A-Za-z]+)\s+(\d{1,2})\s*\|\s*(.+)$/);
      if (!match || !year) continue;
      const session = { values: {}, evidence: {} };
      put(session, 'name', clean(match[5].replace(/\s*\([^)]*\)\s*$/, '')), campPage);
      put(session, 'start_date', date(match[1], match[2], year), campPage);
      put(session, 'end_date', date(match[3], match[4], year), campPage);
      if (schedule) {
        put(session, 'start_time', clean(schedule[1]), campPage);
        put(session, 'end_time', clean(schedule[2]), campPage);
      }
      if (/maximum capacity|no available spots/i.test(label)) put(session, 'registration_status', 'At Maximum Capacity', campPage);
      if (registration) put(session, 'registration_url', registration, campPage);
      activity.sessions.push(session);
    }
    if (activity.values.name && activity.sessions.length) business.activities.push(activity);
  }
  return { business };
}