<?php
/**
 * Newsletter CTA Section – Customizer Settings
 *
 * A branded call-to-action email opt-in banner section.
 * Completely different from Advertisement Banners (which are image/HTML ads).
 * This is an editorial CTA with heading, subtext, MailChimp/custom form shortcode,
 * and full background control.
 *
 * @package Blog_Over
 * @since   1.1.0
 */

// NOTE: Choice functions (blog_over_get_newsletter_layout_choices, etc.) are
// defined in inc/pro-filters.php to keep everything in one canonical place.

// ─────────────────────────────────────────────────────────────────────────────
// Register Customizer Section
// ─────────────────────────────────────────────────────────────────────────────

Kirki::add_section( 'blog_over_newsletter_section', array(
    'title'    => esc_html__( 'Newsletter / CTA Section', 'blog-over' ),
    'panel'    => 'blog_over_frontpage_panel',
    'priority' => 50,
) );

// ═══════════════════════════════════════════
// A) GENERAL SETTINGS HEADING
// ═══════════════════════════════════════════
Kirki::add_field( 'Blog_Over_config', array(
    'type'     => 'custom',
    'settings' => 'blog_over_newsletter_general_heading',
    'section'  => 'blog_over_newsletter_section',
    'default'  => '<div style="background:linear-gradient(135deg,#eff6ff,#dbeafe);padding:10px 14px;border-radius:6px;border-left:3px solid #3b82f6;"><span style="font-size:13px;font-weight:600;color:#1e40af;text-transform:uppercase;letter-spacing:.5px;">' . esc_html__( 'General Settings', 'blog-over' ) . '</span></div>',
    'priority' => 1,
) );

// ═══════════════════════════════════════════
// B) Enable Toggle
// ═══════════════════════════════════════════
Kirki::add_field( 'Blog_Over_config', array(
    'type'     => 'toggle',
    'settings' => 'blog_over_newsletter_enable',
    'label'    => esc_html__( 'Enable Newsletter / CTA Section', 'blog-over' ),
    'description' => esc_html__( 'Display a full-width call-to-action banner to collect email subscribers or promote anything.', 'blog-over' ),
    'section'  => 'blog_over_newsletter_section',
    'default'  => false,
    'priority' => 5,
    'partial_refresh' => array(
        'blog_over_newsletter_enable_refresh' => array(
            'selector'        => '.blog-over-newsletter-wrapper',
            'render_callback' => 'blog_over_render_newsletter_partial',
        ),
    ),
) );

// ═══════════════════════════════════════════
// C) Show On Pages
// ═══════════════════════════════════════════
Kirki::add_field( 'Blog_Over_config', array(
    'type'        => 'multicheck',
    'settings'    => 'blog_over_newsletter_show_on',
    'label'       => esc_html__( 'Show On Pages', 'blog-over' ),
    'description' => esc_html__( 'Select where this CTA section should appear on your site.', 'blog-over' ),
    'section'     => 'blog_over_newsletter_section',
    'default'     => array( 'home', 'blog' ),
    'priority'    => 6,
    'choices'     => array(
        'home'    => esc_html__( 'Home Page', 'blog-over' ),
        'blog'    => esc_html__( 'Blog / Posts Page', 'blog-over' ),
        'archive' => esc_html__( 'Archive Pages', 'blog-over' ),
        'single'  => esc_html__( 'Single Post', 'blog-over' ),
        'page'    => esc_html__( 'Single Page', 'blog-over' ),
    ),
    'active_callback' => array(
        array( 'setting' => 'blog_over_newsletter_enable', 'operator' => '==', 'value' => true ),
    ),
) );

// ═══════════════════════════════════════════
// D) Section Width
// ═══════════════════════════════════════════
Kirki::add_field( 'Blog_Over_config', array(
    'type'     => 'radio-buttonset',
    'settings' => 'blog_over_newsletter_section_width',
    'label'    => esc_html__( 'Section Width', 'blog-over' ),
    'section'  => 'blog_over_newsletter_section',
    'default'  => 'boxed',
    'priority' => 7,
    'choices'  => array(
        'boxed'      => esc_html__( 'Boxed', 'blog-over' ),
        'full-width' => esc_html__( 'Full Width', 'blog-over' ),
    ),
    'active_callback' => array(
        array( 'setting' => 'blog_over_newsletter_enable', 'operator' => '==', 'value' => true ),
    ),
) );

// ═══════════════════════════════════════════
// CONTENT HEADING
// ═══════════════════════════════════════════
Kirki::add_field( 'Blog_Over_config', array(
    'type'     => 'custom',
    'settings' => 'blog_over_newsletter_content_heading',
    'section'  => 'blog_over_newsletter_section',
    'default'  => '<div style="background:linear-gradient(135deg,#eff6ff,#dbeafe);padding:10px 14px;border-radius:6px;border-left:3px solid #3b82f6;margin-top:20px;"><span style="font-size:13px;font-weight:600;color:#1e40af;text-transform:uppercase;letter-spacing:.5px;">' . esc_html__( 'Content Settings', 'blog-over' ) . '</span></div>',
    'priority' => 9,
    'active_callback' => array(
        array( 'setting' => 'blog_over_newsletter_enable', 'operator' => '==', 'value' => true ),
    ),
) );

