import 'package:flutter/Material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:get/get_core/src/get_main.dart';
import 'package:webview_flutter/webview_flutter.dart';

import '../../base/base_page.dart';
import '../../resource/assets.gen.dart';
import '../../router/app_pages.dart';
import 'browser_controller.dart';

class BrowserPage extends BasePage<BrowserController> {
  const BrowserPage({super.key});

  static start(String url) {
    Get.toNamed(RoutePath.browser, arguments: url);
  }

  @override
  bool immersive() {
    // TODO: implement immersive
    return true;
  }

  @override
  Widget buildBody(BuildContext context) {
    return WillPopScope(
      onWillPop: () async {
        return await controller.handleBack();
      },
      child: Scaffold(
        backgroundColor: Colors.transparent,
        appBar: AppBar(
          systemOverlayStyle: SystemUiOverlayStyle.light,
          backgroundColor: Colors.transparent,
          title: Obx(
            () => Text(
              controller.title.value,
              style: TextStyle(
                fontSize: 17.sp,
                color: Colors.white,
              ),
            ),
          ),
          leading: IconButton(
            icon: SizedBox(
                width: 24.w,
                height: 24.w,
                child: Assets.images.iconCommonBack.image()),
            // Custom icon
            onPressed: () {
              Get.back();
            },
          ),
        ),
        body: _buildContentView(),
      ),
    );
  }

  Widget _buildContentView() {
    return WebViewWidget(controller: controller.webViewController);
  }
}
