import { r as registerInstance, h, g as getElement } from './chunk-82a2445c.js';

class Flip {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        this.events = { flipEvents: [], flipBackEvents: [] };
    }
    // private options = { duration: 400, timingFunction: 'ease-in' };
    componentWillLoad() {
        this.init();
    }
    /**
     * add options to the element (duration, timingfunction).
     */
    componentDidLoad() {
        const duration = this.flipDuration || 400;
        const timingFunction = this.flipTimingFunction || 'ease-in';
        ['front', 'back']
            .forEach(key => {
            const el = this.element.querySelector(`.ema-flip__${key}`);
            el['style'].transition = `all ${duration / 1000}s ${timingFunction}`;
        });
    }
    /**
     * handling the `is-flipped` attribute.
     * usually this is used together with modern frameworks.
     */
    componentWillUpdate() {
        if (this.isFlipped !== undefined) {
            this.flipState = this.isFlipped;
        }
    }
    init() {
        if (this.isFlipped !== undefined) {
            this.flipState = this.isFlipped;
        }
        else if (this.flipEvents !== undefined) {
            ['flipEvents', 'flipBackEvents'].forEach(key => {
                this.events[key] = (this[key]) ?
                    this[key].split(',') :
                    [];
            });
            // adding event listeners
            const allEvents = [...this.events.flipEvents, ...this.events.flipBackEvents];
            allEvents
                .filter((eventType, index) => allEvents.indexOf(eventType) === index)
                .forEach(eventType => this.element.addEventListener(eventType, (evt) => this.processFlip(evt)));
            this.flipState = false;
        }
    }
    processFlip(evt) {
        const eventType = evt.type;
        if (this.flipState && this.events.flipBackEvents.indexOf(eventType) !== -1) {
            this.flipState = !this.flipState;
        }
        else if (!this.flipState && this.events.flipEvents.indexOf(eventType) !== -1) {
            this.flipState = !this.flipState;
        }
    }
    async flip() {
        // todo: check
        this.flipState = !this.flipState;
    }
    render() {
        return (h("div", { class: `ema-flip ${(this.flipState ? 'ema-flip--flipped' : '')}` }, h("div", { class: "ema-flip__front" }, h("slot", { name: "front" })), h("div", { class: "ema-flip__back" }, h("slot", { name: "back" }))));
    }
    get element() { return getElement(this); }
    static get style() { return ":root{--ema-color:#343a40;--ema-primary:#007bff;--ema-secondary:#6c757d;--ema-success:#28a745;--ema-info:#17a2b8;--ema-warning:#ffc107;--ema-danger:#dc3545;--ema-light:#f8f9fa;--ema-dark:#343a40;--ema-background:#fff;--ema-background-diap:rgba(29,29,29,0.97);--ema-border-color:#c5c9cd;--ema-border:1px solid #c5c9cd;--ema-border-radius:3px 3px 3px 3px;--ema-box-shadow:1px 1px 10px 1px #ccc;--ema-margin:0.25rem;--ema-margin-sm:0.5rem;--ema-margin-md:1rem;--ema-margin-lg:1.5rem;--ema-margin-xl:2rem;--ema-padding:0.25rem;--ema-padding-sm:0.5rem;--ema-padding-md:1rem;--ema-padding-lg:1.5rem;--ema-padding-xl:2rem;--ema-gray-100:#f8f9fa;--ema-gray-200:#e9ecef;--ema-gray-300:#dee2e6;--ema-gray-400:#ced4da;--ema-gray-500:#adb5bd;--ema-gray-600:#868e96;--ema-gray-700:#495057;--ema-gray-800:#343a40;--ema-gray-900:#212529}.ema-flip{-webkit-perspective:1000px;perspective:1000px;text-align:center}.ema-flip__back,.ema-flip__front{position:absolute;width:inherit;height:inherit;-webkit-transform-style:preserve-3d;transform-style:preserve-3d;-webkit-backface-visibility:hidden;backface-visibility:hidden}.ema-flip__front{z-index:900;-webkit-transform:rotate3d(0,0,0,0deg);transform:rotate3d(0,0,0,0deg)}.ema-flip--flipped .ema-flip__front{z-index:900;-webkit-transform:rotateY(180deg);transform:rotateY(180deg);-ms-transform:rotateY(180deg)}.ema-flip__back{z-index:800;-webkit-transform:rotateY(-180deg);transform:rotateY(-180deg)}.ema-flip--flipped .ema-flip__back{z-index:1000;-webkit-transform:rotate3d(0,0,0,0deg);transform:rotate3d(0,0,0,0deg)}"; }
}

export { Flip as ema_flip };
