'use client'; import { useEffect } from 'react'; // Wires the template's form (#cr-form: name, email, message, honeypot name="website"). // Same checks and payload as hosting-research's careers.js (the owner 2026-12-02: Name, Email and Message, all required). function useCareersForm() { useEffect(() => { const f = document.getElementById('cr-form') as HTMLFormElement | null; if (!f) return undefined; const form = f; const m = document.getElementById('cr-msg') as HTMLElement; const field = (name: string) => ((form.elements.namedItem(name) as HTMLInputElement | null)?.value || '').trim(); async function submit(e: Event) { e.preventDefault(); const n = field('name'); const em = field('email'); const t = field('request'); if (!n) { m.textContent = 'Please add your name.'; return; } if (!/^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/.test(em)) { m.textContent = 'Please add a valid email.'; return; } if (!t) { m.textContent = 'Please write a short message.'; return; } const b = form.querySelector('button') as HTMLButtonElement; b.disabled = true; m.textContent = 'Sending…'; try { const r = await fetch('/api/request', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ request: 'Name: ' + n + '\nEmail: ' + em + '\n\n' + t, name: n, email: em, message: t, site: location.hostname, website: field('website') }), }); if (!r.ok) throw new Error(String(r.status)); form.reset(); m.textContent = 'Thanks. We got your note and will be in touch about joining our team.'; } catch { m.textContent = 'That didn’t go through. Please try again in a minute.'; } finally { b.disabled = false; } } form.addEventListener('submit', submit); return () => form.removeEventListener('submit', submit); }, []); } export function CareersFormScript() { useCareersForm(); return null; }