<?php
namespace Sifency\Includes;
if ( ! defined('ABSPATH') ) {
    exit;
}
final class Sifency_Addons_Elementor_Widgets_Asset_Manager {
    private static $enqueued = [];
    public static function init() {
        add_action( 'elementor/frontend/before_render', [ __CLASS__, 'scan_elements_for_assets' ] );
    }
    public static function scan_elements_for_assets( $element ) {
        $settings = $element->get_settings();
        if ( isset( $settings['sifency_animation_type'] ) && ! empty( $settings['sifency_animation_type'] ) ) {
            self::sifency_enqueue_animation_library( $settings['sifency_animation_type'] );
        }
        if ( $element->get_children() ) {
            foreach ( $element->get_children() as $child_element ) {
                self::scan_elements_for_assets( $child_element );
            }
        }
    }
    private static function sifency_enqueue_animation_library( $library ) {
        if ( isset( self::$enqueued[ $library ] ) ) {
            return;
        }
        switch ( $library ) {
            case 'aos':
                wp_enqueue_style('sifency-aos-style');
                wp_enqueue_script('sifency-aos-script');
                wp_enqueue_script('sifency-frontend-script');
                break;
        }
        self::$enqueued[ $library ] = true;
    }

}