import 'package:NearleDailyBusiness/Globalwidgets/textwidget.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:get/get_core/src/get_main.dart';
import 'package:webview_flutter/webview_flutter.dart';

import '../Controller/More/web_view_controller.dart';
import '../Helper/Constants/Colorconstants.dart';

class WebViewApp extends StatelessWidget {
  final String url;
  final String appBarText;

  const WebViewApp({
    super.key,
    required this.url,
    required this.appBarText,
  });

  @override
  Widget build(BuildContext context) {
    final controller = Get.put(WebViewAppController());
    controller.initializeWebViewController(url);

    return Scaffold(
      appBar: AppBar(
        automaticallyImplyLeading: false,
        backgroundColor: ColorConstants.primaryColor,
        title: Row(
          children: [
            InkWell(
              onTap: () {
                Get.back();
              },
              child: const Icon(
                Icons.arrow_back_ios,
                color: Colors.white,
              ),
            ),
            const SizedBox(width: 5,),
            TextWidget(
              text: appBarText,
              fontSize: 25,
              fontWeight: FontWeight.w700,
              color: Colors.white,
            ),
          ],
        ),
      ),
      body: Stack(
        children: [
          WebViewWidget(
            controller: controller.webViewController,
          ),
          Obx(() {
            return controller.isLoading.value
                ? const Center(child: CircularProgressIndicator())
                : const SizedBox.shrink();
          }),
        ],
      ),
    );
  }
}