import { Controller } from 'stimulus';

export default class extends Controller {
    connect() {
        if (!this.isCookieAccepted()) {
            this.element.classList = 'show';
        } else {
            this.element.classList = 'd-none';
        }
    }

    accept() {
        // Устанавливаем куку на 1 год
        const date = new Date();
        date.setFullYear(date.getFullYear() + 1);
        document.cookie = `cookie_accepted=true; expires=${date.toUTCString()}; path=/`;
        
        this.element.classList = 'd-none';
    }

    isCookieAccepted() {
        return document.cookie.split(';').some(cookie => 
            cookie.trim().startsWith('cookie_accepted=true')
        );
    }
}