import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useState } from 'react';
var CopyState;
(function(CopyState) {
    CopyState[CopyState["Initial"] = 0] = "Initial";
    CopyState[CopyState["Copied"] = 1] = "Copied";
    CopyState[CopyState["Error"] = 2] = "Error";
})(CopyState || (CopyState = {}));
export function CopyButton(param) {
    let { label, successLabel, content, ...props } = param;
    const [copied, setCopied] = useState(0);
    const isDisabled = copied === 2;
    const title = isDisabled ? '' : copied ? successLabel : label;
    return /*#__PURE__*/ _jsx("span", {
        ...props,
        title: title,
        "aria-label": title,
        "aria-disabled": isDisabled,
        role: "button",
        onClick: ()=>{
            if (isDisabled) return;
            if (!navigator.clipboard) {
                setCopied(2);
                return;
            }
            navigator.clipboard.writeText(content).then(()=>{
                if (copied) return;
                setCopied(1);
                setTimeout(()=>setCopied(0), 2000);
            });
        },
        children: copied ? /*#__PURE__*/ _jsx(CopySuccessIcon, {}) : /*#__PURE__*/ _jsx(CopyIcon, {})
    });
}
function CopyIcon() {
    return /*#__PURE__*/ _jsxs("svg", {
        width: "16",
        height: "16",
        viewBox: "0 0 24 24",
        fill: "transparent",
        stroke: "currentColor",
        strokeWidth: "1.5",
        strokeLinecap: "round",
        strokeLinejoin: "round",
        children: [
            /*#__PURE__*/ _jsx("rect", {
                width: "14",
                height: "14",
                x: "8",
                y: "8",
                rx: "2",
                ry: "2"
            }),
            /*#__PURE__*/ _jsx("path", {
                d: "M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"
            })
        ]
    });
}
function CopySuccessIcon() {
    return /*#__PURE__*/ _jsx("svg", {
        height: "16",
        xlinkTitle: "copied",
        viewBox: "0 0 16 16",
        width: "16",
        stroke: "currentColor",
        fill: "currentColor",
        "data-nextjs-data-runtime-error-copy-stack-success": true,
        children: /*#__PURE__*/ _jsx("path", {
            d: "M13.78 4.22a.75.75 0 0 1 0 1.06l-7.25 7.25a.75.75 0 0 1-1.06 0L2.22 9.28a.751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018L6 10.94l6.72-6.72a.75.75 0 0 1 1.06 0Z"
        })
    });
}

//# sourceMappingURL=index.js.map