/**
 * @license
 * Copyright 2025 Google LLC
 * SPDX-License-Identifier: Apache-2.0
 */

import React from 'react';
import { Box, Text } from 'ink';
import Spinner from 'ink-spinner';
import { Colors } from '../colors.js';

interface LoadingIndicatorProps {
  isLoading: boolean;
  currentLoadingPhrase: string;
  elapsedTime: number;
}

export const LoadingIndicator: React.FC<LoadingIndicatorProps> = ({
  isLoading,
  currentLoadingPhrase,
  elapsedTime,
}) => {
  if (!isLoading) {
    return null; // Don't render anything if not loading
  }

  return (
    <Box marginTop={1} paddingLeft={0}>
      <Box marginRight={1}>
        <Spinner type="dots" />
      </Box>
      <Text color={Colors.AccentPurple}>
        {currentLoadingPhrase} ({elapsedTime}s)
      </Text>
      <Box flexGrow={1}>{/* Spacer */}</Box>
      <Text color={Colors.SubtleComment}>(ESC to cancel)</Text>
    </Box>
  );
};
