// SPDX-License-Identifier: GPL-3.0-only namespace { std::string report_number(const Json &value) { return value.is_number_integer() ? number(value.get()) : "—"; } std::string report_zone(int rank, int count, int tier) { if (rank > count - 3) return "relegation"; if (tier == 1) { if (rank <= 4) return "champions"; if (rank == 5) return "europa"; if (rank == 6) return "conference"; } else { if (rank <= (tier == 4 ? 1 : 2)) return "promotion"; if (tier != 4 && rank == 3) return "playoff"; } return {}; } } // namespace std::string App::report_club_button(const std::string &id, bool name_first) { const auto *c = world_->find("clubs", id); const auto live=engine_mode_?engine_report_team(id):Json(); if ((engine_mode_&&live.is_null())||(!engine_mode_&&!c)) return "—"; const auto name = esc(engine_mode_?live.at("name").get():world_->name(*c)); const auto text = "" + name + ""; return btn("club-detail", name_first ? text + crest(c, 42) : crest(c, 42) + text, std::string("report-club-button ") + (name_first ? "name-first " : "") + ((engine_mode_?engine_data_.at("desktop").at("meta").at("scope").at("teamId")==id:snap().state.at("career").value("role","club")=="club"&&manager(snap()).value("club", "") == id) ? "current" : ""), "id=\"report-club-" + esc(id) + "\" data-id=\"" + esc(id) + "\""); } std::string App::render_reports(const std::string &mode) { const auto snapshot = engine_mode_?Snapshot{}:snap(); const auto state = engine_mode_?engine_reports_state_:snapshot.state.at("reports"); const auto *league = world_->find("competitions", state.value("league", "")); const int tier = league ? league->value("tier", 1) : 1; const bool strengths = mode == "strengths", matches = mode == "league" || mode == "other"; const bool opening = !engine_mode_ && mode == "other" && state.value("competition", 0) == 3 && snapshot.state.value("opening_created", false); const auto rows = engine_mode_?engine_reports_rows(mode):matches ? (opening ? report_opening_pairs(*world_, snapshot.state.at("opening_flow")) : report_match_rows(*world_, state, mode == "other")) : strengths ? report_strength_rows(*world_, state) : report_table_rows(*world_, state); const std::vector> headings = matches ? std::vector>{ {"", "Heim"}, {"", "Ergebnis"}, {"", "Auswärts"}} : strengths ? std::vector>{ {"club", "Verein"}, {"keeper", "TW"}, {"defence", "Abwehr"}, {"midfield", "Mittelfeld"}, {"attack", "Sturm"}, {"strength", "Stärke"}} : std::vector>{ {"rank", "Pl. / Verein"}, {"played", "Sp."}, {"wins", "S"}, {"draw", "U"}, {"loss", "N"}, {"form", "Letzte 8"}, {"points", "Punkte"}, {"gf", "Tore"}, {"diff", "Diff."}}; const bool real_other=engine_mode_&&mode=="other"; const auto &fixture=real_other?engine_other_value_:engine_fixtures_value_; const auto own_id = engine_mode_ ? engine_data_.at("desktop").at("meta").at("scope").at("teamId").get() : snap().state.at("career").value("role", "club") == "club" ? manager(snap()).value("club", "") : std::string(); // a place the season decides tints its row: Europe, promotion, relegation const auto zone_of = [&](const Json &row) -> std::string { const auto zone = engine_mode_ ? row.value("zone", std::string()) : report_zone(row.value("rank", 0), int(rows.size()), tier); return zone == "europe" || zone == "champions" || zone == "europa" || zone == "conference" ? "eu" : zone == "promotion" || zone == "playoff" ? "auf" : zone == "relegation" ? "ab" : ""; }; std::string body = "
"; if (matches) { const int round = engine_mode_?fixture.at("round").get()-1:std::clamp(state.value("round", 0), 0, report_round_count(*world_, state, mode == "other") - 1); std::string subtitle; if(real_other)subtitle=fixture.at("name").get(); else if(engine_mode_){const auto &l=fixture.at("league");subtitle=(l.at("nationId").is_string()?world_->nation_name(l.at("nationId")):std::string())+" · "+l.at("name").get();} else if (mode == "league" || state.value("competition", 0) == 0) subtitle = (league ? world_->nation_name(league->value("nation", "")) : "") + " · " + (league ? world_->name(*league) : ""); else { const auto choices = report_picker_items("competition"); subtitle = choices.at(size_t(state.value("competition", 0))).second; } const double mid = real_other ? 190 : 120; body += "

