import { Host, h } from "@stencil/core";
import Movinwords from "../../utils/movinwords";
export class XMovinwords {
    constructor() {
        /**
         * Drawer state of the content
         */
        this.movinInstance = null;
        this.sentence = undefined;
        this.highlight = '';
    }
    /**
     * Watcher hook on sentence change
     */
    watchSentence() {
        if (this.el) {
            this.el.dispatchEvent(new CustomEvent('disconnected'));
            this.el.classList.remove('--v');
            this.movinInstance = new Movinwords({
                el: this.el,
                sentence: this.sentence,
                events: {
                    start: () => {
                        this.onTypingStart.emit();
                    },
                    end: () => {
                        this.onTypingEnd.emit();
                    },
                },
                highlight: {
                    classname: 'highlight',
                    tag: 'strong',
                    words: this.highlight.split(',').map((word) => word.trim()),
                },
            });
            this.movinInstance.start();
        }
    }
    /**
     * On element is mounted
     */
    componentDidLoad() {
        this.movinInstance = new Movinwords({
            el: this.el,
            autostart: true,
            sentence: this.sentence,
            events: {
                start: () => {
                    this.onTypingStart.emit();
                },
                end: () => {
                    this.onTypingEnd.emit();
                },
            },
            highlight: {
                classname: 'highlight',
                tag: 'strong',
                words: this.highlight.split(',').map((word) => word.trim()),
            },
        });
    }
    /**
     * On element is destroyed
     */
    disconnectedCallback() {
        this.el.dispatchEvent(new CustomEvent('disconnected'));
    }
    /**
     * Render component
     */
    render() {
        return h(Host, { key: '02ca2b9e7bc219ca430f6d610ef5c4fe1dadf6c4' }, h("slot", { key: '2b0fb01b638e9c0a63dd07c9de5773ec63819b28' }));
    }
    static get is() { return "x-movinwords"; }
    static get originalStyleUrls() {
        return {
            "$": ["./style.scss"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["style.css"]
        };
    }
    static get properties() {
        return {
            "sentence": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": "Element sentence to animate"
                },
                "attribute": "sentence",
                "reflect": false
            },
            "highlight": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": "Words to highlight"
                },
                "attribute": "highlight",
                "reflect": false,
                "defaultValue": "''"
            }
        };
    }
    static get events() {
        return [{
                "method": "onTypingStart",
                "name": "typingstart",
                "bubbles": false,
                "cancelable": true,
                "composed": true,
                "docs": {
                    "tags": [],
                    "text": "On animation start event"
                },
                "complexType": {
                    "original": "any",
                    "resolved": "any",
                    "references": {}
                }
            }, {
                "method": "onTypingEnd",
                "name": "typingend",
                "bubbles": false,
                "cancelable": true,
                "composed": true,
                "docs": {
                    "tags": [],
                    "text": "On animation end event"
                },
                "complexType": {
                    "original": "any",
                    "resolved": "any",
                    "references": {}
                }
            }];
    }
    static get elementRef() { return "el"; }
    static get watchers() {
        return [{
                "propName": "sentence",
                "methodName": "watchSentence"
            }];
    }
}
