// static/js/components/cookie-consent.js import app from '../app.js'; const COOKIE_CONSENT_KEY = 'mywebdav_cookie_consent'; export class CookieConsent extends HTMLElement { constructor() { super(); this.attachShadow({ mode: 'open' }); this.hasConsented = this.checkConsent(); } connectedCallback() { if (!this.hasConsented) { this.render(); } } checkConsent() { const consent = localStorage.getItem(COOKIE_CONSENT_KEY); if (consent) { // In a real application, you'd parse this and apply preferences // For now, just checking if it exists return true; } return false; } setConsent(status) { // In a real application, 'status' would be a detailed object // For now, a simple string 'accepted' or 'declined' localStorage.setItem(COOKIE_CONSENT_KEY, status); this.hasConsented = true; this.remove(); // Remove the banner after consent app.getLogger().info(`Cookie consent: ${status}`); // Trigger an event for other parts of the app to react to consent change document.dispatchEvent(new CustomEvent('cookie-consent-changed', { detail: { status } })); } render() { this.shadowRoot.innerHTML = ` `; this.shadowRoot.querySelector('.consent-button.accept').addEventListener('click', () => this.setConsent('accepted')); this.shadowRoot.querySelector('.consent-button.decline').addEventListener('click', () => this.setConsent('declined')); this.shadowRoot.querySelector('.consent-button.customize').addEventListener('click', () => { // For now, customize acts like accept. In a real app, this would open a modal. app.getLogger().info('Customize cookie consent clicked. (Placeholder: acting as accept)'); this.setConsent('accepted'); }); } } customElements.define('cookie-consent', CookieConsent);