import 'package:ef/ef.dart';
import 'package:flutter/material.dart';
import 'package:flutterflow_ui/flutterflow_ui.dart';
import 'package:vbvs_app/common/util/FitTool.dart';
import 'package:vbvs_app/component/tool/ClickableContainer.dart';
import 'package:vbvs_app/controller/device/device_share_controller.dart';
import 'package:vbvs_app/controller/message/message_controller.dart';
import 'package:vbvs_app/controller/theme_controller/ThemeController.dart';
import 'package:vbvs_app/enum/MessageStatus.dart';

class ReviewMessageWidgetWidget extends StatefulWidget {
  final data;

  const ReviewMessageWidgetWidget({super.key, required this.data});

  @override
  State<ReviewMessageWidgetWidget> createState() =>
      _ReviewMessageWidgetWidgetState();
}

class _ReviewMessageWidgetWidgetState extends State<ReviewMessageWidgetWidget> {
  ThemeController themeController = Get.find();
  MessageController messageController = Get.find();
  DeviceShareController deviceShareController = Get.find();

  @override
  Widget build(BuildContext context) {
    var messageInfo = widget.data;
    return ClickableContainer(
      backgroundColor: themeController.currentColor.sc5,
      highlightColor: themeController.currentColor.sc21,
      borderRadius: 20.rpx,
      padding: EdgeInsetsDirectional.fromSTEB(31.rpx, 33.rpx, 0.rpx, 33.rpx),
      onTap: () {},
      child: Column(
        mainAxisSize: MainAxisSize.max,
        children: [
          Container(
            width: double.infinity,
            constraints: BoxConstraints(
              minHeight: 66.rpx,
            ),
            child: Align(
              alignment: AlignmentDirectional(-1, 0),
              child: Text(
                // '实时监测结果通知'.tr,
                "${messageInfo['data']!['title']}",
                style: TextStyle(
                  fontFamily: 'Inter',
                  fontSize: 30.rpx,
                  letterSpacing: 0.0,
                  color: themeController.currentColor.sc3,
                ),
              ),
            ),
          ),
          Row(
            mainAxisSize: MainAxisSize.max,
            children: [
              Container(
                constraints: BoxConstraints(
                  minWidth: 30.rpx,
                  maxWidth: 140.rpx,
                ),
                child: Column(
                  mainAxisSize: MainAxisSize.max,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: messageInfo['data']['val']
                      .map<Widget>((mapItem) =>
                          _buildInfoItem(context, mapItem['k'] ?? ''))
                      .toList(),
                ),
              ),
              Container(
                constraints: BoxConstraints(
                  minWidth: 30.rpx,
                ),
                child: Column(
                  mainAxisSize: MainAxisSize.max,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: messageInfo['data']['val']
                      .map<Widget>((mapItem) =>
                          _buildValueItem(context, mapItem['v'] ?? ''))
                      .toList(),
                ),
              ),
            ].divide(SizedBox(width: 35.rpx)),
          ),
        ],
      ),
    );
  }

  Widget _buildInfoItem(BuildContext context, label) {
    return Container(
      constraints: BoxConstraints(
        minHeight: 62.rpx,
      ),
      child: Align(
        alignment: AlignmentDirectional(-1, 0),
        child: Text(
          overflow: TextOverflow.ellipsis,
          maxLines: 1,
          "${label}",
          style: TextStyle(
            fontFamily: 'Inter',
            fontSize: 26.rpx,
            letterSpacing: 0.0,
            color: themeController.currentColor.sc4,
          ),
        ),
      ),
    );
  }

  Widget _buildValueItem(BuildContext context, value) {
    return Container(
      constraints: BoxConstraints(
        minHeight: 62.rpx,
      ),
      child: Align(
        alignment: AlignmentDirectional(-1, 0),
        child: Text(
          overflow: TextOverflow.ellipsis,
          maxLines: 1,
          "${value}",
          style: TextStyle(
            fontFamily: 'Inter',
            fontSize: 26.rpx,
            letterSpacing: 0.0,
            color: themeController.currentColor.sc3,
          ),
        ),
      ),
    );
  }

  String getMessageStatus(int status) {
    if (status == null) {
      return '未知数据'.tr;
    }
    if (status == MessageStatus.noNeed.code) {
      return '无需处理'.tr;
    }
    if (status == MessageStatus.pending.code) {
      return "待处理".tr;
    }
    if (status == MessageStatus.completed.code) {
      return "已处理".tr;
    }
    if (status == MessageStatus.timeout.code) {
      return "已超时".tr;
    }
    return '未知数据'.tr;
  }
}
