import 'package:flutter/material.dart';

import '../../../../core/contracts/danmaku.dart';
import 'danmaku_tokens.dart';


class DanmakuMatchTile extends StatelessWidget {
  const DanmakuMatchTile({
    super.key,
    required this.candidate,
    required this.selected,
    required this.onTap,
    this.trailing,
  });

  final DanmakuMatchCandidate candidate;
  final bool selected;
  final VoidCallback onTap;
  final Widget? trailing;

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: onTap,
      behavior: HitTestBehavior.opaque,
      child: Container(
        margin: const EdgeInsets.only(bottom: 4),
        padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 6),
        decoration: BoxDecoration(
          color: selected ? DanmakuTokens.selectedFill : Colors.transparent,
          borderRadius: BorderRadius.circular(DanmakuTokens.radius),
          border: selected
              ? Border.all(color: DanmakuTokens.accent.withValues(alpha: 0.5))
              : null,
        ),
        child: Row(
          children: [
            Icon(
              selected ? Icons.radio_button_checked : Icons.radio_button_off,
              size: 15,
              color: selected ? DanmakuTokens.accent : DanmakuTokens.textHint,
            ),
            const SizedBox(width: 8),
            Expanded(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    candidate.animeTitle,
                    style: TextStyle(
                      color: selected
                          ? DanmakuTokens.textPrimary
                          : DanmakuTokens.textSecondary,
                      fontSize: 12,
                      fontWeight: selected
                          ? FontWeight.w600
                          : FontWeight.normal,
                    ),
                    maxLines: 1,
                    overflow: TextOverflow.ellipsis,
                  ),
                  if (candidate.episodeTitle.isNotEmpty)
                    Text(
                      candidate.episodeTitle,
                      style: const TextStyle(
                        color: DanmakuTokens.textHint,
                        fontSize: 11,
                      ),
                      maxLines: 1,
                      overflow: TextOverflow.ellipsis,
                    ),
                  Text(
                    candidate.source.displayName,
                    style: const TextStyle(
                      color: DanmakuTokens.textFaint,
                      fontSize: 11,
                    ),
                    maxLines: 1,
                    overflow: TextOverflow.ellipsis,
                  ),
                ],
              ),
            ),
            if (trailing != null) ...[const SizedBox(width: 8), trailing!],
          ],
        ),
      ),
    );
  }
}
