import React, { CSSProperties } from 'react'; import { useNode, UserComponent } from '@craftjs/core'; import { cssPropsToString } from '../../utils/style-helpers'; import { CtaButton, CtasEditor, normalizeCtas, ctaInlineStyle, ctasToHtml } from './_cta-helpers'; import { AnchorIdField } from '../../ui/AnchorIdField'; interface CTASectionProps { heading?: string; description?: string; ctas?: CtaButton[]; /** Legacy props kept for backward compat with saved projects. */ buttonText?: string; buttonHref?: string; gradient?: string; anchorId?: string; style?: CSSProperties; } const defaultGradient = 'linear-gradient(135deg, #2563eb 0%, #7c3aed 100%)'; export const CTASection: UserComponent = ({ heading = 'Ready to Get Started?', description = 'Join thousands of satisfied users and start building your dream website today.', ctas, buttonText, buttonHref, gradient = defaultGradient, anchorId, style = {}, }) => { const { connectors: { connect, drag }, selected, } = useNode((node) => ({ selected: node.events.selected, })); const effectiveCtas = normalizeCtas({ ctas, buttonText, buttonHref }); const ctaDefaults = { primaryBg: '#ffffff', primaryText: '#18181b', outlineText: '#ffffff' }; return (
{ if (ref) connect(drag(ref)); }} id={anchorId || undefined} style={{ background: gradient, padding: '80px 20px', textAlign: 'center', outline: selected ? '2px solid #3b82f6' : 'none', ...style, }} >

{heading}

{description}

{effectiveCtas.map((cta, i) => ( e.preventDefault()} style={ctaInlineStyle(cta, ctaDefaults)}> {cta.text} ))}
); }; /* ---------- Settings panel ---------- */ const CTASectionSettings: React.FC = () => { const { actions: { setProp }, props } = useNode((node) => ({ props: node.data.props as CTASectionProps, })); const gradientPresets = [ { label: 'Blue-Purple', value: 'linear-gradient(135deg, #2563eb 0%, #7c3aed 100%)' }, { label: 'Purple', value: 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)' }, { label: 'Teal', value: 'linear-gradient(135deg, #0d9488 0%, #0f766e 100%)' }, { label: 'Sunset', value: 'linear-gradient(135deg, #f97316 0%, #ec4899 100%)' }, { label: 'Dark', value: 'linear-gradient(135deg, #1e293b 0%, #0f172a 100%)' }, { label: 'Ocean', value: 'linear-gradient(135deg, #0ea5e9 0%, #6366f1 100%)' }, ]; const effectiveCtas = normalizeCtas(props); return (
setProp((p: CTASectionProps) => { p.heading = e.target.value; })} style={{ width: '100%', padding: '4px 8px', background: '#27272a', color: '#e4e4e7', border: '1px solid #3f3f46', borderRadius: 4, fontSize: 12 }} />