<?php
/**
 * Campaign Sales Tile.
 *
 * @package     EDD\Pro\CampaignTracker\Admin\Reports\Endpoints\Tiles
 * @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\Tiles;

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

/**
 * Campaign Sales Tile.
 *
 * @since 3.6.3
 */
class CampaignSales extends CampaignTile {

	/**
	 * Gets the tile endpoint ID.
	 *
	 * @since 3.6.3
	 * @return string
	 */
	protected function get_id(): string {
		return 'campaign_tracker_sales';
	}

	/**
	 * Gets the tile label for display.
	 *
	 * @since 3.6.3
	 * @return string
	 */
	protected function get_label(): string {
		return __( 'Sales', 'easy-digital-downloads' );
	}

	/**
	 * Gets the data for the endpoint.
	 *
	 * @since 3.6.3
	 * @return string
	 */
	protected function get_data() {
		global $wpdb;

		$sales = $wpdb->get_var(
			"SELECT COUNT(DISTINCT o.id)
			{$this->get_from_clause()}
			{$this->get_base_where_clause()}"
		);

		return number_format_i18n( absint( $sales ) );
	}
}
