import { ActionIcon, Box, Button, Group, Overlay, Stack, Text } from '@mantine/core'; import { useCommonHooks, useQueryAPI } from 'hooks'; import { useState } from 'react'; import { FiEdit, FiShuffle, FiTrash, FiX } from 'react-icons/fi'; import { actionIconClasses } from 'styles'; function ThemeCard({ cardTheme, handleOpen, handleDeleteTheme, createTheme, allThemes, }: any) { const { data: themePlaylists } = useQueryAPI({ endpoint: 'api/themePlaylists', }); const [hover, setHover] = useState(false); const [shiftEdit, setShiftEdit] = useState(0); const [shiftShuffle, setShiftShuffle] = useState(0); const { handleThemeChange, currentTheme, setCurrentTheme, theme, currentThemePlaylist, setCurrentThemePlaylist, } = useCommonHooks(); return ( setHover(true)} onMouseLeave={() => setHover(false)} > {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: any) => 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)', }} /> ) : ( { createTheme({ method: 'PATCH', endpoint: 'api/themes', body: { ...cardTheme, randomEnabled: !cardTheme.randomEnabled }, }); }} > {cardTheme.randomEnabled ? : } handleOpen(cardTheme)} mb={2} > handleDeleteTheme(cardTheme)} > )} ); } export default ThemeCard;