import { Dispatch, FC, SetStateAction, useEffect, useState } from 'react'; import { Box, IconButton as MUIIconButton } from '@mui/material'; import { DesktopWindows as DesktopWindowsIcon, PowerOffOutlined as PowerOffOutlinedIcon, } from '@mui/icons-material'; import { BORDER_RADIUS, GREY } from '../../lib/consts/DEFAULT_THEME'; import IconButton from '../IconButton'; import { InnerPanel, InnerPanelHeader, Panel, PanelHeader } from '../Panels'; import { BodyText, HeaderText } from '../Text'; type PreviewOptionalProps = { isShowControls?: boolean; isUseInnerPanel?: boolean; setMode?: Dispatch> | null; }; type PreviewProps = PreviewOptionalProps & { uuid: string; serverName: string | string[] | undefined; }; const PREVIEW_DEFAULT_PROPS: Required = { isShowControls: true, isUseInnerPanel: false, setMode: null, }; const PreviewPanel: FC<{ isUseInnerPanel: boolean }> = ({ children, isUseInnerPanel, }) => isUseInnerPanel ? ( {children} ) : ( {children} ); const PreviewPanelHeader: FC<{ isUseInnerPanel: boolean; text: string }> = ({ children, isUseInnerPanel, text, }) => isUseInnerPanel ? ( {children} ) : ( {children} ); const Preview: FC = ({ isShowControls = PREVIEW_DEFAULT_PROPS.isShowControls, isUseInnerPanel = PREVIEW_DEFAULT_PROPS.isUseInnerPanel, serverName, setMode, uuid, }) => { const [preview, setPreview] = useState(); useEffect(() => { (async () => { try { const res = await fetch( `${process.env.NEXT_PUBLIC_API_URL}/get_server_screenshot?server_uuid=${uuid}`, { method: 'GET', headers: { 'Content-Type': 'application/json', }, }, ); const { screenshot } = await res.json(); setPreview(screenshot); } catch { setPreview(''); } })(); }, [uuid]); return ( :not(:last-child)': { marginRight: '1em', }, }} > setMode?.call(null, false)} sx={{ borderRadius: BORDER_RADIUS, color: GREY, padding: 0, }} > {preview ? ( ) : ( )} {isShowControls && ( setMode?.call(null, false)}> )} ); }; Preview.defaultProps = PREVIEW_DEFAULT_PROPS; export default Preview;