import 'dart:math';

import 'package:auto_route/src/route/page_route_info.dart';
import 'package:cpt_services/components/chooseVisitTimeBottomFooter.dart';
import 'package:cpt_services/modules/services/clean_order_detail/clean_order_detail_vm.dart';
import 'package:cpt_services/modules/services/service_repair_detail/service_repair_detail_vm.dart';
import 'package:cs_resources/generated/assets.dart';
import 'package:cs_resources/theme/app_colors_theme.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:plugin_platform/engine/toast/toast_engine.dart';
import 'package:shared/utils/color_utils.dart';
import 'package:shared/utils/util.dart';
import 'package:widgets/ext/ex_widget.dart';
import 'package:widgets/my_button.dart';
import 'package:widgets/my_load_image.dart';
import 'package:widgets/my_text_view.dart';
import 'package:widgets/utils/dark_theme_util.dart';

class GetQuoteDialogContent extends HookConsumerWidget {

  const GetQuoteDialogContent({
    Key? key,
  }) : super(key: key);

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

    return Container(
      width: double.infinity,
      child: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          MyTextView(
            "Please fill in your remarks information",
            fontSize: 17,
            isFontBold: true,
          ),
          Container(
            height: 175,
            child: _buildTextAreaLayout(context, vm, ref, 'userNotes'),
          ),
        ],
      ),
    );
  }

  /// 多行输入框
  Widget _buildTextAreaLayout(BuildContext context, CleanOrderDetailVm vm, WidgetRef ref, String key) {
    final state = ref.watch(serviceRepairDetailVmProvider);
    final repairDetailVm = ref.read(serviceRepairDetailVmProvider.notifier);
    final noteCount = useState(0);
    return Stack(children: [
      Container(
        color: DarkThemeUtil.multiColors(context, ColorUtils.string2Color("#F2F3F6"), darkColor: Colors.black),
        margin: const EdgeInsets.only(top: 15, bottom: 28.5),
        padding: const EdgeInsets.only(left: 10, right: 10, top: 10, bottom: 10),
        child: TextField(
          cursorColor: context.appColors.authFiledText,
          cursorWidth: 1.5,
          autofocus: false,
          enabled: true,
          maxLines: null,
          focusNode: state.getQuoteFormData![key]!['focusNode'],
          controller: state.getQuoteFormData![key]!['controller'],
          decoration: InputDecoration(
            isDense: true,
            isCollapsed: true,
            border: InputBorder.none,
            hintText: state.getQuoteFormData![key]!['hintText'],
            hintStyle: TextStyle(
              color: context.appColors.authFiledHint,
              fontSize: 16.0,
              fontWeight: FontWeight.w400,
            ),
          ),
          style: TextStyle(
            color: context.appColors.authFiledText,
            fontSize: 16.0,
            fontWeight: FontWeight.w400,
          ),
          textInputAction: TextInputAction.done,
          onSubmitted: (value) {
            FocusScope.of(context).unfocus();
          },
          expands: true,
          onChanged: (text) {
            // 当文本改变时，更新字符数量
            noteCount.value = text.length;
            repairDetailVm.changeGetQuoteFormData(context, text);
          },
        ),
      ),
      // Positioned(
      //   bottom: 0.0,
      //   right: 0.0,
      //   child: Text(
      //     S.current.characters(noteCount.value),
      //     style: TextStyle(
      //       color: context.appColors.textBlack,
      //       fontSize: 15.0,
      //     ),
      //   ),
      // ),
    ]);
  }
}
