import 'dart:ui';

import 'package:electronic_assistant/base/base_controller.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';

import '../resource/colors.gen.dart';

abstract class BasePage<T extends BaseController> extends GetView<T> {
  const BasePage({super.key});

  @override
  Widget build(BuildContext context) {
    return AnnotatedRegion<SystemUiOverlayStyle>(
      value: SystemUiOverlayStyle.light.copyWith(
        statusBarColor: Colors.transparent, // 设置状态栏颜色为透明
        statusBarIconBrightness: _getStatusBarDarkFont(),
        systemNavigationBarColor: navigationBarColor(),
        systemNavigationBarIconBrightness: _getNavigationBarDarkFont(),
      ),
      child: GestureDetector(
        onTap: () {
          // controller.hideKeyboard(context);
          backgroundOnTapEvent();
        },
        child: Container(
          color: backgroundColor(),
          child: immersive()
              ? buildBody(context)
              : SafeArea(child: buildBody(context)),
        ),
      ),
    );
  }

  // 点击空白处
  void backgroundOnTapEvent() {}

  Brightness _getStatusBarDarkFont() {
    return statusBarDarkFont() ? Brightness.dark : Brightness.light;
  }

  Brightness _getNavigationBarDarkFont() {
    return statusBarDarkFont() ? Brightness.dark : Brightness.light;
  }

  bool statusBarDarkFont() {
    return true;
  }

  bool navigationBarDarkFont() {
    return true;
  }

  bool immersive() {
    return false;
  }

  Widget buildBody(BuildContext context);

  Color backgroundColor() {
    return ColorName.bgColorPrimary;
  }

  Color navigationBarColor() {
    return ColorName.bgColorPrimary;
  }
}
