import { useEffect, useRef, useState } from "react";
import { useParams, Link } from "react-router";
import { createMockAuction } from "../auction-mock";
import type {
AuctionState,
AuctionPlayer,
AuctionTeam,
} from "../auction-types";
import { positionIcon, positionLabel, type Position } from "../mock";
// -- 티어 색상 --
function tierColor(tier: string): string {
if (tier.startsWith("챌린저")) return "text-amber-400";
if (tier.startsWith("그랜드마스터")) return "text-red-400";
if (tier.startsWith("마스터")) return "text-purple-400";
if (tier.startsWith("다이아")) return "text-cyan-400";
if (tier.startsWith("에메랄드")) return "text-emerald-400";
if (tier.startsWith("플래티넘")) return "text-teal-300";
if (tier.startsWith("골드")) return "text-yellow-400";
if (tier.startsWith("실버")) return "text-gray-300";
return "text-amber-700";
}
function formatPoints(n: number): string {
return n.toLocaleString();
}
function PosBadge({ pos }: { pos: Position }) {
return (
{positionLabel[pos]}
);
}
// -- 타이머 바 --
function TimerBar({ timer, maxTimer }: { timer: number; maxTimer: number }) {
const pct = (timer / maxTimer) * 100;
const urgent = timer <= 5;
return (
);
}
// -- 팀 패널 --
function TeamPanel({
team,
isActive,
isLeft,
}: {
team: AuctionTeam;
isActive: boolean;
isLeft: boolean;
}) {
const borderColor =
team.side === "blue" ? "border-blue-500/25" : "border-red-500/25";
const accentBar = team.side === "blue" ? "bg-blue-500" : "bg-red-500";
const sideColor = team.side === "blue" ? "text-blue-400" : "text-red-400";
const headerBg = team.side === "blue" ? "bg-blue-500/8" : "bg-red-500/8";
return (
{/* 헤더 */}
{team.side === "blue" ? "블루팀" : "레드팀"}
팀장: {team.captainName}
{formatPoints(team.points)}P
{/* 멤버 목록 */}
{team.members.length === 0 ? (
아직 멤버가 없습니다
) : (
team.members.map((m) => (
{m.summonerName}
{m.cost}
))
)}
{/* 빈 슬롯 */}
{Array.from({ length: 4 - team.members.length }).map((_, i) => (
))}
);
}
// -- 현재 경매 선수 카드 --
function PlayerSpotlight({
player,
phase,
currentBid,
currentBidder,
}: {
player: AuctionPlayer;
phase: AuctionState["phase"];
currentBid: number;
currentBidder: "blue" | "red" | null;
}) {
const winRate =
player.recentStats.games > 0
? Math.round((player.recentStats.wins / player.recentStats.games) * 100)
: 0;
const kdaRatio =
player.recentStats.kda.deaths > 0
? (
(player.recentStats.kda.kills + player.recentStats.kda.assists) /
player.recentStats.kda.deaths
).toFixed(2)
: "Perfect";
return (
{/* 선수 프로필 */}
{player.summonerName}
#{player.tag}
{player.tier.previousSeason}
→
{player.tier.current}
({player.tier.peak})
{" "}
{positionLabel[player.subPosition]}
{/* 스탯 그리드 */}
{/* 숙련도 */}
숙련도 높은 챔피언
{player.masteries.map((m) => (
{m.championName}
Lv.{m.level} · {(m.points / 1000).toFixed(0)}K
))}
{/* 최근 전적 */}
최근 솔로랭크
승률
= 55 ? "text-blue-400" : winRate >= 50 ? "text-base-content" : "text-red-400"}`}
>
{winRate}%
전적
{player.recentStats.wins}W
{" "}
{player.recentStats.losses}L
KDA
{player.recentStats.kda.kills}/{player.recentStats.kda.deaths}/
{player.recentStats.kda.assists}
= 3 ? "text-emerald-400" : "text-base-content/50"}`}
>
({kdaRatio})
평균 CS
{player.recentStats.avgCs}
{/* 현재 입찰 상태 */}
{(phase === "bidding" || phase === "sold") && (
{phase === "sold" ? "낙찰가" : "현재 입찰가"}
{currentBidder && (
{currentBidder === "blue" ? "블루" : "레드"}
)}
{currentBid > 0 ? formatPoints(currentBid) : "—"}
)}
);
}
// -- 입찰 컨트롤 --
function BidControls({
state,
onBid,
}: {
state: AuctionState;
onBid: (side: "blue" | "red", amount: number) => void;
}) {
const [bidAmount, setBidAmount] = useState(100);
const minBid = state.currentBid + 10;
useEffect(() => {
setBidAmount(Math.max(minBid, Math.ceil(minBid / 10) * 10));
}, [state.currentBid]);
if (state.phase !== "bidding") return null;
const presets = [50, 100, 150, 200, 300, 500];
return (
);
}
// -- 입찰 로그 --
function BidLog({ bids }: { bids: AuctionState["bids"] }) {
const endRef = useRef(null);
useEffect(() => {
endRef.current?.scrollIntoView({ behavior: "smooth" });
}, [bids.length]);
if (bids.length === 0) return null;
return (
입찰 기록
{bids.map((b, i) => (
{b.side === "blue" ? "블루" : "레드"}
→
{formatPoints(b.amount)}P
))}
);
}
// -- 메인 --
export default function AuctionPage() {
const { id } = useParams();
const [state, setState] = useState(null);
const auctionRef = useRef | null>(null);
useEffect(() => {
const auction = createMockAuction((newState) => {
setState({ ...newState });
});
auctionRef.current = auction;
auction.start();
return () => {
auction.destroy();
};
}, [id]);
if (!state) {
return (
연결 중...
);
}
const handleBid = (side: "blue" | "red", amount: number) => {
auctionRef.current?.bid(side, amount);
};
const phaseLabel: Record = {
waiting: "경매 준비 중...",
presenting: "다음 선수 등장",
bidding: "입찰 진행 중",
sold: "낙찰!",
complete: "경매 완료",
};
return (
{/* 뒤로가기 */}
내전 상세로
{/* 경매 헤더 */}
경매 팀빌딩
{state.currentPlayerIndex + 1} / {state.totalPlayers} 선수
{phaseLabel[state.phase]}
{state.phase === "bidding" && (
{state.timer}s
)}
{/* 타이머 바 */}
{state.phase === "bidding" && (
)}
{/* 메인 3컬럼 */}
{/* 블루팀 */}
{/* 중앙: 선수 카드 */}
{state.phase === "waiting" && (
)}
{state.phase === "complete" && (
경매 완료
모든 선수가 팀에 배정되었습니다.
결과 확인
)}
{state.currentPlayer &&
(state.phase === "presenting" ||
state.phase === "bidding" ||
state.phase === "sold") && (
<>
{state.phase === "sold" && state.currentBidder && (
{state.currentBidder === "blue" ? "블루팀" : "레드팀"} 낙찰
— {formatPoints(state.currentBid)}P
)}
>
)}
{/* 레드팀 */}
);
}