import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:krow/core/entity/staff_contact_entity.dart';
import 'package:krow/core/presentation/widgets/assigned_staff_item_widget.dart';
import 'package:krow/core/presentation/widgets/ui_kit/kw_app_bar.dart';
import 'package:krow/features/assigned_staff_screen/domain/assigned_staff_bloc.dart';

@RoutePage()
class AssignedStaffScreen extends StatelessWidget implements AutoRouteWrapper {
  final List<StaffContact> staffContacts;

  final String department;

  const AssignedStaffScreen(
      {super.key, required this.staffContacts, required this.department});

  @override
  Widget wrappedRoute(BuildContext context) {
    return BlocProvider(
        create: (context) => AssignedStaffBloc(
            staffContacts: staffContacts, department: department),
        child: this);
  }

  @override
  Widget build(BuildContext context) {
    return BlocBuilder<AssignedStaffBloc, AssignedStaffState>(
      builder: (context, state) {
        return Scaffold(
          appBar: KwAppBar(
            titleText: 'Assigned Staff',
          ),
          body: ListView.builder(
            padding: const EdgeInsets.all(16),
            itemCount: staffContacts.length,
            itemBuilder: (context, index) {
              return AssignedStaffItemWidget(
                  staffContact: staffContacts[index], department: department);
            },
          ),
        );
      },
    );
  }
}
