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

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

class AdminUserRow extends StatelessWidget {
  const AdminUserRow({super.key, required this.user, required this.onTap});

  final AdminUser user;
  final VoidCallback onTap;

  @override
  Widget build(BuildContext context) {
    final fs = Theme.of(context).extension<FabledSwordTheme>()!;
    return ListTile(
      title: Text(
        user.username,
        style: TextStyle(
          color: fs.parchment,
          fontFamily: 'Fraunces',
          fontSize: 16,
        ),
      ),
      subtitle: Wrap(
        spacing: 6,
        children: [
          if (user.isAdmin) _Badge(label: 'admin', color: fs.bronze),
          if (user.autoApproveRequests)
            _Badge(label: 'auto-approve', color: fs.moss),
        ],
      ),
      trailing: Icon(LucideIcons.chevron_right, color: fs.ash),
      onTap: onTap,
    );
  }
}

class _Badge extends StatelessWidget {
  const _Badge({required this.label, required this.color});
  final String label;
  final Color color;

  @override
  Widget build(BuildContext context) {
    final fs = Theme.of(context).extension<FabledSwordTheme>()!;
    return Container(
      padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
      decoration: BoxDecoration(
        color: color,
        borderRadius: BorderRadius.circular(8),
      ),
      child: Text(
        label,
        style: TextStyle(color: fs.obsidian, fontSize: 11),
      ),
    );
  }
}