// ═══════════════════════════════════════════
// E) Pre-Heading Label
// ═══════════════════════════════════════════
Kirki::add_field( 'Blog_Over_config', array(
    'type'     => 'text',
    'settings' => 'blog_over_newsletter_pre_heading',
    'label'    => esc_html__( 'Pre-Heading Label', 'blog-over' ),
    'description' => esc_html__( 'Small text shown above the main heading. e.g. "Join 5,000+ readers"', 'blog-over' ),
    'section'  => 'blog_over_newsletter_section',
    'default'  => esc_html__( 'Join Our Community', 'blog-over' ),
    'priority' => 10,
    'active_callback' => array(
        array( 'setting' => 'blog_over_newsletter_enable', 'operator' => '==', 'value' => true ),
    ),
) );

// ═══════════════════════════════════════════
// F) Main Heading
// ═══════════════════════════════════════════
Kirki::add_field( 'Blog_Over_config', array(
    'type'     => 'text',
    'settings' => 'blog_over_newsletter_heading',
    'label'    => esc_html__( 'Main Heading', 'blog-over' ),
    'description' => esc_html__( 'The primary headline for the CTA section.', 'blog-over' ),
    'section'  => 'blog_over_newsletter_section',
    'default'  => esc_html__( 'Never Miss an Article', 'blog-over' ),
    'priority' => 11,
    'active_callback' => array(
        array( 'setting' => 'blog_over_newsletter_enable', 'operator' => '==', 'value' => true ),
    ),
    'partial_refresh' => array(
        'blog_over_newsletter_heading_refresh' => array(
            'selector'        => '.blog-over-newsletter-heading',
            'render_callback' => function() {
                return esc_html( get_theme_mod( 'blog_over_newsletter_heading', __( 'Never Miss an Article', 'blog-over' ) ) );
            },
        ),
    ),
) );

// ═══════════════════════════════════════════
// G) Sub-text / Description
// ═══════════════════════════════════════════
Kirki::add_field( 'Blog_Over_config', array(
    'type'     => 'text',
    'settings' => 'blog_over_newsletter_subtext',
    'label'    => esc_html__( 'Sub-text / Description', 'blog-over' ),
    'description' => esc_html__( 'A short line of text displayed below the heading to encourage sign-ups.', 'blog-over' ),
    'section'  => 'blog_over_newsletter_section',
    'default'  => esc_html__( 'Subscribe to get the latest articles, news, and updates delivered straight to your inbox. No spam, ever.', 'blog-over' ),
    'priority' => 12,
    'active_callback' => array(
        array( 'setting' => 'blog_over_newsletter_enable', 'operator' => '==', 'value' => true ),
    ),
) );

// ═══════════════════════════════════════════
// H) Form Shortcode
// ═══════════════════════════════════════════
Kirki::add_field( 'Blog_Over_config', array(
    'type'     => 'text',
    'settings' => 'blog_over_newsletter_shortcode',
    'label'    => esc_html__( 'Newsletter Form Shortcode', 'blog-over' ),
    'description' => esc_html__( 'Paste your email form shortcode here. Works with MailChimp, MailPoet, FluentForms, WPForms, etc. e.g. [mc4wp_form id="123"]', 'blog-over' ),
    'section'  => 'blog_over_newsletter_section',
    'default'  => '',
    'priority' => 13,
    'active_callback' => array(
        array( 'setting' => 'blog_over_newsletter_enable', 'operator' => '==', 'value' => true ),
    ),
) );

// ═══════════════════════════════════════════
// DESIGN SETTINGS HEADING
// ═══════════════════════════════════════════
Kirki::add_field( 'Blog_Over_config', array(
    'type'     => 'custom',
    'settings' => 'blog_over_newsletter_design_heading',
    'section'  => 'blog_over_newsletter_section',
    'default'  => '<div style="background:linear-gradient(135deg,#eff6ff,#dbeafe);padding:10px 14px;border-radius:6px;border-left:3px solid #3b82f6;margin-top:20px;"><span style="font-size:13px;font-weight:600;color:#1e40af;text-transform:uppercase;letter-spacing:.5px;">' . esc_html__( 'Design & Style', 'blog-over' ) . '</span></div>',
    'priority' => 18,
    'active_callback' => array(
        array( 'setting' => 'blog_over_newsletter_enable', 'operator' => '==', 'value' => true ),
    ),
) );

// ═══════════════════════════════════════════
// I) Layout Style
// ═══════════════════════════════════════════
Kirki::add_field( 'Blog_Over_config', array(
    'type'     => 'radio-buttonset',
    'settings' => 'blog_over_newsletter_layout',
    'label'    => esc_html__( 'Section Layout', 'blog-over' ),
    'description' => esc_html__( 'Centered is free. Split layout (text left + form right) is available in Pro.', 'blog-over' ),
    'section'  => 'blog_over_newsletter_section',
    'default'  => 'centered',
    'priority' => 19,
    'choices'  => blog_over_get_newsletter_layout_choices(),
    'sanitize_callback' => 'blog_over_sanitize_select',
    'active_callback' => array(
        array( 'setting' => 'blog_over_newsletter_enable', 'operator' => '==', 'value' => true ),
    ),
) );

