import { ActionIcon, Button, Group, Modal, 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 { modalClasses } from 'styles'; import ThemeMiniCard from './ThemeMiniCard'; function ThemePlaylistCard({ cardPlaylist, handleOpen, allThemes }: any) { const [hover, setHover] = useState(false); const { setThemeName, setCurrentThemePlaylist, theme, isMobile, modalStyle, 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)} > { closeModal(); }} style={modalStyle} closeOnEscape closeOnClickOutside > Delete Theme Playlist 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: any) => theme.id)), }, }); } if (cardPlaylist.name === 'Backgrounds') { mutateAsync({ method: 'PATCH', endpoint: 'api/themePlaylists', body: { id: cardPlaylist.id, name: 'Backgrounds', themeList: JSON.stringify( allThemes .filter( (theme: any) => theme.backgroundImage.toLowerCase() !== 'none', ) .map((theme: any) => 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: any) => theme.backgroundImage.toLowerCase() === 'none', ) .map((theme: any) => theme.id), ), }, }); } }} > ) : ( <> { handleOpen(cardPlaylist); }} > {cardPlaylist.default === 0 && ( { openModal(); }} > )} )} ); } export default ThemePlaylistCard;