<?php

namespace EasyContentManager\Classes;

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

use EasyContentManager\Utils\Helper;

class GlobalCss {


	public static function init() {
		$self = new self();
		if ( is_admin() ) {
			add_action( 'admin_head', array( $self, 'get_global_css' ) );
			add_action( 'admin_print_styles', array( $self, 'get_global_css' ), 30 );
		} else {
			add_action( 'wp_head', array( $self, 'get_global_css' ) );
		}
	}
	public function get_global_css() {
		global $ecm_settings;
		$primary_color = ( 'dark' === $ecm_settings->color_theme_mode )
			? $ecm_settings->dark_primary_color
			: $ecm_settings->primary_color;

		$secondary_color = ( 'dark' === $ecm_settings->color_theme_mode )
			? $ecm_settings->dark_secondary_color
			: $ecm_settings->secondary_color;

		$text_color = ( 'dark' === $ecm_settings->color_theme_mode )
			? $ecm_settings->dark_text_color
			: $ecm_settings->text_color;

		$body_color = ( 'dark' === $ecm_settings->color_theme_mode )
			? $ecm_settings->dark_body_color
			: $ecm_settings->body_color;

		$background_color = ( 'dark' === $ecm_settings->color_theme_mode )
			? $ecm_settings->dark_background_color
			: $ecm_settings->background_color;

		$border_color = ( 'dark' === $ecm_settings->color_theme_mode )
			? $ecm_settings->dark_border_color
			: $ecm_settings->border_color;

		// @phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
		echo "
		<style>
			:root {
				--ecm-primary: {$primary_color};
				--ecm-secondary: {$secondary_color};
				--ecm-font-color: {$text_color};
				--ecm-body-background: {$body_color};
				--ecm-background: {$background_color};
				--ecm-border-color: {$border_color};
			}
		</style>
	";
	}
}
