import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:overlay_support/overlay_support.dart';
import 'package:responsive_framework/responsive_framework.dart';
import 'package:IQ/app/global/static_informs.dart';
import 'package:IQ/app/global/translations.dart';
import 'package:IQ/app/modules/selectISP/models/isp_model.dart';
import 'package:IQ/app/modules/selectISP/views/select_isp_view.dart';
import 'package:IQ/app/routes/app_pages.dart';
import 'package:IQ/main.dart';

// ignore: must_be_immutable
class MyApp extends StatelessWidget {
  MyApp({super.key});

  @override
  Widget build(BuildContext context) => _buildApp(context);

  ISPsData isp = ISPsData(
    name: "FiberX",
    serverAddress: "172.16.12.108",
  );
  Widget _buildApp(BuildContext context) {
    selectedISP = isp;
    storage.write('selectedISP', selectedISP?.toJson());
    url = 'https://${selectedISP?.serverAddress}/user/api/index.php/api';
    liveDataUrl =
        'http://${selectedISP?.serverAddress}/userlivetraffic/ucp/traffic?token=';
    storage.write('baseUrl', url);
    storage.write('liveDataUrl', liveDataUrl);
    return OverlaySupport(
      child: GetMaterialApp(
        title: "",
        initialRoute: Routes.AUTOLOGIN,
        translations: Translation(),
        locale: Locale(defaultLocale),
        getPages: AppPages.routes,
        debugShowCheckedModeBanner: false,
        builder: (context, navigator) => ResponsiveWrapper.builder(
          Theme(data: ThemeData(fontFamily: 'DefaultFont'), child: navigator!),
          maxWidth: 1200,
          minWidth: 480,
          defaultScale: true,
          breakpoints: [
            const ResponsiveBreakpoint.resize(480, name: MOBILE),
            const ResponsiveBreakpoint.autoScale(800, name: TABLET),
            const ResponsiveBreakpoint.resize(1000, name: DESKTOP),
          ],
        ),
      ),
    );
  }
}
