import React from 'react';
import {useShopStore} from "./shop_store";

/**
 * Component that displays crate modes
 */
export function CrateMode({crate_index}) {
    const {modes_order, crate_modes, crate, setMode} = useShopStore(state => ({
        modes_order: state.modes_order,
        crate_modes: state.crate_modes,
        crate: state.crates[crate_index],
        setMode: state.setCrateMode
    }))
    return (
        <div className="crate-mode">
            {modes_order.map((mode_name, _) => (
                <a
                    key={mode_name}
                    className={crate.crate_mode === mode_name ? 'active' : ''}
                    onClick={() => setMode(crate.id, mode_name)}
                    href="#"
                    role="button">{crate_modes[mode_name].name}</a>
            ))}
        </div>
    );
}