<?php

/**
 * Plugin Name: VoidPulse - Social Proof Notifications for WooCommerce
 * Description: Turn WooCommerce sales into powerful social proof that builds trust, creates urgency, and helps shoppers buy with confidence.
 * Version:     1.0.0
 * Author:      WPVOID
 * License:     GPL-2.0-or-later
 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
 * Text Domain: voidpulse-social-proof-for-woocommerce
 * Domain Path: /languages
 * Requires at least: 6.2
 * Requires PHP: 7.4
 * Requires Plugins: woocommerce
 * WC requires at least: 8.0
 * WC tested up to: 11.0
 *
 *
 * @package VoidPulse
 */
defined( 'ABSPATH' ) || exit;
if ( function_exists( 'voidpulse_fs' ) ) {
    /*
     * Freemius uses the paid plugin basename to deactivate the Free edition
     * when both editions are present.
     */
    voidpulse_fs()->set_basename( false, __FILE__ );
} else {
    define( 'VOIDPULSE_VERSION', '1.0.0' );
    define( 'VOIDPULSE_SCHEMA_VERSION', '1.0.0' );
    define( 'VOIDPULSE_FILE', __FILE__ );
    define( 'VOIDPULSE_BASENAME', plugin_basename( __FILE__ ) );
    define( 'VOIDPULSE_PATH', plugin_dir_path( __FILE__ ) );
    define( 'VOIDPULSE_URL', plugin_dir_url( __FILE__ ) );
    define( 'VOIDPULSE_TEXT_DOMAIN', 'voidpulse-social-proof-for-woocommerce' );
    /**
     * Do not remove this condition. The early function_exists() branch above
     * depends on this helper being declared only when no other edition loaded it.
     */
    if ( !function_exists( 'voidpulse_fs' ) ) {
        /**
         * Return the Freemius SDK instance, or null when the bundled SDK is absent.
         *
         * @return Freemius|null
         */
        function voidpulse_fs() {
            global $voidpulse_fs;
            if ( isset( $voidpulse_fs ) ) {
                return $voidpulse_fs;
            }
            $start_file = VOIDPULSE_PATH . 'vendor/freemius/start.php';
            if ( !is_readable( $start_file ) ) {
                return null;
            }
            require_once $start_file;
            if ( !function_exists( 'fs_dynamic_init' ) ) {
                return null;
            }
            $voidpulse_fs = fs_dynamic_init( array(
                'id'               => '35834',
                'slug'             => 'voidpulse-social-proof-for-woocommerce',
                'premium_slug'     => 'voidpulse-social-proof-for-woocommerce-pro',
                'type'             => 'plugin',
                'public_key'       => 'pk_2ebe479457b4a9f806e1c09f620e6',
                'is_premium'       => false,
                'premium_suffix'   => 'Pro',
                'has_addons'       => false,
                'has_paid_plans'   => true,
                'is_org_compliant' => true,
                'menu'             => array(
                    'slug'    => 'voidpulse',
                    'contact' => false,
                    'support' => false,
                    'parent'  => array(
                        'slug' => 'woocommerce',
                    ),
                ),
                'is_live'          => true,
            ) );
            return $voidpulse_fs;
        }

        $voidpulse_sdk = voidpulse_fs();
        if ( null !== $voidpulse_sdk ) {
            if ( !function_exists( 'voidpulse_freemius_plugin_icon' ) ) {
                /**
                 * Return the local product icon used by Freemius admin screens.
                 *
                 * @return string
                 */
                function voidpulse_freemius_plugin_icon() {
                    return VOIDPULSE_PATH . 'public/icon-256x256.png';
                }

            }
            $voidpulse_sdk->add_filter( 'plugin_icon', 'voidpulse_freemius_plugin_icon' );
            $voidpulse_sdk->add_action( 'after_uninstall', 'voidpulse_after_uninstall_cleanup' );
            do_action( 'voidpulse_fs_loaded' );
        }
    }
    if ( !function_exists( 'voidpulse_after_uninstall_cleanup' ) ) {
        /**
         * Delete plugin-owned data after Freemius has reported the uninstall event.
         *
         * Data is preserved unless the merchant explicitly enabled deletion.
         *
         * @return void
         */
        function voidpulse_after_uninstall_cleanup() {
            if ( !defined( 'WP_UNINSTALL_PLUGIN' ) || !WP_UNINSTALL_PLUGIN || !class_exists( '\\VoidPulse\\Core\\OwnershipRegistry' ) ) {
                return;
            }
            if ( is_multisite() ) {
                $site_ids = get_sites( array(
                    'fields' => 'ids',
                ) );
                foreach ( $site_ids as $site_id ) {
                    switch_to_blog( (int) $site_id );
                    \VoidPulse\Core\OwnershipRegistry::cleanup_current_site();
                    restore_current_blog();
                }
                return;
            }
            \VoidPulse\Core\OwnershipRegistry::cleanup_current_site();
        }

    }
    require_once VOIDPULSE_PATH . 'includes/Core/Autoloader.php';
    \VoidPulse\Core\Autoloader::register();
    register_activation_hook( VOIDPULSE_FILE, array(\VoidPulse\Core\Activator::class, 'activate') );
    register_deactivation_hook( VOIDPULSE_FILE, array(\VoidPulse\Core\Deactivator::class, 'deactivate') );
    add_action( 'before_woocommerce_init', static function () {
        if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) {
            \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', VOIDPULSE_FILE, true );
            \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'cart_checkout_blocks', VOIDPULSE_FILE, true );
        }
    } );
    \VoidPulse\Core\Plugin::instance()->register();
}