<?php

/**
 * Freemius
 */
namespace HulkPlugins\Woo\ProductConditionManager;

defined( 'ABSPATH' ) || exit;
if ( !function_exists( 'HulkPlugins\\Woo\\ProductConditionManager\\hulk_woo_pcm_fs' ) ) {
    // Create a helper function for easy SDK access.
    function hulk_woo_pcm_fs() {
        global $hulk_woo_pcm_fs;
        if ( !isset( $hulk_woo_pcm_fs ) ) {
            // Include Freemius SDK.
            // SDK is autoloaded through Composer
            $hulk_woo_pcm_fs = fs_dynamic_init( array(
                'id'               => '21421',
                'slug'             => 'product-condition-manager-for-woocommerce',
                'type'             => 'plugin',
                'public_key'       => 'pk_082436365c6ad63c651c175b0a450',
                'is_premium'       => false,
                'premium_suffix'   => 'Pro',
                'has_addons'       => false,
                'has_paid_plans'   => true,
                'trial'            => array(
                    'days'               => 7,
                    'is_require_payment' => true,
                ),
                'menu'             => array(
                    'slug'           => 'wc-settings',
                    'override_exact' => true,
                    'first-path'     => 'admin.php?page=wc-settings&tab=products&section=hulk_woo_pcm',
                    'parent'         => array(
                        'slug' => 'woocommerce',
                    ),
                ),
                'is_live'          => true,
                'is_org_compliant' => true,
            ) );
        }
        return $hulk_woo_pcm_fs;
    }

    // Init Freemius.
    hulk_woo_pcm_fs();
    // Signal that SDK was initiated.
    do_action( 'hulk_woo_pcm_fs_loaded' );
    function hulk_woo_pcm_fs_settings_url() : ?string {
        return admin_url( 'admin.php?page=wc-settings&tab=products&section=hulk_woo_pcm' );
    }

    hulk_woo_pcm_fs()->add_filter( 'connect_url', 'HulkPlugins\\Woo\\ProductConditionManager\\hulk_woo_pcm_fs_settings_url' );
    hulk_woo_pcm_fs()->add_filter( 'after_skip_url', 'HulkPlugins\\Woo\\ProductConditionManager\\hulk_woo_pcm_fs_settings_url' );
    hulk_woo_pcm_fs()->add_filter( 'after_connect_url', 'HulkPlugins\\Woo\\ProductConditionManager\\hulk_woo_pcm_fs_settings_url' );
    hulk_woo_pcm_fs()->add_filter( 'after_pending_connect_url', 'HulkPlugins\\Woo\\ProductConditionManager\\hulk_woo_pcm_fs_settings_url' );
    function hulk_woo_pcm_fs_notice() : string {
        if ( !hulk_woo_pcm_fs()->is_premium() ) {
            // Adds a direct checkout link in the free version.
            return sprintf(
                /** @lang text */
                '%s&nbsp;-&nbsp;<a href="%s" target="_blank">%s</a>',
                esc_attr__( 'To use', 'product-condition-manager-for-woocommerce' ),
                hulk_woo_pcm_fs()->checkout_url(),
                esc_attr__( 'UNLOCK PRO', 'product-condition-manager-for-woocommerce' )
            );
        }
        if ( hulk_woo_pcm_fs()->is_not_paying() ) {
            // Adds a upgrade link
            return sprintf(
                /** @lang text */
                '%s&nbsp;-&nbsp;<a href="%s" target="_blank">%s</a>',
                esc_attr__( 'To use', 'product-condition-manager-for-woocommerce' ),
                hulk_woo_pcm_fs()->get_upgrade_url(),
                esc_attr__( 'UPGRADE NOW!', 'product-condition-manager-for-woocommerce' )
            );
        }
        return '';
    }

}