<?php

/**
 * Plugin Name:       FindAstra — AI Semantic Search for WooCommerce
 * Plugin URI:        https://findastra.com
 * Description:       AI semantic search for WooCommerce. Replaces keyword search with vector embeddings generated in the shopper's browser — no API keys, no signup, no cost.
 * Version:           0.11.7
 * Requires at least: 6.4
 * Requires PHP:      8.1
 * Requires Plugins:  woocommerce
 * Author:            FindAstra
 * Author URI:        https://findastra.com/contact
 * License:           GPL-2.0-or-later
 * License URI:       https://www.gnu.org/licenses/gpl-2.0.html
 * Text Domain:       findastra
 * Domain Path:       /languages
 *
 * @package FindAstra
 */
defined( 'ABSPATH' ) || exit;
define( 'FINDASTRA_VERSION', '0.11.7' );
define( 'FINDASTRA_FILE', __FILE__ );
define( 'FINDASTRA_DIR', plugin_dir_path( __FILE__ ) );
define( 'FINDASTRA_URL', plugin_dir_url( __FILE__ ) );
define( 'FINDASTRA_BASENAME', plugin_basename( __FILE__ ) );
// ---- Freemius SDK bootstrap -----------------------------------------------
// Loaded before our autoloader so every FindAstra_* class can call findastra_fs()
// during construction. The free build of the plugin (auto-stripped by the
// Freemius deployment pipeline) still hits this block — the SDK gracefully
// degrades to "no paid plan" when no license is activated. See
// INTERNAL/FREEMIUS-INTEGRATION.md for the full integration map.
if ( !function_exists( 'findastra_fs' ) ) {
    /**
     * Singleton accessor for the Freemius instance.
     *
     * Do NOT call this from code that needs to run on every WP request — wrap
     * gating logic in FindAstra_License instead, which centralises the
     * findastra_fs() interaction and provides filterable defaults.
     */
    function findastra_fs() {
        global $findastra_fs;
        if ( !isset( $findastra_fs ) ) {
            require_once dirname( __FILE__ ) . '/vendor/freemius/start.php';
            $findastra_fs = fs_dynamic_init( array(
                'id'               => '29942',
                'slug'             => 'findastra',
                'type'             => 'plugin',
                'public_key'       => 'pk_35e3504e009568877cddb5844adde',
                'is_premium'       => false,
                'has_addons'       => false,
                'has_paid_plans'   => true,
                'is_org_compliant' => true,
                'menu'             => array(
                    'slug'       => 'findastra',
                    'first-path' => 'admin.php?page=findastra',
                    'support'    => false,
                    'contact'    => false,
                    'account'    => true,
                    'pricing'    => true,
                ),
                'is_live'          => true,
            ) );
        }
        return $findastra_fs;
    }

    findastra_fs();
    do_action( 'findastra_fs_loaded' );
}
// ---- /Freemius SDK bootstrap ----------------------------------------------
require_once FINDASTRA_DIR . 'includes/class-findastra-autoloader.php';
FindAstra_Autoloader::register();
register_activation_hook( __FILE__, array('FindAstra_Activator', 'activate') );
register_deactivation_hook( __FILE__, array('FindAstra_Activator', 'deactivate') );
// Freemius owns the uninstall flow (it deauthorises the install on its API
// and cleans up SDK options first, then yields to us). Registering through
// findastra_fs()->add_action('after_uninstall', ...) is how the SDK wants it
// wired — a bare register_uninstall_hook would be skipped, and an
// uninstall.php file is explicitly rejected by Freemius's deployment
// validator. See INTERNAL/FREEMIUS-INTEGRATION.md.
findastra_fs()->add_action( 'after_uninstall', array('FindAstra_Activator', 'uninstall') );
// Tell Freemius which icon to render on its own admin screens (opt-in,
// Account, license-activation). Without this the SDK can't find a committed
// icon at vendor/freemius/assets/img/findastra.png and, on localhost, copies
// its generic gray-plug placeholder there — which is why those pages showed
// no logo. The `plugin_icon` filter is checked first and overrides that
// lookup entirely. Point it at our own square brand mark so every build
// shows the real logo, and it survives Freemius SDK updates (lives in our
// assets/, not in vendor/). Applies to all builds.
findastra_fs()->add_filter( 'plugin_icon', static function () {
    return FINDASTRA_DIR . 'assets/findastra-mark.svg';
} );
add_action( 'plugins_loaded', static function () {
    FindAstra_Plugin::instance()->boot();
} );