{
}
export class Flip {
    constructor() {
        this.events = { flipEvents: [], flipBackEvents: [] };
    }
    componentWillLoad() {
        this.init();
    }
    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}`;
        });
    }
    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(',') :
                    [];
            });
            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;
        }
    }
    flip() {
        this.flipState = !this.flipState;
        console.log(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" }))));
    }
    static get is() { return "ema-flip"; }
    static get properties() { return {
        "element": {
            "elementRef": true
        },
        "flip": {
            "method": true
        },
        "flipBackEvents": {
            "type": String,
            "attr": "flip-back-events"
        },
        "flipDuration": {
            "type": Number,
            "attr": "flip-duration"
        },
        "flipEvents": {
            "type": String,
            "attr": "flip-events"
        },
        "flipState": {
            "state": true
        },
        "flipTimingFunction": {
            "type": String,
            "attr": "flip-timing-function"
        },
        "isFlipped": {
            "type": Boolean,
            "attr": "is-flipped"
        }
    }; }
    static get style() { return "/**style-placeholder:ema-flip:**/"; }
}
