<?php

namespace VendorTasksDokanClickUp\Settings;

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

/**
 * Plugin Action Links Handler
 *
 * Handles plugin action links in the plugins list.
 *
 * @package VendorTasksDokanClickUp
 * @subpackage Settings
 */
class PluginLinks {

	/**
	 * Class constructor
	 *
	 * @since 1.0.0
	 */
	public function __construct() {
		add_filter( 'plugin_action_links_' . plugin_basename( VENDOR_TASKS_DOKAN_CLICKUP_FILE ), array( $this, 'add_action_links' ) );
		add_filter( 'plugin_row_meta', array( $this, 'add_row_meta' ), 10, 2 );
	}

	/**
	 * Add action links
	 *
	 * @param array $links Existing action links.
	 *
	 * @return array Modified action links.
	 */
	public function add_action_links( array $links ): array {
		$settings_url = admin_url( 'admin.php?page=vendor-tasks-dokan-clickup' );

		$action_links = array(
			'settings' => '<a href="' . esc_url( $settings_url ) . '">' . esc_html__( 'Settings', 'alamin-vendor-tasks-dokan-clickup' ) . '</a>',
		);

		if ( ! vendor_tasks_dokan_clickup()->plan_manager()->is_pro() ) {
			$action_links['upgrade'] = '<a href="' . esc_url( admin_url( 'admin.php?page=vendor-tasks-dokan-clickup#/plans' ) ) . '" style="color:#d63638;font-weight:600;">' . esc_html__( 'Upgrade to Pro', 'alamin-vendor-tasks-dokan-clickup' ) . '</a>';
		}

		return array_merge( $action_links, $links );
	}

	/**
	 * Add plugin meta row links (Documentation, Support).
	 *
	 * @param array  $links Plugin meta links.
	 * @param string $file  Plugin basename.
	 * @return array
	 */
	public function add_row_meta( array $links, string $file ): array {
		if ( plugin_basename( VENDOR_TASKS_DOKAN_CLICKUP_FILE ) !== $file ) {
			return $links;
		}

		$links[] = '<a href="https://github.com/mralaminahamed/vendor-tasks-dokan-clickup" target="_blank" rel="noopener">' . esc_html__( 'Documentation', 'alamin-vendor-tasks-dokan-clickup' ) . '</a>';
		$links[] = '<a href="https://wordpress.org/support/plugin/alamin-vendor-tasks-dokan-clickup/" target="_blank" rel="noopener">' . esc_html__( 'Support', 'alamin-vendor-tasks-dokan-clickup' ) . '</a>';

		return $links;
	}
}
