import { ActionIcon, Box, Button, Group, Overlay, Stack, Text } from '@mantine/core'; import { useDisclosure } from '@mantine/hooks'; import { useCommonHooks, useMutationAPI } from 'hooks'; import { useState } from 'react'; import { FiEdit, FiShuffle, FiTrash, FiX } from 'react-icons/fi'; import { actionIconClasses } from 'styles'; import type { ThemePlaylist } from 'types'; import DeleteItemModal from '../Shared/DeleteItemModal'; function ThemeCard({ cardTheme, handleOpen, allThemes, themePlaylists }: any) { const [hover, setHover] = useState(false); const [shiftEdit, setShiftEdit] = useState(0); const [shiftShuffle, setShiftShuffle] = useState(0); const { mutateAsync } = useMutationAPI(); const [modalOpened, { open: openModal, close: closeModal }] = useDisclosure(false); const { handleThemeChange, currentTheme, setCurrentTheme, theme, currentThemePlaylist, setCurrentThemePlaylist, handleDelete, } = useCommonHooks(); return ( setHover(true)} onMouseLeave={() => setHover(false)} > Are you sure you want to delete this theme? {`"${cardTheme.name}"`} This action cannot be undone! } /> {cardTheme.name} {currentTheme === 'random' && cardTheme.name === theme.name ? ( { setShiftEdit(2); }} onMouseLeave={() => { setShiftEdit(0); }} onClick={() => { setShiftEdit(0); }} gap={0} style={{ zIndex: 300, position: 'absolute', left: 0, top: 27 - shiftEdit, backgroundColor: shiftEdit === 0 ? 'white' : 'var(--color-background)', borderRadius: '50%', padding: '8px', margin: '4px', border: 'solid 2px', borderColor: shiftEdit === 0 ? 'black' : 'var(--color-text-pri)', transition: 'all 0.2s', }} > { handleOpen(cardTheme); }} style={{ fontSize: '2em', fontWeight: 'bold', color: shiftEdit === 0 ? 'black' : 'var(--color-text-pri)', }} /> { setShiftShuffle(2); }} onMouseLeave={() => { setShiftShuffle(0); }} onClick={() => { setShiftShuffle(0); }} gap={0} style={{ zIndex: 300, position: 'absolute', right: 0, top: 27 - shiftShuffle, backgroundColor: shiftShuffle === 0 ? 'white' : 'var(--color-background)', borderRadius: '50%', padding: '8px', margin: '4px', border: 'solid 2px', borderColor: shiftShuffle === 0 ? 'black' : 'var(--color-text-pri)', transition: 'all 0.2s', }} > { const themeList = JSON.parse( themePlaylists.find( (t: ThemePlaylist) => t.name === currentThemePlaylist, ).themeList, ); const filteredThemes = allThemes.filter((t: any) => themeList.includes(t.id), ); handleThemeChange(filteredThemes, false); }} style={{ fontSize: '2em', fontWeight: 'bold', color: shiftShuffle === 0 ? 'black' : 'var(--color-text-pri)', }} /> ) : ( { mutateAsync({ method: 'PATCH', endpoint: 'api/themes', body: { ...cardTheme, randomEnabled: !cardTheme.randomEnabled }, }); }} > {cardTheme.randomEnabled ? : } handleOpen(cardTheme)} mb={2} > )} ); } export default ThemeCard;