<?php
/**
 * @package ThemeREX\AutoDealer
 */

declare(strict_types=1);

namespace ThemeREX\AutoDealer\Elementor\DynamicTags;

if ( ! class_exists( '\Elementor\Core\DynamicTags\Tag' ) ) {
	return;
}

class DealerNameTag extends AbstractVehicleTag {

	protected string $tag_name  = 'trx-ad-dealer-name';
	protected string $tag_title = 'Vehicle Dealer Name';

	public function __construct( array $data = array() ) {
		parent::__construct( $data );
		$this->tag_title = __( 'Vehicle Dealer Name', 'trx-auto-dealer' );
	}

	protected function resolveValue( int $vehicleId ): string {
		$dealer_id = (int) $this->specs( $vehicleId, 'dealer_id' );
		if ( $dealer_id <= 0 ) {
			$dealer_id = (int) get_post_meta( $vehicleId, '_trx_ad_dealer_id', true );
		}
		if ( $dealer_id <= 0 ) {
			return '';
		}
		return (string) get_the_title( $dealer_id );
	}
}
