<?php
/**
 * Plugin Name:       TechCon Agenda Pro
 * Plugin URI:        https://techconglobal.com/
 * Description:       Official TechCon multi-event agenda management system. Pixel-perfect agenda frontend with speaker profiles, session management, per-event color theming, and dual print modes.
 * Version:           2.3.1
 * Requires at least: 5.8
 * Requires PHP:      7.4
 * Author:            Brilzen Team
 * Author URI:        https://brilzen.com/
 * License:           GPL v2 or later
 * Text Domain:       techcon-agenda
 */

if ( ! defined( 'ABSPATH' ) ) { exit; }

define( 'TCA_VERSION', '2.3.1' );
define( 'TCA_PLUGIN_FILE', __FILE__ );
define( 'TCA_PLUGIN_DIR',  plugin_dir_path( __FILE__ ) );
define( 'TCA_PLUGIN_URL',  plugin_dir_url( __FILE__ ) );
define( 'TCA_PLUGIN_BASE', plugin_basename( __FILE__ ) );
define( 'TCA_TEXT_DOMAIN', 'techcon-agenda' );
define( 'TCA_DB_VERSION',  '2.1.0' );

// AES credential key — must also be defined in wp-config.php.
if ( ! defined( 'TC_CREDENTIAL_KEY' ) ) {
    define( 'TC_CREDENTIAL_KEY', 'CHANGE_THIS_IN_WP_CONFIG' );
}

// Autoloader.
spl_autoload_register( function( $class ) {
    $prefix = 'TCA\\';
    $base   = TCA_PLUGIN_DIR . 'includes/';
    if ( strncmp( $prefix, $class, strlen( $prefix ) ) !== 0 ) return;
    $file = $base . str_replace( '\\', '/', substr( $class, strlen( $prefix ) ) ) . '.php';
    if ( file_exists( $file ) ) require $file;
} );

register_activation_hook(   __FILE__, [ 'TCA\\Installer', 'activate'   ] );
register_deactivation_hook( __FILE__, [ 'TCA\\Installer', 'deactivate' ] );

add_action( 'plugins_loaded', function() {
    load_plugin_textdomain( TCA_TEXT_DOMAIN, false, dirname( TCA_PLUGIN_BASE ) . '/languages' );
    if ( get_option( 'tca_db_version' ) !== TCA_DB_VERSION ) {
        TCA\Installer::create_tables();
        if ( class_exists( \TCA\Defaults\SoCalSeeder::class ) ) { \TCA\Defaults\SoCalSeeder::seed(); }
        update_option( 'tca_db_version', TCA_DB_VERSION );
    }
    if ( class_exists( \TCA\Defaults\SoCalSeeder::class ) ) { \TCA\Defaults\SoCalSeeder::seed(); }
    TCA\Plugin::get_instance()->boot();
} );
