import { CreditCard, Person, Toll } from '@mui/icons-material' import { Avatar, Box, Button, Card, Chip, Divider, FormControl, FormLabel, IconButton, Input, Stack, Typography, } from '@mui/joy' import { useEffect, useState } from 'react' import FadeModal from '../../components/common/FadeModal' import { resolvePhotoURL } from '../../utils/Helpers.jsx' function RedeemPointsModal({ config }) { const [points, setPoints] = useState(0) const predefinedPoints = [1, 5, 10, 25, 50] useEffect(() => { setPoints(0) }, [config]) const handlePointsChange = value => { const numValue = Number(value) if (numValue > config.available) { setPoints(config.available) return } if (numValue < 0) { setPoints(0) return } setPoints(numValue) } const addPredefinedPoints = point => { const newPoints = points + point if (newPoints > config.available) { setPoints(config.available) return } setPoints(newPoints) } const canRedeem = points > 0 && points <= config.available return ( {/* Header Section */} Redeem Points {/* User Info Card */} {config?.user?.displayName || 'User'} } sx={{ mt: 0.5 }} > {config?.available || 0} points available {/* Points Input Section */} Points to Redeem } slotProps={{ input: { min: 0, max: config?.available || 0, placeholder: 'Enter points...', }, }} onChange={e => handlePointsChange(e.target.value)} sx={{ '--Input-decoratorChildHeight': '45px', fontSize: 'lg', fontWeight: 500, '&:focus-within': { borderColor: 'warning.500', boxShadow: '0 0 0 2px rgba(255, 193, 7, 0.2)', }, }} /> {points > config?.available && ( Cannot exceed available points )} {/* Quick Selection Buttons */} Quick Add: {predefinedPoints.map(point => ( config?.available} onClick={() => addPredefinedPoints(point)} sx={{ borderRadius: '50%', minWidth: 45, minHeight: 45, fontWeight: 600, fontSize: 'sm', '&:hover:not(:disabled)': { transform: 'scale(1.05)', boxShadow: 'sm', }, '&:disabled': { opacity: 0.3, }, transition: 'all 0.2s ease', }} > +{point} ))} {/* Summary Section */} {points > 0 && ( You are about to redeem {points} points Remaining: {(config?.available || 0) - points} points )} {/* Action Buttons */} ) } export default RedeemPointsModal