import { faCheck, faCopy } from "@fortawesome/free-solid-svg-icons";
import { h } from "@stencil/core";
import { copyToClipboard } from "../../../utils/copyToClipboa";
export class CopyButton {
    constructor() {
        this.class = 'copy-button';
        this.iconClass = 'copy-button-icon';
        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: '6b9c055e99449eb734f373883f611f2778f4ec0f', href: "/#", class: this.class, onClick: this.handleClick }, h("mvx-fa-icon", { key: 'dca4751babb2dad25cda389351bb03e6d959bf5a', icon: this.isSuccess ? successIcon : copyIcon, class: this.iconClass })));
    }
    static get is() { return "mvx-copy-button"; }
    static get originalStyleUrls() {
        return {
            "$": ["copy-button.css"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["copy-button.css"]
        };
    }
    static get properties() {
        return {
            "class": {
                "type": "string",
                "attribute": "class",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "defaultValue": "'copy-button'"
            },
            "iconClass": {
                "type": "string",
                "attribute": "icon-class",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "defaultValue": "'copy-button-icon'"
            },
            "copyIcon": {
                "type": "unknown",
                "attribute": "copy-icon",
                "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",
                "attribute": "success-icon",
                "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",
                "attribute": "text",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false
            }
        };
    }
    static get states() {
        return {
            "isSuccess": {}
        };
    }
}
//# sourceMappingURL=copy-button.js.map
