package parser

import (
	"path/filepath"
	"strings"
)

var ignoredBasenames = map[string]struct{}{
	".gitignore":         {},
	".dockerignore":      {},
	".gitattributes":     {},
	".editorconfig":      {},
	".prettierignore":    {},
	".eslintignore":      {},
	".npmignore":         {},
	"package-lock.json":  {},
	"npm-shrinkwrap.json": {},
	"yarn.lock":          {},
	"pnpm-lock.yaml":     {},
	"composer.lock":      {},
	"gemfile.lock":       {},
	"poetry.lock":        {},
	"cargo.lock":         {},
	"go.sum":             {},
}

var ignoredPathPrefixes = []string{
	"scripts/fixtures/",
	"test/fixtures/",
	"tests/fixtures/",
	"__fixtures__/",
}

var ignoredSuffixes = []string{
	".min.js",
	".min.css",
	".bundle.js",
	".bundle.css",
	".map",
}

// IsIgnoredPath reports whether a repository path should be excluded from indexing.
func IsIgnoredPath(filePath string) bool {
	normalized := filepath.ToSlash(strings.TrimSpace(filePath))
	if normalized == "" || normalized == "." {
		return false
	}

	lower := strings.ToLower(normalized)
	for _, prefix := range ignoredPathPrefixes {
		if strings.HasPrefix(lower, prefix) {
			return true
		}
	}
	if strings.Contains(lower, "/fixtures/") && strings.HasSuffix(lower, ".html") {
		return true
	}

	base := strings.ToLower(filepath.Base(normalized))
	if _, ok := ignoredBasenames[base]; ok {
		return true
	}

	for _, suffix := range ignoredSuffixes {
		if strings.HasSuffix(lower, suffix) {
			return true
		}
	}
	return false
}
