const React = require('react');
const { countryFlags } = require('./country-flags.cjs');
const Review = ({ review }) => (
{review.user} ({review.rating}/100)
{review.comment}
);
const Grape = ({ grape }) => (
{grape.grape} ({grape.percentage}%)
);
const GrapeComposition = ({ composition }) => (
{composition.map(g => (
))}
);
const WineName = ({ name, hasHighRating }) => (
{name} {hasHighRating && '⭐'}
);
const Winemaker = ({ winemaker }) => (
{winemaker.description}
Established: {winemaker.establishedDate}
);
const Region = ({ region }) => (
);
const Tag = ({ tag }) => (
{tag}
);
const Tags = ({ tags }) => (
);
const Vintage = ({ vintage }) => (
Vintage: {vintage}
);
const getSaleInfo = (price, salePrice) => {
const onSale = salePrice && salePrice < price;
const percentageDiff = onSale ? Math.round(((price - salePrice) / price) * 100) : 0;
return { onSale, percentageDiff };
};
const getPriceRating = (price) => {
if (price < 100) return "€";
if (price < 1000) return "€€";
return "€€€";
};
const PriceRating = ({ price }) => (
{getPriceRating(price)}
);
const Price = ({ price, salePrice }) => {
const onSale = salePrice && salePrice < price;
if (onSale) {
return (
${price} ${salePrice}
);
}
return ${price};
};
const Bottle750 = ({ bottle }) => {
const { quantity, price, salePrice } = bottle;
const { onSale, percentageDiff } = getSaleInfo(price, salePrice);
return (
750ml: {quantity} {quantity < 10 && '(Low stock)'} -
{onSale && ❗({percentageDiff}% off)}
);
};
const BottleMagnum = ({ bottle }) => {
const { quantity, price, salePrice } = bottle;
const { onSale, percentageDiff } = getSaleInfo(price, salePrice);
return (
Magnum: {quantity} {quantity < 10 && '(Low stock)'} -
{onSale && ❗({percentageDiff}% off)}
);
};
const BottleBalthazar = ({ bottle }) => {
const { quantity, price, salePrice } = bottle;
const { onSale, percentageDiff } = getSaleInfo(price, salePrice);
return (
Balthazar: {quantity} {quantity < 10 && '(Low stock)'} -
{onSale && ❗({percentageDiff}% off)}
);
};
const Stock = ({ stock }) => (
Stock
{stock && Object.values(stock).some(s => s.quantity > 0) ? (
{stock["750ml"] && }
{stock["magnum"] && }
{stock["balthazar"] && }
) : (
Out of stock
)}
);
const Wine = ({ wine }) => (
r.rating > 90)} />
Tasting Notes
{wine.tastingNotes}
Grape Composition
Reviews
{wine.reviews.map((review, i) => (
))}
);
const WineList = ({ wines }) => (
Complex Wine List
{wines.map((wine, i) => (
))}
);
module.exports = {
Review,
Grape,
GrapeComposition,
WineName,
Winemaker,
Region,
Tag,
Tags,
Vintage,
Price,
PriceRating,
Bottle750,
BottleMagnum,
BottleBalthazar,
Stock,
Wine,
WineList,
};