import { p as proxyCustomElement, H, h } from './p-3b962989.js';
import { f as faCopy, a as faCheck } from './p-5a6c2a4d.js';
import { c as classNames } from './p-12360e4c.js';
import { d as defineCustomElement$1 } from './p-5eac8600.js';

const isWindowAvailable = () => typeof window != 'undefined' && typeof (window === null || window === void 0 ? void 0 : window.location) != 'undefined';

function fallbackCopyTextToClipboard(text) {
    let success = false;
    if (!document || !document.body) {
        console.error('Document or document.body is not available');
        return success;
    }
    const textArea = document.createElement('textarea');
    textArea.value = text;
    textArea.style.position = 'fixed';
    textArea.style.left = '-9999px';
    textArea.style.top = '0';
    document.body.appendChild(textArea);
    try {
        textArea.focus();
        textArea.setSelectionRange(0, textArea.value.length);
        success = document.execCommand('copy');
    }
    catch (err) {
        console.error('Fallback: Oops, unable to copy', err);
    }
    finally {
        document.body.removeChild(textArea);
    }
    return success;
}
async function copyToClipboard(text) {
    if (!isWindowAvailable()) {
        return false;
    }
    let success = false;
    if (!navigator.clipboard) {
        success = fallbackCopyTextToClipboard(text);
    }
    else {
        success = await navigator.clipboard.writeText(text).then(function done() {
            return true;
        }, function error(err) {
            console.error('Async: Could not copy text: ', err);
            return false;
        });
    }
    return success;
}

const copyButtonCss = "*,:after,:before{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-scroll-snap-strictness:proximity;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:rgba(59,130,246,.5);--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;border:0 solid #e5e7eb;box-sizing:border-box}::backdrop{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-scroll-snap-strictness:proximity;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:rgba(59,130,246,.5);--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;}/*! tailwindcss v3.4.17 | MIT License | https://tailwindcss.com*/:after,:before{--tw-content:\"\"}:host,html{-webkit-text-size-adjust:100%;font-feature-settings:normal;-webkit-tap-highlight-color:transparent;font-family:ui-sans-serif,system-ui,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji;font-variation-settings:normal;line-height:1.5;-moz-tab-size:4;tab-size:4}body{line-height:inherit;margin:0}hr{border-top-width:1px;color:inherit;height:0}abbr:where([title]){text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,pre,samp{font-feature-settings:normal;font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;font-size:1em;font-variation-settings:normal}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}table{border-collapse:collapse;border-color:inherit;text-indent:0}button,input,optgroup,select,textarea{font-feature-settings:inherit;color:inherit;font-family:inherit;font-size:100%;font-variation-settings:inherit;font-weight:inherit;letter-spacing:inherit;line-height:inherit;margin:0;padding:0}button,select{text-transform:none}button,input:where([type=button]),input:where([type=reset]),input:where([type=submit]){-webkit-appearance:button;background-color:transparent;background-image:none}:-moz-focusring{outline:auto}:-moz-ui-invalid{box-shadow:none}progress{vertical-align:baseline}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}blockquote,dd,dl,fieldset,figure,h1,h2,h3,h4,h5,h6,hr,p,pre{margin:0}fieldset,legend{padding:0}menu,ol,ul{list-style:none;margin:0;padding:0}dialog{padding:0}textarea{resize:vertical}input::placeholder,textarea::placeholder{color:#9ca3af;opacity:1}[role=button],button{cursor:pointer}:disabled{cursor:default}audio,canvas,embed,iframe,img,object,svg,video{display:block;vertical-align:middle}img,video{height:auto;max-width:100%}[hidden]:where(:not([hidden=until-found])){display:none}.copy-button{color:#6c757d}.static{position:static}.shadow{--tw-shadow:0 1px 3px 0 rgba(0,0,0,.1),0 1px 2px -1px rgba(0,0,0,.1);--tw-shadow-colored:0 1px 3px 0 var(--tw-shadow-color),0 1px 2px -1px var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow,0 0 #0000),var(--tw-ring-shadow,0 0 #0000),var(--tw-shadow)}.visible{visibility:visible}.hidden{display:none}.fixed{position:fixed}.\\!container{width:100%!important}.container{width:100%}@media (min-width:640px){.\\!container{max-width:640px!important}.container{max-width:640px}}@media (min-width:768px){.\\!container{max-width:768px!important}.container{max-width:768px}}@media (min-width:1024px){.\\!container{max-width:1024px!important}.container{max-width:1024px}}@media (min-width:1280px){.\\!container{max-width:1280px!important}.container{max-width:1280px}}@media (min-width:1536px){.\\!container{max-width:1536px!important}.container{max-width:1536px}}";
const CopyButtonStyle0 = copyButtonCss;

const CopyButton = /*@__PURE__*/ proxyCustomElement(class CopyButton extends H {
    constructor() {
        super();
        this.__registerHost();
        this.__attachShadow();
        this.isSuccess = false;
        this.handleClick = async (event) => {
            event.preventDefault();
            event.stopPropagation();
            const trimmedText = this.text ? this.text.trim() : this.text;
            const success = await copyToClipboard(trimmedText);
            this.isSuccess = success;
            if (success) {
                this.timeoutId = window.setTimeout(() => {
                    this.isSuccess = false;
                }, 1000);
            }
        };
    }
    disconnectedCallback() {
        // Clear the timeout if the component is unmounted
        if (this.timeoutId) {
            clearTimeout(this.timeoutId);
            this.timeoutId = undefined; // Reset the timeout ID
        }
    }
    render() {
        var _a, _b;
        const copyIcon = (_a = this.copyIcon) !== null && _a !== void 0 ? _a : faCopy;
        const successIcon = (_b = this.successIcon) !== null && _b !== void 0 ? _b : faCheck;
        return (h("a", { key: '70cb8b95b633d7b7d6538c29ec6edd6c40a13bc3', href: "/#", class: classNames(this.class, 'copy-button'), onClick: this.handleClick }, h("fa-icon", { key: 'fbaf097295176181c88d6636cc76e166ecd033c7', icon: this.isSuccess ? successIcon : copyIcon })));
    }
    static get style() { return CopyButtonStyle0; }
}, [1, "copy-button", {
        "class": [1],
        "copyIcon": [16],
        "successIcon": [16],
        "text": [1],
        "isSuccess": [32]
    }]);
function defineCustomElement() {
    if (typeof customElements === "undefined") {
        return;
    }
    const components = ["copy-button", "fa-icon"];
    components.forEach(tagName => { switch (tagName) {
        case "copy-button":
            if (!customElements.get(tagName)) {
                customElements.define(tagName, CopyButton);
            }
            break;
        case "fa-icon":
            if (!customElements.get(tagName)) {
                defineCustomElement$1();
            }
            break;
    } });
}

export { CopyButton as C, defineCustomElement as d };

//# sourceMappingURL=p-fcdd38ae.js.map