import Weapon from "./Weapon";
import React from "react";
import {IWeapon} from "../types/IUnit";

export interface WeaponSlotProps {
    hardpoint: number,
    unitWeapons:  Map<number, IWeapon> | undefined
}

const WeaponSlot= (props: WeaponSlotProps) => {

    let weaponThisSlotMap = props.unitWeapons ?? []

    let weaponsSorted = [...weaponThisSlotMap].sort()

    let header = "Weapon slot " + props.hardpoint

    let haveDummy = weaponsSorted.find(wp => !wp[1].filename.includes("dummy"))

    let firstWeapon = weaponsSorted[0][1]

    let onlyDummy = weaponsSorted.filter(wp => !wp[1].filename.includes("dummy")).length === 0

    if(onlyDummy) return (<div></div>)

    return (
        <div>
            <h3>{header}</h3>
            {weaponsSorted.filter(wp => !wp[1].filename.includes("dummy")).map(wp =>

                <div style={{marginLeft: 20}}><Weapon isDefault={!haveDummy || wp[1].filename === firstWeapon.filename} weapon={wp[1]}/></div>
            )}
        </div>
    )
}

export default WeaponSlot;