"use client";
import { useCallback, useMemo } from "react";
import { toast } from "../feedback/toast";
/**
 * Clipboard helper for resource detail pages.
 *
 * Wraps `navigator.clipboard.writeText` with toast feedback so every
 * copy action is confirmed visually (Nielsen heuristic #1 — visibility
 * of system status). Falls back to a hidden textarea for older browsers.
 *
 * @example
 * ```tsx
 * const { copyId, copySlug, copy } = useCopyResource();
 *
 * <ActionMenu.Item onSelect={() => copyId(resource.id)}>
 *   Copy ID
 * </ActionMenu.Item>
 * ```
 */
export function useCopyResource() {
    const copy = useCallback(async (text, label) => {
        try {
            await navigator.clipboard.writeText(text);
            toast.success(`${label} copied`);
        }
        catch {
            fallbackCopy(text);
            toast.success(`${label} copied`);
        }
    }, []);
    const copyId = useCallback((id) => copy(id, "ID"), [copy]);
    const copySlug = useCallback((slug) => copy(slug, "Slug"), [copy]);
    const copyQualifiedSlug = useCallback((org, slug) => copy(`${org}/${slug}`, "Qualified slug"), [copy]);
    return useMemo(() => ({ copy, copyId, copySlug, copyQualifiedSlug }), [copy, copyId, copySlug, copyQualifiedSlug]);
}
function fallbackCopy(text) {
    const textarea = document.createElement("textarea");
    textarea.value = text;
    textarea.style.position = "fixed";
    textarea.style.opacity = "0";
    document.body.appendChild(textarea);
    textarea.select();
    document.execCommand("copy");
    document.body.removeChild(textarea);
}
//# sourceMappingURL=useCopyResource.js.map