"use client"; import { useState } from "react"; import { Button } from "@/components/ui/button"; import { useToast } from "@/components/ui/use-toast"; import { shareVersionWithClient } from "@/actions/versions"; import { Send, CheckCircle2 } from "lucide-react"; interface ShareWithClientButtonProps { versionId: string; isAlreadyShared?: boolean; onShared?: () => void; size?: "sm" | "default"; } export function ShareWithClientButton({ versionId, isAlreadyShared = false, onShared, size = "sm", }: ShareWithClientButtonProps) { const [shared, setShared] = useState(isAlreadyShared); const [loading, setLoading] = useState(false); const { toast } = useToast(); const handleShare = async () => { if (shared) return; setLoading(true); try { await shareVersionWithClient(versionId); setShared(true); toast({ title: "Version shared with client" }); onShared?.(); } catch (err) { toast({ title: "Failed to share version", description: (err as Error).message, variant: "destructive", }); } finally { setLoading(false); } }; if (shared) { return ( ); } return ( ); }