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

class EbayWebViewScreen extends StatefulWidget {
  final String url;
  final String title;

  const EbayWebViewScreen({
    super.key,
    required this.url,
    required this.title,
  });

  @override
  State<EbayWebViewScreen> createState() => _EbayWebViewScreenState();
}

class _EbayWebViewScreenState extends State<EbayWebViewScreen> {
  late final WebViewController _controller;
  bool _isLoading = true;

  @override
  void initState() {
    super.initState();

    _controller = WebViewController()
      ..setJavaScriptMode(JavaScriptMode.unrestricted)
      ..setNavigationDelegate(
        NavigationDelegate(
          onPageFinished: (_) {
            setState(() => _isLoading = false);
          },
        ),
      )
      ..loadRequest(Uri.parse(widget.url));
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Stack(
        children: [
          WebViewWidget(controller: _controller),

          if (_isLoading)
            const Center(
              child: CircularProgressIndicator(),
            ),
        ],
      ),
    );
  }
}
