import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
/*
 * Copyright (c) 2023-2025 Datalayer, Inc.
 * Distributed under the terms of the Modified BSD License.
 */
import { useState, useEffect } from 'react';
import { Box } from '@datalayer/primer-addons';
import { useNavigate } from '../../hooks/useNavigate.js';
import { ConsumptionBar } from './ConsumptionBar.js';
/**
 * Credits indicator component.
 */
export function CreditsIndicator(props) {
    const { serviceManager, kernelId, navigateTo, onClick, onUpdate } = props;
    const navigate = useNavigate();
    const [model, setModel] = useState();
    useEffect(() => {
        serviceManager.runtimesManager.findById(kernelId).then(model => {
            setModel(model);
        });
    }, [kernelId, serviceManager]);
    return model ? (_jsx(Box, { display: "flex", style: { alignItems: 'center' }, children: _jsx(ConsumptionBar, { startedAt: parseFloat(model.started_at), expiredAt: model.expired_at ? parseFloat(model.expired_at) : undefined, burningRate: model.burning_rate, onClick: onClick ?? (navigateTo ? () => navigate(navigateTo) : undefined), onUpdate: onUpdate, style: { cursor: 'pointer' } }) })) : (_jsx(_Fragment, {}));
}
