/* ────────────────────────────────────────────────────────────────
   EPIC E3 — Social & Community
   
   Asset marketplace, game sharing, profiles, game jams,
   comments/ratings, featured games
──────────────────────────────────────────────────────────────── */
function createMarketplaceQuery(partial) {
    return {
        sortBy: 'relevance',
        page: 1,
        pageSize: 20,
        ...partial,
    };
}
function computeRatingAggregate(ratings) {
    var _a, _b;
    const dist = [0, 0, 0, 0, 0];
    let sum = 0;
    for (const r of ratings) {
        const clamped = Math.max(1, Math.min(5, Math.round(r.score)));
        dist[clamped - 1]++;
        sum += clamped;
    }
    return {
        targetId: (_b = (_a = ratings[0]) === null || _a === void 0 ? void 0 : _a.targetId) !== null && _b !== void 0 ? _b : '',
        average: ratings.length > 0 ? sum / ratings.length : 0,
        count: ratings.length,
        distribution: dist,
    };
}
function computeJamPhase(jam, now) {
    if (now < jam.startDate)
        return 'upcoming';
    if (now < jam.endDate)
        return 'submission';
    if (now < jam.votingEndDate)
        return 'voting';
    return 'results';
}
function computeJamResults(submissions, categories) {
    const scored = submissions.map(sub => {
        let total = 0;
        let totalWeight = 0;
        for (const cat of categories) {
            const catScores = sub.scores.filter(s => s.category === cat.name);
            if (catScores.length > 0) {
                const avg = catScores.reduce((a, b) => a + b.score, 0) / catScores.length;
                total += avg * cat.weight;
                totalWeight += cat.weight;
            }
        }
        return { ...sub, finalScore: totalWeight > 0 ? total / totalWeight : 0 };
    });
    scored.sort((a, b) => { var _a, _b; return ((_a = b.finalScore) !== null && _a !== void 0 ? _a : 0) - ((_b = a.finalScore) !== null && _b !== void 0 ? _b : 0); });
    return scored.map((s, i) => ({ ...s, rank: i + 1 }));
}
/** Simple content-based recommendation by genre/tag overlap. */
function recommendGames(userPlayedGames, allGames, limit = 10) {
    var _a, _b, _c, _d;
    const playedIds = new Set(userPlayedGames.map(g => g.id));
    const tagCounts = new Map();
    for (const g of userPlayedGames) {
        for (const tag of g.tags)
            tagCounts.set(tag, ((_a = tagCounts.get(tag)) !== null && _a !== void 0 ? _a : 0) + 1);
        for (const genre of g.genre)
            tagCounts.set(genre, ((_b = tagCounts.get(genre)) !== null && _b !== void 0 ? _b : 0) + 2);
    }
    const scored = [];
    for (const g of allGames) {
        if (playedIds.has(g.id))
            continue;
        let score = 0;
        for (const tag of g.tags)
            score += (_c = tagCounts.get(tag)) !== null && _c !== void 0 ? _c : 0;
        for (const genre of g.genre)
            score += ((_d = tagCounts.get(genre)) !== null && _d !== void 0 ? _d : 0) * 2;
        if (score > 0)
            scored.push({ gameId: g.id, score, reason: 'similar-genre' });
    }
    scored.sort((a, b) => b.score - a.score);
    return scored.slice(0, limit);
}

export { computeJamPhase, computeJamResults, computeRatingAggregate, createMarketplaceQuery, recommendGames };
//# sourceMappingURL=Social.js.map
