<?php
/**
 * CSS
 *
 * Generates CSS custom-property strings from plugin options.
 * Templates use var(--relatedly-*) instead of inline styles,
 * so user-configured colours are set once on the container element.
 *
 * @package Relatedly\Utilities
 * @since   2.0.0
 */

namespace Relatedly\Utilities;

use Relatedly\Core\Options;

defined( 'ABSPATH' ) || exit;

/**
 * Builds CSS custom-property strings from options.
 *
 * @since 2.0.0
 */
class CSS {

	/**
	 * Build a CSS custom-properties string from a map of variable → option key.
	 *
	 * Example:
	 *   CSS::vars( $options, [ '--relatedly-bg' => 'inline_theme1_bg' ] )
	 *   → "--relatedly-bg:#f9f9f9"
	 *
	 * @param Options              $options Plugin options instance.
	 * @param array<string,string> $map     [ '--css-var-name' => 'option_key' ].
	 * @return string Semicolon-separated CSS custom properties (no trailing semicolon).
	 */
	public static function vars( Options $options, array $map ): string {
		$parts = [];
		foreach ( $map as $var => $option_key ) {
			$val = (string) $options->get( $option_key, '' );
			if ( '' !== $val ) {
				$parts[] = esc_attr( $var ) . ':' . esc_attr( $val );
			}
		}
		return implode( ';', $parts );
	}
}
