import CourtSvg from "../../assets/basketball_court.svg?react"
import "../../style/basket_court.css"
import { RefObject, useRef } from "react"
import CourtPlayer from "./CourtPlayer"
import { Player } from "../../model/tactic/Player"

export interface BasketCourtProps {
    players: Player[]
    onPlayerRemove: (p: Player) => void
    onBallDrop: (ref: HTMLDivElement) => void
    onPlayerChange: (p: Player) => void
    courtImage: string
    courtRef: RefObject<HTMLDivElement>
}

export function BasketCourt({
    players,
    onPlayerRemove,
    onBallDrop,
    onPlayerChange,
    courtImage,
    courtRef,
}: BasketCourtProps) {
    return (
        <div
            id="court-container"
            ref={courtRef}
            style={{ position: "relative" }}>
            <img src={courtImage} alt={"court"} id="court-svg" />
            {players.map((player) => {
                return (
                    <CourtPlayer
                        key={player.team + player.role}
                        player={player}
                        onChange={onPlayerChange}
                        onRemove={() => onPlayerRemove(player)}
                        onBallDrop={onBallDrop}
                        parentRef={courtRef}
                    />
                )
            })}
        </div>
    )
}
