import React from 'react' import { Button, Text, Flex, Close, Divider } from 'theme-ui' import Balancer from 'react-wrap-balancer' import Quantity from './quantity' import { tr } from 'date-fns/locale' import { useState, useEffect } from 'react' /** @jsxImportSource theme-ui */ const Prizes = ({ img, text, subtext, fulfillmentDescription, fullName, name, smallName, cost, link = null, quantity, onQuantityChange, index, hoursBalance = null, stock, categories, pub, inStock = true, ...props }) => { const parsedFulfillmentDesc = fulfillmentDescription?.replace( /\[(.*?)\]\((.*?)\)/g, '$1' ) const parsedSubText = subtext?.replace( /\[(.*?)\]\((.*?)\)/g, '$1' ) const parsedFullName = fullName?.replace(' ', '-') const [pRotate, setPRotate] = useState(0) const [tRotate, setTRotate] = useState(0) useEffect(() => { setPRotate((1 + Math.random() * 4) * (Math.random() > 0.5 ? 1 : -1)) setTRotate((5 + Math.random() * 14) * (Math.random() > 0.5 ? 1 : -1)) }, []) return ( <> = 100 ? '#1A696B' : cost > 50 ? '#2B8184' : cost > 10 ? '#09AFB4' : '#28CCD1', borderRadius: '10px', flexDirection: 'column', justifyContent: 'space-between', padding: '20px', position: 'relative', transform: `rotate(${pRotate}deg)`, transitionDuration: '0.5s', opacity: stock === 0 ? '0.5' : 1, '&:hover': { transform: stock === 0 ? null : 'scale(1.1)', cursor: stock === 0 ? 'default' : 'pointer' } }} onClick={e => { const div = e.currentTarget const quantity = div.querySelector('[id*="dropdown-"]') const buy = div.querySelector('#buy') if (quantity === e.target || buy === e.target) { console.log('TRUE') return } else { stock !== 0 ? document.getElementById(`${parsedFullName}-info`).showModal() : null } }} {...props} > {text} {stock <= 100 && stock !== null && ( {stock === 0 ? <>Sold out : <>Only {stock} left! } )} {name} {smallName} {pub ? ( <> ) : ( You can order up to{' '} {Math.min(quantity, Math.floor(hoursBalance / cost))} of these )} {link && ( { // only show the quantity dropdown if you have enough hours to buy at least 2 of the item ( hoursBalance ? hoursBalance / cost >= 2 ? stock !== 0 : null : null ) ? ( ) : null } { // only show the buy button if you have enough hours to buy at least 1 of the item // (hoursBalance ? hoursBalance / cost < 1 ? stock != 0 ? null ) null : ( ( hoursBalance ? hoursBalance / cost >= 1 ? stock !== 0 : null : null ) ? ( ) : null } )} {cost} 🎟️ = 100 ? '#1A696B' : cost > 50 ? '#2B8184' : cost > 10 ? '#09AFB4' : '#28CCD1', border: `5px dashed ${cost >= 100 ? '#094243' : cost >= 50 ? '#1A696B' : cost >= 10 ? '#2B8184' : '#09AFB4'}`, borderRadius: '10px', flexDirection: 'column', padding: '30px', scrollbarWidth: 'none', textAlign: 'center', maxWidth: '800px', width: 'calc(100vw - 30px)', ':-internal-dialog-in-top-layer::backdrop': { background: '#33333344' } }} > = 100 ? '#094243' : cost >= 50 ? '#1A696B' : cost >= 10 ? '#2B8184' : '#09AFB4'}` }} onClick={e => { document.getElementById(`${parsedFullName}-info`).close() }} />
{cost} {cost === 1 ? 'ticket' : 'tickets'} {text} {fullName}
{parsedSubText?.length > 0 && parsedFulfillmentDesc?.length > 0 && ( )}
{link && ( { // only show the quantity dropdown if you have enough hours to buy at least 2 of the item ( hoursBalance ? hoursBalance / cost >= 2 ? stock !== 0 : null : null ) ? ( ) : null } { // only show the buy button if you have enough hours to buy at least 1 of the item ( hoursBalance ? hoursBalance / cost >= 1 ? stock !== 0 : null : null ) ? ( ) : null } )} You can order up to{' '} {Math.min(quantity, Math.floor(hoursBalance / cost))} of these
) } export default Prizes