"use client";
import {
Lock,
Eye,
Globe,
Bookmark,
BookmarkCheck,
Trash2,
Loader2,
} from "lucide-react";
import { useTranslations } from "next-intl";
import { useRouter } from "next/navigation";
import { Button } from "ui/button";
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
} from "ui/dropdown-menu";
import { Tooltip, TooltipContent, TooltipTrigger } from "ui/tooltip";
import { WriteIcon } from "ui/write-icon";
import { useMemo } from "react";
export type Visibility = "private" | "public" | "readonly";
const VISIBILITY_ICONS = {
private: Lock,
readonly: Eye,
public: Globe,
} as const;
const VISIBILITY_CONFIG = {
agent: {
private: {
label: "Agent.private",
description: "Agent.privateDescription",
},
readonly: {
label: "Agent.readOnly",
description: "Agent.readOnlyDescription",
},
public: { label: "Agent.public", description: "Agent.publicDescription" },
},
workflow: {
private: {
label: "Workflow.private",
description: "Workflow.privateDescription",
},
readonly: {
label: "Workflow.readonly",
description: "Workflow.readonlyDescription",
},
public: {
label: "Workflow.public",
description: "Workflow.publicDescription",
},
},
mcp: {
private: {
label: "MCP.private",
description: "MCP.privateDescription",
},
public: {
label: "MCP.featured",
description: "MCP.featuredDescription",
},
},
} as const;
interface ShareableActionsProps {
type: "agent" | "workflow" | "mcp";
visibility?: Visibility;
isOwner: boolean;
canChangeVisibility?: boolean;
isBookmarked?: boolean;
editHref?: string;
onVisibilityChange?: (visibility: Visibility) => void;
isVisibilityChangeLoading?: boolean;
onBookmarkToggle?: (isBookmarked: boolean) => void;
isBookmarkToggleLoading?: boolean;
onDelete?: () => void;
isDeleteLoading?: boolean;
renderActions?: () => React.ReactNode;
disabled?: boolean;
}
export function ShareableActions({
type,
visibility,
isOwner,
canChangeVisibility = true,
isBookmarked = false,
editHref,
onVisibilityChange,
onBookmarkToggle,
onDelete,
renderActions,
isVisibilityChangeLoading = false,
isBookmarkToggleLoading = false,
isDeleteLoading = false,
disabled = false,
}: ShareableActionsProps) {
const t = useTranslations();
const router = useRouter();
const isAnyLoading = useMemo(
() =>
isVisibilityChangeLoading || isBookmarkToggleLoading || isDeleteLoading,
[isVisibilityChangeLoading, isBookmarkToggleLoading, isDeleteLoading],
);
const VisibilityIcon = visibility ? VISIBILITY_ICONS[visibility] : null;
const visibilityItems = Object.entries(VISIBILITY_CONFIG[type]).map(
([value, config]) => {
const IconComponent =
VISIBILITY_ICONS[value as keyof typeof VISIBILITY_ICONS];
return {
icon:
{t(visibilityItem.label)}
{t(visibilityItem.description)}