import '../../../../../../food_delivery_client.dart';

class WBrowseBody extends StatefulWidget {
  const WBrowseBody({super.key});

  @override
  State<WBrowseBody> createState() => _WBrowseBodyState();
}

class _WBrowseBodyState extends State<WBrowseBody> {
  late FocusNode _focusNode;
  late TextEditingController _controller;

  @override
  void initState() {
    _controller = TextEditingController();
    _focusNode = FocusNode();
    _focusNode.addListener(() {
      context.read<BrowseBloc>().add(BrowseEvent.focusChanged(true));
    });
    super.initState();
  }

  void listener() {
    _focusNode.addListener(() {
      log("${_focusNode.hasFocus}");
      setState(() {});
    });
  }

  @override
  void dispose() {
    _controller.dispose();
    _focusNode.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return BlocBuilder<BrowseBloc, BrowseState>(
      builder: (context, state) {
        return Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            DecoratedBox(
              decoration: BoxDecoration(color: AppColors.cFFFFFF),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  10.verticalSpace,
                  Row(
                    spacing: 15,
                    children: [
/*
                      InkWell(
                        onTap: () {},
                        borderRadius: AppUtils.kBorderRadius25,
                        child: Ink(
                          height: 44,
                          width: 44,
                          decoration: BoxDecoration(
                            color: AppColors.cEEEEEE,
                            borderRadius: AppUtils.kBorderRadius25,
                          ),
                          child: SizedBox(
                            height: 44,
                            width: 44,
                            child: SvgPicture.asset(
                              AppIcons.icBack,
                              height: 20,
                              width: 20,
                            ).paddingAll(10),
                          ),
                        ),
                      ),
*/
                      Expanded(
                        child: AppTextFormField(
                          focusNode: _focusNode,
                          controller: _controller,
                          prefixIcon: SvgPicture.asset(AppIcons.icSearch),
                          hintText: context.loc.categoriesShort,
                          hintTextStyle: AppTextStyles.size16Medium.copyWith(
                            color: AppColors.c660000,
                          ),
                        ),
                      ),
                    ],
                  ),
                  15.verticalSpace,
                ],
              ),
            ),
            Expanded(
              child: RefreshIndicator.adaptive(
                onRefresh: () async {
                  context.read<BrowseBloc>()
                    ..add(BrowseEvent.getTopCategories())
                    ..add(BrowseEvent.getAllCategories());
                },
                child: SingleChildScrollView(
                  child: Column(
                    children: [
                      WTopCategories(),
                      WAllCategories(),
                      40.verticalSpace,
                    ],
                  ),
                ),
              ),
            ),
          ],
        );
      },
    ).paddingSymmetric(horizontal: 16);
  }
}
