<?php
/**
 * Plugin Name: TukiFlow Direct Checkout for WooCommerce
 * Plugin URI:  https://tukidevs.com/tukiflow-direct-checkout-for-woocommerce/
 * Description: Add a Buy Now button and native checkout landing pages to WooCommerce, so shoppers move from product to checkout in fewer steps.
 * Version:     1.2.0
 * Author:      tukiDevs
 * Author URI:  https://tukidevs.com
 * Text Domain: tukiflow-direct-checkout-woocommerce
 * Domain Path: /languages
 * Requires Plugins: woocommerce
 * Requires at least: 6.0
 * Requires PHP: 7.4
 * WC requires at least: 7.0
 * WC tested up to: 10.9.1
 * License: GPL v2 or later
 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
 */

// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

require_once __DIR__ . '/vendor/autoload.php';

if ( ! function_exists( 'tfdc_fs' ) ) {
	// Create a helper function for easy SDK access.
	function tfdc_fs() {
		global $tfdc_fs;

		if ( ! isset( $tfdc_fs ) ) {
			// Activate multisite network integration.
			if ( ! defined( 'WP_FS__PRODUCT_27817_MULTISITE' ) ) {
				define( 'WP_FS__PRODUCT_27817_MULTISITE', true );
			}

			// Include Freemius SDK.
			require_once __DIR__ . '/vendor/freemius/wordpress-sdk/start.php';

			$tfdc_fs = fs_dynamic_init(
				array(
					'id'                  => '27817',
					'slug'                => 'tukiflow-direct-checkout-woocommerce',
					'type'                => 'plugin',
					'public_key'          => 'pk_5c6bc5e95682f3c32327a3436c3cc',
					'is_premium'          => false,
					'has_premium_version' => false,
					'has_addons'          => false,
					'has_paid_plans'      => false,
					'menu'                => array(
						'slug'       => 'tukiflow',
						'first-path' => 'admin.php?page=tukiflow',
						'support'    => false,
						'contact'    => false,
						'account'    => false,
					),
				)
			);
		}

		return $tfdc_fs;
	}

	// Init Freemius.
	tfdc_fs();
	// Signal that SDK was initiated.
	do_action( 'tfdc_fs_loaded' );
}
// Plugin constants.
define( 'TFDC_VER', '1.2.0' );
define( 'TFDC_FILE', __FILE__ );
define( 'TFDC_DIR', plugin_dir_path( __FILE__ ) );
define( 'TFDC_URL', plugin_dir_url( __FILE__ ) );
define( 'TFDC_BASENAME', plugin_basename( __FILE__ ) );

// Autoload includes.
require_once TFDC_DIR . 'includes/class-tfdc-install.php';
require_once TFDC_DIR . 'includes/class-tfdc-loader.php';

// Activation / deactivation.
register_activation_hook( __FILE__, array( 'TFDC_Install', 'activate' ) );
register_deactivation_hook( __FILE__, array( 'TFDC_Install', 'deactivate' ) );

/**
 * Return the main plugin instance.
 *
 * @return TFDC_Loader
 */
function tfdc_tukiflow() {
	return TFDC_Loader::get_instance();
}

// Declare WooCommerce feature compatibility.
add_action( 'before_woocommerce_init', function () {
	if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) {
		\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true );
	}
} );

// Boot the plugin after all plugins have loaded.
add_action( 'plugins_loaded', 'tfdc_tukiflow', 10 );
