import { r as registerInstance, h, H as Host } from './index-6191c26c.js';

const XCopy = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        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' }));
    }
};

export { XCopy as x_copy };
