import variables from 'config/variables'; import { useState } from 'react'; import { Header, Row, Content, Action, PreferencesWrapper, Section, } from 'components/Layout/Settings'; import { Checkbox, Switch, Text } from 'components/Form/Settings'; import { TextareaAutosize } from '@mui/material'; import { Button } from 'components/Elements'; import defaultEvents from '../events.json'; import { MdEventNote, MdAdd, MdCancel, MdRefresh } from 'react-icons/md'; const GreetingOptions = () => { const [customEvents, setCustomEvents] = useState( JSON.parse(localStorage.getItem('customEvents')) || [], ); const [events, setEvents] = useState(false); const [birthday, setBirthday] = useState( new Date(localStorage.getItem('birthday')) || new Date(), ); const changeDate = (e) => { const newDate = e.target.value ? new Date(e.target.value) : new Date(); localStorage.setItem('birthday', newDate); setBirthday(newDate); }; const GREETING_SECTION = 'modals.main.settings.sections.greeting'; function addEvent() { // Retrieve the current array of events from localStorage const customEvents = JSON.parse(localStorage.getItem('customEvents')) || []; // Create a new event const newEvent = { id: 'widgets.greeting.halloween', name: '', month: 10, date: 31, }; // Add the new event to the array const updatedEvents = [...customEvents, newEvent]; // Add the new event to the array customEvents.push(newEvent); // Store the updated array back in localStorage localStorage.setItem('customEvents', JSON.stringify(customEvents)); setCustomEvents(updatedEvents); } function removeEvent(index) { // Remove the event at the given index const updatedEvents = customEvents.filter((_, i) => i !== index); // Store the updated array back in localStorage localStorage.setItem('customEvents', JSON.stringify(updatedEvents)); // Update the state setCustomEvents(updatedEvents); } function resetEvents() { // Reset the events array in localStorage localStorage.setItem('customEvents', JSON.stringify(defaultEvents)); // Update the state setCustomEvents(defaultEvents); } function updateEvent(index, updatedEvent) { // Update the event in your state setCustomEvents((prevEvents) => { const newEvents = [...prevEvents]; newEvents[index] = updatedEvent; return newEvents; }); // Update the event in localStorage const customEvents = JSON.parse(localStorage.getItem('customEvents') || '[]'); customEvents[index] = updatedEvent; localStorage.setItem('customEvents', JSON.stringify(customEvents)); } const AdditionalOptions = () => { return ( ); }; const BirthdayOptions = () => { return (

{variables.getMessage(`${GREETING_SECTION}.birthday_date`)}

); }; const CustomEventsSection = () => { return ( <>
{customEvents.map((event, index) => (
Event Name { const updatedEvent = { ...event, name: e.target.value }; updateEvent(index, updatedEvent); }} varient="outlined" style={{ padding: '0' }} />
{ const updatedEvent = { ...event, month: parseInt(e.target.value, 10) }; updateEvent(index, updatedEvent); }} />
{ const updatedEvent = { ...event, date: parseInt(e.target.value, 10) }; updateEvent(index, updatedEvent); }} />
))}
{customEvents.length === 0 && (
No Events Add Some Events
)} ); }; let header; if (events) { header = (
setEvents(false)} report={false} /> ); } else { header = (
); } return ( <> {header} {events ? ( <> {BirthdayOptions()} {CustomEventsSection()} ) : (
setEvents(true)} icon={} /> )} ); }; export { GreetingOptions as default, GreetingOptions };