<?php
namespace IcreatorCookieConsent;

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

class Plugin {
    private static $instance;

    public static function instance(): self {
        return self::$instance ?: self::$instance = new self();
    }

    public function boot(): void {
        // Core services
        Ajax::boot();

        if (is_admin()) {
            Utils::boot();
            Settings::boot();
            Admin::boot();
        } else {
            Frontend::boot();
        }
    }

    public static function activate(): void {
        update_option('iccb_banner_position', 'bottom');
        update_option('iccb_layout_style', 'full');
        update_option('iccb_overlay_mode', 'none');
    }

    public static function deactivate(): void {
        return;
    }

    public static function uninstall(): void {
        // If it's multisite, loop through each site
        if (is_multisite()) {
            $sites = get_sites();
            foreach ($sites as $site) {
                switch_to_blog($site->blog_id);
                self::cleanup_plugin_data();
                restore_current_blog();
            }
        } else {
            self::cleanup_plugin_data();
        }
    }
    
    /**
     * Clean up plugin data
     */
    public static function cleanup_plugin_data(): void  {
        // Delete plugin options
        delete_option('iccb_accent_color');
        delete_option('iccb_banner_title');
        delete_option('iccb_banner_position');
        delete_option('iccb_layout_style');
        delete_option('iccb_banner_font_size');
        delete_option('iccb_button_style');
        delete_option('iccb_button_radius');
        delete_option('iccb_default_categories');
        delete_option('iccb_accept_text');
        delete_option('iccb_decline_text');
        delete_option('iccb_save_preference_text');
        delete_option('iccb_banner_text');
        delete_option('iccb_overlay_mode');
        delete_option('iccb_banner_font_family');
        delete_option('iccb_manage_preference_text');
        delete_option('iccb_actions_preset');
        delete_option('iccb_learn_more_text');
        delete_option('iccb_learn_more_page');
        delete_option('iccb_cookie_definitions');
    }
}
