<?php

/**
 * Plugin Name: ZS SEO Audit and Optimization
 * Description: Complete SEO + GEO (AI Search) Optimization for developers. Audit & fix On-Page SEO, Technical SEO, Performance, Accessibility and AI Search visibility — all in one clean dashboard.
 * Version:     1.0.1
 * Author:      Satish Thakor
 * Author URI:  https://profiles.wordpress.org/satish0125/
 * License:     GPL-2.0-or-later
 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
 * Text Domain: zs-seo-audit-optimization
 * Domain Path: /languages
 * Requires at least: 6.0
 * Requires PHP: 7.4
 */

defined('ABSPATH') || exit;

// ─── Constants ────────────────────────────────────────────────────────────────
define('ZS_SEO_VERSION',   '1.0.1');
define('ZS_SEO_FILE',      __FILE__);
define('ZS_SEO_DIR',       plugin_dir_path(__FILE__));
define('ZS_SEO_URL',       untrailingslashit(plugin_dir_url(__FILE__)));
define('ZS_SEO_ASSETS',    ZS_SEO_URL . '/assets/');

// ─── Freemius SDK ─────────────────────────────────────────────────────────────
if (! function_exists('zs_seo_fs')) {

    function zs_seo_fs()
    {
        global $zs_seo_fs;

        if (! isset($zs_seo_fs)) {
            // Include Freemius SDK.
            require_once ZS_SEO_DIR . 'vendor/freemius/start.php';

            $zs_seo_fs = fs_dynamic_init([
                'id'                  => '31123',
                'slug'                => 'zenseo',
                'type'                => 'plugin',
                'public_key'          => 'pk_c913bd285b927c4f202bd2d7206c3',
                'is_premium'          => false,       // false = this is FREE version
                'premium_suffix'      => 'Pro',
                'has_premium_version' => true,        // true = Pro version exists
                'has_addons'          => false,
                'has_paid_plans'      => true,        // true = paid plans available
                'is_org_compliant'    => true,
                'trial'               => [
                    'days'               => 7,
                    'is_require_payment' => false,
                ],
                'menu'                => [
                    'slug'       => 'zs-seo-audit-optimization',
                    'support'    => false,
                    'pricing'    => true,
                    'account'    => true,
                    'contact'    => false,
                ],
            ]);
        }

        return $zs_seo_fs;
    }

    // Init Freemius
    zs_seo_fs();

    // Signal that SDK was initiated
    do_action('zs_seo_fs_loaded');
}

// ─── Helper: Is Pro? ──────────────────────────────────────────────────────────
function zs_seo_is_pro(): bool
{
    return function_exists('zs_seo_fs') && zs_seo_fs()->can_use_premium_code();
}

// ─── Autoloader ───────────────────────────────────────────────────────────────
spl_autoload_register(function ($class) {
    $prefix = 'ZS_SEO\AuditOptimization\\';
    if (strncmp($prefix, $class, strlen($prefix)) !== 0) return;
    $relative = str_replace('\\', '/', substr($class, strlen($prefix)));
    $file = ZS_SEO_DIR . 'includes/' . $relative . '.php';
    if (file_exists($file)) require_once $file;
});

// ─── Boot ─────────────────────────────────────────────────────────────────────
function zs_seo_init()
{
    \ZS_SEO\AuditOptimization\Core\Plugin::get_instance();
}
add_action('plugins_loaded', 'zs_seo_init');

// ─── Activation / Deactivation ────────────────────────────────────────────────
register_activation_hook(__FILE__, ['\ZS_SEO\AuditOptimization\Core\Installer', 'activate']);
register_deactivation_hook(__FILE__, ['\ZS_SEO\AuditOptimization\Core\Installer', 'deactivate']);
