<?php
/**
 * Small helper for page-scoped inline assets.
 *
 * @package TradeSchoolManager
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

class TSM_Inline_Assets {

	public static function style( $handle, $css ) {
		$handle = sanitize_key( $handle );
		if ( '' === $handle || '' === trim( (string) $css ) ) {
			return;
		}

		wp_register_style( $handle, false, array(), defined( 'TSM_VERSION' ) ? TSM_VERSION : '1' );
		wp_enqueue_style( $handle );
		wp_add_inline_style( $handle, (string) $css );
		wp_print_styles( array( $handle ) );
	}

	public static function script( $handle, $js, $deps = array() ) {
		$handle = sanitize_key( $handle );
		if ( '' === $handle || '' === trim( (string) $js ) ) {
			return;
		}

		wp_register_script( $handle, false, (array) $deps, defined( 'TSM_VERSION' ) ? TSM_VERSION : '1', true );
		wp_enqueue_script( $handle );
		wp_add_inline_script( $handle, (string) $js );
		wp_print_scripts( array( $handle ) );
	}
}
