import 'package:circle_app/router/app_routers.dart';
import 'package:circle_app/util/util.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import 'logic.dart';

class HomePage extends StatelessWidget {
  HomePage({Key? key}) : super(key: key);

  final logic = Get.lazyPut(() => HomeLogic());
  final state = Get.find<HomeLogic>().state;

  final List _tabs = [
    Container(),
    Container(),
    Container(),
  ];

  final List<BottomNavigationBarItem> _bottomTabs = [
    //icon部分的设置！！！！
    BottomNavigationBarItem(
        icon:Padding(padding: EdgeInsets.all(8),
            child: Image.asset(getTabbarImage('msg_normal'),fit: BoxFit.cover,width: 25,height: 25)),
        activeIcon:Padding(padding: EdgeInsets.all(8),
            child: Image.asset(getTabbarImage('msg_selected'),fit: BoxFit.cover,width: 25,height: 25)),
        label:''
    ),
    BottomNavigationBarItem(
      icon:Padding(padding: EdgeInsets.all(8),
          child: Image.asset(getTabbarImage('circle_normal'),fit: BoxFit.cover,width: 25,height: 25)),
      activeIcon:Padding(padding: EdgeInsets.all(8),
          child: Image.asset(getTabbarImage('circle_selected'),fit: BoxFit.cover,width: 25,height: 25)),
        label:''
    ),
    BottomNavigationBarItem(
        icon:Padding(padding: EdgeInsets.all(8),
            child: Image.asset(getTabbarImage('mine_normal'),fit: BoxFit.cover,width: 25,height: 25)),
        activeIcon:Padding(padding: EdgeInsets.all(8),
            child: Image.asset(getTabbarImage('mine_selected'),fit: BoxFit.cover,width: 25,height: 25)),
        label:''
    )
  ];

  @override
  Widget build(BuildContext context) {
    return GetBuilder(builder: (HomeLogic controller) {
      return GestureDetector(
        onTap: () {
          Get.toNamed(AppRoutes.Complete_materialPage);
        },
        child: Scaffold(
          // backgroundColor: Color.fromRGBO(244, 245, 245, 1.0),
            bottomNavigationBar: Container(
              height: Get.bottomBarHeight,
              width: Get.width,
              padding: EdgeInsets.only(left: 50.sp,right: 50.sp),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                children: [
                  funcItem(0, 'msg', 0 == controller.currentIndex, controller),
                  funcItem(1, 'circle', 1 == controller.currentIndex, controller),
                  funcItem(2, 'mine', 2 == controller.currentIndex, controller),
                ],
              ),
            ),
            body:_tabs[controller.currentIndex]
        ),
      );
    });
  }

  funcItem(int index,String image,bool isSelected,HomeLogic controller) {
    return GestureDetector(
      onTap: () {
        if (!isSelected) {
          controller.updateIndex(index);
        }
      },
      child: Container(
        child: Image.asset(isSelected ? getTabbarImage(image + '_selected') : getTabbarImage(image + '_normal'),width: 34.sp,height: 34.sp,),
      ),
    );
  }

}

