import 'package:aves/app_flavor.dart';
import 'package:aves/main_common.dart';
import 'package:aves/widget_common.dart';
import 'package:aves/widgets/cast/cast_controller.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import 'package:mapbox_maps_flutter/mapbox_maps_flutter.dart';

const _flavor = AppFlavor.play;

void _initMapbox() {
  const mapboxToken = String.fromEnvironment('MAPBOX_ACCESS_TOKEN');

  debugPrint(
    '[mapbox] token present=${mapboxToken.isNotEmpty} '
    'length=${mapboxToken.length}',
  );

  if (mapboxToken.isNotEmpty) {
    MapboxOptions.setAccessToken(mapboxToken);
  }
}

@pragma('vm:entry-point')
Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();

  _initMapbox();

  // Carica backend salvato
  await CastController.instance.loadSavedBackend();

  // Avvia Aves come fa il main originale
  mainCommon(_flavor);
}

@pragma('vm:entry-point')
void widgetMain() => widgetMainCommon(_flavor);
