<?php
/**
 * Links on the Plugins screen (Settings action + Donate row meta).
 *
 * @package SuiteMkt3k
 */

namespace SuiteMkt3k\Admin;

defined( 'ABSPATH' ) || exit;

final class Plugin_List {

	private const DONATE_URL = 'https://www.paypal.com/donate/?hosted_button_id=AKMXXA2THYD4N';

	public static function register(): void {
		add_filter( 'plugin_action_links_' . SUITEMKT3K_BASENAME, array( __CLASS__, 'action_links' ) );
		add_filter( 'plugin_row_meta', array( __CLASS__, 'row_meta' ), 10, 2 );
	}

	/**
	 * @param string[] $links Existing action links.
	 * @return string[]
	 */
	public static function action_links( array $links ): array {
		$settings = sprintf(
			'<a href="%s">%s</a>',
			esc_url( admin_url( 'admin.php?page=suitemkt3k-settings' ) ),
			esc_html__( 'Settings', 'suitemkt3k' )
		);
		array_unshift( $links, $settings );
		return $links;
	}

	/**
	 * @param string[] $links Plugin row meta links.
	 * @param string   $file  Plugin basename.
	 * @return string[]
	 */
	public static function row_meta( array $links, string $file ): array {
		if ( SUITEMKT3K_BASENAME !== $file ) {
			return $links;
		}
		$links[] = sprintf(
			'<a href="%s" target="_blank" rel="noopener noreferrer" style="color:#00a32a;font-weight:600;">%s</a>',
			esc_url( self::DONATE_URL ),
			esc_html__( 'Donate to author', 'suitemkt3k' )
		);
		return $links;
	}
}
