import 'package:flutter/material.dart';
import 'package:flutter_lucide/flutter_lucide.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

import '../../cache/audio_cache_manager.dart';
import '../../theme/theme_extension.dart';

/// Small download glyph shown next to a track row when the track is
/// cached locally. FutureBuilder one-shot — track rows are short-lived
/// and cache state rarely changes mid-render.
class CachedIndicator extends ConsumerWidget {
  const CachedIndicator({required this.trackId, super.key});
  final String trackId;

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    final mgr = ref.read(audioCacheManagerProvider);
    final fs = Theme.of(context).extension<FabledSwordTheme>()!;
    return FutureBuilder<bool>(
      future: mgr.isCached(trackId),
      builder: (ctx, snap) {
        if (snap.data != true) return const SizedBox.shrink();
        return Padding(
          padding: const EdgeInsets.only(left: 4),
          child: Icon(LucideIcons.circle_check_big, size: 14, color: fs.accent),
        );
      },
    );
  }
}
