<?php
/**
 * Wrapper for various WooCommerce Integrations
 *
 * @link https://personalizewp.com/
 * @since 3.2.0
 *
 * @package PersonalizeWP
 * @subpackage PersonalizeWP/Integrations/WooCommerce
 */

namespace PersonalizeWP\Integrations\WooCommerce;

use PersonalizeWP\Integrations\WooCommerce\WooCommerce_Memberships;
use PersonalizeWP\Integrations\WooCommerce\WooCommerce_Subscriptions;
use PersonalizeWP\Integrations\WooCommerce\WooCommerce_Memberships_Teams;

/**
 * Register the NinjaForms integation, and setup various actions/filters.
 *
 * @param \PersonalizeWP\PersonalizeWP $personalizewp Instance of plugin
 *
 * @return void
 */
function register_integration( $personalizewp ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found

	// Use WP functions to check activeness.
	require_once ABSPATH . 'wp-admin/includes/plugin.php';

	// Await full loading of PersonalizeWP before loading these classes, due to dependancies.
	add_action(
		'personalizewp_loaded',
		function () {

			// WooCommerce Memberships.
			if ( \is_plugin_active( 'woocommerce-memberships/woocommerce-memberships.php' ) ) {
				new WooCommerce_Memberships();
			}

			// WooCommerce Subscriptions.
			if ( \is_plugin_active( 'woocommerce-subscriptions/woocommerce-subscriptions.php' ) ) {
				new WooCommerce_Subscriptions();
			}

			// Teams for WooCommerce Memberships.
			if ( \is_plugin_active( 'woocommerce-memberships-for-teams/woocommerce-memberships-for-teams.php' ) ) {
				// Teams doesn't extend the Editor 'integrations', so starts differently.
				$teams = WooCommerce_Memberships_Teams::instance();
				$teams->setup();
			}
		}
	);
}
add_action( 'personalizewp_register_integrations', __NAMESPACE__ . '\register_integration' );
