package mark2web

import (
	"path"
	"strings"

	"gitbase.de/apairon/mark2web/pkg/helper"
)

// ResolveNavPath fixes nav target relative to current navigation path
func ResolveNavPath(target string) string {
	curNavPath := (*CurrentContext)["CurrentPath"].(string)
	if strings.HasPrefix(target, "/") {
		target = helper.BackToRoot(curNavPath) + target
	}
	target = path.Clean(target)
	return target
}

// ResolveOutputPath fixes output directory relative to current navigation path
func ResolveOutputPath(target string) string {
	if strings.HasPrefix(target, "/") {
		target = Config.Directories.Output + "/" + target
	} else {
		target = CurrentTreeNode.OutputPath + "/" + target
	}
	return path.Clean(target)
}

// ResolveInputPath fixes input directory relative to current navigation path
func ResolveInputPath(target string) string {
	if strings.HasPrefix(target, "/") {
		target = Config.Directories.Input + "/" + target
	} else {
		target = CurrentTreeNode.InputPath + "/" + target
	}
	return path.Clean(target)
}
