/*
 * @author lsy
 * @date   2019-11-05
 **/
import 'dart:math';
import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:gmalpha_flutter/Annotations/RouterCenterRestore.mark.dart';
import 'package:gmalpha_flutter/commonModel/GMBase.dart';
import 'package:gmalpha_flutter/res/GMRes.dart';

class HomeItem {
  HomeItem(this.index, this.svgIcon);

  int index;
  String svgIcon;
}

class HomeModel extends BaseModel {
  LiveData<int> indexLive = new LiveData();
  LiveData<int> widgetLive = new LiveData();
  final List<HomeItem> items = [];
  final List<Widget> pages = [];
  int currentIndex = 0;

  @override
  void dispose() {
    indexLive.dispost();
    widgetLive.dispost();
  }

  void init() {
    var mainWidget = RouterCenterImpl().findMainRouter()?.getMainWidget();
    var findPage = RouterCenterImpl().findFindRouter()?.getFindPage("ww");
    var showModel = RouterCenterImpl().findAskRouter()?.showModel();
    var messagePage =
        RouterCenterImpl().findNewMessageRouter()?.getMessagePage("main");
    var userPage = RouterCenterImpl().findUserRouter()?.getUserPage();
    int index = 0;
    if (mainWidget != null) {
      items.add(HomeItem(index, "images/home.svg"));
      pages.add(mainWidget);
      index++;
    }
    if (findPage != null) {
      items.add(HomeItem(index, "images/find.svg"));
      pages.add(findPage);
      index++;
    }
    if (showModel) {
      items.add(HomeItem(index, "images/add.svg"));
//      items.add(baseItem(index, "images/add.svg"));
      index++;
    }
    if (messagePage != null) {
      items.add(HomeItem(index, "images/message.svg"));
      pages.add(messagePage);
      index++;
    }
    if (userPage != null) {
      items.add(HomeItem(index, "images/user.svg"));
      pages.add(userPage);
      index++;
    }
  }


  void onTap(int index) {
    indexLive.notifyView(index);
    if (index == 2) {
      //TODO
    } else if (index < 2) {
      widgetLive.notifyView(index);
    } else {
      widgetLive.notifyView(index - 1);
    }
  }
}
