<?php
/**
 * Freemius SDK bootstrap.
 *
 * One freemium product, one codebase. Everything premium lives in /addon/, which the
 * `@fs_premium_only /addon/` annotation in the main plugin file removes from the free
 * build — so the wordpress.org version ships with no locked code, which is what the
 * Plugin Directory requires. Nothing here gates a feature at runtime.
 *
 * The SDK contacts freemius.com. That is an external service, so it is disclosed in
 * readme.txt under "External services" with links to their terms and privacy policy,
 * and it transmits nothing until the user accepts the opt-in.
 *
 * @package EstimatedDeliveryDateWC
 */

defined( 'ABSPATH' ) || exit;

if ( ! function_exists( 'edfw_fs' ) ) {

	/**
	 * Freemius instance for this plugin.
	 *
	 * Named `edfw_fs`, matching this plugin's prefix. Freemius's generated snippet
	 * suggests `edd_fs`, which is unusable here: `edd_` is Easy Digital Downloads'
	 * namespace, and a three-letter prefix is exactly what the Plugin Review team asked
	 * us to stop using.
	 *
	 * @since 1.0.0
	 * @return Freemius
	 */
	function edfw_fs() {
		global $edfw_fs;

		if ( ! isset( $edfw_fs ) ) {
			// The SDK lives at /freemius, not /vendor/freemius as the generated snippet
			// assumes — /vendor is excluded from the release build.
			require_once __DIR__ . '/../freemius/start.php';

			$edfw_fs = fs_dynamic_init(
				array(
					'id'                  => '34538',
					'slug'                => 'wpactpro-estimated-delivery-date',
					'premium_slug'        => 'wpactpro-estimated-delivery-date-pro',
					'type'                => 'plugin',
					'public_key'          => 'pk_03cd9e1ada03479c6dddbc4d484ac',
					'is_premium'          => false,
					'premium_suffix'      => '( Premium )',
					'has_premium_version' => true,
					'has_addons'          => false,
					'has_paid_plans'      => true,
					'is_org_compliant'    => true,

					/*
					 * Stripped from the free build. Freemius removes this when IT
					 * generates the free version; we build ours locally, so
					 * bin/build.sh removes it instead — and the build fails outright if
					 * this string is ever found in a free package.
					 */
					'trial'               => array(
						'days'               => 3,
						'is_require_payment' => true,
					),
					'menu'                => array(
						'slug'    => 'edfw-settings',
						'support' => false,
						// Our settings page is a WooCommerce submenu, not a top-level
						// menu. Without this Freemius looks for a top-level page with
						// our slug and cannot attach its Account / Add-ons links.
						'parent'  => array(
							'slug' => 'woocommerce',
						),
					),
				)
			);
		}

		return $edfw_fs;
	}

	edfw_fs();

	/**
	 * Signal that the Freemius SDK has been initialised.
	 *
	 * @since 1.0.0
	 */
	do_action( 'edfw_fs_loaded' );
}
