import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:tanami_app/features/contactAdmin/bloc/contact_admin_event.dart';
import 'package:tanami_app/features/contactAdmin/presentation/widgets/bottom_section.dart';

import '../../../../core/styles/app_color.dart';
import '../../../../core/styles/app_text.dart';
import '../../../../core/utils/language/localizations_delegate.dart';
import '../../../../shared/components/appbar_widget.dart';
import '../../bloc/contact_admin_bloc.dart';
import '../../bloc/contact_admin_state.dart';
import '../widgets/top_section.dart';

class ContactAdminScreen extends StatelessWidget {
  const ContactAdminScreen({super.key});

  @override
  Widget build(BuildContext context) {
    var localizations = AppLocalizations.of(context);

    return BlocProvider(
      create: (context) => ContactAdminBloc()..add(const FetchContactData()),
      child: Scaffold(
        backgroundColor: AppColor.plainWhite,
        appBar: AppBarWidget(
          height: 75,
          titleTxt: localizations.translate(AppText.contactAdminText),
        ),
        body: BlocBuilder<ContactAdminBloc, ContactAdminState>(
          builder: (context, state) {
            if (state is ContactAdminLoading) {
              return const Center(child: CircularProgressIndicator());
            } else if (state is ContactAdminLoaded) {
              return ListView(
                children: [
                  topSection(context),
                  bottomSection(context, state.contactAdminModel),
                ],
              );
            } else {
              return const Center(child: Text('Something went wrong!'));
            }
          },
        ),
      ),
    );
  }
}
