import { Box, Button, Group, Overlay, Stack, Switch, Text } from '@mantine/core'; import { useDisclosure } from '@mantine/hooks'; import { useCommonHooks, useMutationAPI } from 'hooks'; import { useEffect, useState } from 'react'; import { FiChevronRight, FiPlus } from 'react-icons/fi'; import '@mantine/core/styles/ModalBase.css'; import '@mantine/core/styles/Modal.css'; import { modals } from '@mantine/modals'; import { buttonClasses, textClasses } from 'styles'; import ThemeCard from './ThemeCard'; import ThemeModal from './ThemeModal'; function ThemesSettings() { const [opened, { open, close }] = useDisclosure(false); const [pickerOpen, { open: openPicker, close: closePicker }] = useDisclosure(false); const [colorId, setColorId] = useState(''); const [colorValue, setColorValue] = useState('#000000'); const [backgroundList, setBackgroundList] = useState(['None']); const [selectedTheme, setSelectedTheme] = useState({}); const { mutateAsync: createTheme } = useMutationAPI(); const { mutateAsync: deleteTheme } = useMutationAPI(); const { currentTheme, setCurrentTheme, backgrounds, isBackgroundFetched, isMobile, theme, allThemes, } = useCommonHooks(); useEffect(() => { if (backgrounds && isBackgroundFetched) { setBackgroundList(['None', ...backgrounds]); } }, [backgrounds, isBackgroundFetched]); const handleOpen = (theme: any) => { setSelectedTheme(theme); open(); }; const handleClose = () => { close(); closePicker(); }; const handleSaveTheme = () => { createTheme({ method: selectedTheme.id === undefined ? 'POST' : 'PATCH', endpoint: 'api/themes', body: selectedTheme, }); close(); }; const openDeleteConfirmModal = (theme: any) => modals.openConfirmModal({ title: 'Are you sure you want to delete this theme?', labels: { confirm: 'Delete', cancel: 'Cancel' }, confirmProps: { color: 'red' }, onConfirm: () => deleteTheme({ method: 'DELETE', endpoint: 'api/themes', body: theme }), }); const handleDeleteTheme = (theme: any) => { openDeleteConfirmModal(theme); close(); }; return ( <> Themes Random Theme} labelPosition='left' checked={currentTheme === 'random'} onChange={(e) => { setCurrentTheme(e.target.checked ? 'random' : theme.name); }} color={theme.primaryColor} /> {allThemes?.map((cardTheme: any) => ( {cardTheme.name === currentTheme && ( )} ))} ); } export default ThemesSettings;