import { useEffect, type CSSProperties, type MouseEvent as ReactMouseEvent } from 'react';
import { RESIZE_BORDER } from '../chrome.ts';
import { chipFor } from '../updateModel.ts';
import { AccountSwitcher } from './AccountSwitcher.tsx';
import { AppMenu, AppMenuLogo } from './AppMenu.tsx';
import { invoke } from './bridge.ts';
import { useT, useUpdateStatus } from './hooks.ts';
import { tx } from './i18n.ts';
import { site } from './site.ts';
import { TitlebarExtras } from './TitlebarExtras.tsx';
import { close, minimize, os, startResize, systemMenu, toggleMaximize, type ResizeDirection } from './windowBinding.ts';
const isInteractive = (target: EventTarget | null) =>
target instanceof Element && !!target.closest('button, input, textarea, a, .dv-tab, [role="button"]');
/** Right-click on empty titlebar space: the native system menu (Restore, Move, Size, ...). */
export function titlebarContextMenu(event: ReactMouseEvent | MouseEvent) {
if (isInteractive(event.target)) return;
event.preventDefault();
const scale = window.devicePixelRatio || 1;
systemMenu(Math.round(event.screenX * scale), Math.round(event.screenY * scale));
}
/**
* The 44px titlebar row. It sits under the dockview root: the top groups' tab headers are
* transparent and let clicks through to the drag layer, the logo and the caption buttons. The logo
* is the app menu's second trigger (AppMenu.tsx); everything else that is empty drags the window.
*/
export function Titlebar({ maximized }: { maximized: boolean }) {
return
{/* One home for the app menu: the logo. Alt+F, F10, the palette and the account menu's last row open it there. */}
{os !== 'macos' && }
;
}
/** "Update ready ยท restart": appears only when a verified update is downloaded (or failed to start). */
function UpdateChip() {
const [status, apply] = useUpdateStatus();
const chip = chipFor(status, site().product, key => tx(key, undefined, '') || undefined);
// Widen the tab strip's right reserve while the chip is shown so tabs never sit under it.
useEffect(() => {
const root = document.documentElement;
if (chip) root.dataset.update = chip.kind; else delete root.dataset.update;
return () => { delete root.dataset.update; };
}, [chip?.kind]);
if (!chip) return null;
if (chip.kind === 'problem') {
return ;
}
return ;
}
function WindowControls({ maximized }: { maximized: boolean }) {
const t = useT();
return