import 'package:app/extensions/obtainProviderExtension.dart';
import 'package:app/state/mapState.dart';
import 'package:app/util/watchState.dart';
import 'package:app/view/appInfo.dart';
import 'package:app/view/status.dart';
import 'package:app/view/map.dart';
import 'package:flutter/material.dart';

class HomeView extends StatefulWidget {
  const HomeView({super.key});

  @override
  State<HomeView> createState() => _HomePageState();
}

class _HomePageState extends State<HomeView> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: const Text("Bubatzkarte"),
        actions: [
          IconButton(
            icon: const Icon(Icons.search),
            onPressed: () {

            },
          ),
          IconButton(
            icon: const Icon(Icons.info_outline),
            onPressed: () {
              showDialog(
                context: context,
                builder: (context) => const AppInfoView(),
              );
            },
          ),
        ],
      ),
      floatingActionButton: FloatingActionButton(
        child: WatchState<MapState>((context, state) => Icon(state.followLocation ? Icons.my_location : Icons.location_disabled)),
        onPressed: () => context.obtainState<MapState>().toggleLocationLock(),
      ),
      body: const Column(
        children: [
          SizedBox(
            height: 100,
            child: StatusView(),
          ),
          Expanded(
            child: MapView(),
          )
        ],
      ),
    );
  }
}