// Final CTA band — navy, sits between the contact form and the footer. The brand
// signature stroke draws itself in when the band scrolls into view.
const { useState: useStateCb, useRef: useRefCb } = React;
const useEffectCb = React.useLayoutEffect;

function SigStroke() {
  const ref = useRefCb(null);
  const [seen, setSeen] = useStateCb(false);
  const staticRender = useStaticRender();
  useEffectCb(() => {
    if (staticRender) { setSeen(true); return; }
    const el = ref.current;
    if (!el || !('IntersectionObserver' in window)) { setSeen(true); return; }
    const io = new IntersectionObserver((entries) => {
      entries.forEach((e) => { if (e.isIntersecting) { setSeen(true); io.unobserve(e.target); } });
    }, { threshold: 0.4 });
    io.observe(el);
    return () => io.disconnect();
  }, [staticRender]);
  return (
    <svg ref={ref} viewBox="0 0 280 28" fill="none" aria-hidden="true" style={{ display: 'block', width: 'clamp(180px,24vw,280px)', height: 'auto', margin: '0 auto' }}>
      <path
        d="M6 20 C 64 8, 150 6, 204 12 C 232 15, 252 19, 274 14"
        pathLength="1"
        stroke="#FFCC57"
        strokeWidth="4.5"
        strokeLinecap="round"
        style={{
          strokeDasharray: 1,
          strokeDashoffset: seen ? 0 : 1,
          transition: staticRender ? 'none' : 'stroke-dashoffset 1100ms ' + EASE + ' 150ms',
        }}
      />
    </svg>
  );
}

function CtaBand() {
  const mag = useMagnetic(3);
  return (
    <section data-dark="true" className="relative overflow-hidden" style={{ background: '#1A3066', paddingTop: 'clamp(56px,8vw,88px)', paddingBottom: 'clamp(56px,8vw,88px)', borderBottom: '1px solid rgba(255,255,255,0.1)' }}>
      <Grain opacity={0.07} />
      <Blob color="#FFCC57" size={320} opacity={0.09} blur={12} speed={22} rotate={5} style={{ top: '-130px', left: '6%' }} />
      <Blob color="#4A6FA4" size={340} opacity={0.3} blur={14} speed={-18} rotate={-5} style={{ bottom: '-140px', right: '-60px' }} />

      <div className="relative mx-auto max-w-[860px] px-5 text-center sm:px-7">
        <Reveal as="h2" className="mx-auto font-display font-normal text-white" style={{ fontSize: 'clamp(30px,4.6vw,52px)', lineHeight: 1.1, letterSpacing: '-0.015em', maxWidth: '18ch' }}>
          Your Will, <em style={{ fontStyle: 'italic', color: '#FFCC57' }}>your way.</em> Ready when you are.
        </Reveal>
        <Reveal delay={100} className="mt-3">
          <SigStroke />
        </Reveal>
        <Reveal delay={160} as="p" className="mx-auto mt-4 font-sans" style={{ fontSize: 16.5, lineHeight: 1.65, color: 'rgba(255,255,255,0.85)', maxWidth: '46ch' }}>
          A friendly chat costs nothing and sorts a lot. Talk to us today, with no obligation and no jargon.
        </Reveal>
        <Reveal delay={230} className="mt-8 flex flex-col items-center justify-center gap-3 sm:flex-row">
          <a
            ref={mag.ref}
            onMouseMove={mag.onMouseMove}
            onMouseLeave={mag.onMouseLeave}
            href={PHONE_TEL}
            className="cta-sheen inline-flex items-center justify-center gap-2 rounded-full bg-gold px-8 py-4 font-sans font-semibold text-[17px] text-navy hover:bg-gold-deep"
            style={{ boxShadow: '0 18px 38px -14px rgba(240,184,60,0.8)', transition: 'transform 250ms ' + EASE + ', background-color 250ms ' + EASE }}
          >
            <Icon name="phone" size={18} strokeWidth={2} className="ico-ring" />
            Call {PHONE_DISPLAY}
          </a>
          <a
            href={WHATSAPP_URL}
            target="_blank"
            rel="noopener noreferrer"
            className="inline-flex items-center justify-center gap-2 rounded-full px-8 py-4 font-sans font-semibold text-[17px] text-white"
            style={{ boxShadow: 'inset 0 0 0 1.5px rgba(255,255,255,0.55)', transition: 'background-color 250ms ' + EASE }}
            onMouseEnter={(e) => (e.currentTarget.style.background = 'rgba(255,255,255,0.1)')}
            onMouseLeave={(e) => (e.currentTarget.style.background = 'transparent')}
          >
            <Icon name="whatsapp" size={19} />
            WhatsApp us
          </a>
        </Reveal>
        <Reveal delay={300} as="p" className="mt-5 font-sans" style={{ fontSize: 13.5, color: 'rgba(255,255,255,0.6)' }}>
          Home visits across Somerset, or online anywhere in England and Wales.
        </Reveal>
      </div>
    </section>
  );
}

Object.assign(window, { CtaBand });
