<?php
/**
 * Plugin Name: PrimeLink - WooCommerce Import Export
 * Plugin URI: https://primelink.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: 8.0
 * Author: Malo Top
 * Author URI: https://malotop.ro/
 * License: GPLv2 or later
 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
 * Text Domain: primelink
 * Domain Path: /languages
 *
 * @package PrimeLink
 */

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

// Check PHP version - require PHP 8.0+ for Composer dependencies
if ( version_compare( PHP_VERSION, '8.0', '<' ) ) {
    add_action( 'admin_notices', function() {
        ?>
        <div class="notice notice-error">
            <p>
                <strong><?php esc_html_e( 'PrimeLink Error:', 'primelink' ); ?></strong>
                <?php
                printf(
                    esc_html__( 'PrimeLink requires PHP 8.0 or higher. You are running PHP %s. Please upgrade your PHP version.', 'primelink' ),
                    esc_html( PHP_VERSION )
                );
                ?>
            </p>
        </div>
        <?php
    } );
    return;
}

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 (vendor libraries require PHP 8.0+ for League CSV and other dependencies).
if ( version_compare( PHP_VERSION, '8.0', '>=' ) ) {
    $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;
} );
