/*
* SPDX-FileCopyrightText: 2021-2024 The Refinery Authors
*
* SPDX-License-Identifier: EPL-2.0
*/
import type { Diagnostic } from '@codemirror/lint';
import CancelIcon from '@mui/icons-material/Cancel';
import CheckIcon from '@mui/icons-material/Check';
import FileOpenIcon from '@mui/icons-material/FileOpen';
import FormatListNumberedIcon from '@mui/icons-material/FormatListNumbered';
import FormatPaintIcon from '@mui/icons-material/FormatPaint';
import InfoOutlinedIcon from '@mui/icons-material/InfoOutlined';
import LooksIcon from '@mui/icons-material/Looks';
import RedoIcon from '@mui/icons-material/Redo';
import SaveIcon from '@mui/icons-material/Save';
import SaveAsIcon from '@mui/icons-material/SaveAs';
import SearchIcon from '@mui/icons-material/Search';
import UndoIcon from '@mui/icons-material/Undo';
import WarningIcon from '@mui/icons-material/Warning';
import IconButton from '@mui/material/IconButton';
import Stack from '@mui/material/Stack';
import ToggleButton from '@mui/material/ToggleButton';
import ToggleButtonGroup from '@mui/material/ToggleButtonGroup';
import Tooltip from '@mui/material/Tooltip';
import { observer } from 'mobx-react-lite';
import ConnectButton from './ConnectButton';
import type EditorStore from './EditorStore';
// Exhastive switch as proven by TypeScript.
// eslint-disable-next-line consistent-return
function getLintIcon(severity: Diagnostic['severity'] | undefined) {
switch (severity) {
case 'error':
return ;
case 'warning':
return ;
case 'info':
return ;
default:
return ;
}
}
export default observer(function EditorButtons({
editorStore,
}: {
editorStore: EditorStore | undefined;
}): JSX.Element {
return (
editorStore?.openFile()}
color="inherit"
>
editorStore?.saveFile()}
color="inherit"
>
{'showSaveFilePicker' in window && (
editorStore?.saveFileAs()}
color="inherit"
>
)}
editorStore?.undo()}
color="inherit"
sx={{ ml: 1 }}
>
editorStore?.redo()}
color="inherit"
>
editorStore?.toggleLineNumbers()}
value="show-line-numbers"
>
editorStore?.toggleColorIdentifiers()}
value="color-identifiers"
>
editorStore?.searchPanel?.toggle()}
{...(editorStore !== undefined &&
editorStore.searchPanel.state && {
'aria-controls': editorStore.searchPanel.id,
})}
value="show-search-panel"
>
editorStore?.lintPanel.toggle()}
{...(editorStore !== undefined &&
editorStore.lintPanel.state && {
'aria-controls': editorStore.lintPanel.id,
})}
value="show-lint-panel"
>
{getLintIcon(editorStore?.delayedErrors?.highestDiagnosticLevel)}
editorStore?.formatText()}
color="inherit"
>
);
});