<?php
/**
 * Plugin Name:       NR Brief Builder
 * Description:       Smart client brief builder for freelancers and agencies. Add a multi-step brief form anywhere with the [nr_brief] shortcode.
 * Version:           1.0.3
 * Requires at least: 6.0
 * Requires PHP:      7.4
 * Author:            Nicolas Raux
 * Author URI:        https://nicolasraux.fr
 * License:           GPL v2 or later
 * License URI:       https://www.gnu.org/licenses/gpl-2.0.html
 * Text Domain:       nr-brief-builder
 * Domain Path:       /languages
 *
 * @package Briefify
 */

// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

// ---------------------------------------------------------------------
// Freemius SDK.
//
// Must be initialized as early as possible in the plugin's lifecycle —
// before anything else runs, including the plugin's own bootstrap below.
// Never carries a Secret Key (that key is server/API-only and has no
// place in code that ships to users, free or premium).
//
// 'is_premium' is NOT a per-user license check — that's nrbb_is_pro()'s
// job (includes/nrbb-licensing.php), unrelated and unchanged here. This
// flag tells the SDK itself which *code variant* is currently running,
// which the SDK uses for its own opt-in/update/licensing-requirement
// bookkeeping. It's computed rather than hardcoded because this exact
// file ships unmodified in both packages: the free WP.org build (from
// trunk/, no includes/pro/ at all) and the Premium build sold via
// Freemius (trunk/ + includes/pro/ layered on top, see ROADMAP.md). A
// hardcoded true here would have mislabeled the free package as premium
// too, since both packages share this literal file.
// ---------------------------------------------------------------------

if ( ! function_exists( 'nrbb_fs' ) ) {
	/**
	 * Create a helper function for easy SDK access.
	 *
	 * @return Freemius
	 */
	function nrbb_fs() {
		global $nrbb_fs;

		if ( ! isset( $nrbb_fs ) ) {
			require_once __DIR__ . '/freemius/start.php';

			$nrbb_fs = fs_dynamic_init(
				array(
					'id'             => '37700',
					'slug'           => 'nr-brief-builder',
					'type'           => 'plugin',
					'public_key'     => 'pk_0edea3f13b37e8382151cabad247f',
					'is_premium'     => is_dir( __DIR__ . '/includes/pro' ),
					'has_addons'     => false,
					'has_paid_plans' => true,
					'menu'           => array(
						'slug'       => 'nr-brief-builder',
						'first-path' => 'admin.php?page=nr-brief-builder',
					),
				)
			);
		}

		return $nrbb_fs;
	}

	// Init Freemius.
	nrbb_fs();

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

// ---------------------------------------------------------------------
// Constants.
// ---------------------------------------------------------------------

define( 'BRIEFIFY_VERSION', '1.0.3' );
define( 'BRIEFIFY_PLUGIN_FILE', __FILE__ );
define( 'BRIEFIFY_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
define( 'BRIEFIFY_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
define( 'BRIEFIFY_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
define( 'BRIEFIFY_CPT', 'briefify_submission' );

// ---------------------------------------------------------------------
// Licensing.
//
// nrbb_is_pro() is the single point of truth Pro-gated code should
// check. Loaded here, right after Freemius and right before the core
// loader, so it's available to every file required below.
// ---------------------------------------------------------------------

require_once BRIEFIFY_PLUGIN_DIR . 'includes/nrbb-licensing.php';

// ---------------------------------------------------------------------
// Uninstall cleanup.
//
// Routed through Freemius's after_uninstall hook rather than a
// uninstall.php file at the plugin root — see includes/nrbb-uninstall.php
// for why (Freemius flagged the file during their pre-listing review).
// ---------------------------------------------------------------------

require_once BRIEFIFY_PLUGIN_DIR . 'includes/nrbb-uninstall.php';

// ---------------------------------------------------------------------
// Core loader.
// ---------------------------------------------------------------------

require_once BRIEFIFY_PLUGIN_DIR . 'includes/class-briefify-core.php';

/**
 * Boot the plugin once all plugins are loaded.
 */
function briefify_init() {
	Briefify_Core::instance();
}
add_action( 'plugins_loaded', 'briefify_init' );

// ---------------------------------------------------------------------
// Activation / deactivation.
// ---------------------------------------------------------------------

register_activation_hook( __FILE__, array( 'Briefify_Core', 'activate' ) );
register_deactivation_hook( __FILE__, array( 'Briefify_Core', 'deactivate' ) );
