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();
        if (navigator.clipboard) {
            navigator.clipboard
                .writeText(this.content)
                .catch(err => {
                console.warn('Clipboard write failed', err);
            });
        }
        else {
            console.warn('Clipboard API not supported');
        }
        document.body.removeChild(textArea);
    }
    /**
     * Render element
     */
    render() {
        return h(Host, { key: '7dbd8d41982f60cc65609aef27901080eb4e4efa', onClick: this.copyContent }, h("slot", { key: 'aceeb5f0819540433bc2a3f2dc08e0124de37c77' }));
    }
    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
            }
        };
    }
}
