/*!
 * Crafted with ❤ by Salla
 */
import { Host, h } from "@stencil/core";
import Cancel from "../../assets/svg/cancel.svg";
export class SallaMaintenanceAlert {
    componentWillLoad() {
        this.title = salla.config.get('maintenance_details.title');
        this.message = salla.config.get('maintenance_details.message');
        // Use matchMedia instead of window.innerWidth to avoid forced reflow (Lighthouse/PageSpeed)
        const isMobile = typeof window !== 'undefined' && !window.matchMedia('(min-width: 768px)').matches;
        this.buttonTitle = isMobile ? salla.config.get('maintenance_details.button_title') : salla.config.get('maintenance_details.button_full_title');
    }
    closeAlert() {
        salla.storage.set('hide_salla-maintenance-alert_at', Date.now());
        this.host.style.display = 'none';
    }
    render() {
        return (h(Host, { key: 'e76dcd0a076d1b72ead3398196f962713e975ce5', class: "s-maintenance-alert-wrapper" }, h("button", { key: '2105bc891908dab5a1c9edec1c534a600bb35fe5', class: "s-maintenance-alert-close", innerHTML: Cancel, onClick: () => this.closeAlert() }), h("div", { key: 'a01b014066fbbc08da96962ad9a0c98e24fddf1c', class: "s-maintenance-alert-content" }, h("div", { key: 'c8b6ac96a881fc40bdb65908bb309378035235ea', class: "s-maintenance-alert-container" }, h("div", { key: '5d9fb2968315674e0d3a3172f82f9109db55da1d', class: "s-maintenance-alert-icon" }, h("img", { key: '2649551a12d0958375a89cc1dcb8176b28f5e41f', src: salla.url.cdn('images/alert.png'), alt: "Alert" })), h("div", { key: '2b3f99a39857bcf87b034aa48074c1f4229bff95', class: "s-maintenance-alert-text" }, h("h2", { key: '5a3c0969cd45f666a8bd043d171e00bc88031f3e' }, this.title), h("p", { key: 'd3df4ada2bf5f7192b22affeeb10edec481a0038' }, this.message))), h("div", { key: '818d96f7680dc4b02fed14a2d8c09dab9b8e5d86' }, h("a", { key: '794a0c273fc4d84b0319b38e11fb43af5681ce67', class: "s-maintenance-alert-btn", href: salla.config.get('maintenance_details.button_url') }, this.buttonTitle)))));
    }
    componentDidLoad() {
        //auto-hide the alert if close button is clicked before one hour
        let hidden_at = salla.storage.get('hide_salla-maintenance-alert_at');
        if (hidden_at && ((Date.now() - hidden_at) / 1000 / 60) < 60) {
            this.closeAlert();
        }
    }
    static get is() { return "salla-maintenance-alert"; }
    static get originalStyleUrls() {
        return {
            "$": ["salla-maintenance-alert.scss"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["salla-maintenance-alert.css"]
        };
    }
    static get states() {
        return {
            "title": {},
            "message": {},
            "buttonTitle": {}
        };
    }
    static get elementRef() { return "host"; }
}
