"use client";
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
import { useCallback, useState } from "react";
import { cn } from "@stigmer/theme";
/**
 * One-time banner displayed after a new invitation link is created.
 *
 * Shows the invite URL in a monospace read-only field with a **Copy**
 * button. While invite URLs are always retrievable from the invitation
 * list, surfacing the URL immediately after creation provides the
 * critical "copy and share" moment that admins expect.
 *
 * This is a standalone alert component, not a modal — the parent
 * decides how to present and position it.
 *
 * All visual properties flow through `--stgm-*` design tokens.
 *
 * @example
 * ```tsx
 * <InvitationCreatedAlert
 *   inviteUrl="https://app.stigmer.ai/invite/abc123..."
 *   label="Engineering team invite"
 *   onDismiss={() => setCreatedUrl(null)}
 * />
 * ```
 */
export function InvitationCreatedAlert({ inviteUrl, label, onDismiss, className, }) {
    const [copied, setCopied] = useState(false);
    const handleCopy = useCallback(async () => {
        try {
            await navigator.clipboard.writeText(inviteUrl);
            setCopied(true);
            setTimeout(() => setCopied(false), 2000);
        }
        catch {
            const el = document.getElementById("stgm-invite-url-reveal");
            if (el) {
                const selection = window.getSelection();
                const range = document.createRange();
                range.selectNodeContents(el);
                selection?.removeAllRanges();
                selection?.addRange(range);
            }
        }
    }, [inviteUrl]);
    return (_jsxs("div", { role: "alert", className: cn("rounded-lg border border-primary/30 bg-primary-subtle p-4", className), children: [_jsxs("div", { className: "mb-2 flex items-start justify-between gap-3", children: [_jsxs("div", { className: "min-w-0", children: [_jsxs("p", { className: "text-sm font-medium text-foreground", children: ["Invite link created: ", label] }), _jsx("p", { className: "mt-0.5 text-xs text-muted-foreground", children: "Share this link to invite people to your organization." })] }), _jsx("button", { type: "button", onClick: onDismiss, "aria-label": "Dismiss", className: cn("shrink-0 rounded p-1", "text-muted-foreground hover:text-foreground hover:bg-accent-hover", "transition-colors"), children: _jsx(CloseIcon, {}) })] }), _jsxs("div", { className: "flex items-center gap-2", children: [_jsx("code", { id: "stgm-invite-url-reveal", className: cn("min-w-0 flex-1 select-all truncate rounded-md", "border border-input bg-background px-2.5 py-1.5", "font-mono text-xs text-foreground"), children: inviteUrl }), _jsxs("button", { type: "button", onClick: handleCopy, className: cn("inline-flex shrink-0 items-center gap-1.5 rounded-md px-3 py-1.5 text-xs font-medium", "bg-primary text-primary-foreground hover:bg-primary-hover", "transition-colors"), children: [copied ? _jsx(CheckIcon, {}) : _jsx(CopyIcon, {}), copied ? "Copied" : "Copy"] })] })] }));
}
// ---------------------------------------------------------------------------
// Icons
// ---------------------------------------------------------------------------
function CopyIcon() {
    return (_jsxs("svg", { width: "12", height: "12", viewBox: "0 0 16 16", fill: "none", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [_jsx("rect", { x: "5", y: "5", width: "9", height: "9", rx: "1.5" }), _jsx("path", { d: "M5 11H3.5A1.5 1.5 0 0 1 2 9.5V3.5A1.5 1.5 0 0 1 3.5 2h6A1.5 1.5 0 0 1 11 3.5V5" })] }));
}
function CheckIcon() {
    return (_jsx("svg", { width: "12", height: "12", viewBox: "0 0 16 16", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: _jsx("path", { d: "M3 8.5l3.5 3.5L13 5" }) }));
}
function CloseIcon() {
    return (_jsx("svg", { width: "14", height: "14", viewBox: "0 0 16 16", fill: "none", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", "aria-hidden": "true", children: _jsx("path", { d: "M4 4l8 8M12 4l-8 8" }) }));
}
//# sourceMappingURL=InvitationCreatedAlert.js.map