<?php

namespace CouponsPlus\App\Handlers;

use CouponsPlus\Original\Characters\StringManager;
use CouponsPlus\Original\Collections\Collection;
use CouponsPlus\Original\Environment\Env;
use CouponsPlus\Original\Events\Handler\EventHandler;

Class PluginScreenActionButtonsRegistratorhandler extends EventHandler
{
    protected $numberOfArguments = 1;
    protected $priority = 10;

    public function execute()
    {
        add_filter('plugin_action_links', function ($actions, $plugin_file, $plugin_data, $context) {
            // Check if this is your plugin
            (object) $newActions = new Collection([]);

            if (StringManager::create($plugin_file)->endsWith(Env::settings()->app->pluginFileName.'.php')) {
                $url = admin_url('edit.php?post_type=shop_coupon');

                $newActions->add(
                    Env::getWithPrefix('go_to_coupons'),
                    sprintf(
                        '<a href="%s" style="color:#788c0b">%s</a>',
                        esc_url($url),
                        esc_html(__('Add Coupons', 'coupons-plus-for-woocommerce'))
                    )
                );
            }

            return $newActions->append($actions)->asArray();
        }, 10, 4);   
    }
}