<?php

/**
 * Spasalon Theme - Main functions.php
 * Freemius integration - loads free or pro version based on license
 */
if ( !class_exists( 'Spasalon_Freemius_Mock' ) ) {
    class Spasalon_Freemius_Mock {
        public function can_use_premium_code() {
            return false;
        }

        public function is_premium() {
            return false;
        }

        public function is_plan( $plan ) {
            return false;
        }

        public function is_free_plan() {
            return true;
        }

    }

}
if ( !function_exists( 'spa_fs' ) ) {
    // Create a helper function for easy SDK access.
    function spa_fs() {
        global $spa_fs;
        if ( !isset( $spa_fs ) ) {
            $spasalon_theme = wp_get_theme();
            $allowed_themes = array(
                'Spasalon',
                'Spasalon child',
                'Spasalon Child',
                'SpaSalon Pro',
                'SpaSalon Pro child',
                'SpaSalon Pro Child',
                'Spasalon Pro',
                'Spasalon Pro child',
                'Spasalon Pro Child'
            );
            if ( in_array( $spasalon_theme->get( 'Name' ), $allowed_themes ) || true ) {
                // Or true to ensure it runs
                // Include Freemius SDK.
                if ( file_exists( dirname( __FILE__ ) . '/freemius/start.php' ) ) {
                    require_once dirname( __FILE__ ) . '/freemius/start.php';
                } elseif ( defined( 'WC__PLUGIN_DIR' ) && file_exists( WC__PLUGIN_DIR . 'freemius/start.php' ) ) {
                    require_once WC__PLUGIN_DIR . 'freemius/start.php';
                }
                if ( function_exists( 'fs_dynamic_init' ) ) {
                    $spa_fs = fs_dynamic_init( array(
                        'id'               => '11283',
                        'slug'             => 'spasalon',
                        'premium_slug'     => 'spasalon-pro',
                        'type'             => 'theme',
                        'public_key'       => 'pk_bbf2edd33df2ecbab4887066f1391',
                        'is_premium'       => false,
                        'premium_suffix'   => 'Pro',
                        'has_addons'       => false,
                        'has_paid_plans'   => true,
                        'is_org_compliant' => true,
                        'menu'             => array(
                            'slug'    => 'spasalon-welcome',
                            'account' => true,
                            'support' => true,
                            'contact' => false,
                            'parent'  => array(
                                'slug' => 'themes.php',
                            ),
                        ),
                        'navigation'       => 'menu',
                        'is_live'          => true,
                    ) );
                }
            }
        }
        if ( !isset( $spa_fs ) || !is_object( $spa_fs ) ) {
            $spa_fs = new Spasalon_Freemius_Mock();
        }
        return $spa_fs;
    }

    // Init Freemius.
    spa_fs();
    // Signal that SDK was initiated.
    do_action( 'spa_fs_loaded' );
}
// Load Pro or Free functions based on Freemius license
if ( spa_fs()->can_use_premium_code() ) {
    require get_template_directory() . '/pro/functions.php';
} else {
    require get_template_directory() . '/free/functions.php';
}