import 'package:flutter/material.dart';

import '../../domain/media_link.dart';

/// Brand colors for each social platform. Hardcoded on purpose — these are
/// the official platform brand colors, not theme tokens, so they remain
/// recognisable regardless of the app's color scheme.
const Map<SocialPlatform, Color> _platformAccent = <SocialPlatform, Color>{
  SocialPlatform.instagram: Color(0xFFE1306C),
  SocialPlatform.youtube: Color(0xFFFF0000),
  SocialPlatform.twitter: Color(0xFF1DA1F2),
  SocialPlatform.tiktok: Color(0xFF69C9D0),
};

const Map<SocialPlatform, IconData> _platformIcon = <SocialPlatform, IconData>{
  SocialPlatform.instagram: Icons.photo_camera,
  SocialPlatform.youtube: Icons.play_circle_filled,
  SocialPlatform.twitter: Icons.tag,
  SocialPlatform.tiktok: Icons.music_note,
};

/// Wide tappable card for a single social platform. Shows a brand-colored
/// icon leading, the platform name + handle as the title/subtitle, and a
/// trailing chevron. Tapping surfaces an "Opening …" snackbar — actual URL
/// launching will be wired up once `url_launcher` is added to pubspec.
class SocialLinkCard extends StatelessWidget {
  const SocialLinkCard({super.key, required this.link});

  final MediaLink link;

  @override
  Widget build(BuildContext context) {
    final theme = Theme.of(context);
    final scheme = theme.colorScheme;
    final accent = _platformAccent[link.platform] ?? scheme.primary;
    final icon = _platformIcon[link.platform] ?? Icons.public;

    return Card(
      clipBehavior: Clip.antiAlias,
      child: ListTile(
        onTap: () => _handleTap(context),
        leading: Container(
          width: 44,
          height: 44,
          alignment: Alignment.center,
          decoration: BoxDecoration(
            color: accent.withValues(alpha: 0.15),
            shape: BoxShape.circle,
          ),
          child: Icon(icon, color: accent, size: 24),
        ),
        title: Text(
          link.displayName,
          style: theme.textTheme.titleMedium?.copyWith(
            fontWeight: FontWeight.w700,
          ),
        ),
        subtitle: Text(
          link.handle,
          style: theme.textTheme.bodyMedium?.copyWith(
            color: scheme.onSurfaceVariant,
          ),
        ),
        trailing: Icon(
          Icons.chevron_right,
          color: scheme.onSurfaceVariant,
        ),
      ),
    );
  }

  void _handleTap(BuildContext context) {
    ScaffoldMessenger.of(context)
      ..hideCurrentSnackBar()
      ..showSnackBar(
        SnackBar(
          content: Text('Opening ${link.displayName}...'),
          duration: const Duration(seconds: 2),
        ),
      );
  }
}
