import React from 'react';
import {ArrowDownToLine} from '@gravity-ui/icons';
import {ActionTooltip, Button, Icon} from '@gravity-ui/uikit';
import {DrawerWrapper} from '../../../../components/Drawer';
import type {DrawerControl} from '../../../../components/Drawer';
import {EnableFullscreenButton} from '../../../../components/EnableFullscreenButton/EnableFullscreenButton';
import type {SelfCheckResult} from '../../../../types/api/healthcheck';
import {uiFactory} from '../../../../uiFactory/uiFactory';
import {createAndDownloadJsonFile} from '../../../../utils/downloadFile';
import type {HealthcheckAssistantTarget} from '../types';
import {HealthcheckDrawerTitle} from './HealthcheckDrawerTitle';
interface HealthcheckDrawerProps {
target?: HealthcheckAssistantTarget;
children: React.ReactNode;
isDrawerVisible: boolean;
onCloseDrawer: () => void;
onTransitionInComplete?: () => void;
renderDrawerContent: () => React.ReactNode;
drawerId: string;
storageKey: string;
title: React.ReactNode;
status?: SelfCheckResult;
healthcheckData: unknown;
downloadFilePrefix: string;
downloadTooltip: string;
isDownloadDisabled?: boolean;
}
export function HealthcheckDrawer({
target,
children,
isDrawerVisible,
onCloseDrawer,
onTransitionInComplete,
renderDrawerContent,
drawerId,
storageKey,
title,
status,
healthcheckData,
downloadFilePrefix,
downloadTooltip,
isDownloadDisabled,
}: HealthcheckDrawerProps) {
const renderDrawerExtension = uiFactory.healthcheck.renderDrawerExtension;
const renderContentWithExtension = React.useCallback(() => {
if (!renderDrawerExtension) {
return renderDrawerContent();
}
return (
{renderDrawerExtension({target})}
{renderDrawerContent()}
);
}, [renderDrawerContent, renderDrawerExtension, target]);
const handleDownload = React.useCallback(
(event: React.MouseEvent) => {
event.stopPropagation();
createAndDownloadJsonFile(
healthcheckData,
`${downloadFilePrefix}-${new Date().getTime()}`,
);
},
[downloadFilePrefix, healthcheckData],
);
const drawerControls = React.useMemo(
() => [
{
type: 'custom',
key: 'download',
node: (
),
},
{
type: 'custom',
node: ,
key: 'fullscreen',
},
{type: 'close'},
],
[downloadTooltip, handleDownload, isDownloadDisabled],
);
return (
}
>
{children}
);
}