import { r as registerInstance, h } from './index-Co4V4Zk-.js';

const spwCookiesCss = () => `html{line-height:1.3;-webkit-text-size-adjust:100%;}h1,h2,h3,h4,h5,h6,p,ul,li{padding:0;margin:0}ul{list-style:none}:host{box-sizing:border-box;line-height:1.3;-webkit-text-size-adjust:100%;font-size:100%}:host *,:host *::before,:host *::after{box-sizing:inherit;font-family:var(--spw-ds-font-main)}body{margin:0}hr{box-sizing:content-box;height:0;overflow:visible;}pre{font-family:monospace, monospace;font-size:1em;}a{background-color:transparent}abbr[title]{border-bottom:none;text-decoration:underline;text-decoration:underline dotted;}b,strong{font-weight:bolder}code,kbd,samp{font-family:monospace, monospace;font-size:1em;}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-0.25em}sup{top:-0.5em}img{border-style:none}button,input,optgroup,select,textarea{font-family:inherit;font-size:100%;line-height:1.15;margin:0;}button,input{overflow:visible}button,select{text-transform:none}button,[type=button],[type=reset],[type=submit]{-webkit-appearance:button}button::-moz-focus-inner,[type=button]::-moz-focus-inner,[type=reset]::-moz-focus-inner,[type=submit]::-moz-focus-inner{border-style:none;padding:0}button:-moz-focusring,[type=button]:-moz-focusring,[type=reset]:-moz-focusring,[type=submit]:-moz-focusring{outline:1px dotted ButtonText}fieldset{padding:0.35em 0.75em 0.625em}legend{box-sizing:border-box;color:inherit;display:table;max-width:100%;padding:0;white-space:normal;}progress{vertical-align:baseline}textarea{overflow:auto}[type=checkbox],[type=radio]{box-sizing:border-box;padding:0;}[type=number]::-webkit-inner-spin-button,[type=number]::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px;}[type=search]::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit;}details{display:block}summary{display:list-item}template{display:none}[hidden]{display:none}:root{--spw-ds-container-xl:1232px;--spw-ds-container-lg:1024px;--spw-ds-container-md:768px;--spw-ds-container-sm:640px}.spw-ds-container{width:100%;padding-left:16px;padding-right:16px;margin-left:auto;margin-right:auto}@media (min-width: 460px){.spw-ds-container{max-width:var(--spw-ds-container-sm)}}@media (min-width: 768px){.spw-ds-container{max-width:var(--spw-ds-container-md)}}@media (min-width: 1024px){.spw-ds-container{max-width:var(--spw-ds-container-lg)}}@media (min-width: 1350px){.spw-ds-container{max-width:var(--spw-ds-container-xl)}}:host{display:block}.spw-cookies{position:fixed;top:0;left:0;width:100%;height:100%;background-color:rgba(0, 0, 0, 0.5);display:flex;align-items:flex-end;justify-content:end;z-index:9999}.spw-cookies__container{background:white;border-radius:5px;box-shadow:0 2px 10px rgba(0, 0, 0, 0.1);max-width:400px;width:100%;margin:12px;line-height:1.5;max-height:calc(-24px + 100vh);overflow-y:auto}.spw-cookies__content,.spw-cookies__buttons{padding:16px}@media (min-width: 768px){.spw-cookies__content,.spw-cookies__buttons{padding:24px}}.spw-cookies__content{padding-bottom:0}.spw-cookies__buttons{position:sticky;z-index:10;bottom:0;background:#fff;display:flex;flex-direction:column;gap:12px;text-align:center}.spw-cookies__buttons spw-button{--spw-button-py-medium:var(--spw-button-py-large)}.spw-cookies__title{font-size:24px;line-height:1.2;color:var(--spw-colors-support-grey-grey-900);margin-bottom:8px}.spw-cookies__text{color:var(--spw-color-themes-grey-grey-600);margin-bottom:16px}.spw-cookies__checkbox{padding-top:4px}.spw-cookies__checkbox-text{color:var(--spw-color-themes-grey-grey-600)}`;

