<?php
if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

class Trstemp_Dependencies {

    const ELEMENTOR = 'elementor/elementor.php';
    const TURBO_ADDONS = 'turbo-addons-elementor/turbo-addons-elementor.php';

    /**
     * Check if all required plugins are active
     */
    public static function is_ready() {

        if ( ! function_exists( 'is_plugin_active' ) ) {
            require_once ABSPATH . 'wp-admin/includes/plugin.php';
        }

        return (
            is_plugin_active( self::ELEMENTOR ) &&
            is_plugin_active( self::TURBO_ADDONS )
        );
    }


    /**
     * Get required plugin information for display
     */
    public static function get_required_plugins() {
        return array(
            'elementor' => array(
                'name' => 'Elementor',
                'slug' => 'elementor',
                'file' => self::ELEMENTOR,
                'url' => 'https://wordpress.org/plugins/elementor/'
            ),
            'turbo-addons' => array(
                'name' => 'Turbo Addons for Elementor',
                'slug' => 'turbo-addons-elementor',
                'file' => self::TURBO_ADDONS,
                'url' => 'https://wordpress.org/plugins/turbo-addons-elementor/'
            )
        );
    }

    /**
     * Get plugin installation status
     */
    public static function get_plugin_status( $plugin_file ) {
        if ( ! function_exists( 'is_plugin_active' ) ) {
            require_once ABSPATH . 'wp-admin/includes/plugin.php';
        }

        if ( is_plugin_active( $plugin_file ) ) {
            return 'active';
        }

        if ( file_exists( WP_PLUGIN_DIR . '/' . $plugin_file ) ) {
            return 'installed';
        }

        return 'not_installed';
    }

    /**
     * Admin notice - show only on plugins page after activation
     */
    public static function admin_notice() {
        // Only show on plugins page
        $screen = get_current_screen();
        if ( ! $screen || $screen->id !== 'plugins' ) {
            return;
        }

        if ( self::is_ready() ) {
            return;
        }

        echo '<div class="notice notice-warning is-dismissible">';
        echo '<p><strong>"Turbo Templates Library for Elementor"</strong> requires Elementor and Turbo Addons to be installed and activated. Please install and activate Elementor and Turbo Addons to use all features of Turbo Templates Library.</p>';
        echo '</div>';
    }

}
