<?php
/**
 * SVG Helper Functions
 */

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

/**
 * Get inline SVG content with optional custom class.
 *
 * @param string $icon_name Name of the icon (without 'icon-' prefix and '.svg' extension)
 * @param string $class Optional CSS class to add to the <svg> tag
 * @return string The SVG HTML string
 */
function kaz_get_icon($icon_name, $class = '')
{
    $file_path = get_template_directory() . '/assets/icons/' . $icon_name . '.svg';
    if (!file_exists($file_path)) {
        if (strpos($icon_name, 'icon-') === 0 || strpos($icon_name, 'logo_') === 0) {
            $file_path = get_template_directory() . '/assets/icons/' . $icon_name . '.svg';
        } else {
            $file_path = get_template_directory() . '/assets/icons/icon-' . $icon_name . '.svg';
        }
    }

    if (file_exists($file_path)) {
        $svg = file_get_contents($file_path);

        if (!empty($class)) {
            // Ubacuje prosleđenu klasu unutar prvog <svg> taga
            $svg = preg_replace('/<svg/', '<svg class="' . esc_attr($class) . '"', $svg, 1);
        }

        return $svg;
    }

    return '<!-- SVG icon not found: ' . esc_html($icon_name) . ' -->';
}