" + (real_other?fixture.at("heading").get():opening ? std::string("1. Runde") : std::to_string(round + 1) + ". Spieltag") + "

" + esc(subtitle) + "
" "
" + pg_kicker("Heim", "text-align:right;") + "ERGEBNIS" + pg_kicker("Auswärts") + "
" "
"; for (const auto &row : rows) { const auto home = row.at("home").get(), away = row.at("away").get(); std::string value = row.at("home_goals").is_null() || row.at("away_goals").is_null() ? std::string() : report_number(row["home_goals"]) + " : " + report_number(row["away_goals"]); std::string middle, detail; if (real_other) { const auto phase = [](const Json &v) { return v == 1 ? std::string(" n.V.") : v == 2 ? std::string(" n.E.") : std::string(); }; if (!value.empty()) value += phase(row.at("phase")); if (row.at("secondLegVisible").get()) { detail = "Hin: " + (row.at("secondLeg").is_null() ? std::string("–") : report_number(row.at("secondLeg")[0]) + ":" + report_number(row.at("secondLeg")[1]) + phase(row.at("secondLegPhase"))); if (!value.empty()) value = "Rück: " + value; } else if (row.at("status") == "scheduled" && row.at("date").is_string()) detail = row.at("date").get(); } const bool moved = engine_mode_ && (row.value("status", "") == "rescheduled" || row.value("status", "") == "postponed"); if (!value.empty()) middle = "" + esc(value) + "" + (detail.empty() ? "" : "" + esc(detail) + ""); else if (moved) middle = "verlegt"; else if (!detail.empty()) middle = "" + esc(detail) + ""; else middle = "–"; body += "
" + pg_club(home, 50, true) + "
" + middle + "
" + pg_club(away) + "
"; } if (real_other && rows.empty()) body += "
" + std::string(!fixture.at("available").get() ? "Diese Runde ist noch nicht ausgelost oder die vorherige Phase ist noch nicht abgeschlossen." : "Keine Paarungen vorhanden.") + "
"; body += "
"; } else { // the widths of the columns in design units; the first takes the room that is left const std::vector widths = strengths ? std::vector{0, 150, 150, 150, 150, 110} : std::vector{0, 52, 52, 52, 52, 190, 80, 80, 70}; const auto sorting = state.at("sorts").at(mode); const double row_height = rows.size() > 20 ? 1420.0 / rows.size() : 70; body += "
"; for (size_t column = 0; column < headings.size(); ++column) { const auto &[key, label] = headings[column]; const bool current = sorting.value("key", "") == key, descending = sorting.value("desc", false); body += pg_th(label, widths[column], column == 0 ? "" : !strengths && column == 5 ? "" : "r", "report-sort", "id=\"report-sort-" + key + "\" data-id=\"" + key + "\" aria-label=\"Nach " + esc(label) + " sortieren\"", current ? (descending ? -1 : 1) : 0); } body += "
"; for (const auto &row : rows) { const auto club = row.value("club", std::string()); const auto zone = strengths ? std::string() : zone_of(row); body += "
"; for (size_t column = 0; column < headings.size(); ++column) { const auto &key = headings[column].first; if (column == 0) body += pg_td((strengths ? std::string() : "" + std::to_string(row.value("rank", 0)) + "") + pg_club(club), 0, "", true); else if (strengths && column < 5) { const auto value = row.at(key).is_number_integer() ? row.at(key).get() : 0; body += pg_td("" + pg_bar((value - 50) / 40.0 * 100) + "" + report_number(row.at(key)) + "", widths[column], "r", true); } else if (strengths) body += pg_td("" + report_number(row.at(key)) + "", widths[column], "r"); else if (column == 5) body += pg_td(pg_form(row.value("form_text", "")), widths[column], "", true); else if (column == 6) body += pg_td("" + report_number(row.at(key)) + "", widths[column], "r"); else if (column == 7) body += pg_td(report_number(row["gf"]) + ":" + report_number(row["ga"]), widths[column], "r"); else if (column == 8) { const auto diff = row.at(key).is_number_integer() ? row.at(key).get() : 0; body += pg_td((diff > 0 ? "+" : "") + report_number(row.at(key)), widths[column], "r"); } else body += pg_td(report_number(row.at(key)), widths[column], "r"); } body += "
"; } body += "
"; } // the foot: steps and pickers at the left, a legend or a note at the right body += "
" + render_report_detail(); }