import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
/*
 * Copyright (c) 2023-2025 Datalayer, Inc.
 * Distributed under the terms of the Modified BSD License.
 */
import { NotebookCommandIds } from '@datalayer/jupyter-react';
import { Button } from '@primer/react';
import { PlayIcon, StopIcon } from '@primer/octicons-react';
import { useEffect, useState } from 'react';
/**
 * Notebook editor toolbar
 */
export function NotebookEditorToolbar(props) {
    const { commandRegistry, runtimeDesc, sessionConnection } = props;
    const [kernelStatus, setKernelStatus] = useState();
    useEffect(() => {
        const onStatusChanged = () => {
            setKernelStatus(sessionConnection?.kernel?.status);
        };
        onStatusChanged();
        sessionConnection?.statusChanged.connect(onStatusChanged);
        sessionConnection?.connectionStatusChanged.connect(onStatusChanged);
        return () => {
            sessionConnection?.statusChanged.disconnect(onStatusChanged);
            sessionConnection?.connectionStatusChanged.disconnect(onStatusChanged);
        };
    }, [sessionConnection]);
    return (_jsxs(_Fragment, { children: [_jsx(Button, { variant: "invisible", size: "small", leadingVisual: PlayIcon, disabled: !runtimeDesc?.location || kernelStatus === 'busy', onClick: (e) => commandRegistry?.execute(NotebookCommandIds.runAll), children: "Run all" }), _jsx(Button, { variant: "invisible", size: "small", leadingVisual: StopIcon, disabled: !runtimeDesc?.location || kernelStatus !== 'busy', onClick: (e) => commandRegistry?.execute(NotebookCommandIds.interrupt), children: "Interrupt" })] }));
}
export default NotebookEditorToolbar;
