<?php
/**
 * Plugin Name: TeknoTok AI Translator Pro
 * Plugin URI: https://soft.teknotok.com/teknotok-translator-pro/
 * Description: One-click AI translation plugin for WordPress and WooCommerce. Translate pages, posts, products, categories, tags, menus, widgets, and frontend strings.
 * Version: 1.1.0
 * Author: TeknoTok Soft
 * Author URI: https://soft.teknotok.com
 * Text Domain: teknotok-ai-translator-pro
 * Domain Path: /languages
 * Requires at least: 6.2
 * Requires PHP: 7.4
 * WC requires at least: 7.0
 * License: GPLv2 or later
 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
 *
 * @package TeknoTokAiTranslatorPro
 */

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

define( 'TEKNOTOK_AIT_VERSION', '1.1.0' );
define( 'TEKNOTOK_AIT_FILE', __FILE__ );
define( 'TEKNOTOK_AIT_DIR', plugin_dir_path( __FILE__ ) );
define( 'TEKNOTOK_AIT_URL', plugin_dir_url( __FILE__ ) );
define( 'TEKNOTOK_AIT_BASENAME', plugin_basename( __FILE__ ) );
define( 'TEKNOTOK_AIT_PRODUCT_SLUG', 'teknotok-ai-translator-pro' );

$teknotok_ait_settings = function_exists( 'get_option' ) ? get_option( 'teknotok_ait_settings', array() ) : array();
$teknotok_ait_gateway_base = isset( $teknotok_ait_settings['gateway_base_url'] ) ? esc_url_raw( $teknotok_ait_settings['gateway_base_url'] ) : '';
if ( empty( $teknotok_ait_gateway_base ) ) {
	$teknotok_ait_gateway_base = 'https://soft.teknotok.com';
}
$teknotok_ait_gateway_base = untrailingslashit( $teknotok_ait_gateway_base );

define( 'TEKNOTOK_AIT_GATEWAY_BASE_URL', $teknotok_ait_gateway_base );
define( 'TEKNOTOK_AIT_LICENSE_API', TEKNOTOK_AIT_GATEWAY_BASE_URL . '/?rest_route=/teknotok-license/v1/' );
define( 'TEKNOTOK_AIT_TRANSLATE_API', TEKNOTOK_AIT_GATEWAY_BASE_URL . '/?rest_route=/teknotok-translator/v1/translate' );
unset( $teknotok_ait_settings, $teknotok_ait_gateway_base );

// Load Composer Autoloader if available.
if ( file_exists( TEKNOTOK_AIT_DIR . 'vendor/autoload.php' ) ) {
	require_once TEKNOTOK_AIT_DIR . 'vendor/autoload.php';
} else {
	// Fallback autoloader for our PSR-4 structure to handle cases where composer hasn't finished running yet.
	spl_autoload_register( function( $class ) {
		$prefix = 'TeknoTok\\AiTranslator\\';
		$base_dir = TEKNOTOK_AIT_DIR . 'includes/';
		$len = strlen( $prefix );
		if ( strncmp( $prefix, $class, $len ) !== 0 ) {
			return;
		}
		$relative_class = substr( $class, $len );
		$file = $base_dir . str_replace( '\\', '/', $relative_class ) . '.php';
		if ( file_exists( $file ) ) {
			require_once $file;
		}
	});
}

// Activation and Deactivation Hooks
register_activation_hook( __FILE__, array( 'TeknoTok\\AiTranslator\\Plugin', 'activate' ) );
register_deactivation_hook( __FILE__, array( 'TeknoTok\\AiTranslator\\Plugin', 'deactivate' ) );

// Bootstrap the plugin
add_action( 'plugins_loaded', array( 'TeknoTok\\AiTranslator\\Plugin', 'instance' ) );
