import React, { useMemo, useState, type ChangeEvent } from "react"; import clsx from 'clsx'; import RdsRadio from "../../raaghu-elements/rds-radio/rds-radio"; import RdsCard from "../../raaghu-elements/rds-card/rds-card"; import RdsStack from "../../raaghu-elements/rds-stack/rds-stack"; import RdsBox from "../../raaghu-elements/rds-box/rds-box"; import RdsTypography from "../../raaghu-elements/rds-typography/rds-typography"; import RdsAvatar from "../../raaghu-elements/rds-avatar/rds-avatar"; import RdsChip from "../../raaghu-elements/rds-chip/rds-chip"; import FormControl from "@mui/material/FormControl"; import Select, { type SelectChangeEvent } from "@mui/material/Select"; import MenuItem from "@mui/material/MenuItem"; import ExpandMoreIcon from "@mui/icons-material/ExpandMore"; import InfoOutlined from "@mui/icons-material/InfoOutlined"; import RdsButton from '../../raaghu-elements/rds-button/rds-button'; import IconButton from "@mui/material/IconButton"; import CloseIcon from "@mui/icons-material/Close"; import ImageList from "@mui/material/ImageList"; import ImageListItem from "@mui/material/ImageListItem"; // @ts-ignore Side-effect stylesheet import is resolved by bundler. import './rds-comp-adaptive-cards.scss'; export interface AdaptiveCardProps { onBtn1Click?: () => void; nameValue?: string; emailValue?: string; phoneValue?: string; onNameChange?: (e: ChangeEvent) => void; onEmailChange?: (e: ChangeEvent) => void; onPhoneChange?: (e: ChangeEvent) => void; nameError?: string; emailError?: string; phoneError?: string; entreeValue?: string; sideValue?: string; drinkValue?: string; onEntreeChange?: (e: SelectChangeEvent) => void; onSideChange?: (e: SelectChangeEvent) => void; onDrinkChange?: (e: SelectChangeEvent) => void; showBtn1?: boolean; showBtn2?: boolean; btn1style?: string; btn2style?: string; btn1Label?: string; btn2Label?: string; smallText?: string; cardText?: string; cardTitle?: string; showHeader?: boolean; showDismiss?: boolean; type?: string; closeIcon?: boolean; label?: string; nameLabel?: string; namePlaceholder?: string; emailLabel?: string; emailPlaceholder?: string; phoneLabel?: string; phonePlaceholder?: string; requiredText?: string; block?: boolean; images?: string[]; leagueName?: string; leagueAvatar?: string; isLive?: boolean; matchDate?: string; isFinal?: boolean; homeTeamName?: string; homeTeamLogo?: string; homeTeamStatus?: string; awayTeamName?: string; awayTeamLogo?: string; awayTeamStatus?: string; homeScore?: number; awayScore?: number; time?: string; finalText?: string; footballProps?: Partial<{ leagueName?: string; leagueAvatar?: string; isLive?: boolean; date?: string; isFinal?: boolean; homeTeam?: { name?: string; logo?: string; status?: string; }; awayTeam?: { name?: string; logo?: string; status?: string; }; homeScore?: number; awayScore?: number; time?: string; finalText?: string; }>; activityProps?: Partial<{ avatar?: string; name?: string; date?: string; radioOptions?: { value: string; label: string; desc: string }[]; }>; name?: string; date?: string; calendarReminderPlaceholder?: string; calendarReminderLabel?: string; entreeLabel?: string; entreePlaceholder?: string; entreeOptions?: { value: string; label: string }[]; sideLabel?: string; sidePlaceholder?: string; sideOptions?: { value: string; label: string }[]; drinkLabel?: string; drinkPlaceholder?: string; drinkOptions?: { value: string; label: string }[]; snoozeLabel?: string; lateLabel?: string; options?: { value: string; label: string }[]; placeholder?: string; avatar?: string; radioOptions?: { value: string; label: string; desc: string }[]; homeTeam?: { name: string; logo: string; status: string }; awayTeam?: { name: string; logo: string; status: string }; onChange?: (data: { name: string; email: string; phone: string }) => void; } const renderSelectValue = (placeholder?: string) => (selected: unknown) => selected === "" ? ( {placeholder} ) : (typeof selected === 'string' ? selected : ''); export function InputFormCard(props: AdaptiveCardProps) { const { label = '', smallText = '', nameLabel, namePlaceholder, emailLabel, emailPlaceholder, phoneLabel, phonePlaceholder, requiredText, onChange, nameValue, emailValue, phoneValue, onNameChange, onEmailChange, onPhoneChange, nameError, emailError, phoneError } = props; const [name, setName] = useState(''); const [email, setEmail] = useState(''); const [phone, setPhone] = useState(''); const nameRef = React.useRef(name); const emailRef = React.useRef(email); const phoneRef = React.useRef(phone); nameRef.current = name; emailRef.current = email; phoneRef.current = phone; return (
{label}
{smallText}
{ const v = e.target.value; setName(v); onChange?.({ name: v, email: emailRef.current, phone: phoneRef.current }); })} name="name" /> {nameError &&
{nameError}
}
{ const v = e.target.value; setEmail(v); onChange?.({ name: nameRef.current, email: v, phone: phoneRef.current }); })} name="email" /> {emailError &&
{emailError}
}
{ const v = e.target.value; setPhone(v); onChange?.({ name: nameRef.current, email: emailRef.current, phone: v }); })} name="phone" /> {phoneError &&
{phoneError}
}
); } export function ImageGalleryCard({ cardTitle, smallText, images, showHeader, closeIcon, showDismiss, onImageClick }: AdaptiveCardProps & { cardTitle?: string; showHeader?: boolean; closeIcon?: boolean; showDismiss?: boolean; onImageClick?: (index: number) => void }) { return ( {showHeader && (
{showDismiss && } {cardTitle} {closeIcon && ( )}
)}
{smallText} {(images ?? []).reduce((items, src, index) => { if (!src) { return items; } items.push( onImageClick && onImageClick(index)}> {`Thumbnail ); return items; }, [])}
); } export function FootballScorecardCard({ leagueName, leagueAvatar, isLive, date, isFinal, homeTeam, awayTeam, homeScore, awayScore, time, finalText, }: AdaptiveCardProps) { return (
{leagueName}
{isLive && ( } className="rds-adaptive-cards__football-live rds-adaptive-cards__football-live--aligned" /> )}
{date} {isFinal && ( {finalText} )}
{homeTeam?.logo ? ( {homeTeam.name} ) : null} {homeTeam?.name} {homeTeam?.status} {homeScore} : {awayScore} {awayTeam?.logo ? ( {awayTeam.name} ) : null} {awayTeam?.name} {awayTeam?.status}
); } export type CalendarReminderOption = { value: string; label: string; }; export type CalendarReminderFormProps = { label?: string; smallText?: string; placeholder?: string; calendarReminderLabel?: string; sideOptions?: CalendarReminderOption[]; selectPlaceholder?: string; snoozeLabel?: string; lateLabel?: string; showBtn1?: boolean; showBtn2?: boolean; btn1Label?: string; btn2Label?: string; }; const EMPTY_CALENDAR_REMINDER_OPTIONS: CalendarReminderOption[] = []; const EMPTY_MENU_OPTIONS: { value: string; label: string }[] = []; export function CalendarReminderForm({ label, smallText, placeholder, calendarReminderLabel, selectPlaceholder, snoozeLabel, lateLabel, sideOptions, showBtn1, showBtn2, btn1Label, btn2Label, }: CalendarReminderFormProps) { const [selected, setSelected] = useState(""); const resolvedSideOptions = sideOptions ?? EMPTY_CALENDAR_REMINDER_OPTIONS; return ( {label} {smallText}
{calendarReminderLabel || "Snooze for"}
{showBtn1 && ( )} {showBtn2 && ( )}
); } export function ActivityUpdateCard({ avatar, name, date, cardText, radioOptions }: AdaptiveCardProps) { const [selectedValue, setSelectedValue] = useState(''); const radioOptionsMapped = useMemo( () => radioOptions?.map(opt => ({ value: opt.value, text: `${opt.label} : ${opt.desc}` })) ?? [], [radioOptions] ); return ( {name} {date} {cardText} setSelectedValue(e.target.value)} direction="column" layout="icon with label" className="rds-adaptive-cards__activity-update-radio-group" /> ); } export type RestaurantOrderFormProps = { entree: string; setEntree: (v: string) => void; side: string; setSide: (v: string) => void; drink: string; setDrink: (v: string) => void; entreeValue?: string; sideValue?: string; drinkValue?: string; onEntreeChange?: (e: SelectChangeEvent) => void; onSideChange?: (e: SelectChangeEvent) => void; onDrinkChange?: (e: SelectChangeEvent) => void; entreeLabel?: string; entreePlaceholder?: string; entreeOptions?: { value: string; label: string }[]; sideLabel?: string; sidePlaceholder?: string; sideOptions?: { value: string; label: string }[]; drinkLabel?: string; drinkPlaceholder?: string; drinkOptions?: { value: string; label: string }[]; }; export function RestaurantOrderForm({ entree, setEntree, side, setSide, drink, setDrink, entreeValue, sideValue, drinkValue, onEntreeChange, onSideChange, onDrinkChange, entreeLabel, entreePlaceholder, entreeOptions, sideLabel, sidePlaceholder, sideOptions, drinkLabel, drinkPlaceholder, drinkOptions, }: RestaurantOrderFormProps) { const resolvedEntreeOptions = entreeOptions ?? EMPTY_MENU_OPTIONS; const resolvedSideOptions = sideOptions ?? EMPTY_MENU_OPTIONS; const resolvedDrinkOptions = drinkOptions ?? EMPTY_MENU_OPTIONS; const entreeRenderValue = renderSelectValue(entreePlaceholder); const sideRenderValue = renderSelectValue(sidePlaceholder); const drinkRenderValue = renderSelectValue(drinkPlaceholder); return ( {entreeLabel}* {sideLabel}* {drinkLabel}* ); } InputFormCard.displayName = 'InputFormCard'; ImageGalleryCard.displayName = 'ImageGalleryCard'; FootballScorecardCard.displayName = 'FootballScorecardCard'; CalendarReminderForm.displayName = 'CalendarReminderForm'; ActivityUpdateCard.displayName = 'ActivityUpdateCard'; RestaurantOrderForm.displayName = 'RestaurantOrderForm';