// Reusable in-flow CTA banner and a mobile-only sticky CTA bar.
// Both invoke the same openCallback() handler passed from App.

// In-flow banner: full-bleed strip, Borderless palette.
// `variant`: 'dark' (default, charcoal) | 'light' (cream)
function CTABanner({ lang, openCallback, variant = 'dark', kicker, title, body, cta }) {
  const t = (ru, en) => (lang === 'ru' ? ru : en);
  const dark = variant === 'dark';
  return (
    // `dark-section` makes `.display em` render in the brand-book beige
    // (rgba(255,232,192,.85)) instead of dark green — unreadable on #191C1F
    // (Nastya, 11.06). Applies to the dark variant only.
    <section className={dark ? 'dark-section' : undefined} style={{
      background: dark ? '#191C1F' : '#F4F4F2',
      color: dark ? '#FFFFFF' : '#191C1F',
      padding: '56px 0',
      borderTop: '1px solid', borderColor: dark ? 'rgba(255,255,255,0.08)' : 'var(--border)',
      borderBottom: '1px solid', borderBottomColor: dark ? 'rgba(255,255,255,0.08)' : 'var(--border)',
    }}>
      <div className="container-wide" style={{
        display: 'grid', gridTemplateColumns: '1.5fr auto', gap: 32,
        alignItems: 'center',
      }}>
        <div>
          {kicker && (
            <div className="mono" style={{
              fontSize: 11, letterSpacing: '0.14em', textTransform: 'uppercase',
              color: dark ? 'rgba(255,255,255,0.62)' : 'var(--fg-muted)',
              marginBottom: 12,
            }}>– {kicker}</div>
          )}
          <h3 className="display" style={{
            margin: 0,
            fontSize: 'clamp(24px, 2.6vw, 36px)', lineHeight: 1.1, letterSpacing: '-0.02em',
            maxWidth: 640, fontWeight: 700,
          }}>{title}</h3>
          {body && (
            <p style={{
              margin: '12px 0 0', fontSize: 15, lineHeight: 1.55, maxWidth: 560,
              color: dark ? 'rgba(255,255,255,0.74)' : 'var(--fg-muted)',
            }}>{body}</p>
          )}
        </div>
        <button onClick={openCallback}
                style={{
                  height: 56, padding: '0 28px',
                  background: dark ? '#FFFFFF' : '#191C1F',
                  color:      dark ? '#191C1F' : '#FFFFFF',
                  border: '1px solid', borderColor: dark ? '#FFFFFF' : '#191C1F',
                  fontSize: 13, fontWeight: 600, letterSpacing: '0.04em',
                  textTransform: 'uppercase', fontFamily: 'var(--f-sans)',
                  cursor: 'pointer', transition: 'opacity .15s',
                  whiteSpace: 'nowrap',
                }}
                onMouseEnter={(e) => { e.currentTarget.style.opacity = '0.88'; }}
                onMouseLeave={(e) => { e.currentTarget.style.opacity = '1'; }}>
          {cta || t('Бесплатная консультация →', 'Free consultation →')}
        </button>
      </div>
    </section>
  );
}

// Mobile-only sticky CTA bar – appears once user scrolls past hero.
function StickyCTA({ lang, openCallback }) {
  const t = (ru, en) => (lang === 'ru' ? ru : en);
  const [visible, setVisible] = React.useState(false);

  React.useEffect(() => {
    const onScroll = () => {
      // Show after scrolling past first viewport height
      setVisible(window.scrollY > window.innerHeight * 0.65);
    };
    window.addEventListener('scroll', onScroll, { passive: true });
    onScroll();
    return () => window.removeEventListener('scroll', onScroll);
  }, []);

  return (
    <>
      <div className="sticky-cta-mobile" style={{
        position: 'fixed', left: 0, right: 0, bottom: 0,
        zIndex: 95,
        padding: '10px 12px env(safe-area-inset-bottom, 12px)',
        background: '#191C1F',
        borderTop: '1px solid rgba(255,255,255,0.12)',
        transform: visible ? 'translateY(0)' : 'translateY(100%)',
        transition: 'transform .25s var(--ease-out)',
        boxShadow: '0 -6px 24px rgba(0,0,0,0.18)',
      }}>
        <button onClick={openCallback}
                style={{
                  width: '100%', height: 50,
                  background: '#FFFFFF', color: '#191C1F',
                  border: 0,
                  fontSize: 13, fontWeight: 700, letterSpacing: '0.04em',
                  textTransform: 'uppercase', fontFamily: 'var(--f-sans)',
                  cursor: 'pointer',
                }}>
          {t('Бесплатная консультация →', 'Free consultation →')}
        </button>
      </div>
      <style dangerouslySetInnerHTML={{ __html: `
        .sticky-cta-mobile { display: none; }
        @media (max-width: 768px) {
          .sticky-cta-mobile { display: block; }
          .ai-fab { bottom: 84px !important; }
        }
      `}} />
    </>
  );
}

window.CTABanner = CTABanner;
window.StickyCTA = StickyCTA;
