"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const index = require("./index-QSf6WJj0.cjs");
const defaultResponder = require("./defaultResponder-ZNP4idbH.cjs");
const getAppKeysFromSlug = require("./getAppKeysFromSlug-duun9y1Q.cjs");
const encodeOAuthState = require("./encodeOAuthState-VBfelnxQ.cjs");
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.getAppKeysFromSlug("closecom");
  if (!client_id || typeof client_id !== "string")
    return res.status(400).json({ message: "Close.com client_id missing." });
  const state = encodeOAuthState.encodeOAuthState(req) ?? "";
  const params = new URLSearchParams({
    client_id,
    redirect_uri: `${index.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.defaultResponder(handler);
exports.default = _getAdd;
