<?php
/**
 * WeCodeArt Framework.
 *
 * WARNING: This file is part of the core WeCodeArt Framework. DO NOT edit this file under any circumstances.
 * Please do all modifications in the form of a child theme.
 *
 * @package 	WeCodeArt Framework
 * @subpackage 	Support\Styles\Property\FontFamily
 * @copyright   Copyright (c) 2025, WeCodeArt Framework
 * @since 		5.0.0
 * @version		5.5.8
 */

namespace WeCodeArt\Support\Styles\Sanitize\Property;

defined( 'ABSPATH' ) || exit;

use WeCodeArt\Support\Styles\Sanitize\Property;

/**
 * Output for CSS properties.
 */
class Background extends Property {
	/**
	 * Modifies the value.
	 *
	 * @access protected
	 */
	protected function process_value() {
		$processed = ''; 

		if ( $this->value ) {
			// If is array, make sure it has url
			if ( is_array( $this->value ) && isset( $this->value['url'] ) ) {
				$this->value = $this->value['url'];
			}
			// If is URL
			if( filter_var( $this->value, FILTER_VALIDATE_URL ) ) {
				$processed = sprintf( 'url("%s")', esc_url( set_url_scheme( $this->value ) ) );
			// If is data URL
			} elseif( strpos( $this->value, 'data:image' ) !== false  ) {
				$processed = sprintf( 'url("%s")', esc_url_raw( $this->value, [ 'data' ] ) );
			// If is image ID
			} elseif ( preg_match( '/^\d+$/', $this->value ) ) {
				$processed = sprintf( 'url("%s")', esc_url( set_url_scheme( wp_get_attachment_url( $this->value ) ) ) );
			// else is a gradient/string
			} else {
				$processed = filter_var( $this->value, FILTER_SANITIZE_STRING );
			}
		}
		
		$this->value = $processed;
	}
}