<?php
/**
 * Watson Assets Loader
 * 
 * This file handles loading of all assets for the Watson plugin
 */

if (!defined('ABSPATH')) {
    exit; // Exit if accessed directly.
}

/**
 * Enqueue ZMND assets
 */
function ws_zmnd_enqueue_assets() {
    // Get plugin URL
    $plugin_url = plugin_dir_url(WS_FILE);
    $version = defined('WS_VERSION') ? WS_VERSION : '1.0.0';
    
    // Full paths to style and script files
    $widgets_css = $plugin_url . 'elementor/zmnd/assets/css/ws-zmnd-widgets.css';
    $tabs_css = $plugin_url . 'elementor/zmnd/assets/css/ws-horizontal-tabs.css';
    $moving_gallery_css = $plugin_url . 'elementor/zmnd/assets/css/ws-moving-gallery.css';
    $animation_button_css = $plugin_url . 'elementor/zmnd/assets/css/ws-animation-button.css';
    $animation_image_css = $plugin_url . 'elementor/zmnd/assets/css/ws-animation-image.css';
    $cta_user_css = $plugin_url . 'elementor/zmnd/assets/css/ws-cta-user.css';
    $icon_box_css = $plugin_url . 'elementor/zmnd/assets/css/ws-icon-box.css';
    $marquebox_css = $plugin_url . 'elementor/zmnd/assets/css/ws-marquebox.css';
    $before_after_css = $plugin_url . 'elementor/zmnd/assets/css/ws-before-after.css';
    $interactive_hover_image_css = $plugin_url . 'elementor/zmnd/assets/css/ws-interactive-hover-image.css';
    $woo_product_grid_css = $plugin_url . 'elementor/zmnd/assets/css/ws-woo-product-grid.css';
    $tabs_js = $plugin_url . 'elementor/zmnd/assets/js/ws-horizontal-tabs.js';
    $marquebox_js = $plugin_url . 'elementor/zmnd/assets/js/ws-marquebox.js';
    $before_after_js = $plugin_url . 'elementor/zmnd/assets/js/ws-before-after.js';
    $interactive_hover_image_js = $plugin_url . 'elementor/zmnd/assets/js/ws-interactive-hover-image.js';
    
    // Check if files exist
    $widgets_css_path = WS_PATH . 'elementor/zmnd/assets/css/ws-zmnd-widgets.css';
    $tabs_css_path = WS_PATH . 'elementor/zmnd/assets/css/ws-horizontal-tabs.css';
    $moving_gallery_css_path = WS_PATH . 'elementor/zmnd/assets/css/ws-moving-gallery.css';
    $animation_button_css_path = WS_PATH . 'elementor/zmnd/assets/css/ws-animation-button.css';
    $animation_image_css_path = WS_PATH . 'elementor/zmnd/assets/css/ws-animation-image.css';
    $cta_user_css_path = WS_PATH . 'elementor/zmnd/assets/css/ws-cta-user.css';
    $icon_box_css_path = WS_PATH . 'elementor/zmnd/assets/css/ws-icon-box.css';
    $marquebox_css_path = WS_PATH . 'elementor/zmnd/assets/css/ws-marquebox.css';
    $before_after_css_path = WS_PATH . 'elementor/zmnd/assets/css/ws-before-after.css';
    $interactive_hover_image_css_path = WS_PATH . 'elementor/zmnd/assets/css/ws-interactive-hover-image.css';
    $woo_product_grid_css_path = WS_PATH . 'elementor/zmnd/assets/css/ws-woo-product-grid.css';
    $tabs_js_path = WS_PATH . 'elementor/zmnd/assets/js/ws-horizontal-tabs.js';
    $marquebox_js_path = WS_PATH . 'elementor/zmnd/assets/js/ws-marquebox.js';
    $before_after_js_path = WS_PATH . 'elementor/zmnd/assets/js/ws-before-after.js';
    $interactive_hover_image_js_path = WS_PATH . 'elementor/zmnd/assets/js/ws-interactive-hover-image.js';
    
    // Output debug information
    if (defined('WP_DEBUG') && WP_DEBUG) {
        error_log('[WS_ZMND] Watson Plugin CSS URL: ' . $widgets_css);
        error_log('[WS_ZMND] Watson Plugin CSS Path: ' . $widgets_css_path);
        error_log('[WS_ZMND] CSS File Exists: ' . (file_exists($widgets_css_path) ? 'Yes' : 'No'));
        error_log('[WS_ZMND] Watson Plugin JS URL: ' . $tabs_js);
        error_log('[WS_ZMND] JS File Exists: ' . (file_exists($tabs_js_path) ? 'Yes' : 'No'));
    }
    
    // Enqueue styles
    if (file_exists($widgets_css_path)) {
        wp_enqueue_style('ws-zmnd-widgets', $widgets_css, [], $version);
    }
    
    if (file_exists($tabs_css_path)) {
        wp_enqueue_style('ws-zmnd-horizontal-tabs', $tabs_css, [], $version);
    }
    
    if (file_exists($moving_gallery_css_path)) {
        wp_enqueue_style('ws-zmnd-moving-gallery', $moving_gallery_css, [], $version);
    }
    
    if (file_exists($animation_button_css_path)) {
        wp_enqueue_style('ws-zmnd-animation-button', $animation_button_css, [], $version);
    }

    if (file_exists($animation_image_css_path)) {
        wp_enqueue_style('ws-zmnd-animation-image', $animation_image_css, [], $version);
    }

    if (file_exists($cta_user_css_path)) {
        wp_enqueue_style('ws-zmnd-cta-user', $cta_user_css, [], $version);
    }

    if (file_exists($icon_box_css_path)) {
        wp_enqueue_style('ws-zmnd-icon-box', $icon_box_css, [], $version);
    }
    
    if (file_exists($marquebox_css_path)) {
        wp_enqueue_style('ws-zmnd-marquebox', $marquebox_css, [], $version);
    }
    
    if (file_exists($before_after_css_path)) {
        wp_enqueue_style('ws-zmnd-before-after', $before_after_css, [], $version);
    }
    
    if (file_exists($interactive_hover_image_css_path)) {
        wp_enqueue_style('ws-zmnd-interactive-hover-image', $interactive_hover_image_css, [], $version);
    }
    
    if (file_exists($woo_product_grid_css_path)) {
        wp_enqueue_style('ws-zmnd-woo-product-grid', $woo_product_grid_css, [], $version);
    }
    
    // Enqueue jQuery
    wp_enqueue_script('jquery');
    
    // Enqueue scripts
    if (file_exists($tabs_js_path)) {
        wp_enqueue_script('ws-zmnd-horizontal-tabs', $tabs_js, ['jquery'], $version, true);
    }
    
    if (file_exists($marquebox_js_path)) {
        wp_enqueue_script('ws-zmnd-marquebox', $marquebox_js, ['jquery'], $version, true);
    }
    
    if (file_exists($before_after_js_path)) {
        wp_enqueue_script('ws-zmnd-before-after', $before_after_js, ['jquery'], $version, true);
    }
    
    if (file_exists($interactive_hover_image_js_path)) {
        wp_enqueue_script('ws-zmnd-interactive-hover-image', $interactive_hover_image_js, ['jquery'], $version, true);
    }
}

// Register hooks for loading resources
add_action('wp_enqueue_scripts', 'ws_zmnd_enqueue_assets');
add_action('elementor/frontend/after_enqueue_styles', 'ws_zmnd_enqueue_assets');
add_action('elementor/frontend/after_enqueue_scripts', 'ws_zmnd_enqueue_assets');
add_action('elementor/preview/enqueue_scripts', 'ws_zmnd_enqueue_assets');
