import GrainCable from "./GrainCable";
import { Bin } from "models";
import React from "react";
import { CableData } from "../../Data/BuildCableData";
import { NodeData } from "../../Data/BuildNodeData";

interface Props {
    cableData: CableData[],
    nodeData: NodeData[],
    bin: Bin,
    renderOrder?: number,
    displayTemp?: boolean,
    displayMoisture?: boolean,
    onNodeClick?: (node: NodeData, cable: CableData) => void
}

export default function BinCables(props: Props){
    const {bin, cableData, nodeData, onNodeClick, renderOrder, displayTemp, displayMoisture} = props
    return (
        <React.Fragment>
            {cableData.map((cable, i) => {
                const cableNodes = nodeData.filter(n => n.cableIndex === cable.cableIndex);

                return (
                    <GrainCable 
                        key={"cable " + i} 
                        cable={cable} 
                        nodes={cableNodes} 
                        bin={bin} 
                        displayTemp={displayTemp}
                        displayMoisture={displayMoisture}
                        onNodeClick={(node) => {
                            if(onNodeClick){
                                onNodeClick(node, cable)
                            }
                        }}
                        renderOrder={renderOrder}
                    />
                )}
            )}

        </React.Fragment>
    )
}