// Newsletter signup ("The Ledger"). Lives in the footer so it is reachable from
// every page: the previous signup box sat in an unrendered home-page variant,
// which left /api/subscribe with no caller anywhere on the live site.
function FooterNewsletter({ navigate }) {
 const [email, setEmail] = React.useState('');
 const [sent, setSent] = React.useState(false);
 const [busy, setBusy] = React.useState(false);
 const [error, setError] = React.useState('');
 const honeypotRef = React.useRef(null);

 const submit = async (e) => {
 e.preventDefault();
 if (busy) return;
 if (!/^[^@\s]+@[^@\s]+\.[^@\s]+$/.test(email.trim())) {
 setError('That email address does not look right, please check it.');
 return;
 }
 setBusy(true); setError('');
 try {
 const r = await fetch('/api/subscribe', {
 method: 'POST',
 headers: { 'Content-Type': 'application/json' },
 body: JSON.stringify({
 email: email.trim(),
 source: 'footer-ledger',
 // Honeypot: empty for people, filled by bots. The endpoint checks it.
 website: (honeypotRef.current && honeypotRef.current.value) || '',
 }),
 });
 if (r.ok) { setSent(true); }
 else {
 const d = await r.json().catch(() => ({}));
 setError(d.error || 'We could not save that just now. Please try again in a moment.');
 }
 } catch (err) {
 setError('We could not save that just now. Please try again in a moment.');
 }
 setBusy(false);
 };

 return (
 <div style={{ borderBottom: '1px solid rgba(255,255,255,0.20)' }}>
 <div className="container stack-mobile" style={{
 padding: '40px 32px',
 display: 'grid',
 gridTemplateColumns: '1.1fr 1fr',
 gap: 40,
 alignItems: 'center',
 }}>
 <div>
 <div style={{
 fontSize: 11, fontWeight: 700, letterSpacing: '0.14em',
 textTransform: 'uppercase', color: '#C7D6EE',
 }}>The Ledger · monthly</div>
 <h2 style={{ fontSize: 24, fontWeight: 700, color: '#fff', margin: '12px 0 10px', lineHeight: 1.25 }}>
 Subscribe to The Ledger.
 </h2>
 <p style={{ fontSize: 14.5, lineHeight: 1.6, color: 'rgba(255,255,255,0.78)', margin: 0, maxWidth: 460 }}>
 One email a month: policy updates, research opportunities and community events, in three or four short items. Unsubscribe any time.
 </p>
 </div>
 {sent ? (
 <div role="status" style={{
 background: 'rgba(255,255,255,0.08)', borderLeft: '3px solid #4A7EC7',
 borderRadius: 5, padding: '16px 18px',
 }}>
 <strong style={{ display: 'block', color: '#fff', fontSize: 15, marginBottom: 4 }}>You are on the list.</strong>
 <span style={{ fontSize: 13.5, lineHeight: 1.55, color: 'rgba(255,255,255,0.78)' }}>Look out for the next issue. If it does not arrive, check your junk folder and add us to your contacts.</span>
 </div>
 ) : (
 <form onSubmit={submit} noValidate>
 <label htmlFor="footer-newsletter-email" style={{
 display: 'block', fontSize: 12.5, fontWeight: 600,
 color: 'rgba(255,255,255,0.82)', marginBottom: 8,
 }}>Email address</label>
 <div style={{ display: 'flex', gap: 10, flexWrap: 'wrap' }}>
 <input
 id="footer-newsletter-email"
 type="email"
 autoComplete="email"
 value={email}
 onChange={(e) => { setEmail(e.target.value); setError(''); }}
 placeholder="your@email.org.au"
 aria-describedby={error ? 'footer-newsletter-error' : 'footer-newsletter-privacy'}
 aria-invalid={error ? 'true' : undefined}
 style={{
 flex: '1 1 220px', minWidth: 0, boxSizing: 'border-box',
 fontFamily: 'inherit', fontSize: 15, padding: '13px 15px',
 border: '1.5px solid rgba(255,255,255,0.35)', borderRadius: 5,
 outline: 'none', color: '#0D1B2A', background: '#fff',
 }} />
 {/* Honeypot: invisible to people, irresistible to bots. */}
 <input ref={honeypotRef} type="text" name="website" tabIndex="-1" autoComplete="off" aria-hidden="true"
 style={{ position: 'absolute', left: -9999, top: 'auto', width: 1, height: 1, overflow: 'hidden' }} />
 <Button type="submit" variant="onTeal" disabled={busy}>{busy ? 'Saving…' : 'Subscribe'}</Button>
 </div>
 {error && (
 <div id="footer-newsletter-error" role="alert" style={{ marginTop: 10, fontSize: 13, lineHeight: 1.5, color: '#F3C9D9' }}>{error}</div>
 )}
 <div id="footer-newsletter-privacy" style={{ marginTop: 10, fontSize: 12, lineHeight: 1.5, color: 'rgba(255,255,255,0.62)' }}>
 We never share your address. Read our{' '}
 <a href="/privacy" onClick={(e)=>{e.preventDefault();navigate('privacy');}}
 style={{ color: 'rgba(255,255,255,0.82)' }}>privacy policy</a>.
 </div>
 </form>
 )}
 </div>
 </div>
 );
}

