import { built_default } from "./config/dist/esm/built.mjs";
import { readFileSync } from "node:fs";
import { join } from "node:path";
import { getAppLogger } from "@intlayer/config";
import simpleGit from "simple-git";

//#region ../cli/dist/esm/chokidar/dist/esm/listGitFiles.mjs
const getGitRootDir = async () => {
	try {
		return (await simpleGit().revparse(["--show-toplevel"])).trim();
	} catch (error) {
		getAppLogger(built_default)(`Error getting git root directory: ${error}`, { level: "error" });
		return null;
	}
};
const listGitFiles = async ({ mode, baseRef = "origin/main", currentRef = "HEAD", absolute = true }) => {
	try {
		const git = simpleGit();
		const diff = /* @__PURE__ */ new Set();
		if (mode.includes("untracked")) (await git.status()).not_added.forEach((f) => diff.add(f));
		if (mode.includes("uncommitted")) (await git.diff(["--name-only", "HEAD"])).split("\n").filter(Boolean).forEach((file) => diff.add(file));
		if (mode.includes("unpushed")) (await git.diff(["--name-only", "@{push}...HEAD"])).split("\n").filter(Boolean).forEach((file) => diff.add(file));
		if (mode.includes("gitDiff")) {
			await git.fetch(baseRef);
			(await git.diff(["--name-only", `${baseRef}...${currentRef}`])).split("\n").filter(Boolean).forEach((file) => diff.add(file));
		}
		if (absolute) {
			const gitRootDir = await getGitRootDir();
			if (!gitRootDir) return [];
			return Array.from(diff).map((file) => join(gitRootDir, file));
		}
		return Array.from(diff);
	} catch (error) {
		console.warn("Failed to get changes list:", error);
	}
};

//#endregion
export { listGitFiles };
//# sourceMappingURL=listGitFiles.mjs.map