import 'dart:async';

import 'package:flutter/material.dart';
// import 'package:webview_flutter/webview_flutter.dart';
import 'package:flutter_widget_from_html_core/flutter_widget_from_html_core.dart';
import 'package:fwfh_webview/fwfh_webview.dart';

import '../splash.dart';
import 'app_bar_webview.dart';
// import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart';

class WebViewHtml extends StatelessWidget {
  const WebViewHtml({
    super.key,
    required this.titleAppBar,
    required this.url,
  });

  final String titleAppBar;
  final String url;

  Future<bool> tapUrl(x, BuildContext context) async {
    if (x.contains('jasaotp')) {
      // Navigator.push(
      //   context,
      //   MaterialPageRoute(
      //     builder: (_) => Splash(
      //       pathSegmentString: [''],
      //       context: context,
      //     ),
      //   ),
      // );
    }
    return true;
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        CustomAppBar(
          titleAppBar: titleAppBar,
        ),
        Expanded(
          child: HtmlWidget(
            '<iframe src="$url"></iframe>',
            factoryBuilder: () => MyWidgetFactory(),
            onTapImage: (x) {
              print(x);
            },
            onTapUrl: (x) {
              return tapUrl(x, context);
            },
          ),
        ),
        // WebView(
        //   initialUrl: url,
        //   onWebViewCreated: (WebViewController controller) {
        //     _controller.complete(controller);
        //   },
        // )
      ],
    );
    // return Scaffold(
    //   appBar: AppBar(
    //     title: const Text('Flutter WebView example'),
    //     // actions: <Widget>[
    //     //   _SampleMenu(_controller.future),
    //     // ],
    //   ),
    //   body: WebView(
    //     initialUrl: url,
    //     onWebViewCreated: (WebViewController controller) {
    //       _controller.complete(controller);
    //     },
    //   ),
    // );
  }
}

class MyWidgetFactory extends WidgetFactory with WebViewFactory {}
