<?php
if (!defined('WP_UNINSTALL_PLUGIN')) {
    exit;
}

function seekmake_core_uninstall_cleanup() {
    // Delete the hidden WooCommerce product if it exists
    $wc_product_id = get_option('seekmake_wc_product_id', 0);
    if ($wc_product_id && function_exists('wp_delete_post')) {
        wp_delete_post($wc_product_id, true);
    }

    delete_option('seekmake_manufacturer_id');
    delete_option('seekmake_authenticated');
    delete_option('seekmake_user_email');
    delete_option('seekmake_settings');
    delete_option('seekmake_version');
    delete_option('seekmake_woocommerce_enabled');
    delete_option('seekmake_wc_product_id');
    
    delete_transient('seekmake_auth_check');
    delete_transient('seekmake_api_cache');
    
    if (is_multisite()) {
        global $wpdb;
        
        $blog_ids = $wpdb->get_col("SELECT blog_id FROM {$wpdb->blogs}");
        
        foreach ($blog_ids as $blog_id) {
            switch_to_blog($blog_id);
            
            $wc_product_id = get_option('seekmake_wc_product_id', 0);
            if ($wc_product_id && function_exists('wp_delete_post')) {
                wp_delete_post($wc_product_id, true);
            }

            delete_option('seekmake_manufacturer_id');
            delete_option('seekmake_authenticated');
            delete_option('seekmake_user_email');
            delete_option('seekmake_settings');
            delete_option('seekmake_version');
            delete_option('seekmake_woocommerce_enabled');
            delete_option('seekmake_wc_product_id');
            
            delete_transient('seekmake_auth_check');
            delete_transient('seekmake_api_cache');
            
            restore_current_blog();
        }
    }
}

seekmake_core_uninstall_cleanup();
