/*!
 * Copyright (c) Microsoft. All rights reserved.
 * Licensed under the MIT license. See LICENSE file in the project.
 */ import merge from 'lodash-es/merge.js';
/**
 * Constructs a command for listing out items with checks
 * @param list - full list of items to display
 * @param checked - subset of items to display with checkbox
 * @param onCheckChange -
 * @param props - any override ICommandBarItemProps to overlay on the command
 * @returns
 */ export function checkedItemsCommand(list, checked, onCheckChange, props) {
    const hash = (checked || []).reduce((acc, cur)=>{
        acc[cur] = true;
        return acc;
    }, {});
    const items = list.map((name, index)=>({
            key: name,
            text: name,
            canCheck: true,
            checked: hash[name],
            onClick: (ev, _item)=>{
                ev?.preventDefault();
                return onCheckChange && onCheckChange(name, !hash[name], index);
            }
        }));
    return merge({
        key: 'checked-items',
        title: 'Choose items',
        iconProps: {
            iconName: 'MultiSelect'
        },
        subMenuProps: {
            items
        }
    }, props);
}
