export function isMessageExist(data) {
    return data.message && data.statusMessage;
}

export function getMessageInfo(data) {
    return {
        message: data.message,
        status: data.statusMessage,
    };
}

export function showNotification(data, containerSelector = '.notification-area') {
    let notificationType;
    switch (data.statusMessage) {
        case 'accConfirmedMsgs':
            notificationType = 'success';
            break;
        case 'accWarnMsgs':
            notificationType = 'warning';
            break;
        case 'accErrorMsgs':
            notificationType = 'error';
            break;
    }

    Wick.Notification.show({
        text: data.message,
        container: containerSelector,
        type: notificationType,
        closeBtn: true,
    });
}

export function getCartEntries(data) {
    return data?.deliveryOrderGroups
        .concat(data.pickupOrderGroups)
        .map((orderGroup) => orderGroup?.entries)
        .flatMap((entries) => entries);
}

export function checkProductArrays(cart) {
    return cart.pickupUniqueItemsNumber || cart.deliveryUniqueItemsNumber;
}

export function updatePromotion(
    data,
    orderItemSelector,
    orderItemOffersSelector,
    orderItemInfoSelector,
    addPromotionsFn
) {
    $(orderItemSelector).each(function () {
        let itemNumber = { entryNumber: +$(this).attr('data-id') };
        $(this).find(orderItemOffersSelector).remove();
        $(this).find(orderItemInfoSelector).append(addPromotionsFn(itemNumber, data));
    });
}
