import React from 'react';
import { useTranslation } from 'react-i18next';
import { HeaderGlobalAction } from '@carbon/react';
import { useConfig, launchWorkspace } from '@openmrs/esm-framework';
import { ConfigObject } from './config-schema';
import starsIcon from './assets/stars.png';

export interface AiAnalysisActionButtonProps {
  patientUuid: string;
}

const AiAnalysisActionButton: React.FC<AiAnalysisActionButtonProps> = ({ patientUuid }) => {
  const { t } = useTranslation();
  const { enabled } = useConfig<ConfigObject>();

  const handleLaunchWorkspace = () => {
    launchWorkspace('ai-analysis-workspace', {
      workspaceTitle: t('aiAnalysis', 'AI Analysis'),
    });
  };

  if (!enabled) {
    return null;
  }

  return (
    <HeaderGlobalAction
      aria-label={t('aiAnalysis', 'AI Analysis')}
      onClick={handleLaunchWorkspace}
    >
      <img 
        src={starsIcon} 
        alt="AI Analysis" 
        style={{ 
          width: '20px', 
          height: '20px',
          filter: 'brightness(0) invert(1)' // Make it white for the header
        }} 
      />
    </HeaderGlobalAction>
  );
};

export default AiAnalysisActionButton; 