package ultidraw

import "strings"

const ExcalidrawExtension = "excalidraw"

// Config holds UltiDraw editor integration settings.
type Config struct {
	Enabled             bool
	HocuspocusPublicURL string
	HocuspocusSecret    string
	APIInternalURL      string
}

func normalizePath(p string) string {
	p = strings.TrimSpace(p)
	if p == "" {
		return "/"
	}
	if !strings.HasPrefix(p, "/") {
		p = "/" + p
	}
	return strings.ReplaceAll(p, "//", "/")
}

func fileNameFromPath(p string) string {
	p = normalizePath(p)
	if p == "/" {
		return ""
	}
	if i := strings.LastIndex(p, "/"); i >= 0 {
		return p[i+1:]
	}
	return p
}

func isExcalidrawPath(path string) bool {
	lower := strings.ToLower(path)
	return strings.HasSuffix(lower, "."+ExcalidrawExtension) || strings.HasSuffix(lower, ".excalidraw.json")
}
