import 'package:aves/model/entry/entry.dart';
import 'package:aves/model/gpx/gpx_track.dart';
import 'package:aves/model/settings/settings.dart';
import 'package:aves/widgets/common/map/geo_map.dart';
import 'package:aves/widgets/common/providers/map_theme_provider.dart';
import 'package:aves_map/aves_map.dart';
import 'package:flutter/material.dart';

class GpxMapPage extends StatefulWidget {
  static const routeName = '/gpx/map';

  final GpxTrack track;

  const GpxMapPage({
    super.key,
    required this.track,
  });

  @override
  State<GpxMapPage> createState() => _GpxMapPageState();
}

class _GpxMapPageState extends State<GpxMapPage> {
  final AvesMapController _mapController = AvesMapController();
  final ValueNotifier<bool> _isAnimatingNotifier = ValueNotifier(false);

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

  @override
  Widget build(BuildContext context) {
    final center = widget.track.center;

    return Scaffold(
      appBar: AppBar(
        title: Text(widget.track.name),
      ),
      body: MapTheme(
        interactive: true,
        showCoordinateFilter: false,
        navigationButton: MapNavigationButton.back,
        child: GeoMap(
          controller: _mapController,
          entries: const <AvesEntry>[],
          availableSize: MediaQuery.sizeOf(context),
          initialCenter: center,
          initialZoom: settings.infoMapZoom,
          isAnimatingNotifier: _isAnimatingNotifier,
          tracks: widget.track.tracks,
        ),
      ),
    );
  }
}
