import { proxyCustomElement, HTMLElement, h, Host } from '@stencil/core/internal/client';

const XCopy$1 = /*@__PURE__*/ proxyCustomElement(class XCopy extends HTMLElement {
    constructor() {
        super();
        this.__registerHost();
        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' }));
    }
}, [4, "x-copy", {
        "content": [1]
    }]);
function defineCustomElement$1() {
    if (typeof customElements === "undefined") {
        return;
    }
    const components = ["x-copy"];
    components.forEach(tagName => { switch (tagName) {
        case "x-copy":
            if (!customElements.get(tagName)) {
                customElements.define(tagName, XCopy$1);
            }
            break;
    } });
}

const XCopy = XCopy$1;
const defineCustomElement = defineCustomElement$1;

export { XCopy, defineCustomElement };
