import clsx from 'clsx'; import { motion } from 'motion/react'; import { MouseEvent } from 'react'; import styles from './item-card-controls.module.css'; import { ItemListStateActions } from '/@/renderer/components/item-list/helpers/item-list-state'; import { ItemControls } from '/@/renderer/components/item-list/types'; import { useIsPlayerFetching } from '/@/renderer/features/player/context/player-context'; import { animationVariants } from '/@/shared/components/animations/animation-variants'; import { AppIcon, Icon, IconProps } from '/@/shared/components/icon/icon'; import { Rating } from '/@/shared/components/rating/rating'; import { Album, AlbumArtist, Artist, LibraryItem, Playlist, Song, } from '/@/shared/types/domain-types'; import { Play } from '/@/shared/types/types'; interface ItemCardControlsProps { controls?: ItemControls; internalState?: ItemListStateActions; item: Album | AlbumArtist | Artist | Playlist | Song | undefined; itemType: LibraryItem; type?: 'compact' | 'default' | 'poster'; } const containerProps = { compact: { animate: 'show', exit: 'hidden', initial: 'hidden', variants: animationVariants.combine(animationVariants.zoomIn, animationVariants.fadeIn), }, default: { animate: 'show', exit: 'hidden', initial: 'hidden', variants: animationVariants.combine(animationVariants.zoomIn, animationVariants.fadeIn), }, poster: { animate: 'show', exit: 'hidden', initial: 'hidden', variants: animationVariants.combine(animationVariants.slideInUp, animationVariants.fadeIn), }, }; export const ItemCardControls = ({ controls, internalState, item, itemType, type = 'default', }: ItemCardControlsProps) => { const isPlayerFetching = useIsPlayerFetching(); return ( {controls?.onPlay && ( <> { e.stopPropagation(); if (!item) { return; } controls?.onPlay?.({ event: e, internalState, item, itemType, playType: Play.NOW, }); }} /> { e.stopPropagation(); if (!item) { return; } controls?.onPlay?.({ event: e, internalState, item, itemType, playType: Play.NEXT, }); }} /> { e.stopPropagation(); if (!item) { return; } controls?.onPlay?.({ event: e, internalState, item, itemType, playType: Play.LAST, }); }} /> )} {controls?.onFavorite && ( { e.stopPropagation(); if (!item) { return; } const newFavorite = !(item as { userFavorite: boolean }).userFavorite; controls?.onFavorite?.({ event: e, favorite: newFavorite, internalState, item, itemType, }); }} /> )} {controls?.onRating && ( { if (!item) { return; } let newRating = rating; if (rating === (item as { userRating: number }).userRating) { newRating = 0; } controls?.onRating?.({ event: null, internalState, item, itemType, rating: newRating, }); }} onClick={(e) => { e.stopPropagation(); }} size="xs" /> )} {controls?.onMore && ( { e.stopPropagation(); e.preventDefault(); controls?.onMore?.({ event: e, internalState, item, itemType, }); }} onDoubleClick={(e) => { e.stopPropagation(); e.preventDefault(); }} /> )} {controls?.onExpand && ( { e.stopPropagation(); controls?.onExpand?.({ event: e, internalState, item, itemType, }); }} /> )} ); }; const PlayButton = ({ disabled, loading, onClick, }: { disabled?: boolean; loading?: boolean; onClick?: (e: MouseEvent) => void; }) => { return ( ); }; const SecondaryPlayButton = ({ className, icon, onClick, }: { className?: string; icon: keyof typeof AppIcon; onClick?: (e: MouseEvent) => void; }) => { return ( ); }; interface SecondaryButtonProps { className?: string; icon: keyof typeof AppIcon; onClick?: (e: MouseEvent) => void; } const SecondaryButton = ({ className, icon, iconProps, onClick, onDoubleClick, }: SecondaryButtonProps & { iconProps?: Partial; onDoubleClick?: (e: MouseEvent) => void; }) => { return ( ); };