import { getItemKey, RewardSelectionItem } from '@isa/checkout/data-access';

export const itemSelectionChanged = (
  inputItems: RewardSelectionItem[],
  resultItems?: RewardSelectionItem[],
): boolean => {
  if (!resultItems) return true;

  return inputItems.some((inputItem) => {
    const resultItem = resultItems.find(
      (i) => getItemKey(i.item) === getItemKey(inputItem.item),
    );

    return (
      !resultItem ||
      resultItem.cartQuantity !== inputItem.cartQuantity ||
      resultItem.rewardCartQuantity !== inputItem.rewardCartQuantity
    );
  });
};
