import { Host, h } from "@stencil/core";
export class XCopy {
    constructor() {
        this.content = undefined;
    }
    /**
     * Copy the content to clipboard
     *
     * @returns
     */
    copyContent() {
        if (!navigator.clipboard) {
            this.fallbackCopyTextToClipboard();
            return;
        }
        navigator.clipboard
            .writeText(this.content)
            .then(() => { }, err => {
            console.warn(err);
        });
    }
    /**
     * Fallback for copy text
     */
    fallbackCopyTextToClipboard() {
        const textArea = document.createElement("textarea");
        textArea.value = this.content;
        textArea.style.top = "0";
        textArea.style.left = "0";
        textArea.style.position = "fixed";
        document.body.appendChild(textArea);
        textArea.focus();
        textArea.select();
        try {
            document.execCommand('copy');
        }
        catch (err) {
            console.warn(err);
        }
        document.body.removeChild(textArea);
    }
    /**
     * Render element
     */
    render() {
        return h(Host, { key: 'cf335b97f84b055ebd5de911e880c85a440cba84', onClick: this.copyContent }, h("slot", { key: '5e797834504f24557bdcce2bb1e1e00636e81a26' }));
    }
    static get is() { return "x-copy"; }
    static get properties() {
        return {
            "content": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Element content text to copy on click"
                },
                "attribute": "content",
                "reflect": false
            }
        };
    }
}
