<?php
/**
 * Newsletter Module Settings Schema
 * 
 * Example of schema-based settings for the Newsletter module
 * 
 * @package WooNooW\Modules
 */

namespace WooNooW\Modules;

class NewsletterSettings {
    
    public static function init() {
        // Register settings schema
        add_filter('woonoow/module_settings_schema', [__CLASS__, 'register_schema']);
    }
    
    /**
     * Register newsletter settings schema
     */
    public static function register_schema($schemas) {
        $schemas['newsletter'] = [
            'sender_name' => [
                'type' => 'text',
                'label' => __('Sender Name', 'woonoow'),
                'description' => __('The name that appears in the "From" field of newsletter emails', 'woonoow'),
                'placeholder' => get_bloginfo('name'),
                'default' => get_bloginfo('name'),
                'required' => true,
            ],
            'sender_email' => [
                'type' => 'email',
                'label' => __('Sender Email', 'woonoow'),
                'description' => __('The email address that appears in the "From" field', 'woonoow'),
                'placeholder' => get_option('admin_email'),
                'default' => get_option('admin_email'),
                'required' => true,
            ],
            'reply_to_email' => [
                'type' => 'email',
                'label' => __('Reply-To Email', 'woonoow'),
                'description' => __('Email address for replies (leave empty to use sender email)', 'woonoow'),
                'placeholder' => get_option('admin_email'),
            ],
            'double_opt_in' => [
                'type' => 'toggle',
                'label' => __('Double Opt-In', 'woonoow'),
                'description' => __('Require subscribers to confirm their email address before being added to the list', 'woonoow'),
                'default' => true,
            ],
            'welcome_email' => [
                'type' => 'toggle',
                'label' => __('Send Welcome Email', 'woonoow'),
                'description' => __('Automatically send a welcome email to new subscribers', 'woonoow'),
                'default' => true,
            ],
            'unsubscribe_page' => [
                'type' => 'select',
                'label' => __('Unsubscribe Page', 'woonoow'),
                'description' => __('Page to redirect users after unsubscribing', 'woonoow'),
                'placeholder' => __('-- Select Page --', 'woonoow'),
                'options' => self::get_pages_options(),
            ],
            'gdpr_consent' => [
                'type' => 'toggle',
                'label' => __('GDPR Consent Checkbox', 'woonoow'),
                'description' => __('Show a consent checkbox on subscription forms (recommended for EU compliance)', 'woonoow'),
                'default' => false,
            ],
            'consent_text' => [
                'type' => 'textarea',
                'label' => __('Consent Text', 'woonoow'),
                'description' => __('Text shown next to the consent checkbox', 'woonoow'),
                'placeholder' => __('I agree to receive marketing emails', 'woonoow'),
                'default' => __('I agree to receive marketing emails and understand I can unsubscribe at any time.', 'woonoow'),
            ],
            // Campaign Settings
            'campaign_scheduling' => [
                'type' => 'toggle',
                'label' => __('Campaign Scheduling', 'woonoow'),
                'description' => __('Enable scheduled campaigns. When on, you can schedule campaigns to be sent at a specific date and time.', 'woonoow'),
                'default' => false,
            ],
            'subscriber_limit_enabled' => [
                'type' => 'toggle',
                'label' => __('Subscriber Limit', 'woonoow'),
                'description' => __('Limit subscribers to 1000. When disabled, a custom database table will be created for unlimited subscribers.', 'woonoow'),
                'default' => true,
            ],
            'subscriber_limit' => [
                'type' => 'number',
                'label' => __('Max Subscribers', 'woonoow'),
                'description' => __('Maximum number of subscribers when limit is enabled (default: 1000)', 'woonoow'),
                'default' => 1000,
            ],
        ];
        
        return $schemas;
    }
    
    /**
     * Get pages as options for select field
     */
    private static function get_pages_options() {
        $pages = get_pages();
        $options = [];
        
        foreach ($pages as $page) {
            $options[$page->ID] = $page->post_title;
        }
        
        return $options;
    }
}
