"use client";
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
import { useCallback, useState } from "react";
import { useSessionArtifacts, } from "../useSessionArtifacts.js";
import { ArtifactCard } from "../../execution/ArtifactCard.js";
import { ArtifactPreviewModal } from "../../execution/ArtifactPreviewModal.js";
import { isPlanArtifact } from "../../library/detect-plan-artifact.js";
/**
 * Artifacts facet for the session panel (a `useSessionRailViews` rail view).
 *
 * Wraps `useSessionArtifacts` → `ArtifactCard` list with
 * `ArtifactPreviewModal` — the same content as `ArtifactsWidget`
 * without the section heading.
 */
export function ArtifactsTab({ executions, org, onApplied, onImplementPlan, onOpenPlan, }) {
    const { artifacts, hasArtifacts } = useSessionArtifacts(executions);
    const [previewEntry, setPreviewEntry] = useState(null);
    const handlePreview = useCallback((entry) => {
        // The plan opens as a document (the panel's plan tab), never a popup.
        if (onOpenPlan && isPlanArtifact(entry.artifact)) {
            onOpenPlan(entry.executionId);
            return;
        }
        setPreviewEntry(entry);
    }, [onOpenPlan]);
    const handleClosePreview = useCallback(() => {
        setPreviewEntry(null);
    }, []);
    if (!hasArtifacts) {
        return (_jsx("div", { className: "flex flex-col items-center justify-center px-4 py-8 text-center", children: _jsx("p", { className: "text-xs text-muted-foreground", children: "No artifacts yet. Files generated by the agent will appear here." }) }));
    }
    return (_jsxs(_Fragment, { children: [_jsx("div", { role: "list", className: "space-y-2", children: artifacts.map((entry) => (_jsx("div", { role: "listitem", children: _jsx(ArtifactCard, { artifact: entry.artifact, executionId: entry.executionId, org: org, hasNameCollision: entry.hasNameCollision, onPreview: () => handlePreview(entry) }) }, entry.artifact.sandboxPath || entry.artifact.name))) }), previewEntry && (_jsx(ArtifactPreviewModal, { artifact: previewEntry.artifact, executionId: previewEntry.executionId, isTerminal: previewEntry.isTerminal, org: org, open: true, onClose: handleClosePreview, onApplied: onApplied, onImplement: isPlanArtifact(previewEntry.artifact) ? onImplementPlan : undefined }))] }));
}
//# sourceMappingURL=ArtifactsTab.js.map