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

import 'package:minstrel/models/playlist.dart';
import 'package:minstrel/playlists/widgets/playlist_card.dart';
import 'package:minstrel/theme/theme_data.dart';

const _userPlaylist = Playlist(
  id: 'p1',
  userId: 'u1',
  name: 'Road trip',
  description: '',
  isPublic: false,
  systemVariant: null,
  trackCount: 12,
  coverUrl: '',
  ownerUsername: 'alice',
  createdAt: '2026-05-01T00:00:00Z',
  updatedAt: '2026-05-01T00:00:00Z',
);

const _forYou = Playlist(
  id: 'p2',
  userId: 'u1',
  name: 'For You',
  description: '',
  isPublic: false,
  systemVariant: 'for_you',
  trackCount: 75,
  coverUrl: '',
  ownerUsername: 'alice',
  createdAt: '2026-05-01T00:00:00Z',
  updatedAt: '2026-05-01T00:00:00Z',
);

void main() {
  testWidgets('renders name and no badge for user playlist', (tester) async {
    await tester.pumpWidget(ProviderScope(
        child: MaterialApp(
      theme: buildThemeData(),
      home: const Scaffold(
        body: PlaylistCard(playlist: _userPlaylist),
      ),
    )));
    expect(find.text('Road trip'), findsOneWidget);
    expect(find.text('for you'), findsNothing);
  });

  testWidgets('renders system badge for system playlist', (tester) async {
    await tester.pumpWidget(ProviderScope(
        child: MaterialApp(
      theme: buildThemeData(),
      home: const Scaffold(
        body: PlaylistCard(playlist: _forYou),
      ),
    )));
    expect(find.text('For You'), findsOneWidget);
    expect(find.text('for you'), findsOneWidget);
  });

  testWidgets('shows refresh kebab on system playlists', (tester) async {
    await tester.pumpWidget(ProviderScope(
        child: MaterialApp(
      theme: buildThemeData(),
      home: const Scaffold(
        body: PlaylistCard(playlist: _forYou),
      ),
    )));
    expect(find.byIcon(LucideIcons.ellipsis_vertical), findsOneWidget);
  });

  testWidgets('no refresh kebab on user playlists', (tester) async {
    await tester.pumpWidget(ProviderScope(
        child: MaterialApp(
      theme: buildThemeData(),
      home: const Scaffold(
        body: PlaylistCard(playlist: _userPlaylist),
      ),
    )));
    expect(find.byIcon(LucideIcons.ellipsis_vertical), findsNothing);
  });
}
