<?php

namespace fluXtore\Core\Settings;

if (!defined('ABSPATH')) {
    exit;
}

if (!class_exists('fluXtore_Analytics_Settings')) {
    class fluXtore_Analytics_Settings {
        /** @var self|null */
        private static $instance = null;

        private function __construct() {}

        public static function init() {
            if (null !== self::$instance) {
                return;
            }

            self::$instance = new self();
            add_action('fluxtore_register_options', [self::$instance, 'add_options']);
        }

        public function add_options() {
            fluXtore_Settings::register_option('analytics', 'analytics_benchmark_opt_in', [
                'type' => 'bool',
                'label' => __('Share anonymized funnel benchmarks', 'fluxtore'),
                'description' => __('Enable this to contribute aggregated, anonymous funnel data to improve benchmark insights.', 'fluxtore'),
                'section' => 'analytics_benchmarks',
                'default' => (bool) fluXtore_Settings::get('analytics_benchmark_opt_in', false),
            ]);

            fluXtore_Settings::register_option('analytics', 'analytics_benchmark_schedule_enabled', [
                'type' => 'bool',
                'label' => __('Enable scheduled benchmark aggregation', 'fluxtore'),
                'description' => __('Allows fluXtore to collect funnel metrics on the defined WP-Cron schedule.', 'fluxtore'),
                'section' => 'analytics_benchmarks',
                'default' => (bool) fluXtore_Settings::get('analytics_benchmark_schedule_enabled', true),
            ]);

            fluXtore_Settings::register_option('analytics', 'analytics_benchmark_schedule', [
                'type' => 'select',
                'label' => __('Aggregation frequency', 'fluxtore'),
                'description' => __('Choose how often the benchmark data should be refreshed.', 'fluxtore'),
                'section' => 'analytics_benchmarks',
                'default' => fluXtore_Settings::get('analytics_benchmark_schedule', 'daily'),
                'options' => [
                    'hourly' => __('Hourly', 'fluxtore'),
                    'twicedaily' => __('Twice daily', 'fluxtore'),
                    'daily' => __('Daily', 'fluxtore'),
                    'weekly' => __('Weekly', 'fluxtore'),
                ],
            ]);
        }
    }
}

fluXtore_Analytics_Settings::init();
