import 'package:flutter/material.dart';
import 'package:chatwoot_flutter_sdk/chatwoot_sdk.dart';
import '../controllers/kr_chatwoot_controller.dart';
import 'package:get/get.dart';

class KRChatwootView extends StatefulWidget {
  const KRChatwootView({super.key});

  @override
  State<KRChatwootView> createState() => _KRChatwootViewState();
}

class _KRChatwootViewState extends State<KRChatwootView> {
  // 实例化控制器
  final KRChatwootController _controller = KRChatwootController();

  @override
  Widget build(BuildContext context) {
    // 获取系统状态栏高度
    final double statusBarHeight = MediaQuery.of(context).padding.top;

    return Scaffold(
      backgroundColor: const Color(0xFFF9F9FB),
      body: SafeArea(
        top: false, // 依然保持禁用自动顶部保护
        child: Padding(
          // 在状态栏高度的基础上减去 10 像素，实现向上移动
          padding: EdgeInsets.only(top: statusBarHeight - 10),
          child: ChatwootWidget(
            baseUrl: _controller.baseUrl,
            websiteToken: _controller.inboxIdentifier,
            user: _controller.chatUser,
            locale: "zh_CN",
            onAttachFile: _controller.onFilePicker,
            onLoadStarted: () => debugPrint("KRChatwoot: 开始加载 SDK"),
            closeWidget: () => Get.back(),
            onLoadCompleted: () => debugPrint("KRChatwoot: SDK 加载完毕"),
          ),
        ),
      ),
    );
  }
}