"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.resolveWorkspacePromptAbsolutePath = resolveWorkspacePromptAbsolutePath;
exports.resolvePromptSuffix = resolvePromptSuffix;
const node_path_1 = __importDefault(require("node:path"));
const config_contract_1 = require("../config/config-contract");
const paths_1 = require("../paths");
function resolveWorkspacePromptAbsolutePath(options) {
    const resolvedConfig = (0, config_contract_1.resolveDayShiftConfig)({
        repositoryContext: createExplicitRepositoryContext(options.repositoryRoot),
        repositoryConfig: options.config
    });
    const promptSuffix = resolvePromptSuffix(options.promptPath, options.config);
    if (options.promptPath.startsWith(`${options.config.prompt_user_root}/`)) {
        return node_path_1.default.join(resolvedConfig.derived.promptUserRootPath, promptSuffix);
    }
    if (options.promptPath.startsWith(`${options.config.prompt_latest_root}/`)) {
        return node_path_1.default.join(resolvedConfig.derived.promptLatestRootPath, promptSuffix);
    }
    if (options.promptPath.startsWith(`${options.config.prompt_root}/`)) {
        return node_path_1.default.join(resolvedConfig.derived.promptRootPath, promptSuffix);
    }
    return (0, paths_1.resolveRepositoryRelativePath)(options.repositoryRoot, options.promptPath);
}
function resolvePromptSuffix(requestedPromptPath, config) {
    if (requestedPromptPath.startsWith(`${config.prompt_user_root}/`)) {
        return requestedPromptPath.slice(config.prompt_user_root.length + 1);
    }
    if (requestedPromptPath.startsWith(`${config.prompt_latest_root}/`)) {
        return requestedPromptPath.slice(config.prompt_latest_root.length + 1);
    }
    if (requestedPromptPath.startsWith(`${config.prompt_root}/`)) {
        return requestedPromptPath.slice(config.prompt_root.length + 1);
    }
    return node_path_1.default.posix.basename(requestedPromptPath);
}
function createExplicitRepositoryContext(repositoryRoot) {
    return {
        root: repositoryRoot,
        detectionSource: "explicit",
        warnedAboutFallback: false
    };
}
