var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import * as React from "react";
import { cn } from "@utils";
import { textCopyVariants } from "./textCopyVariants";
import { ADPIcon, iconList } from "../adpIcon";
import { Button } from "../button";
/**
 * TextCopy component for copying text to clipboard with visual confirmation
 */
export const TextCopy = React.forwardRef((_a, ref) => {
    var { className, text = "", children, displayOnHover = false, copyButtonTitle, confirmationMessage = "Copied" } = _a, props = __rest(_a, ["className", "text", "children", "displayOnHover", "copyButtonTitle", "confirmationMessage"]);
    const [copied, setCopied] = React.useState(false);
    const copyText = async () => {
        setCopied(true);
        // Copy text, if not exists copy children if children is string or empty string
        const textToCopy = text || (typeof children === "string" ? children : "");
        await navigator.clipboard.writeText(textToCopy);
        setTimeout(() => {
            setCopied(false);
        }, 1500);
    };
    return (_jsxs("div", Object.assign({ ref: ref, "data-testid": "copyComponent", className: cn(textCopyVariants({ displayOnHover }), displayOnHover && "group", className) }, props, { children: [children, copied ? (_jsxs("div", { className: "inline-flex align-bottom items-center gap-1 text-success-500 ms-2", "data-testid": "textCopied", "aria-live": "polite", children: [_jsx(ADPIcon, { size: "xs", fixedWidth: true, icon: iconList.checkCircle }), _jsx("span", { children: confirmationMessage })] })) : (_jsx(Button, { variant: "text", onClick: copyText, title: copyButtonTitle || "Copy Text", className: cn("cursor-pointer transition-opacity ease-in-out inline-flex align-text-top ms-2", displayOnHover && "opacity-0 group-hover:opacity-100 group-hover:delay-100 delay-300"), "data-testid": "copyButton", children: _jsx(ADPIcon, { size: "xs", fixedWidth: true, icon: iconList.clone }) }))] })));
});
TextCopy.displayName = "TextCopy";
//# sourceMappingURL=textCopy.js.map