import React, { useState } from 'react';
import { Button, IconButton, Tooltip, Dialog, DialogTitle, DialogContent,
DialogActions, Typography, Box, Divider, RadioGroup, Radio, FormControlLabel,
FormControl, FormLabel } from '@mui/material';
import CookieIcon from '@mui/icons-material/Cookie';
import consentService, { CONSENT_LEVELS } from '../services/consentService';
/**
* Button to open cookie settings dialog
* Can be placed in the footer or other accessible areas of the app
*/
const CookieSettingsButton = ({ variant = 'text', icon = false, label = 'Cookie Settings' }) => {
const [open, setOpen] = useState(false);
const [consentLevel, setConsentLevel] = useState(() => {
const storedConsent = consentService.getStoredConsent();
return storedConsent?.level || CONSENT_LEVELS.NECESSARY;
});
const handleOpen = () => {
setOpen(true);
};
const handleClose = () => {
setOpen(false);
};
const handleConsentLevelChange = (event) => {
setConsentLevel(event.target.value);
};
const handleSave = () => {
consentService.saveConsent(consentLevel);
setOpen(false);
};
const handleAcceptAll = () => {
const allConsent = CONSENT_LEVELS.ALL;
setConsentLevel(allConsent);
consentService.saveConsent(allConsent);
setOpen(false);
};
const handleNecessaryOnly = () => {
const necessaryOnly = CONSENT_LEVELS.NECESSARY;
setConsentLevel(necessaryOnly);
consentService.saveConsent(necessaryOnly);
setOpen(false);
};
// Render as icon button or regular button
if (icon) {
return (
<>
{renderDialog()}
>
);
}
return (
<>
{renderDialog()}
>
);
function renderDialog() {
return (
);
}
};
export default CookieSettingsButton;