import { Ionicons } from '@expo/vector-icons';
import React, { useEffect, useState } from 'react';
import { StyleSheet } from 'react-native';
import HealthDataService from '../../services/healthData';
import HealthDataCard from './HealthDataCard';

interface HeartRateCardProps {
  resetToken: number;
  style?: object;
}

const HeartRateCard: React.FC<HeartRateCardProps> = ({
  resetToken,
  style
}) => {
  const [heartRate, setHeartRate] = useState<number | null>(null);

  useEffect(() => {
    const fetchHeartRate = async () => {
      const data = await HealthDataService.getHeartRate();
      setHeartRate(data);
    };

    fetchHeartRate();
  }, [resetToken]);

  const heartIcon = (
    <Ionicons name="heart" size={24} color="#EF4444" />
  );

  return (
    <HealthDataCard
      title="心率"
      value={heartRate !== null ? heartRate.toString() : '--'}
      unit="bpm"
      icon={heartIcon}
      style={style}
    />
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
});

export default HeartRateCard;