import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:initial_folder/theme.dart';
import 'package:webview_flutter/webview_flutter.dart';

class TermsAndCondition extends StatefulWidget {
  static const routeName = '/article_web';

  final String url;
  final String? id;

  const TermsAndCondition({Key? key, required this.url, this.id})
      : super(key: key);

  @override
  State<TermsAndCondition> createState() => _TermsAndConditionState();
}

class _TermsAndConditionState extends State<TermsAndCondition> {
  double progres = 0;
  @override
  Widget build(BuildContext context) {
    final juduls = {
      'sk': Text('Syarat dan Ketentuan'),
      'prv': Text('Kebijakan Privasi'),
      'about': Text('Tentang Vocasia'),
      'ctc': Text('Kontak Kami'),
      'help': Text('Bantuan'),
      'gopay': Text('Gopay'),
    };
    final judul = juduls[widget.id];

    var controller = WebViewController()
      ..setJavaScriptMode(JavaScriptMode.unrestricted)
      ..setBackgroundColor(const Color(0x00000000))
      ..setNavigationDelegate(
        NavigationDelegate(
          onProgress: (int progress) {
            // Update loading bar.
          },
          onPageStarted: (String url) {},
          onPageFinished: (String url) {},
          onWebResourceError: (WebResourceError error) {},
          onUrlChange: (change) {},
          onNavigationRequest: (NavigationRequest request) {
            if (request.url != widget.url) {
              // Prevent navigation to other URLs and about:blank
              print("Navigation prevented: ${request.url}");
              return NavigationDecision.prevent;
            } else {
              print("Navigation Accesed: ${request.url}");
              return NavigationDecision.navigate;
            }
          },
        ),
      )
      ..loadRequest(Uri.parse(widget.url));

    return Scaffold(
      appBar: AppBar(title: judul),
      body: Column(
        children: [
          LinearProgressIndicator(
            value: progres,
            color: sevenColor,
            backgroundColor: secondaryColor,
          ),
          Expanded(child: WebViewWidget(controller: controller)),
        ],
      ),
    );
  }
}
