import 'package:flutter/material.dart';
import 'package:on_field_work/helpers/widgets/avatar.dart';
import 'package:on_field_work/helpers/widgets/my_text.dart';
import 'package:on_field_work/helpers/widgets/my_spacing.dart';
import 'package:on_field_work/helpers/utils/base_bottom_sheet.dart';

class TeamBottomSheet {
  static void show({
    required BuildContext context,
    required List<dynamic> teamMembers,
  }) {
    showModalBottomSheet(
      context: context,
      isScrollControlled: true,
      backgroundColor: Colors.transparent,
      builder: (_) {
        return BaseBottomSheet(
          title: 'Team Members',
          onCancel: () => Navigator.pop(context),
          onSubmit: () {}, 
          showButtons: false, 
          child: _TeamMemberList(teamMembers: teamMembers),
        );
      },
    );
  }
}

class _TeamMemberList extends StatelessWidget {
  final List<dynamic> teamMembers;

  const _TeamMemberList({required this.teamMembers});

  @override
  Widget build(BuildContext context) {
    if (teamMembers.isEmpty) {
      return Center(
        child: Padding(
          padding: const EdgeInsets.symmetric(vertical: 20),
          child: MyText.bodySmall(
            "No team members found.",
            fontWeight: 600,
            color: Colors.grey,
          ),
        ),
      );
    }

    return ListView.separated(
      shrinkWrap: true,
      physics: const NeverScrollableScrollPhysics(),
      itemCount: teamMembers.length,
      separatorBuilder: (_, __) => const Divider(thickness: 0.8, height: 12),
      itemBuilder: (_, index) {
        final member = teamMembers[index];
        final String name = member.firstName ?? 'Unnamed';

        return Padding(
          padding: const EdgeInsets.symmetric(vertical: 4),
          child: Row(
            children: [
              Avatar(firstName: member.firstName, lastName: '', size: 36),
              MySpacing.width(10),
              MyText.bodyMedium(name, fontWeight: 500),
            ],
          ),
        );
      },
    );
  }
}
