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/kr_message_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_help_entrance.dart';
import 'package:kaer_with_panels/app/widgets/hi_collapsible_list.dart';
import 'package:kaer_with_panels/app/widgets/hi_fixed_scrollbar.dart';
import '../../../widgets/kr_simple_loading.dart';
import 'package:kaer_with_panels/app/widgets/swipe/has_swipe_config.dart';
import 'package:kaer_with_panels/app/widgets/swipe/swipe_config.dart';

class KRMessageView extends GetView<KRMessageController>
    implements HasSwipeConfig {
  const KRMessageView({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: Stack(
          children: [
            // 主要内容区域
            Obx(() {
              return Column(
                children: [
                  Expanded(
                    child: Padding(
                      padding: EdgeInsets.only(bottom: 90.w),
                      child: EasyRefresh(
                        controller: controller.refreshController,
                        onRefresh: controller.kr_onRefresh,
                        onLoad: controller.kr_onLoadMore,
                        header: ClassicHeader(
                          dragText: '下拉刷新',
                          armedText: '释放刷新',
                          readyText: '正在刷新...',
                          processingText: '正在刷新...',
                          processedText: '刷新成功',
                          failedText: '刷新失败',
                          messageText: '最后更新于 %T',
                          textStyle:
                              TextStyle(color: Colors.white.withOpacity(0.7)),
                          messageStyle: TextStyle(
                              color: Colors.white.withOpacity(0.5),
                              fontSize: 12.sp),
                          iconTheme: IconThemeData(
                              color: Colors.white.withOpacity(0.7)),
                        ),
                        footer: ClassicFooter(
                          dragText: '上拉加载',
                          armedText: '释放加载',
                          readyText: '正在加载...',
                          processingText: '正在加载...',
                          processedText: '加载成功',
                          failedText: '加载失败',
                          noMoreText: '没有更多数据了',
                          messageText: '最后更新于 %T',
                          textStyle:
                              TextStyle(color: Colors.white.withOpacity(0.7)),
                          messageStyle: TextStyle(
                              color: Colors.white.withOpacity(0.5),
                              fontSize: 12.sp),
                          iconTheme: IconThemeData(
                              color: Colors.white.withOpacity(0.7)),
                        ),
                        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),
                                );
                              },
                            ),
                          ),
                        ),
                      ),
                    ),
                  ),
                ],
              );
            }),
            // 底部帮助入口
            const HIHelpEntrance(),
          ],
        ),
      ),
    );
  }
}
