import { i as readInteractions } from "./interactions-writer-B8XAzdqR.js";
import { t as readPipeline } from "./pipeline-writer-CIllfnZl.js";
import { t as scoreOpportunity } from "./opportunity-score-BTMOQSTV.js";
//#region src/core/nba.ts
const STAGE_ACTION = {
	lead: "Qualify the lead and book a discovery call",
	qualified: "Send a tailored proposal",
	proposal: "Follow up on the open proposal",
	negotiation: "Address objections and push to close",
	won: "Kick off onboarding",
	lost: "Run a loss post-mortem"
};
const RANK = {
	high: 0,
	medium: 1,
	low: 2
};
async function nextBestAction(dataDir, slug) {
	const actions = [];
	const deals = await readPipeline(dataDir, slug).catch(() => []);
	const open = deals.filter((d) => d.stage !== "won" && d.stage !== "lost");
	for (const d of open) {
		const { score } = scoreOpportunity(d);
		const priority = score >= 70 ? "high" : score >= 40 ? "medium" : "low";
		actions.push({
			action: STAGE_ACTION[d.stage],
			reason: `Deal '${d.name}' is in ${d.stage} (win-likelihood ${score})`,
			priority,
			deal: d.name
		});
	}
	const interactions = await readInteractions(dataDir, slug).catch(() => "");
	if (!/## \d{4}-\d{2}-\d{2}/.test(interactions)) actions.push({
		action: "Re-engage — no logged interactions yet",
		reason: "No interaction history for this customer",
		priority: "medium"
	});
	if (open.length === 0 && deals.length === 0) actions.push({
		action: "Create an opportunity",
		reason: "No pipeline deals exist for this customer",
		priority: "low"
	});
	return actions.sort((a, b) => RANK[a.priority] - RANK[b.priority]);
}
//#endregion
export { nextBestAction };

//# sourceMappingURL=nba-DwdfM93s.js.map