'use client';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useCallback } from 'react';
import { Copy, FolderOpen } from 'lucide-react';
import { toast } from 'sonner';
import { Button } from '../../ui/button.js';
import { openFolder } from '../../../app/actions/open-folder.js';
import { GitStatusCluster } from './git-status-cluster.js';
/** Collapse a long absolute path to just its last segment. */
function shortPath(path) {
    const normalized = path.replace(/\\/g, '/').replace(/\/+$/, '');
    const idx = normalized.lastIndexOf('/');
    return idx === -1 ? normalized : normalized.slice(idx + 1);
}
export function PathCluster({ applicationId, repositoryPath }) {
    const handleCopy = useCallback(async () => {
        try {
            await navigator.clipboard.writeText(repositoryPath);
            toast.success('Path copied', { description: repositoryPath });
        }
        catch {
            toast.error('Failed to copy path');
        }
    }, [repositoryPath]);
    const handleOpen = useCallback(async () => {
        const result = await openFolder(repositoryPath);
        if (!result.success) {
            toast.error('Could not open folder', { description: result.error });
        }
    }, [repositoryPath]);
    return (_jsxs("div", { className: "text-muted-foreground flex min-w-0 items-center gap-1.5 text-xs", children: [_jsx("span", { className: "truncate font-mono text-[11px]", title: repositoryPath, children: shortPath(repositoryPath) }), _jsx(Button, { variant: "ghost", size: "icon", className: "text-muted-foreground hover:text-foreground h-5 w-5", onClick: handleCopy, "aria-label": "Copy path", title: "Copy path", children: _jsx(Copy, { className: "h-3 w-3" }) }), _jsx(Button, { variant: "ghost", size: "icon", className: "text-muted-foreground hover:text-foreground h-5 w-5", onClick: handleOpen, "aria-label": "Open in file manager", title: "Open in file manager", children: _jsx(FolderOpen, { className: "h-3 w-3" }) }), _jsx("span", { className: "text-muted-foreground/40", children: "\u00B7" }), _jsx(GitStatusCluster, { applicationId: applicationId, repositoryPath: repositoryPath })] }));
}
