<?php

namespace Convertforce\Utils;

class ViewUtils
{
    

    /**
     * Enqueue a script with optional dependencies, loading arguments, and localization.
     *
     * @param string $handle      Script handle (will be prefixed with 'convertforce-').
     * @param string $build_path  Path to the script file relative to the build directory.
     * @param array  $more        Optional configuration array:
     *                           - deps: array - Script dependencies
     *                           - args: bool|array{strategy: string, in_footer: bool} - Script loading arguments
     *                           - localize: array{key: string, value: array} - Localization data
     * @return void
     */
    public static function enqueue_scripts($handle, $build_path, $more = [])
    {
        $handle = 'convertforce-' . $handle;
        wp_register_script(
            $handle,
            CONVERTFORCE_URL . '/build/' . $build_path,
            $more['deps'] ?? [],
            CONVERTFORCE_VERSION,
            $more['args'] ?? []
        );

        if (isset($more['localize']) && isset($more['localize']['key']) && isset($more['localize']['value'])) {
            wp_localize_script($handle, $more['localize']['key'], $more['localize']['value']);
        }

        wp_enqueue_script($handle);
    }


    public static function enqueue_styles($handle, $build_path, $deps = [], $media = 'all')
    {
        $handle = 'convertforce-' . $handle;
        wp_enqueue_style(
            $handle,
            CONVERTFORCE_URL . '/build/' . $build_path,
            $deps,
            CONVERTFORCE_VERSION,
            $media
        );
    }
}