import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:rogapp/model/gps_data.dart';
import 'package:rogapp/pages/destination/destination_controller.dart';
import 'package:rogapp/pages/drawer/drawer_page.dart';
import 'package:rogapp/pages/index/index_controller.dart';
import 'package:rogapp/routes/app_pages.dart';
import 'package:rogapp/utils/database_gps.dart';
import 'package:rogapp/widgets/list_widget.dart';
import 'package:rogapp/widgets/map_widget.dart';

class IndexPage extends GetView<IndexController> {
  IndexPage({Key? key}) : super(key: key);

  final IndexController indexController = Get.find<IndexController>();
  final DestinationController destinationController =
      Get.find<DestinationController>();

  @override
  Widget build(BuildContext context) {
    return WillPopScope(
      onWillPop: () async => false,
      child: Scaffold(
        drawer: DrawerPage(),
        appBar: AppBar(
          title: Text("add_location".tr),
          actions: [
            IconButton(
                onPressed: () async {
                  // GpsDatabaseHelper db = GpsDatabaseHelper.instance;
                  // List<GpsData> data = await db.getGPSData(
                  //     indexController.currentUser[0]["user"]['team_name'],
                  //     indexController.currentUser[0]["user"]["event_code"]);
                  // print("GPS data is ${data.length}");
                  Get.toNamed(AppPages.GPS);
                },
                icon: const Icon(Icons.telegram)),
            IconButton(
                onPressed: () {
                  Get.toNamed(AppPages.HISTORY);
                },
                icon: const Icon(Icons.history)),
            IconButton(
                onPressed: () {
                  final tk = indexController.currentUser[0]["token"];
                  if (tk != null) {
                    destinationController.fixMapBound(tk);
                  }
                },
                icon: const Icon(Icons.refresh)),
            InkWell(
              onTap: () {
                Get.toNamed(AppPages.SEARCH);
              },
              child: Container(
                height: 32,
                width: 75,
                decoration: BoxDecoration(
                  color: Colors.blue,
                  borderRadius: BorderRadius.circular(25),
                ),
                child: const Center(
                  child: Icon(Icons.search),
                ),
              ),
            ),
            //CatWidget(indexController: indexController,),
          ],
        ),
        // bottomNavigationBar: BottomAppBar(
        //   child: Row(
        //     mainAxisAlignment: MainAxisAlignment.spaceBetween,
        //     children: <Widget>[
        //       Obx(
        //         () => destinationController.isInRog.value == true
        //             ? IconButton(
        //                 onPressed: () {},
        //                 icon: const Icon(
        //                   Icons.run_circle,
        //                   size: 44,
        //                   color: Colors.green,
        //                 ))
        //             : IconButton(
        //                 onPressed: () {},
        //                 icon: const Icon(
        //                   Icons.run_circle,
        //                   size: 44,
        //                   color: Colors.black12,
        //                 )),
        //       ),
        //       Padding(
        //         padding:
        //             const EdgeInsets.only(right: 10.0, top: 4.0, bottom: 4.0),
        //         child: InkWell(
        //             child: Obx(() => destinationController
        //                         .isGpsSelected.value ==
        //                     true
        //                 ? Padding(
        //                     padding: const EdgeInsets.only(
        //                         right: 10.0, top: 4.0, bottom: 4.0),
        //                     child: InkWell(
        //                       child: const Image(
        //                         image:
        //                             AssetImage('assets/images/route3_off.png'),
        //                         width: 35,
        //                         height: 35,
        //                       ),
        //                       onTap: () {
        //                         //indexController.switchPage(AppPages.TRAVEL);
        //                       },
        //                     ),
        //                   )
        //                 : Padding(
        //                     padding: const EdgeInsets.only(
        //                         right: 10.0, top: 4.0, bottom: 4.0),
        //                     child: InkWell(
        //                       child: const Image(
        //                         image:
        //                             AssetImage('assets/images/route2_on.png'),
        //                         width: 35,
        //                         height: 35,
        //                       ),
        //                       onTap: () {
        //                         //indexController.switchPage(AppPages.TRAVEL);
        //                       },
        //                     ),
        //                   ))),
        //       ),
        //     ],
        //   ),
        // ),
        floatingActionButton: FloatingActionButton(
          onPressed: () {
            indexController.toggleMode();
          },
          elevation: 1.0,
          child: Obx(
            () => indexController.mode.value == 0
                ? const Image(image: AssetImage('assets/images/list2.png'))
                : const Image(image: AssetImage('assets/images/map.png')),
          ),
        ),
        floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
        body: SafeArea(
          child: Column(
            children: [
              Expanded(
                  child: Obx(
                () => indexController.mode.value == 0
                    ? MapWidget()
                    : const ListWidget(),
              ))
            ],
          ),
        ),
      ),
    );
  }
}
