import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';

import '../../models/artist.dart';
import '../../theme/theme_extension.dart';

class ArtistCard extends StatelessWidget {
  const ArtistCard({required this.artist, required this.onTap, super.key});
  final ArtistRef artist;
  final VoidCallback onTap;

  @override
  Widget build(BuildContext context) {
    final fs = Theme.of(context).extension<FabledSwordTheme>()!;
    return GestureDetector(
      onTap: onTap,
      child: SizedBox(
        width: 140,
        child: Padding(
          padding: const EdgeInsets.symmetric(horizontal: 8),
          child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
            ClipOval(
              child: Container(
                width: 124,
                height: 124,
                color: fs.slate,
                child: artist.coverUrl.isEmpty
                    ? SvgPicture.asset('assets/svg/album-fallback.svg', fit: BoxFit.cover)
                    : Image.network(artist.coverUrl, fit: BoxFit.cover),
              ),
            ),
            const SizedBox(height: 8),
            Text(
              artist.name,
              maxLines: 1,
              overflow: TextOverflow.ellipsis,
              style: TextStyle(color: fs.parchment, fontSize: 14),
            ),
          ]),
        ),
      ),
    );
  }
}
