"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.gatherFeedback = exports.sendFeedback = void 0;
const readline_1 = __importDefault(require("readline"));
const constants_1 = require("./constants");
const fetch_1 = require("./fetch");
const logger_1 = __importDefault(require("./logger"));
async function sendFeedback(feedback) {
    const resp = await (0, fetch_1.fetchWithProxy)(`${constants_1.REMOTE_API_BASE_URL}/api/feedback`, {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
        },
        body: JSON.stringify({
            message: feedback,
        }),
    });
    if (resp.ok) {
        logger_1.default.info('Feedback sent. Thank you!');
    }
    else {
        logger_1.default.info('Sorry, feedback failed to send for some reason. You can also open an issue at https://github.com/promptfoo/promptfoo/issues/new');
    }
}
exports.sendFeedback = sendFeedback;
function gatherFeedback(message) {
    if (message) {
        sendFeedback(message);
    }
    else {
        const reader = readline_1.default.createInterface({
            input: process.stdin,
            output: process.stdout,
        });
        reader.on('keypress', (str, key) => {
            if (key.name === 'enter' && key.shift) {
                reader.write('\n');
            }
        });
        reader.question('\n\nPlease enter your feedback. Leave your email address if you want to hear back:\n\n> ', (input) => {
            reader.close();
            sendFeedback(input);
        });
    }
}
exports.gatherFeedback = gatherFeedback;
//# sourceMappingURL=feedback.js.map