import 'dart:ui';

import 'package:electronic_assistant/base/base_controller.dart';
import 'package:electronic_assistant/data/repositories/account_repository.dart';
import 'package:electronic_assistant/resource/assets.gen.dart';
import 'package:electronic_assistant/resource/colors.gen.dart';
import 'package:electronic_assistant/resource/string.gen.dart';
import 'package:electronic_assistant/utils/expand.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../../router/app_pages.dart';

class MainController extends BaseController {
  final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();

  final List<TabBean> tabBeans = [
    TabBean(
        StringName.mainTabHome,
        Assets.images.mainTabHomeUnSelect.path,
        Assets.images.mainTabHomeSelected.path,
        "#969696".toColor(),
        ColorName.primaryTextColor),
    TabBean(
        StringName.mainTabFile,
        Assets.images.mainTabFileUnSelect.path,
        Assets.images.mainTabFileSelected.path,
        "#969696".toColor(),
        ColorName.primaryTextColor),
  ];

  final _currentIndex = 0.obs;

  int get currentIndex => _currentIndex.value;


  void changeIndex(int index) {
    _currentIndex.value = index;
  }

  void updateIndex(int index) {
    _currentIndex.value = index;
  }

  void updateIndexByPageName(String pageName) {
    for (var value in tabBeans) {
      if (value.title == pageName) {
        _currentIndex.value = tabBeans.indexOf(value);
        break;
      }
    }
  }

  void openDrawer() {
    scaffoldKey.currentState?.openDrawer();
  }

  void closeDrawer() {
    scaffoldKey.currentState?.closeDrawer();
  }

  void onChatClick() {
    if (accountRepository.isLogin.value) {
      Get.toNamed(RoutePath.chat);
    } else {
      Get.toNamed(RoutePath.login);
    }
  }
}

class TabBean {
  final String title;
  final String normalIcon;
  final String selectedIcon;
  final Color txtNormalColor;
  final Color txtSelectedColor;

  TabBean(this.title, this.normalIcon, this.selectedIcon, this.txtNormalColor,
      this.txtSelectedColor);
}
