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

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

/// Same dimensions as PlaylistCard so the home Playlists row keeps
/// visual rhythm whether real or placeholder. Mirrors the web
/// PlaylistPlaceholderCard. Variant decides the state copy below
/// the label.
class PlaylistPlaceholderCard extends StatelessWidget {
  const PlaylistPlaceholderCard({
    super.key,
    required this.label,
    required this.variant,
  });

  /// "For You" or "Songs like…" — what the slot is reserved for.
  final String label;

  /// One of: 'building' | 'failed' | 'pending' | 'seed-needed'.
  final String variant;

  @override
  Widget build(BuildContext context) {
    final fs = Theme.of(context).extension<FabledSwordTheme>()!;
    return SizedBox(
      width: 176,
      child: Padding(
        padding: const EdgeInsets.symmetric(horizontal: 8),
        child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
          Container(
            width: 144,
            height: 144,
            decoration: BoxDecoration(
              color: fs.iron,
              borderRadius: BorderRadius.circular(6),
              border: Border.all(color: fs.slate, width: 1),
            ),
            child: Center(child: _stateIcon(fs)),
          ),
          const SizedBox(height: 8),
          Text(
            label,
            maxLines: 1,
            overflow: TextOverflow.ellipsis,
            style: TextStyle(color: fs.parchment, fontSize: 14),
          ),
          Padding(
            padding: const EdgeInsets.only(top: 2),
            child: Text(
              _stateText(),
              style: TextStyle(color: fs.ash, fontSize: 11),
            ),
          ),
        ]),
      ),
    );
  }

  Widget _stateIcon(FabledSwordTheme fs) {
    switch (variant) {
      case 'building':
        return SizedBox(
          width: 28,
          height: 28,
          child: CircularProgressIndicator(strokeWidth: 2, color: fs.accent),
        );
      case 'failed':
        return Icon(LucideIcons.triangle_alert, color: fs.error, size: 32);
      default:
        return Icon(LucideIcons.list_music, color: fs.ash, size: 40);
    }
  }

  String _stateText() {
    switch (variant) {
      case 'building':
        return 'Building…';
      case 'failed':
        return "Couldn't generate";
      case 'seed-needed':
        return 'Like more music';
      default:
        return 'Coming soon';
    }
  }
}
