<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
/**
 * Fired during plugin activation.
 *
 * This class defines all code necessary to run during the plugin's activation.
 *
 * @since      1.0.0
 * @package    Woocommerce_Conditional_Product_Fees_For_Checkout_Pro
 * @subpackage Woocommerce_Conditional_Product_Fees_For_Checkout_Pro/includes
 * @author     Multidots <inquiry@multidots.in>
 */
class Woocommerce_Conditional_Product_Fees_For_Checkout_Pro_Activator {
	/**
	 * Short Description. (use period)
	 *
	 * Long Description.
	 *
	 * @since    1.0.0
	 */
	public static function activate() {
		set_transient( '_welcome_screen_wcpfc_pro_mode_activation_redirect_data', true, 30 );
		add_option( 'wcpfc_version', Woocommerce_Conditional_Product_Fees_For_Checkout_Pro::WCPFC_VERSION );
		if ( ! in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ), true ) && ! is_plugin_active_for_network( 'woocommerce/woocommerce.php' ) ) {
			wp_die( "<strong> WooCommerce Extra Fees Plugin</strong> Plugin requires <strong>WooCommerce</strong> <a href='" . esc_url( get_admin_url( null, 'plugins.php' ) ) . "'>Plugins page</a>." );
		} else {
			set_transient( '_welcome_screen_activation_redirect_data', true, 30 );
		}

        // Check if the plugin is activated on a multisite network (Popup = per site, because each site owner/admin experience differs.)
        if ( is_multisite() ) {

            foreach ( get_sites( [ 'fields' => 'ids' ] ) as $blog_id ) {
                // We only need to switch DB context to access post data.
                // No plugins, themes, or hooks from the target blog are required.
                switch_to_blog( $blog_id ); // phpcs:ignore 

                // New install → mark feature as introduced NOW
                update_option( 'wcpfc_popup_feature_introduced', time() );

                if ( ! get_option( 'wcpfc_installed_at' ) ) {
                    update_option( 'wcpfc_installed_at', time() );
                }

                restore_current_blog();
            }
        } else {

            // New install → mark feature as introduced NOW
            update_option( 'wcpfc_popup_feature_introduced', time() );

            if ( ! get_option( 'wcpfc_installed_at' ) ) {
                update_option( 'wcpfc_installed_at', time() );
            }
        }
	}
}