const SpwCookies = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        /** Titre affiché dans la bannière de cookies */
        this.cookiesTitle = 'Nous utilisons des cookies';
        /** Description des cookies et de leur utilisation, affichée dans la bannière */
        this.cookiesDescription = `Ce site web utilise des cookies essentiels pour assurer son bon fonctionnement et des cookies de suivi pour comprendre comment vous interagissez avec lui. Ces derniers ne seront installés qu'après avoir obtenu votre consentement.`;
        /** Texte du bouton pour accepter tous les cookies */
        this.acceptAllButtonText = 'Accepter tous les cookies';
        /** Texte du bouton pour accepter uniquement les cookies fonctionnels */
        this.acceptRequiredButtonText = 'Accepter uniquement les cookies fonctionnels';
        this.isVisible = false;
        this.analyticsEnabled = false;
    }
    componentWillLoad() {
        this.initializeCookieSettings();
        this.checkCookieSettings();
    }
    initializeCookieSettings() {
        if (localStorage.getItem('spw-cookie-settings__required') === null) {
            localStorage.setItem('spw-cookie-settings__required', 'false');
        }
        if (localStorage.getItem('spw-cookie-settings__analytics') === null) {
            localStorage.setItem('spw-cookie-settings__analytics', 'false');
        }
        if (localStorage.getItem('spw-cookie-settings__saved') === null) {
            localStorage.setItem('spw-cookie-settings__saved', 'false');
        }
    }
    checkCookieSettings() {
        const settings = this.getCookieSettings();
        if (!settings['spw-cookie-settings__saved']) {
            this.isVisible = true;
        }
        this.analyticsEnabled = settings['spw-cookie-settings__analytics'];
    }
    getCookieSettings() {
        return {
            'spw-cookie-settings__required': JSON.parse(localStorage.getItem('spw-cookie-settings__required')),
            'spw-cookie-settings__analytics': JSON.parse(localStorage.getItem('spw-cookie-settings__analytics')),
            'spw-cookie-settings__saved': JSON.parse(localStorage.getItem('spw-cookie-settings__saved')),
        };
    }
    setCookieSettings(settings) {
        Object.keys(settings).forEach(key => {
            localStorage.setItem(key, JSON.stringify(settings[key]));
        });
    }
    toggleAnalytics() {
        this.analyticsEnabled = !this.analyticsEnabled;
        this.setCookieSettings({ 'spw-cookie-settings__analytics': this.analyticsEnabled });
    }
    acceptAllCookies() {
        this.setCookieSettings({
            'spw-cookie-settings__required': true,
            'spw-cookie-settings__analytics': true,
            'spw-cookie-settings__saved': true,
        });
        this.isVisible = false;
    }
    acceptRequiredCookies() {
        this.setCookieSettings({
            'spw-cookie-settings__required': true,
            'spw-cookie-settings__analytics': false,
            'spw-cookie-settings__saved': true,
        });
        this.isVisible = false;
    }
    render() {
        if (!this.isVisible) {
            return null;
        }
        return (h("div", { class: "spw-cookies" }, h("div", { class: "spw-cookies__container" }, h("div", { class: "spw-cookies__content" }, h("h2", { class: "spw-cookies__title" }, this.cookiesTitle), h("p", { class: "spw-cookies__text" }, this.cookiesDescription), h("spw-accordion", null, h("spw-accordion-item", null, h("spw-accordion-title", { slot: "title" }, "Param\u00E9trer les cookies"), h("spw-accordion-content", { slot: "content" }, h("div", { class: "spw-cookies__checkbox" }, h("spw-checkbox", { checked: this.analyticsEnabled, onSpwChange: () => this.toggleAnalytics() }, h("span", { class: "spw-cookies__checkbox-text" }, "Les cookies de statistiques proviennent de soci\u00E9t\u00E9s de externes (\"cookies tiers\") et sont utilis\u00E9s pour collecter des informations sur les sites web visit\u00E9s par l'utilisateur."))))))), h("div", { class: "spw-cookies__buttons" }, h("spw-button", { "is-full-width": "true", onClick: () => this.acceptAllCookies() }, this.acceptAllButtonText), h("spw-button", { "is-full-width": "true", variant: "secondary", onClick: () => this.acceptRequiredCookies() }, this.acceptRequiredButtonText)))));
    }
};
SpwCookies.style = spwCookiesCss();

export { SpwCookies as spw_cookies };
