<?php
/**
 * Plugin Name: PrimeLink - WooCommerce Import Export
 * Plugin URI: https://malotop.ro/
 * Description: Advanced import-export plugin for WooCommerce with visual mapping, cron scheduling and background processing.
 * Version: 1.0.0
 * Requires at least: 5.8
 * Requires PHP: 7.4
 * Author: Malo Top
 * Author URI: https://malotop.ro/
 * Text Domain: primelink
 * Domain Path: /languages
 *
 * @package PrimeLink
 */

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

define( 'MT_PRIMELINK_VERSION', '1.0.0' );
define( 'MT_PRIMELINK_FILE', __FILE__ );
define( 'MT_PRIMELINK_PATH', plugin_dir_path( __FILE__ ) );
define( 'MT_PRIMELINK_URL', plugin_dir_url( __FILE__ ) );
define( 'MT_PRIMELINK_BASENAME', plugin_basename( __FILE__ ) );

// Load Composer autoloader only on PHP 8.1.2+ (vendor libraries require PHP 8.0+).
// On PHP 7.4, use native functions only (fallback mode without heavy vendor deps).
if ( version_compare( PHP_VERSION, '8.1.2', '>=' ) ) {
    $composer_autoload = MT_PRIMELINK_PATH . 'lib/vendor/autoload.php';
    if ( file_exists( $composer_autoload ) ) {
        require_once $composer_autoload;
    }
}

require_once MT_PRIMELINK_PATH . 'includes/Autoloader.php';
require_once MT_PRIMELINK_PATH . 'includes/Helpers.php';

PrimeLink\Autoloader::run();

register_activation_hook( __FILE__, array( 'PrimeLink\\Core\\Activator', 'activate' ) );
register_deactivation_hook( __FILE__, array( 'PrimeLink\\Core\\Deactivator', 'deactivate' ) );

add_action( 'plugins_loaded', function () {
    require_once MT_PRIMELINK_PATH . 'includes/Bootstrap.php';
    ( new PrimeLink\Bootstrap() )->init();
} );

/**
 * Add "Settings" link to plugin row actions (next to Activate/Deactivate).
 */
add_filter( 'plugin_action_links_' . MT_PRIMELINK_BASENAME, function ( $links ) {
    $settings_url = admin_url( 'admin.php?page=mt-primelink-settings' );
    // Use core textdomain for this common string to avoid triggering just-in-time loading
    // for the plugin textdomain before the recommended 'init' hook.
    $settings_link = '<a href="' . esc_url( $settings_url ) . '">' . esc_html__( 'Settings' ) . '</a>';
    // Prepend Settings so it appears before Deactivate
    array_unshift( $links, $settings_link );
    return $links;
} );
