/**
* Copyright 2026 aphrody-code
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import type { Squad } from "./squad.ts";
export function renderAsciiPitch(squad: Squad): string {
const slots = squad.getSlots();
const chem = squad.getChemistry();
const stats = squad.getStats();
const header = [
`┌────────────────────────────────────────────────────────────────────────┐`,
`│ EA SPORTS FC 27 SQUAD BUILDER — FORMATION: ${squad.formation.name.padEnd(10)} │`,
`│ RATING: ${String(stats.squadRating).padEnd(3)} | CHEM: ${String(chem.totalChemistry).padStart(2)}/33 | ATT: ${String(stats.attackRating).padEnd(3)} | MID: ${String(stats.midfieldRating).padEnd(3)} | DEF: ${String(stats.defenseRating).padEnd(3)} │`,
`├────────────────────────────────────────────────────────────────────────┤`,
];
// Sort slots by Y ascending (Attackers at top, GK at bottom)
const sorted = [...slots].sort((a, b) => a.coordinates.y - b.coordinates.y);
const lines: string[] = [...header];
for (const slot of sorted) {
const p = slot.player;
const name = p ? p.name.slice(0, 20) : "Empty Slot";
const rating = p ? String(p.rating) : "--";
const chemDiamonds = "●".repeat(slot.chemistry) + "○".repeat(3 - slot.chemistry);
const roleBadge = slot.assignedRoleTier === "plus_plus" ? `${slot.assignedRole}++` : slot.assignedRoleTier === "plus" ? `${slot.assignedRole}+` : slot.assignedRole;
const inPosTag = p ? (slot.inPosition ? "✔" : "✘ (OOP)") : "";
const row = `│ [${slot.position.padEnd(3)}] ${name.padEnd(20)} (${rating}) Chem: ${chemDiamonds} Role: ${(roleBadge ?? "").padEnd(16)} ${inPosTag} │`;
lines.push(row);
}
lines.push(`├────────────────────────────────────────────────────────────────────────┤`);
if (squad.manager) {
lines.push(`│ MANAGER: ${squad.manager.name} (${squad.manager.nation} / ${squad.manager.league})`.padEnd(73) + `│`);
}
lines.push(`│ BENCH: ${squad.substitutes.map((s) => `${s.name} (${s.rating})`).join(", ") || "None"}`.slice(0, 72).padEnd(73) + `│`);
lines.push(`└────────────────────────────────────────────────────────────────────────┘`);
return lines.join("\n");
}
export function renderSvgPitch(squad: Squad): string {
const slots = squad.getSlots();
const chem = squad.getChemistry();
const stats = squad.getStats();
const width = 1000;
const height = 1350;
const cardSvgElements = slots
.map((slot) => {
const x = (slot.coordinates.x / 100) * (width - 160) + 20;
const y = (slot.coordinates.y / 100) * (height - 350) + 160;
const p = slot.player;
const name = p ? p.name.slice(0, 16) : `Add ${slot.position}`;
const rating = p ? p.rating : "--";
const club = p?.club ?? "";
const nation = p?.nation ?? "";
const chemActive = slot.chemistry;
const diamond1 = chemActive >= 1 ? "#00FF66" : "#4B5563";
const diamond2 = chemActive >= 2 ? "#00FF66" : "#4B5563";
const diamond3 = chemActive >= 3 ? "#00FF66" : "#4B5563";
const roleTag = slot.assignedRole
? `
${slot.assignedRoleTier === "plus_plus" ? `${slot.assignedRole}++` : slot.assignedRoleTier === "plus" ? `${slot.assignedRole}+` : slot.assignedRole}`
: "";
return `
${rating}
${slot.position}
${name}
${club} · ${nation}
${roleTag}
`;
})
.join("\n");
return `
`;
}