import { CONFIRMED, PROCESSED, PROCESSING, } from '@orderingstack/front-components-common';
export const getElements = (lines) => {
    const toPrepare = [];
    const toDone = [];
    const allDone = [];
    const toConfirm = [];
    lines.forEach((line) => {
        if (line.status === CONFIRMED) {
            toPrepare.push(line.id);
            toDone.push(line.id);
        }
        else if (line.status === PROCESSING) {
            toConfirm.push(line.id);
            toDone.push(line.id);
        }
        else if (line.status === PROCESSED) {
            allDone.push(line.id);
        }
    });
    return { toPrepare, toDone, allDone, toConfirm };
};
export const shoudShowDeliverButton = (toDone) => toDone && toDone.length > 0;
export const showDeliveredButton = (allDone, toDone) => allDone && allDone.length > 0 && toDone && toDone.length === 0;
export const getBackgroundColor = (allDone, toDone, toConfirm, toPrepare) => {
    if (toPrepare &&
        toPrepare.length === 0 &&
        toConfirm &&
        toConfirm.length > 0) {
        return '#4CAF50';
    }
    if (allDone &&
        allDone.length > 0 &&
        toDone &&
        toDone.length === 0 &&
        toConfirm &&
        toConfirm.length === 0) {
        return '#ddd';
    }
    return '#ffc200';
};
export function groupLines(array) {
    const result = [];
    array.reduce((res, value) => {
        if (!res[value.hash]) {
            res[value.hash] = {
                ...value,
                quantity: 0,
                discounted: 0,
                discounts: [],
                firstProductQuantity: value.quantity,
                itemsToRemove: [],
            };
            result.push(res[value.hash]);
        }
        res[value.hash].quantity += value.quantity;
        res[value.hash].itemsToRemove.push(value.id);
        if (value.discounts) {
            if (!res[value.hash].discounts) {
                res[value.hash].discounts = [];
            }
            res[value.hash].discounts = res[value.hash].discounts.concat(value.discounts);
            res[value.hash].discounted = 0;
            for (let i = 0; i < res[value.hash].discounts.length; i += 1) {
                if (res[value.hash].discounts[i]) {
                    res[value.hash].discounted += parseFloat(res[value.hash].discounts[i].discountPrice);
                }
            }
        }
        return res;
    }, {});
    return result;
}
//# sourceMappingURL=helperFunctions.js.map