import { m as WEBAPP_URL } from "./index-Cw1zbw54.js";
import { d as defaultResponder } from "./defaultResponder-s4VQhYfH.js";
import { g as getAppKeysFromSlug } from "./getAppKeysFromSlug-S62aYXii.js";
import { e as encodeOAuthState } from "./encodeOAuthState-ADe35aHB.js";
async function handler(req, res) {
  if (!req.session?.user?.id) {
    return res.status(401).json({ message: "You must be logged in to do this" });
  }
  const { client_id } = await getAppKeysFromSlug("closecom");
  if (!client_id || typeof client_id !== "string")
    return res.status(400).json({ message: "Close.com client_id missing." });
  const state = encodeOAuthState(req) ?? "";
  const params = new URLSearchParams({
    client_id,
    redirect_uri: `${WEBAPP_URL}/api/integrations/closecom/callback`,
    response_type: "code",
    state
  });
  return res.status(200).json({
    url: `https://app.close.com/oauth2/authorize/?${params.toString()}`
  });
}
const _getAdd = defaultResponder(handler);
export {
  _getAdd as default
};
