import './menu-with-top-button.css'
import {IMenuWithTopButton} from "../../interfaces/menu/IMenuWithTopButton.ts";

export default function MenuWithTopButton(props: IMenuWithTopButton) {
    const list = props.list.map((item, index) => (
        // 创建项目下三个选项
        <li className={item.active ? 'active' : ''} key={item.id} onClick={(e) => {
            props.handleListItem(e, index, item);
        }}>
            {item.icon ? (<img src={item.icon} className="menu-icon" alt="加载失败"/>) : <></>}
            <span className="menu-name">{item.name}</span>
        </li>
    ));

    return (
        <div className="menu-with-top-button">
            {/* button 是三个黄色按钮 */}
            <button className="btn btn-orange top-button"
                    onClick={(e) => {
                        props.button.handle(e);
                    }}
            >
                {props.button.name}
            </button>
            <ul>{list}</ul>
        </div>
    )
}