// Package utils provides utility functions for the renderer package.
package utils

import (
	"strings"
)

// GetValueFromPath retrieves a value from a nested map using a dot-separated path.
func GetValueFromPath(data map[string]any, path string) (any, bool) {
	// Handle the special case where path is "." or empty, meaning the root data itself
	if path == "." || path == "" {
		return data, true
	}

	keys := strings.Split(path, ".")
	var current any = data
	for _, key := range keys {
		if key == "" { // Skip empty keys from ".." or "path."
			continue
		}
		if m, ok := current.(map[string]any); ok {
			if val, found := m[key]; found {
				current = val
			} else {
				return nil, false
			}
		} else {
			return nil, false
		}
	}
	return current, true
}
