import { formatEnvironmentTypeLabel } from "./format-environment-type.js";
const TYPE_ORDER = {
    "working-copy": 0,
    preview: 1,
    production: 2,
};
const FALLBACK_ORDER = 3;
export function sortEnvironmentsForPrompt(envs) {
    return [...envs].sort((a, b) => {
        const aOrder = TYPE_ORDER[formatEnvironmentTypeLabel(a.environmentType)] ??
            FALLBACK_ORDER;
        const bOrder = TYPE_ORDER[formatEnvironmentTypeLabel(b.environmentType)] ??
            FALLBACK_ORDER;
        if (aOrder !== bOrder) {
            return aOrder - bOrder;
        }
        return visibleSortKey(a).localeCompare(visibleSortKey(b));
    });
}
function visibleSortKey(env) {
    const type = formatEnvironmentTypeLabel(env.environmentType);
    if (type === "working-copy") {
        return env.name;
    }
    return env.branchName || env.name;
}
//# sourceMappingURL=sort-environments-for-prompt.js.map