'use client';
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
/**
 * AppTopBar — the application page header.
 *
 * Reorganised around a single primary action (SmartDeployButton) plus a
 * couple of supporting tools and an overflow menu for everything that
 * isn't day-to-day. Visual contract: 5 top-level groups separated by 1px
 * dividers — identity, source-context, primary action + local preview,
 * view switcher, overflow.
 *
 *    [◼] [Name] [● Ready]  ·  [slug] [📁]   →spacer→   [Save & publish ▾]   [▶ Preview]   [IDE Term Web]   [⋯]
 *    └── identity ──────┘     └── context ┘            └─── primary ───┘    └ local ┘    └── view ─┘   └ overflow ┘
 */
import { Database, LayoutGrid, ShieldCheck } from 'lucide-react';
import { BedrockTargetKind, DeploymentState } from '../../../../../../packages/core/src/domain/generated/output.js';
import { featureIdForApplication } from '../../../../../../packages/core/src/domain/shared/feature-id.js';
import { cn } from '../../../lib/utils.js';
import { BedrockMemoryToggle } from '../../bedrock-memory-toggle.js';
import { BedrockMemorySection } from '../../bedrock-memory-section.js';
import { Sheet, SheetContent, SheetDescription, SheetHeader, SheetTitle, SheetTrigger, } from '../../ui/sheet.js';
import { useState } from 'react';
import { SmartDeployCluster } from '../../features/application-page/smart-deploy-cluster.js';
import Link from 'next/link';
import { Button } from '../../ui/button.js';
import { DropdownMenuItem, DropdownMenuSeparator } from '../../ui/dropdown-menu.js';
import { useFeatureFlags } from '../../../hooks/feature-flags-context.js';
import { AppOverflowMenu } from './app-overflow-menu.js';
import { AppViewTabs } from './app-view-tabs.js';
import { CopyPromptButton } from './copy-prompt-button.js';
import { DeleteApplicationMenuItem } from './delete-application-menu-item.js';
import { OpenInControlCenterMenuItem } from './open-in-control-center-menu-item.js';
import { PathCluster } from './path-cluster.js';
import { SessionChip } from './session-chip.js';
import { StatusPill } from './status-pill.js';
/** Single source of truth for top-bar height. Both panes hang off this
 *  so nothing misaligns horizontally between left and right. */
export const TOP_BAR_HEIGHT_CLASS = 'h-12';
export function AppTopBar({ application, activeView, onViewChange, agentRunning, initialChatState, deploy, cloudDeploy, }) {
    const { collaboration, bedrockIntegration } = useFeatureFlags();
    const [bedrockSheetOpen, setBedrockSheetOpen] = useState(false);
    return (_jsxs("header", { className: cn('bg-background/95 supports-[backdrop-filter]:bg-background/70 sticky top-0 z-20 flex shrink-0 items-center gap-2 border-b px-3 backdrop-blur', TOP_BAR_HEIGHT_CLASS), children: [_jsx("div", { className: "flex h-7 w-7 shrink-0 items-center justify-center rounded-md bg-gradient-to-br from-indigo-500 to-violet-500 shadow-xs", children: _jsx(LayoutGrid, { className: "h-3.5 w-3.5 text-white" }) }), _jsx("h1", { className: "min-w-0 truncate text-sm font-semibold", children: application.name }), _jsx(StatusPill, { applicationId: application.id, persistedStatus: application.status, deployReady: deploy.status === DeploymentState.Ready }), _jsx(Divider, {}), _jsx(PathCluster, { applicationId: application.id, repositoryPath: application.repositoryPath }), _jsx("div", { className: "flex-1" }), _jsx(SmartDeployCluster, { application: application, cloudDeploy: cloudDeploy, agentRunning: agentRunning }), _jsx(AppViewTabs, { active: activeView, onChange: onViewChange, disabledTabs: [], deploy: deploy, 
                // "Building" covers both the initial setup window
                // (setupComplete flips true after the scaffolder + plan
                // finish) AND live user iterations that rewrite the project
                // tree — in both cases the preview is stale so we surface the
                // building stub instead of the old iframe.
                isBuilding: !application.setupComplete || agentRunning }), bedrockIntegration ? (_jsxs(_Fragment, { children: [_jsx(Divider, {}), _jsxs(Sheet, { open: bedrockSheetOpen, onOpenChange: setBedrockSheetOpen, children: [_jsx(SheetTrigger, { asChild: true, children: _jsxs(Button, { variant: "ghost", size: "sm", className: "h-8 gap-1.5 px-2", "data-testid": "top-bar-bedrock", title: "Bedrock memory", children: [_jsx(Database, { className: "size-3.5" }), _jsx("span", { className: "hidden text-xs lg:inline", children: "Bedrock" }), application.bedrockEnabled ? (_jsx("span", { className: "ml-0.5 size-1.5 rounded-full bg-emerald-500" })) : null] }) }), _jsxs(SheetContent, { side: "right", className: "w-[560px] sm:max-w-[560px]", children: [_jsxs(SheetHeader, { children: [_jsx(SheetTitle, { children: "Bedrock memory" }), _jsxs(SheetDescription, { children: ["Persistent markdown project memory for AI coding agents in ", application.name, "."] })] }), _jsx("div", { className: "mt-4", children: _jsx(BedrockMemorySection, { targetKind: BedrockTargetKind.Application, targetId: application.id, targetLabel: application.name, initialEnabled: application.bedrockEnabled === true }) })] })] })] })) : null, collaboration ? (_jsxs(_Fragment, { children: [_jsx(Divider, {}), _jsx(Button, { asChild: true, variant: "ghost", size: "sm", className: "h-8 gap-1.5 px-2", children: _jsxs(Link, { href: `/application/${application.id}/supervisor`, "data-testid": "top-bar-supervisor", title: "Configure supervisor for this application", children: [_jsx(ShieldCheck, { className: "size-3.5" }), _jsx("span", { className: "hidden text-xs lg:inline", children: "Supervisor" })] }) })] })) : null, _jsxs(AppOverflowMenu, { children: [_jsxs("div", { className: "px-2 py-1.5", children: [_jsx("div", { className: "text-muted-foreground text-[10px] tracking-wide uppercase", children: "Session" }), _jsx("div", { className: "mt-1", children: _jsx(SessionChip, { featureId: featureIdForApplication(application.id), initialChatState: initialChatState, persistedSessionId: application.agentSessionId }) })] }), _jsx("div", { className: "px-2 pb-2", children: _jsx(CopyPromptButton, { applicationId: application.id }) }), bedrockIntegration ? (_jsxs(_Fragment, { children: [_jsx(DropdownMenuSeparator, {}), _jsx("div", { className: "px-2 py-1.5", children: _jsx(BedrockMemoryToggle, { applicationId: application.id, initialEnabled: application.bedrockEnabled }) })] })) : null, _jsx(DropdownMenuSeparator, {}), collaboration ? (_jsx(DropdownMenuItem, { asChild: true, children: _jsxs(Link, { href: `/application/${application.id}/supervisor`, className: "flex cursor-pointer items-center gap-2", children: [_jsx(ShieldCheck, { className: "size-4" }), "Configure supervisor"] }) })) : null, _jsx(OpenInControlCenterMenuItem, { applicationId: application.id }), _jsx(DeleteApplicationMenuItem, { applicationId: application.id, applicationName: application.name })] })] }));
}
function Divider() {
    return _jsx("span", { className: "bg-border/60 mx-1 h-5 w-px shrink-0" });
}
