import 'package:flutter/material.dart';

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

class AdminRequestRow extends StatelessWidget {
  const AdminRequestRow({
    super.key,
    required this.request,
    required this.requesterDisplay,
    required this.onApprove,
    required this.onReject,
  });

  final AdminRequest request;

  /// Pre-resolved username (or UUID-prefix fallback) for the requester.
  final String requesterDisplay;

  final VoidCallback onApprove;
  final VoidCallback onReject;

  @override
  Widget build(BuildContext context) {
    final fs = Theme.of(context).extension<FabledSwordTheme>()!;
    final subtitle =
        '${request.kind} · ${request.artistName} · requested by $requesterDisplay';
    return ListTile(
      title: Text(
        request.displayName,
        style: TextStyle(
          color: fs.parchment,
          fontFamily: 'Fraunces',
          fontSize: 16,
        ),
      ),
      subtitle: Text(subtitle, style: TextStyle(color: fs.ash)),
      trailing: Row(
        mainAxisSize: MainAxisSize.min,
        children: [
          TextButton(
            onPressed: onApprove,
            style: TextButton.styleFrom(foregroundColor: fs.moss),
            child: const Text('Approve'),
          ),
          TextButton(
            onPressed: () async {
              final ok = await showDialog<bool>(
                context: context,
                builder: (ctx) => AlertDialog(
                  title: const Text('Reject request?'),
                  content: Text('Reject "${request.displayName}"?'),
                  actions: [
                    TextButton(
                      onPressed: () => Navigator.pop(ctx, false),
                      child: const Text('Cancel'),
                    ),
                    TextButton(
                      onPressed: () => Navigator.pop(ctx, true),
                      style: TextButton.styleFrom(foregroundColor: fs.oxblood),
                      child: const Text('Reject'),
                    ),
                  ],
                ),
              );
              if (ok == true) onReject();
            },
            style: TextButton.styleFrom(foregroundColor: fs.oxblood),
            child: const Text('Reject'),
          ),
        ],
      ),
    );
  }
}
