import { closeAllModals, openModal } from '@mantine/modals';
import { useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { SettingsOptions } from '/@/renderer/features/settings/components/settings-option';
import { useCssSettings, useSettingsStoreActions } from '/@/renderer/store';
import { sanitizeCss } from '/@/renderer/utils/sanitize';
import { Button } from '/@/shared/components/button/button';
import { Code } from '/@/shared/components/code/code';
import { ConfirmModal } from '/@/shared/components/modal/modal';
import { Switch } from '/@/shared/components/switch/switch';
import { Text } from '/@/shared/components/text/text';
import { Textarea } from '/@/shared/components/textarea/textarea';
export const StylesSettings = () => {
const [open, setOpen] = useState(false);
const { t } = useTranslation();
const { content, enabled } = useCssSettings();
const [css, setCss] = useState(content);
const { setSettings } = useSettingsStoreActions();
const handleSave = () => {
setSettings({
css: {
content: css,
enabled,
},
});
};
const handleResetToDefault = () => {
setSettings({
css: {
content,
enabled: true,
},
});
closeAllModals();
};
useEffect(() => {
if (content !== css) {
setCss(content);
}
// eslint-disable-next-line react-hooks/exhaustive-deps -- Reason: This is to only fire if an external source updates the stores css.content
}, [content]);
const openConfirmModal = () => {
openModal({
children: (
{t('setting.customCssNotice', { postProcess: 'sentenceCase' })}
),
title: t('setting.customCssEnable', { postProcess: 'sentenceCase' }),
});
};
return (
<>
{
if (!e.currentTarget.checked) {
setSettings({
css: {
content,
enabled: false,
},
});
} else {
openConfirmModal();
}
}}
/>
}
description={t('setting.customCssEnable', {
context: 'description',
postProcess: 'sentenceCase',
})}
title={t('setting.customCssEnable', { postProcess: 'sentenceCase' })}
/>
{enabled && (
<>
{open && (
)}
>
}
description={t('setting.customCss', {
context: 'description',
postProcess: 'sentenceCase',
})}
title={t('setting.customCss', { postProcess: 'sentenceCase' })}
/>
{open && (
<>