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

declare(strict_types=1);

namespace ThemeREX\AutoDealer\Elementor\DynamicTags;

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

use function ThemeREX\AutoDealer\getSettings;

class MileageTag extends AbstractVehicleTag {

	protected string $tag_name  = 'trx-ad-mileage';
	protected string $tag_title = 'Vehicle Mileage';

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

	protected function resolveValue( int $vehicleId ): string {
		$value = $this->specs( $vehicleId, 'mileage' );
		if ( '' === $value || ! is_numeric( $value ) ) {
			return '';
		}
		$unit = (string) getSettings( 'mileage_unit', 'km' );
		return number_format( (float) $value, 0, '.', ',' ) . ' ' . $unit;
	}
}
