<?php
/**
 * Campaign Sources Table.
 *
 * @package     EDD\Pro\CampaignTracker\Admin\Reports\Endpoints\Tables
 * @copyright   Copyright (c) 2025, Sandhills Development, LLC
 * @license     https://opensource.org/licenses/gpl-2.0.php GNU Public License
 * @since       3.6.3
 */

namespace EDD\Pro\CampaignTracker\Admin\Reports\Endpoints\Tables;

// Exit if accessed directly.
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore

use EDD\Reports\Endpoints\Tables\Table;

/**
 * Campaign Sources Table.
 *
 * @since 3.6.3
 */
class CampaignSources extends Table {

	/**
	 * Gets the ID for the table.
	 *
	 * @since 3.6.3
	 * @return string
	 */
	protected function get_id(): string {
		return 'campaign_sources';
	}

	/**
	 * Gets the label for the table.
	 *
	 * @since 3.6.3
	 * @return string
	 */
	protected function get_label(): string {
		// Check if a specific campaign is being filtered.
		// phpcs:ignore WordPress.Security.NonceVerification.Recommended
		$has_campaign_filter = isset( $_GET['campaign_tracker'] );
		$campaign            = \EDD\Reports\get_filter_value( 'campaign_tracker' );

		// If filtering by a specific campaign, show it in the label.
		if ( $has_campaign_filter && 'all' !== $campaign ) {
			if ( '' === $campaign ) {
				$campaign_name = __( 'Unknown Campaign', 'easy-digital-downloads' );
			} else {
				$campaign_name = esc_html( $campaign );
			}
			return sprintf(
				/* translators: %s: Campaign name */
				__( '%s &mdash; Campaign Sources', 'easy-digital-downloads' ),
				$campaign_name
			) . ' &mdash; ' . $this->get_chart_label();
		}

		return __( 'Campaign Sources', 'easy-digital-downloads' ) . ' &mdash; ' . $this->get_chart_label();
	}

	/**
	 * Gets the class name for the table.
	 *
	 * @since 3.6.3
	 * @return string
	 */
	protected function get_class_name(): string {
		return '\\EDD\\Pro\\CampaignTracker\\Admin\\Reports\\Data\\CampaignSourcesListTable';
	}
}
