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: '4b1febe42e5970fe4c0ece871c620a3ed58168fa', onClick: this.copyContent }, h("slot", { key: 'b7cd8d93eb34ba613b9da9069b522fae2f90f6b2' }));
    }
}, [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 };
