import { ProductContextModel } from "@insite/client-framework/Components/ProductContext";
import { BadgeTypeValues } from "@insite/client-framework/Types/ApiModels";

interface Props {
    productContext: ProductContextModel;
    showTextBadges?: boolean;
    showImageBadges?: boolean;
}

const useWidgetBadges = ({ productContext: { product }, showTextBadges, showImageBadges }: Props) => {
    let imageBadges = null;
    if (showImageBadges && product.badges) {
        imageBadges = product.badges.filter(
            o => o.displayOnBadgeWidget && o.badgeType === BadgeTypeValues.Image && o.largeImageBadgePath,
        );
    }

    let textBadges = null;
    if (showTextBadges && product.badges) {
        textBadges = product.badges.filter(
            o => o.displayOnBadgeWidget && o.badgeType === BadgeTypeValues.Text && o.displayText,
        );
    }

    return {
        imageBadges,
        textBadges,
    };
};

export default useWidgetBadges;
