<?php
class kavehdyanmicCss
{
    public function __construct()
    {
        add_action('wp_enqueue_scripts', [$this, 'theme_dynamic_css'], 999999);
        add_action('elementor/editor/after_enqueue_styles', [$this, 'theme_dynamic_css']);
        add_action('elementor/preview/enqueue_styles', [$this, 'theme_dynamic_css']);

        add_action('wp_ajax_nopriv_kavehdynamiccss', [$this, 'serve_kaveh_dynamic_css']);
        add_action('wp_ajax_kavehdynamiccss', [$this, 'serve_kaveh_dynamic_css']);

    }

    public function serve_kaveh_dynamic_css()
    {
        require KAVEH_TEMPLATE_PATH . '/dynamic.css.php';
        exit;
    }

    public function theme_dynamic_css()
    {
        wp_enqueue_style(
            'kavehdynamiccss',
            admin_url('admin-ajax.php') . '?action=kavehdynamiccss',
            [],
            filemtime(KAVEH_TEMPLATE_PATH . '/dynamic.css.php') // or time()
        );
    }

}