import 'package:flutter/material.dart';
import '../../../../../core/services/it_support_service.dart';
import '../it_support_widgets.dart';

class ITSupportTeamPage extends StatelessWidget {
  const ITSupportTeamPage({super.key, required this.members, required this.manager,
    required this.more, required this.onRefresh, required this.onLoadMore, required this.onRole});
  final List<SupportJson> members;
  final bool manager, more;
  final Future<void> Function() onRefresh;
  final VoidCallback onLoadMore;
  final ValueChanged<SupportJson> onRole;

  @override
  Widget build(BuildContext context) => RefreshIndicator(onRefresh: onRefresh,
    child: ListView.builder(physics: const AlwaysScrollableScrollPhysics(),
      padding: const EdgeInsets.fromLTRB(16, 4, 16, 85), itemCount: members.length + 1,
      itemBuilder: (context, index) {
        if (index == members.length) return Padding(padding: const EdgeInsets.all(24), child: Center(child: more
          ? TextButton(onPressed: onLoadMore, child: const Text('Load more'))
          : Text(members.isEmpty ? 'No team members found.' : '${members.length} team members loaded',
            textAlign: TextAlign.center, style: const TextStyle(color: Color(0xFF7A887F), fontSize: 12))));
        final member = members[index];
        return Padding(padding: const EdgeInsets.only(bottom: 7), child: Container(color: Colors.white,
          child: ListTile(leading: Container(width: 36, height: 36, color: const Color(0xFFEAF3EE),
            child: const Icon(Icons.person_outline, color: supportGreen, size: 20)),
            title: Text('${member['name']}', style: const TextStyle(color: supportInk, fontWeight: FontWeight.w700)),
            subtitle: Text('${member['email']}', maxLines: 1, overflow: TextOverflow.ellipsis),
            trailing: manager ? TextButton(onPressed: () => onRole(member), child: Text(supportLabel(member['role'])))
              : SupportBadge(supportLabel(member['role'])))));
      }));
}
