import { ActionIcon, Button, Group, Overlay, ScrollArea, Stack, Text, } from '@mantine/core'; import { useDisclosure } from '@mantine/hooks'; import { useCommonHooks, useMutationAPI } from 'hooks'; import { useState } from 'react'; import { FiEdit, FiRefreshCcw, FiTrash } from 'react-icons/fi'; import type { Theme, ThemePlaylist } from 'types'; import DeleteItemModal from '../Shared/DeleteItemModal'; import ThemeMiniCard from './ThemeMiniCard'; function ThemePlaylistCard({ cardPlaylist, handleOpen, allThemes, }: { cardPlaylist: any; handleOpen: (cardPlaylist: ThemePlaylist) => void; allThemes: Theme[]; }) { const [hover, setHover] = useState(false); const { setThemeName, setCurrentThemePlaylist, theme, handleDelete } = useCommonHooks(); const syncableLists = ['All', 'Backgrounds', 'No Backgrounds']; const { mutateAsync } = useMutationAPI(); const [modalOpened, { open: openModal, close: closeModal }] = useDisclosure(false); const themeList = JSON.parse( cardPlaylist.themeList.name === 'Time of Day' ? '[]' : cardPlaylist.themeList, ); return ( setHover(true)} onMouseLeave={() => setHover(false)} > Are you sure you want to delete this Theme Playlist? {`"${cardPlaylist.name}"`} This action cannot be undone! } /> {cardPlaylist.name} {syncableLists.includes(cardPlaylist.name) ? ( { event.stopPropagation(); if (cardPlaylist.name === 'All') { mutateAsync({ method: 'PATCH', endpoint: 'api/themePlaylists', body: { id: cardPlaylist.id, name: 'All', themeList: JSON.stringify(allThemes.map((theme: Theme) => theme.id)), }, }); } if (cardPlaylist.name === 'Backgrounds') { mutateAsync({ method: 'PATCH', endpoint: 'api/themePlaylists', body: { id: cardPlaylist.id, name: 'Backgrounds', themeList: JSON.stringify( allThemes .filter( (theme: Theme) => theme.backgroundImage.toLowerCase() !== 'none', ) .map((theme: Theme) => theme.id), ), }, }); } if (cardPlaylist.name === 'No Backgrounds') { mutateAsync({ method: 'PATCH', endpoint: 'api/themePlaylists', body: { id: cardPlaylist.id, name: 'No Backgrounds', themeList: JSON.stringify( allThemes .filter( (theme: Theme) => theme.backgroundImage.toLowerCase() === 'none', ) .map((theme: Theme) => theme.id), ), }, }); } }} > ) : ( <> { handleOpen(cardPlaylist); }} > {cardPlaylist.default === 0 && ( { openModal(); }} > )} )} ); } export default ThemePlaylistCard;