<?php 
/**
 * Class ST_ProQyz_Admin_Page_Evaluation_Cost
 */


defined( 'ABSPATH' ) || exit;


/**
  * Ielts_Lms_Menus Class.
  */
class ST_ProQyz_Admin_Page_Evaluation {
    private static $instance;
    public static $current_class        = null;
    public static $is_error             = false;
    public static $error                = "";
    public static $slug                 = 'st-proqyz-evaluation';
    public static $current_tab          = "evaluation-cost";
    public static $current_tab_context  = null;
    public static $tabs = [
        "evaluation-cost" => [
            "title"         => "Plans",
            "slug"          => "evaluation-cost",
            "location"      => "/includes/templates/admin/evaluation/evaluation-cost/evaluation-cost.php",
            "class"         => ST_PROQYZ_ABSPATH . "/includes/admin/class-st-proqyz-admin-page-evaluation-cost.php",
            "class_name"    => 'ST_ProQyz_Admin_Page_Evaluation_Cost'
        ],
        "ai-evaluation" => [
            "title"         => "API Key",
            "slug"          => "ai-evaluation",
            "location"      => "/includes/templates/admin/evaluation/ai-evaluation/ai-evaluation.php",
            "class"         => ST_PROQYZ_ABSPATH . "/includes/admin/class-st-proqyz-admin-page-ai-evaluation.php",
            "class_name"    => 'ST_ProQyz_Admin_Page_Ai_Evaluation'
        ],
    ];

        /**
	 * Main Ielts_Lms Instance.
	 *
	 * Ensures only one instance of Ielts_Lms is loaded or can be loaded.
	 *
	 * @since 1.0
	 * @static
	 * @see ST()
	 * @return Ielts_Lms - Main instance.
	 */
	public static function get_instance() {
		if ( ! isset( self::$instance ) ) {
			/** @psalm-suppress InvalidPropertyAssignmentValue */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort
			self::$instance = new self();
			/** @psalm-suppress InvalidPropertyAssignmentValue */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort
		}
		return self::$instance;
	}



    /**
    * Hook in tabs.
    */
    public function __construct($parent = 'st-proqyz') {
        $this->hooks();
        $this->includes();
    }


    /**
      * register hooks
      */
    public function hooks() { 
        if(isset($_GET['tab']) && !empty($_GET['tab'])) {
            self::$current_tab = $_GET['tab'];
        }

    }

    /**
      * includes
      */
    public function includes() { 
        # include the class according to tab and its object and then load the class
        // Check if the current tab exists in the tabs array
        if ( isset( self::$tabs[ self::$current_tab ] ) ) {
            // Get the tab data
            $tab_data = (object) self::$tabs[ self::$current_tab ];

            self::$current_tab_context = $tab_data;

            // Define the path to the class file
            $class_file = $tab_data->class;
            $class_name = $tab_data->class_name;

            // Check if the class file exists before including it
            
            if ( file_exists( $class_file ) ) {
                // Include the class file
                require_once $class_file;

                // Check if the class exists before instantiating it
                if ( class_exists( $class_name ) ) {
                    // Instantiate the class (you can also store the object if needed)
                    self::$current_class = new $class_name();
                } else {
                    // error_log( "Class {$class_name} not found in {$class_file}" );
                    self::$is_error = true;
                    self::$error = "Class to this tab not found";
                }
            } else {
                // error_log( "File {$class_file} does not exist." );
                self::$is_error = true;
                self::$error = "Class file realted to this tab not found: ".$class_file;
            }
        } else {
            // error_log( "Tab {$this->current_tab} not found in tabs array." );
            self::$is_error = true;
            self::$error = "No Access to this page";
            
        }

    }

    public static function get_page_layout(){
        $current_tab_context    = self::$current_tab_context;
        $current_tab            = self::$current_tab;
        $current_class          = self::$current_class;
        $is_error               = self::$is_error;
        $error                  = self::$error;
        $tabs                   = self::$tabs;
        $slug                   = self::$slug;

        $load_template = true;
        if(!class_exists('woocommerce')){ 
            $load_template = false;
            ?>
            <div class="st-proqyz-custom-notice st-proqyz-notice-warning">
                <p> 
                    The <strong>WooCommerce</strong> plugin is required and must be activated to use this feature.           
                </p>
            </div>
        <?php }

        if($load_template){
            require_once ST_PROQYZ_ABSPATH . "/includes/templates/admin/evaluation/evaluation.php"; // checked
        }
    }

}


return ST_ProQyz_Admin_Page_Evaluation::get_instance();

