import 'package:fis_ui/index.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flyinsono/architecture/define.dart';
import 'package:flyinsono/architecture/router/mobile/names.dart';
import 'package:flyinsono/architecture/states/states.dart';
import 'package:flyinsono/views/wechat_mini_program/wx_debug/widgets/debug_menu_buttons.dart';
import 'package:flyinsono/views/wechat_mini_program/wx_public_widgets/wx_scaffold.dart';
import 'package:flyinsono/views/wechat_mini_program/wx_public_widgets/wx_screen_direction_lock.dart';

import '../wx_env/index.dart';
import 'index.dart';

class WxDebugPage extends FisView<WxDebugController> {
  const WxDebugPage({Key? key}) : super(key: key);

  @override
  FWidget build(BuildContext context) {
    return FisBuilder<WxDebugController>(
      builder: (_) {
        return WxScreenDirectionLock(
            direction: ScreenDirection.vertical,
            page: WxScaffold(
              body: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Padding(
                    padding: const EdgeInsets.all(20.0),
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.start,
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        _buildDebugTextItem(
                          "小程序环境(kIsWechat):",
                          "$kIsWechat ${kIsWechat ? '✅' : '❌'}",
                        ),
                        _buildDebugTextItem(
                          "浏览器环境(kIsWeb):",
                          " $kIsWeb ${kIsWeb ? '✅' : '❌'}",
                        ),
                        _buildDebugTextItem(
                          "移动设备环境(kIsMobile):",
                          " $kIsMobile ${kIsMobile ? '✅' : '❌'}",
                        ),
                        _buildDebugTextItem(
                          "Token(Store.user.token):",
                          " ${Store.user.token} ${Store.user.token.isEmpty ? 'null❌' : '✅'}",
                        ),
                        _buildDebugTextItem(
                          "OpenId(Store.user.openid):",
                          " ${Store.user.openid} ${Store.user.openid.isEmpty ? 'null❌' : '✅'}",
                        ),
                        _buildDebugTextItem(
                          "userId(Store.user.code):",
                          " ${Store.user.code} ${Store.user.code.isEmpty ? 'null❌' : '✅'}",
                        ),
                        _buildDebugTextItem(
                          "用户名(Store.user.displayName):",
                          " ${Store.user.displayName} ${Store.user.displayName.isEmpty ? 'null❌' : '✅'}",
                        ),
                        _buildDebugTextItem(
                          "机构(Store.user.rootOrganizationName):",
                          " ${Store.user.rootOrganizationName} ${Store.user.rootOrganizationName.isEmpty ? 'null❌' : '✅'}",
                        ),
                      ],
                    ),
                  ),
                  Expanded(
                      child: ListView(
                    children: [
                      Container(
                          padding: EdgeInsets.all(20),
                          child: DebugMenuButtons())
                    ],
                  )),
                ],
              ),
              title: "小程序调试工具",
              parentRoute: MobileRouteNames.Wechat.MiniProgramHome,
            ));
      },
    );
  }

  FWidget _buildDebugTextItem(String key, String value) {
    return FContainer(
      padding: EdgeInsets.only(
        bottom: 10,
      ),
      margin: EdgeInsets.only(bottom: 10),
      decoration: BoxDecoration(
        /// 下边框
        border: Border(
          bottom: BorderSide(
            color: Colors.grey.withOpacity(0.5),
            width: 0.5,
          ),
        ),
      ),
      child: FRow(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          FText(key),
          FExpanded(
            child: FText(
              value,
              textAlign: TextAlign.right,
              maxLines: 1,
              overflow: TextOverflow.clip,
              style: TextStyle(fontSize: 14),
            ),
          ),
        ],
      ),
    );
  }
}
