<?php

namespace CouponsPlus\App\Handlers;

use CouponsPlus\Original\Environment\Env;
use CouponsPlus\Original\Events\Handler\EventHandler;

#[\AllowDynamicProperties]
Class TGMLoader extends EventHandler
{
    protected $numberOfArguments = 1;
    protected $priority = 10;

    public function execute()
    {
        if (!is_admin()) {
            return;
        }

        // if we have an update we ant tgm to be aware!
        /*if (class_exists(\CouponURLs\Original\Core\Application::class)) {
            return;
        }*/

        require_once Env::directory().'vendor/TGM/class-tgm-plugin-activation.php';

        add_action('tgmpa_register', function() {
            /*
             * Array of plugin arrays. Required keys are name and slug.
             * If the source is NOT from the .org repo, then source is also required.
             */
            $plugins = array(

                // Plugin from WordPress.org repository
                array(
                    'name'               => 'Coupon URLs', // The plugin name.
                    'slug'               => 'coupon-urls-for-woocommerce', // The plugin slug (typically the folder name).
                    'required'           => false, // If false, the plugin is only 'recommended' instead of required.
                ),

                // This is an example of how to include a plugin from the WordPress Plugin Repository.
                /*array(
                    'name'      => 'BuddyPress',
                    'slug'      => 'buddypress',
                    'required'  => false,
                ),*/
                
                // <snip />
            );

            /*
             * Array of configuration settings. Amend each line as needed.
             *
             * TGMPA will start providing localized text strings soon. If you already have translations of our standard
             * strings available, please help us make TGMPA even better by giving us access to these translations or by
             * sending in a pull-request with .po file(s) with the translations.
             *
             * Only uncomment the strings in the config array if you want to customize the strings.
             */
            $config = array(
                'id'           => Env::idLowerCase(),                 // Unique ID for hashing notices for multiple instances of TGMPA.
                'default_path' => Env::directory().'vendor/TGM/plugins/',                      // Default absolute path to bundled plugins.
                'menu'         => Env::idLowerCase().'tgmpa-install-plugins', // Menu slug.
                'parent_slug'  => 'plugins.php',            // Parent menu slug.
                'capability'   => 'manage_options',    // Capability needed to view plugin install page, should be a capability associated with the parent menu used.
                'has_notices'  => true,                    // Show admin notices or not.
                'dismissable'  => true,                    // If false, a user cannot dismiss the nag message.
                'dismiss_msg'  => '',                      // If 'dismissable' is false, this message will be output at top of nag.
                'is_automatic' => true,                   // Automatically activate plugins after installation or not.
                'message'      => '',                      // Message to output right before the plugins table.
                'strings'      => array(
                    'page_title'                      => __( 'Install Coupons+ extensions', 'coupons-plus-for-woocommerce' ),
                    'menu_title'                      => __( 'Install Coupons+ extensions', 'coupons-plus-for-woocommerce' ),
                    /* translators: extensions list  */
                    'installing'                      => __( 'Installing extension: %s', 'coupons-plus-for-woocommerce' ),
                    /* translators: extensions list  */
                    'updating'                        => __( 'Updating extension: %s', 'coupons-plus-for-woocommerce' ),
                    'oops'                            => __( 'Something went wrong with the plugin API.', 'coupons-plus-for-woocommerce' ),
                    /* translators: extension name  */
                    'notice_can_install_required'     => _n_noop(
                        'You have a Coupons+ extension available: %1$s.',
                        'You have Coupons+ extensions available: %1$s.',
                        'coupons-plus-for-woocommerce'
                    ),
                    /* translators: extension name  */
                    'notice_can_install_recommended'  => _n_noop(
                        'You have a Coupons+ extension available: %1$s.',
                        'You have Coupons+ extensions available: %1$s.',
                        'coupons-plus-for-woocommerce'
                    ),
                    /* translators: extension name  */
                    'notice_ask_to_update'            => _n_noop(
                        'The following plugin needs to be updated to its latest version to ensure maximum compatibility with this plugin: %1$s.',
                        'The following plugins need to be updated to their latest version to ensure maximum compatibility with this plugin: %1$s.', 'coupons-plus-for-woocommerce'
                    ),
                    /* translators: extension name  */
                    'notice_ask_to_update_maybe'      => _n_noop(
                        'There is an update available for: %1$s.',
                        'There are updates available for the following plugins: %1$s.', 'coupons-plus-for-woocommerce'
                    ),
                    /* translators: extension name  */
                    'notice_can_activate_required'    => _n_noop(
                        'The following required plugin is currently inactive: %1$s.',
                        'The following required plugins are currently inactive: %1$s.', 'coupons-plus-for-woocommerce'
                    ),
                    /* translators: extension name  */
                    'notice_can_activate_recommended' => _n_noop(
                        'The following recommended plugin is currently inactive: %1$s.',
                        'The following recommended plugins are currently inactive: %1$s.', 'coupons-plus-for-woocommerce'
                    ),
                    'install_link'                    => _n_noop(
                        'Begin installing plugin',
                        'Begin installing plugins', 'coupons-plus-for-woocommerce'
                    ),
                    'update_link'                     => _n_noop(
                        'Begin updating plugin',
                        'Begin updating plugins', 'coupons-plus-for-woocommerce'
                    ),
                    'activate_link'                   => _n_noop(
                        'Begin activating plugin',
                        'Begin activating plugins', 'coupons-plus-for-woocommerce'
                    ),
                    'return'                          => __( 'Return to Required Plugins Installer', 'coupons-plus-for-woocommerce' ),
                    'plugin_activated'                => __( 'Plugin activated successfully.', 'coupons-plus-for-woocommerce' ),
                    'activated_successfully'          => __( 'The following plugin was activated successfully:', 'coupons-plus-for-woocommerce' ),
                     /* translators: plugin name  */
                    'plugin_already_active'           => __( 'No action taken. Plugin %1$s was already active.', 'coupons-plus-for-woocommerce' ),
                    /* translators: plugin name  */
                    'plugin_needs_higher_version'     => __( 'Plugin not activated. A higher version of %s is needed for this plugin. Please update the plugin.', 'coupons-plus-for-woocommerce' ),
                    /* translators: plugin name  */
                    'complete'                        => __( 'All plugins installed and activated successfully. %1$s', 'coupons-plus-for-woocommerce' ),
                    'dismiss'                         => __( 'Dismiss this notice', 'coupons-plus-for-woocommerce' ),
                    'notice_cannot_install_activate'  => __( 'There are one or more required or recommended plugins to install, update or activate.', 'coupons-plus-for-woocommerce' ),
                    'contact_admin'                   => __( 'Please contact the administrator of this site for help.', 'coupons-plus-for-woocommerce' ),

                    'nag_type'                        => '', // Determines admin notice type - can only be one of the typical WP notice classes, such as 'updated', 'update-nag', 'notice-warning', 'notice-info' or 'error'. Some of which may not work as expected in older WP versions.
                ),
            );

            \tgmpa( $plugins, $config );
        });
    }
}