function Footer({ navigate }) {
 const cols = [
 {
 title: 'Support',
 links: [
 ['Newly diagnosed', 'newly-diagnosed'],
 ['Use our navigation tool', 'navigator'],
 ['Understand SCN2A & DEE', 'understand'],
 ['Seizure types & management', 'seizures'],
 ['NDIS Navigation', 'ndis'],
 ['Carer support', 'carers'],
 ]
 },
 {
 title: 'Driving change',
 links: [
 ['Our impact', 'impact'],
 ['Clinical trials', 'trials'],
 ['Research opportunities', 'research'],
 ['Publications', 'publications'],
 ['Global collaboration', 'global'],
 ['Blogs & news', 'news'],
 ]
 },
 {
 title: 'Get involved',
 links: [
 ['Donate or fundraise', 'https://give.scn2aaustralia.org/'],
 ['All ways to get involved', 'involved'],
 ['Partner with us', 'partners'],
 ]
 },
 {
 title: 'About',
 links: [
 ['Our story', 'about'],
 ['Our team', 'about'],
 ['Our impact', 'impact'],
 ['Partners', 'partners'],
 ['Contact us', 'contact'],
 ]
 },
 ];
 return (
 <footer style={{ background: '#1E3A6E', color: '#fff', marginTop: 0 }}>
 <FooterNewsletter navigate={navigate} />
 <div className="container stack-mobile" style={{
 padding: '40px 32px 20px',
 display: 'grid',
 gridTemplateColumns: '1.6fr repeat(4, 1fr)',
 gap: 32,
 }} >
 <div>
 <Logo variant="light" size="md" />
 <p style={{ fontSize: 14, lineHeight: 1.6, color: 'rgba(255,255,255,0.78)', marginTop: 22, maxWidth: 320 }}>
 The authoritative, family-led voice for SCN2A-related disorders, and the broader developmental and epileptic encephalopathy (DEE) community.
 </p>
 <div style={{ display: 'flex', gap: 2, marginTop: 18, marginLeft: -10, color: 'rgba(255,255,255,0.78)' }}>
 <a href="https://www.facebook.com/SCN2AAustralia" target="_blank" rel="noopener" aria-label="Facebook" style={{ color: 'inherit', display: 'inline-flex', alignItems: 'center', justifyContent: 'center', width: 44, height: 44 }}>
 <i data-lucide="facebook" style={{ width: 20, height: 20 }} />
 </a>
 <a href="https://www.instagram.com/scn2aaustralia" target="_blank" rel="noopener" aria-label="Instagram" style={{ color: 'inherit', display: 'inline-flex', alignItems: 'center', justifyContent: 'center', width: 44, height: 44 }}>
 <i data-lucide="instagram" style={{ width: 20, height: 20 }} />
 </a>
 <a href="https://www.linkedin.com/company/scn2a-australia" target="_blank" rel="noopener" aria-label="LinkedIn" style={{ color: 'inherit', display: 'inline-flex', alignItems: 'center', justifyContent: 'center', width: 44, height: 44 }}>
 <i data-lucide="linkedin" style={{ width: 20, height: 20 }} />
 </a>
 <a href="https://www.youtube.com/@scn2australia" target="_blank" rel="noopener" aria-label="YouTube" style={{ color: 'inherit', display: 'inline-flex', alignItems: 'center', justifyContent: 'center', width: 44, height: 44 }}>
 <i data-lucide="youtube" style={{ width: 20, height: 20 }} />
 </a>
 </div>
 <div style={{ marginTop: 28, padding: '14px 16px', background: 'rgba(255,255,255,0.06)', borderLeft: '3px solid #8E3B5E', fontSize: 13, lineHeight: 1.5 }}>
 <strong style={{ display: 'block', marginBottom: 4 }}>Need an interpreter?</strong>
 Call <span className="ledger-mono">TIS National 131 450</span> and ask for SCN2A Australia.
 </div>
 <a href="https://www.acnc.gov.au/charityregister" target="_blank" rel="noopener"
 style={{ display: 'inline-flex', marginTop: 22, width: 96, height: 96, padding: 6, background: 'rgba(255,255,255,0.04)', border: '1px solid rgba(255,255,255,0.10)', borderRadius: 0 }}
 aria-label="ACNC Registered Charity">
 <img src="assets/acnc-registered-charity.png" alt="ACNC Registered Charity"
 style={{ width: '100%', height: '100%', objectFit: 'contain' }} />
 </a>
 </div>
 {cols.map((c) => (
 <div key={c.title}>
 <div style={{
 fontSize: 11, fontWeight: 700, letterSpacing: '0.14em',
 textTransform: 'uppercase', color: '#C7D6EE', marginBottom: 16,
 }}>{c.title}</div>
 <ul style={{ listStyle: 'none', padding: 0, margin: 0, display: 'flex', flexDirection: 'column', gap: 10 }}>
 {c.links.map(([l, r]) => (
 <li key={l}>
 <a href={/^https?:/.test(r) ? r : hrefFor(r)}
 onClick={/^https?:/.test(r) ? undefined : (e)=>{e.preventDefault();navigate(r);}}
 style={{ color: 'rgba(255,255,255,0.88)', textDecoration: 'none', fontSize: 14 }}>
 {l}
 </a>
 </li>
 ))}
 </ul>
 </div>
 ))}
 </div>

 <div style={{ background: 'rgba(0,0,0,0.18)' }}>
 <div className="container" style={{ padding: '14px 32px 0', fontSize: 12, color: 'rgba(255,255,255,0.62)', lineHeight: 1.6 }}>
 Information on this site is general in nature and is not medical advice. Always talk to your child's or your own treating clinicians about diagnosis, treatment, and care decisions.
 </div>
 <div className="container" style={{
 padding: '12px 32px',
 display: 'flex', justifyContent: 'space-between', alignItems: 'center',
 flexWrap: 'wrap', gap: 12,
 fontSize: 12, color: 'rgba(255,255,255,0.62)',
 }}>
 <div>© 2026 SCN2A Australia Ltd · ABN 70 665 788 161 · Registered charity (ACNC)</div>
 <div style={{ display: 'flex', gap: 18, alignItems: 'center' }}>
 <a href="/privacy" onClick={(e)=>{e.preventDefault();navigate('privacy');}} style={{ color: 'rgba(255,255,255,0.62)' }}>Privacy</a>
 <a href="/about" onClick={(e)=>{e.preventDefault();navigate('about');}} style={{ color: 'rgba(255,255,255,0.62)' }}>Governance</a>
 <a href="/accessibility" onClick={(e)=>{e.preventDefault();navigate('accessibility');}} style={{ color: 'rgba(255,255,255,0.62)' }}>Accessibility</a>
 <span>Acknowledges the Traditional Owners of the lands on which we work.</span>
 </div>
 </div>
 </div>
 </footer>
 );
}

Object.assign(window, { Footer });
