'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const index = require('./index-f6e770c8.js');

const XCopy = class {
    constructor(hostRef) {
        index.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();
        try {
            document.execCommand('copy');
        }
        catch (err) {
            console.warn(err);
        }
        document.body.removeChild(textArea);
    }
    /**
     * Render element
     */
    render() {
        return index.h(index.Host, { key: 'a289df472974df8a42fc9cb039ff54e1878baf33', onClick: this.copyContent }, index.h("slot", { key: 'bfc68f693f295687825567501ac1f0120e02f179' }));
    }
};

exports.x_copy = XCopy;
