<?php

namespace EasyLinkAutomations\Views;

if (!defined('ABSPATH')) {
    exit;
}

use EasyLinkAutomations\Config;

/**
 * Renders quick-links under the plugin name on the Plugins page.
 */
final class PluginPageActions
{
    /**
     * Define action links shown on the Plugins list page.
     *
     * @return array<string, array{title: string, url: string}>
     */
    public function getActionLinks(): array
    {
        $adminUrl = Config::get('ADMIN_URL') . 'admin.php?page=' . Config::SLUG;

        $links = [
            'settings' => [
                'title' => __('Settings', 'easylink-automations'),
                'url'   => $adminUrl . '#/settings',
            ],
            'automations' => [
                'title' => __('Automations', 'easylink-automations'),
                'url'   => $adminUrl . '#/automations',
            ],
        ];

        if (!Config::isProActivated()) {
            $links['upgrade_to_pro'] = [
                'title' => __('Upgrade to Pro', 'easylink-automations'),
                'url'   => Config::get('PRO_UPGRADE_URL'),
            ];
        }

        return $links;
    }

    /**
     * Append action links to the Plugins page.
     *
     * @param array $links Existing links
     * @return array Modified links
     */
    public function renderActionLinks(array $links): array
    {
        foreach ($this->getActionLinks() as $link) {
            $links[] = '<a href="' . esc_url($link['url']) . '">' . esc_html($link['title']) . '</a>';
        }

        return $links;
    }
}
