<?php
/**
 * Plugin Name: Gigneo
 * Description: A complete freelance service & job marketplace solution to manage services, jobs, orders, and communication in one seamless platform.
 * Plugin URI: https://gigneo.com
 * Version: 0.0.7
 * Author: Deveasel
 * Author URI: https://deveasel.com
 * Text Domain: gigneo
 * Domain Path: /languages
 * Requires PHP: 8.0
 * Requires Plugins: woocommerce
 * WC requires at least: 8.0
 * WC tested up to: 9.8.2
 * License: GPLv3 or later
 * License URI: https://www.gnu.org/licenses/gpl-3.0.html
 *
 *
 * Copyright (C) 2026 Deveasel
 *
 * Gigneo is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * Gigneo is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Gigneo. If not, see <https://www.gnu.org/licenses/>.
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}

define( 'GIGNEO_VERSION', '0.0.7' );
define( 'GIGNEO_FILE', __FILE__ );
define( 'GIGNEO_BASE', plugin_basename( __FILE__ ) );
define( 'GIGNEO_DIR_PATH', plugin_dir_path( GIGNEO_FILE ) );
define( 'GIGNEO_DIR_URL', plugin_dir_url( GIGNEO_FILE ) );

/**
 * Class Gigneo
 *
 * Main plugin class for Gigneo.
 *
 * @since 0.0.1
 */
final class Gigneo {

	/**
	 * The single instance of the class.
	 *
	 * @var Gigneo|null
	 * @since 0.0.1
	 */
	private static $instance = null;

	/**
	 * Minimum PHP Version
	 *
	 * @var string Minimum PHP version required to run the plugin.
	 * @since 1.0.0
	 */
	private static string $minimum_php_version = '8.0';

	/**
	 * Gigneo constructor.
	 *
	 * Initializes the plugin by setting up hooks.
	 *
	 * @since 0.0.1
	 */
	public function __construct() {

		// Include the autoloader
		if ( file_exists( GIGNEO_DIR_PATH . 'vendor/autoload.php' ) ) {
			require_once GIGNEO_DIR_PATH . 'vendor/autoload.php';
		}

		//Activation / Deactivation
		register_activation_hook( __FILE__, array( \Gigneo\Base::class, 'plugin_activate' ) );
		register_deactivation_hook( __FILE__, array( \Gigneo\Base::class, 'plugin_deactivate' ) );

		//Plugin base
		add_action( 'plugins_loaded', array( $this, 'plugin_base' ) );
	}

	/**
	 * Initialize the plugin base.
	 *
	 * This function sets up the base functionality of the plugin by instantiating
	 * the Base class and triggering the `gigneo_loaded` action.
	 *
	 * @since 0.0.1
	 */
	public function plugin_base() {

		// Check for a required PHP version
		if ( version_compare( PHP_VERSION, self::$minimum_php_version, '<' ) ) {
			add_action( 'admin_notices', array( $this, 'admin_notice_minimum_php_version' ) );
			return;
		}

		// Check WooCommerce dependency.
		if ( ! class_exists( 'WooCommerce' ) || ! function_exists( 'WC' ) || ! WC() ) {
			add_action( 'admin_notices', array( $this, 'admin_notice_missing_woocommerce' ) );

			return;
		}

		// Instantiate the Base class
		\Gigneo\Base::instance();

		// Plugin loaded action
		do_action( 'gigneo_loaded' );
	}

	/**
	 * Ensures only one instance of the class is loaded or can be loaded.
	 *
	 * @return Gigneo
	 * @since 0.0.1
	 */
	public static function instance() {
		if ( is_null( self::$instance ) ) {
			self::$instance = new self();
		}

		return self::$instance;
	}

	/**
	 * Display an admin notice for unsupported PHP version.
	 *
	 * This function outputs an error message in the WordPress admin area
	 * if the server's PHP version is lower than the required minimum version.
	 *
	 * @since 0.0.1
	 */
	public function admin_notice_minimum_php_version() {
		$message = sprintf(
		// translators: 1: Plugin name, 2: PHP version
			esc_html__( '%1$s requires PHP version %2$s or greater.', 'gigneo' ),
			'<strong>' . esc_html__( 'Gigneo', 'gigneo' ) . '</strong>',
			esc_html( self::$minimum_php_version )
		);

		$notice = sprintf(
			'<div class="notice notice-error"><p>%1$s</p></div>',
			$message
		);

		echo wp_kses_post( $notice );
	}

	/**
	 * Display admin notice if WooCommerce is missing.
	 *
	 * @since 0.0.1
	 */
	public function admin_notice_missing_woocommerce() {

		$message = sprintf(
		// translators: %s: Plugin name.
			esc_html__( '%s requires WooCommerce to be installed and active.', 'gigneo' ),
			'<strong>' . esc_html__( 'Gigneo', 'gigneo' ) . '</strong>'
		);

		printf(
			'<div class="notice notice-error"><p>%s</p></div>',
			wp_kses_post( $message )
		);
	}
}

// Instantiate
Gigneo::instance();
