import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:storemonitor/Screens/Constants.dart';

class MyHomePage extends StatefulWidget {
  final String message;

  const MyHomePage({super.key, required this.message});

  @override
  _VideoPlayerScreenState createState() => _VideoPlayerScreenState();
}

class _VideoPlayerScreenState extends State<MyHomePage> {
  var isMeeters = '';
  InAppWebViewController? webViewController;
  String? userId = '';
  //double _scale = 1.0;
  //String? url = 'http://192.168.65.111:8100/restream';
  String urlData = '';

  @override
  void initState() {
    super.initState();
    isMeeters = widget.message;
    //getLoadData();
  }

  Future<void> getLoadData() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    userId = prefs.getString('empId');
    urlData = 'https://vaman.plutokm.com/sa_mob_report/$userId';
    //await Future.delayed(Duration(seconds: 1));
    if (kDebugMode) {
      print(urlData);
    }
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        leading: IconButton(
          icon: Image.asset(
            "assets/images/back_arrow.png",
            width: 24,
            height: 24,
            color: Colors.white,
          ),
          //color: Colors.white,
          onPressed: () => Navigator.pop(context),
        ),
        title: const Text(
          'Weekly Report',
          style: Constants.fontStyle,
        ),
        flexibleSpace: Container(
          decoration: BoxDecoration(
            gradient: Constants.getReturn(),
          ),
        ),
      ),
      body: SizedBox(
        height: MediaQuery.of(context).size.height,
        child: InAppWebView(
          initialUrlRequest: URLRequest(
            url: Uri.parse(isMeeters),
          ),
          onWebViewCreated: (controller) {
            webViewController = controller;
          },
          initialOptions: InAppWebViewGroupOptions(
            crossPlatform: InAppWebViewOptions(),
            android: AndroidInAppWebViewOptions(
              supportMultipleWindows:    true,
            ),
            ios: IOSInAppWebViewOptions(
              allowsInlineMediaPlayback: true,
            ),
          ),
        ),
      ),
    );
  }
}
// class VideoStream extends StatefulWidget {
//   const VideoStream({Key? key}) : super(key: key);
//   @override
//   State<VideoStream> createState() => _VideoStreamState();
// }// class _VideoStreamState extends State<VideoStream> {
//   final WebSocket _socket = WebSocket('http://192.168.65.111:8100/restream');
//   bool _isConnected = false;
//   void connect(BuildContext context) async {
//     _socket.connect();
//     setState(() {
//       _isConnected = true;
//     });
//   }
//   void disconnect() {
//     _socket.disconnect();
//     setState(() {
//       _isConnected = false;
//     });
//   }
//   @override
//   Widget build(BuildContext context) {
//     return Scaffold(
//       appBar: AppBar(
//         title: const Text("Live Video"),
//       ),
//       body: Padding(
//         padding: const EdgeInsets.all(20.0),
//         child: Center(
//           child: Column(
//             children: [
//               Row(
//                 mainAxisAlignment: MainAxisAlignment.spaceBetween,
//                 children: [
//                   ElevatedButton(
//                     onPressed: () => connect(context),
//                     //style: buttonStyle,
//                     child: const Text("Connect"),
//                   ),
//                   ElevatedButton(
//                     onPressed: disconnect,
//                     //style: buttonStyle,
//                     child: const Text("Disconnect"),
//                   ),
//                 ],
//               ),
//               const SizedBox(
//                 height: 50.0,
//               ),
//               _isConnected
//                   ? StreamBuilder(
//                       stream: _socket.stream,
//                       builder: (context, snapshot) {
//                         if (!snapshot.hasData) {
//                           return const CircularProgressIndicator();
//                         }
//                         if (snapshot.connectionState == ConnectionState.done) {
//                           return const Center(
//                             child: Text("Connection Closed !"),
//                           );
//                         }
//                         //? Working for single frames
//                         return Image.memory(
//                           Uint8List.fromList(
//                             base64Decode(
//                               (snapshot.data.toString()),
//                             ),
//                           ),
//                           gaplessPlayback: true,
//                           excludeFromSemantics: true,
//                         );
//                       },
//                     )
//                   : const Text("Initiate Connection")
//             ],
//           ),
//         ),
//       ),
//     );
//   }
// }