import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:easy_refresh/easy_refresh.dart';
import 'package:flutter_html/flutter_html.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import '../../../model/response/kr_message_list.dart';
import '../controllers/hi_help_controller.dart';
import 'package:kaer_with_panels/app/widgets/kr_app_text_style.dart';
import 'package:kaer_with_panels/app/localization/app_translations.dart';
import 'package:kaer_with_panels/app/widgets/hi_base_scaffold.dart';
import 'package:kaer_with_panels/app/widgets/hi_collapsible_list.dart';
import 'package:kaer_with_panels/app/widgets/hi_fixed_scrollbar.dart';
import 'package:kaer_with_panels/app/modules/hi_menu/widgets/hi_menu_list_item.dart';
import '../../../routes/app_pages.dart';
import 'package:kaer_with_panels/app/widgets/swipe/has_swipe_config.dart';
import 'package:kaer_with_panels/app/widgets/swipe/swipe_config.dart';
import '../../../utils/kr_common_util.dart';

class HIHelpView extends GetView<HIHelpController> implements HasSwipeConfig {
  const HIHelpView({super.key});

  @override
  SwipeConfig get swipeConfig =>
      SwipeConfig(enableLeft: true, onLeft: () => Get.back());

  @override
  Widget build(BuildContext context) {

    return HIBaseScaffold(
      child: Padding(
        padding: const EdgeInsets.only(left: 0),
        child: Column(
          children: [
            Expanded(
              child: Obx(
                () => EasyRefresh(
                  // controller: controller.refreshController,
                  // onRefresh: controller.kr_onRefresh,
                  // onLoad: controller.kr_onLoadMore,
                  // header: const DeliveryHeader(
                  //   triggerOffset: 50.0,
                  //   springRebound: true,
                  // ),
                  // footer: const DeliveryFooter(
                  //   triggerOffset: 50.0,
                  //   springRebound: true,
                  // ),
                  onRefresh: null, // 设置为 null 来禁用下拉刷新
                  onLoad: null, // 设置为 null 来禁用上拉加载
                  child: Padding(
                    padding: EdgeInsets.only(right: 0.w), // 滚动条与内容间距
                    child: HiFixedScrollbar(
                      controller: controller.kr_scrollController,
                      child: ListView.builder(
                        controller: controller.kr_scrollController,
                        padding: EdgeInsets.only(left: 40.w, right: 40.w),
                        itemCount: controller.kr_messages.length,
                        itemBuilder: (context, index) {
                          final message = controller.kr_messages[index];
                          final collapsibleItemData = HICollapsibleItem(
                            title: message.title,
                            content: message.content,
                          );
                          return Padding(
                            padding: EdgeInsets.only(bottom: 10.w),
                            child: HICollapsibleItemWidget(
                                item: collapsibleItemData),
                          );
                        },
                      ),
                    ),
                  ),
                ),
              ),
            ),
            SizedBox(height: 60.w),
            // 增加在线客服入口
            Padding(
              padding: EdgeInsets.symmetric(horizontal: 40.w),
              child: MenuListItem(
                // 2. 创建一个 MenuItem 数据对象
                item: MenuItem(
                  iconName: 'icon-5',
                  title: '在线客服',
                  // 3. 使用 onTap 回调来处理跳转逻辑
                  onTap: () {
                    KRCommonUtil.kr_openCustomerService();
                  },
                ),
              ),
            ),
            SizedBox(height: 30.w)
          ],
        ),
      ),
    );
  }
}
