import { t as __exportAll } from "./rolldown-runtime-Cbj13DAv.js";

//#region src/slack/http/registry.ts
const slackHttpRoutes = /* @__PURE__ */ new Map();
function normalizeSlackWebhookPath(path) {
	const trimmed = path?.trim();
	if (!trimmed) return "/slack/events";
	return trimmed.startsWith("/") ? trimmed : `/${trimmed}`;
}
function registerSlackHttpHandler(params) {
	const normalizedPath = normalizeSlackWebhookPath(params.path);
	if (slackHttpRoutes.has(normalizedPath)) {
		const suffix = params.accountId ? ` for account "${params.accountId}"` : "";
		params.log?.(`slack: webhook path ${normalizedPath} already registered${suffix}`);
		return () => {};
	}
	slackHttpRoutes.set(normalizedPath, params.handler);
	return () => {
		slackHttpRoutes.delete(normalizedPath);
	};
}
async function handleSlackHttpRequest(req, res) {
	const url = new URL(req.url ?? "/", "http://localhost");
	const handler = slackHttpRoutes.get(url.pathname);
	if (!handler) return false;
	await handler(req, res);
	return true;
}

//#endregion
//#region src/slack/http/index.ts
var http_exports = /* @__PURE__ */ __exportAll({
	handleSlackHttpRequest: () => handleSlackHttpRequest,
	normalizeSlackWebhookPath: () => normalizeSlackWebhookPath,
	registerSlackHttpHandler: () => registerSlackHttpHandler
});

//#endregion
export { normalizeSlackWebhookPath as n, registerSlackHttpHandler as r, http_exports as t };