
import 'package:cpt_services/components/chooseVisitTimeBottomFooter_vm.dart';
import 'package:cpt_services/components/chooseVisitTimeContent_vm.dart';
import 'package:cpt_services/components/status_card_item.dart';
import 'package:cs_resources/generated/l10n.dart';
import 'package:cs_resources/theme/app_colors_theme.dart';
import 'package:flutter/material.dart';
import 'package:auto_route/auto_route.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:shared/utils/log_utils.dart';
import 'package:widgets/ext/ex_widget.dart';
import 'package:widgets/my_text_view.dart';
import 'package:widgets/utils/dark_theme_util.dart';
import 'package:widgets/widget_export.dart';
import 'package:widgets/my_cart_num.dart';

import '../modules/services/service_order_confirm/service_order_confirm_vm.dart';

class ChooseVisitTimeBottomFooter extends HookConsumerWidget {
  final int id;
  final int? cleanServiceTypeId;

  const ChooseVisitTimeBottomFooter({Key? key,required this.id, this.cleanServiceTypeId}) : super(key: key);

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    final vm = ref.read(chooseVisitTimeBottomFooterVmProvider.notifier);
    final state = ref.watch(chooseVisitTimeBottomFooterVmProvider);

    num cleanServiceToast = ref.watch(serviceOrderConfirmVmProvider.select((state) => state.cleanServiceToTalCost??0.0));

    num extraPrice = ref.watch(chooseVisitTimeContentVmProvider.select((state) => state.extraTotalCost??0.0));

    num totalPrice = cleanServiceToast + extraPrice;



    useEffect((){
      // 组件挂载时执行 - 执行接口请求
      // Future.microtask(() => vm.initPageData());
      return () {
        // 组件卸载时执行
      };
    },[]);

    return Container(
      height: 50,
      width: double.infinity,
      child: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        mainAxisSize: MainAxisSize.max,
        children: [
          Container(
            constraints: const BoxConstraints(
              minWidth: 122,
            ),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.center,
              mainAxisSize: MainAxisSize.max,
              children: [
                Container(
                  alignment: Alignment.center,
                  padding: const EdgeInsets.only(left:5, right: 0,top:5,bottom: 5),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    mainAxisSize: MainAxisSize.max,
                    children: [
                      MyTextView(
                        "\$$totalPrice",
                        fontSize: 18,
                        textColor: DarkThemeUtil.multiColors(context, context.appColors.textWhite, darkColor: Colors.white),
                        isFontRegular: true,
                        maxLines:2,
                        isTextEllipsis: true,
                        marginLeft: 5,
                        marginRight: 15,
                      ),
                    ],
                  ),
                ),
              ],
            ).backgroundColor(DarkThemeUtil.multiColors(context, AppColorsTheme.colorPrimary, darkColor: AppColorsTheme.colorPrimary)),
          ),
          Expanded(
            child: Container(
              color: DarkThemeUtil.multiColors(context, context.appColors.redDefault, darkColor: context.appColors.redDefault),
              child: Center(
                child: MyTextView(
                 S.current.confirm,
                  textColor: DarkThemeUtil.multiColors(context, context.appColors.textWhite, darkColor: Colors.white),
                  fontSize: 17,
                  isFontMedium: true,
                  textAlign: TextAlign.center,
                ),
              ),
            ).onTap((){
              vm.handlerClickVisitTimeConfirm(context, id: id , cleanServiceTypeId: cleanServiceTypeId);
            }),
          ),
        ],
      ),
    );
  }
}
