import 'package:cpt_rewards/modules/rewards_successful/rewards_successful_page.dart';
import 'package:cs_resources/generated/assets.dart';
import 'package:cs_resources/generated/l10n.dart';
import 'package:cs_resources/theme/app_colors_theme.dart';
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:shared/utils/color_utils.dart';
import 'package:widgets/ext/ex_widget.dart';
import 'package:widgets/my_load_image.dart';
import 'package:widgets/my_text_view.dart';
import 'package:widgets/widget_export.dart';
import '../rewards_list_vm.dart';

class RewardsListfilterAllDialo extends HookConsumerWidget {
  VoidCallback confirmAction;

  RewardsListfilterAllDialo({
    required this.confirmAction,
  });

  Widget CheckboxList(BuildContext context, ref, _vm) {
    final state = ref.watch(rewardsListVmProvider);
    List itemsList = state.categoryList;
    return Column(
      children: [
        Column(
            children: List.generate(
          itemsList.length,
          (index) {
            return Container(
                height: 45,
                decoration: BoxDecoration(
                    border: Border(
                        bottom: BorderSide(
                  width: 1.0, // 底边边框的宽度
                  color: ColorUtils.string2Color('#F2F3F6'), // 底边边框的颜色
                ))),
                child: Row(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Row(
                      children: [
                        Text(
                          itemsList[index]['name'],
                          style: TextStyle(
                              fontSize: 16.0,
                              color: itemsList[index]['id'] == state.category_id
                                  ? ColorUtils.string2Color('#FF5E75')
                                  : ColorUtils.string2Color('#000000'),
                              fontWeight: FontWeight.w400),
                        ),
                      ],
                    ),
                    itemsList[index]['id'] == state.category_id
                        ? const MyAssetImage(
                            Assets.rewardsRewardListChoose,
                            width: 17,
                            height: 17,
                          )
                        : Container()
                  ],
                )).onTap(() {
              _vm.categoryClick(itemsList[index]);
              onCancel();
            });
          },
        )).paddingOnly(left: 15, right: 15),
      ],
    );
  }

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    final _vm = ref.read(rewardsListVmProvider.notifier);

    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      mainAxisAlignment: MainAxisAlignment.start,
      children: [
        Container(
          transform: Matrix4.translationValues(0.0, 160.0, 0.0),
          width: double.infinity,
          padding: const EdgeInsets.only(top: 12, bottom: 15),
          decoration: BoxDecoration(
            color: context.appColors.whiteSecondBG,
            boxShadow: const [
              BoxShadow(
                  color: Color.fromRGBO(184, 191, 217, 0.3), blurRadius: 6)
            ],
          ),
          child: Column(
            children: [
              Container(child: CheckboxList(context, ref, _vm)),
            ],
          ),
        ),
      ],
    );
  }

//取消弹框
  void onCancel() async {
    SmartDialog.dismiss();
  }
}
