<?php
/**
 * Plugin Name:       Smart eGift Card
 * Plugin URI:        https://wordpress.org/plugins/smart-gift-card/
 * Description:       Adds an eGift Card system to WooCommerce, allowing customers to send gift cards by email.
 * Version:           1.0.7
 * Requires at least: 5.6
 * Requires PHP:      7.4
 * Author:            Smarty Soft
 * Author URI:        https://profiles.wordpress.org/smartysoftbd/
 * License:           GPL v2 or later
 * License URI:       https://www.gnu.org/licenses/gpl-2.0.html
 * Text Domain:       smart-gift-card
 * Domain Path:       /languages
 * Tags:              digital gift card, egift card, gift voucher, customizable gift card
 *
 * Smart eGift Card plugin for WooCommerce store. Provides gift cards, allowing customers to send gift cards to friends and family via email.
 */

defined('ABSPATH') || exit; // Prevent direct file access.

define('SMART_GIFT_CARD_PLUGIN_ASSET_ID', 'smart-gift-card');
define('SMART_GIFT_CARD_PLUGIN_ASSET_VARS', 'sgc_gift');

// Define constants only if they are not already defined.
defined('SMART_GIFT_CARD_VERSION') || define('SMART_GIFT_CARD_VERSION', '1.0.7');
defined('SMART_GIFT_CARD_PLUGIN_PATH') || define('SMART_GIFT_CARD_PLUGIN_PATH', __FILE__);
defined('SMART_GIFT_CARD_PLUGIN_DIR') || define('SMART_GIFT_CARD_PLUGIN_DIR', __DIR__);
defined('SMART_GIFT_CARD_PLUGIN_URL') || define('SMART_GIFT_CARD_PLUGIN_URL', plugin_dir_url(__FILE__));
defined('SMART_GIFT_CARD_PLUGIN_BASE_PATH') || define('SMART_GIFT_CARD_PLUGIN_BASE_PATH', plugin_dir_path(__FILE__));

// Check for the autoloader file's existence and include it.
if ( file_exists(__DIR__ . '/autoloader.php' ) ) {
    require_once __DIR__ . '/autoloader.php';
} else {
    wp_die( esc_html__( 'Autoloader file is missing.', 'smart-gift-card' ) );
}

// Register activation hook with a callable array method.
register_activation_hook( __FILE__, array('SGC\eGiftCard\Config\Bootstrap', 'activate_me' ) );

/**
 * Check if WooCommerce is active.
 */
function sgc_check_woocommerce_active() {
    if ( ! class_exists( 'WooCommerce' ) ) {
        add_action( 'admin_notices', 'sgc_show_woocommerce_inactive_notice' );
        return false;
    }
    return true;
}

/**
 * Show admin notice if WooCommerce is not active.
 */
function sgc_show_woocommerce_inactive_notice() {
    ?>
    <div class="notice notice-error">
        <p><?php esc_html_e( 'Smart eGift Card requires WooCommerce to be installed and active.', 'smart-gift-card' ); ?></p>
    </div>
    <?php
}

/**
 * Initializes the Smart eGift Card plugin.
 */
function sgc_egift_card_init()
{
    if ( ! sgc_check_woocommerce_active() ) {
        return;
    }

    if (class_exists('SGC\eGiftCard\Config\Bootstrap')) {
        $bootstrap = new SGC\eGiftCard\Config\Bootstrap();
        $bootstrap->boot();
    } else {
        wp_die( esc_html__( 'Smart eGift Card plugin is not properly installed.', 'smart-gift-card' ) );
    }
}

add_action( 'plugins_loaded', 'sgc_egift_card_init' );