// ═══════════════════════════════════════════
// J) Background Type
// ═══════════════════════════════════════════
Kirki::add_field( 'Blog_Over_config', array(
    'type'     => 'radio-buttonset',
    'settings' => 'blog_over_newsletter_bg_type',
    'label'    => esc_html__( 'Background Type', 'blog-over' ),
    'section'  => 'blog_over_newsletter_section',
    'default'  => 'gradient',
    'priority' => 20,
    'choices'  => blog_over_get_newsletter_bg_type_choices(),
    'sanitize_callback' => 'blog_over_sanitize_select',
    'active_callback' => array(
        array( 'setting' => 'blog_over_newsletter_enable', 'operator' => '==', 'value' => true ),
    ),
) );

// ═══════════════════════════════════════════
// K) Solid Background Color (when type = solid)
// ═══════════════════════════════════════════
Kirki::add_field( 'Blog_Over_config', array(
    'type'     => 'color',
    'settings' => 'blog_over_newsletter_bg_color',
    'label'    => esc_html__( 'Background Color', 'blog-over' ),
    'section'  => 'blog_over_newsletter_section',
    'default'  => '#1e293b',
    'priority' => 21,
    'choices'  => array( 'alpha' => true ),
    'active_callback' => array(
        array( 'setting' => 'blog_over_newsletter_enable', 'operator' => '==', 'value' => true ),
        array( 'setting' => 'blog_over_newsletter_bg_type', 'operator' => '==', 'value' => 'solid' ),
    ),
) );

// ═══════════════════════════════════════════
// L) Gradient Start Color
// ═══════════════════════════════════════════
Kirki::add_field( 'Blog_Over_config', array(
    'type'     => 'color',
    'settings' => 'blog_over_newsletter_gradient_start',
    'label'    => esc_html__( 'Gradient Start Color', 'blog-over' ),
    'section'  => 'blog_over_newsletter_section',
    'default'  => '#1e40af',
    'priority' => 22,
    'active_callback' => array(
        array( 'setting' => 'blog_over_newsletter_enable', 'operator' => '==', 'value' => true ),
        array( 'setting' => 'blog_over_newsletter_bg_type', 'operator' => '==', 'value' => 'gradient' ),
    ),
) );

// ═══════════════════════════════════════════
// M) Gradient End Color
// ═══════════════════════════════════════════
Kirki::add_field( 'Blog_Over_config', array(
    'type'     => 'color',
    'settings' => 'blog_over_newsletter_gradient_end',
    'label'    => esc_html__( 'Gradient End Color', 'blog-over' ),
    'section'  => 'blog_over_newsletter_section',
    'default'  => '#7c3aed',
    'priority' => 23,
    'active_callback' => array(
        array( 'setting' => 'blog_over_newsletter_enable', 'operator' => '==', 'value' => true ),
        array( 'setting' => 'blog_over_newsletter_bg_type', 'operator' => '==', 'value' => 'gradient' ),
    ),
) );

// ═══════════════════════════════════════════
// N) Text Color
// ═══════════════════════════════════════════
Kirki::add_field( 'Blog_Over_config', array(
    'type'     => 'radio-buttonset',
    'settings' => 'blog_over_newsletter_text_color',
    'label'    => esc_html__( 'Text Color Mode', 'blog-over' ),
    'description' => esc_html__( 'Choose light text for dark backgrounds, or dark text for light backgrounds.', 'blog-over' ),
    'section'  => 'blog_over_newsletter_section',
    'default'  => 'light',
    'priority' => 24,
    'choices'  => array(
        'light' => esc_html__( 'Light (White)', 'blog-over' ),
        'dark'  => esc_html__( 'Dark', 'blog-over' ),
    ),
    'active_callback' => array(
        array( 'setting' => 'blog_over_newsletter_enable', 'operator' => '==', 'value' => true ),
    ),
) );

// ═══════════════════════════════════════════
// O) Section Padding
// ═══════════════════════════════════════════
Kirki::add_field( 'Blog_Over_config', array(
    'type'     => 'slider',
    'settings' => 'blog_over_newsletter_padding',
    'label'    => esc_html__( 'Section Vertical Padding (px)', 'blog-over' ),
    'section'  => 'blog_over_newsletter_section',
    'default'  => 80,
    'priority' => 25,
    'choices'  => array( 'min' => 30, 'max' => 160, 'step' => 5 ),
    'transport' => 'auto',
    'output'   => array(
        array(
            'element'  => '.blog-over-newsletter-wrapper',
            'property' => 'padding-top',
            'units'    => 'px',
        ),
        array(
            'element'  => '.blog-over-newsletter-wrapper',
            'property' => 'padding-bottom',
            'units'    => 'px',
        ),
    ),
    'active_callback' => array(
        array( 'setting' => 'blog_over_newsletter_enable', 'operator' => '==', 'value' => true ),
    ),
) );
