import { faCheck, faCopy } from "@fortawesome/free-solid-svg-icons";
import { h } from "@stencil/core";
import classNames from "classnames";
import { copyToClipboard } from "../../../utils/copyToClipboa";
export class CopyButton {
    constructor() {
        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 is() { return "copy-button"; }
    static get encapsulation() { return "shadow"; }
    static get originalStyleUrls() {
        return {
            "$": ["copy-button.css"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["copy-button.css"]
        };
    }
    static get properties() {
        return {
            "class": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "attribute": "class",
                "reflect": false
            },
            "copyIcon": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "IconDefinition",
                    "resolved": "IconDefinition",
                    "references": {
                        "IconDefinition": {
                            "location": "import",
                            "path": "@fortawesome/free-solid-svg-icons",
                            "id": "node_modules::IconDefinition"
                        }
                    }
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false
            },
            "successIcon": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "IconDefinition",
                    "resolved": "IconDefinition",
                    "references": {
                        "IconDefinition": {
                            "location": "import",
                            "path": "@fortawesome/free-solid-svg-icons",
                            "id": "node_modules::IconDefinition"
                        }
                    }
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false
            },
            "text": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "attribute": "text",
                "reflect": false
            }
        };
    }
    static get states() {
        return {
            "isSuccess": {}
        };
    }
}
//# sourceMappingURL=copy-button.js.map
