import 'package:feelverapp/model/Login/login_model.dart';
import 'package:feelverapp/model/category/category_model.dart';
import 'package:feelverapp/model/editprofile/getprofilemodel.dart';
import 'package:feelverapp/model/home/home_model.dart';
import 'package:feelverapp/service/Loading.dart';

import 'package:feelverapp/service/api.dart';
import 'package:feelverapp/service/base_presenter.dart';
import 'package:feelverapp/ui/home/home.dart';
import 'package:feelverapp/util/Accout_util.dart';
import 'package:flutter/material.dart';
import 'package:rflutter_alert/rflutter_alert.dart';
import 'package:shared_preferences/shared_preferences.dart';

class HomePresenter extends BasePresenter<HomePage> {
  Api _api;
  String uid;
  final formkey = GlobalKey<FormState>();
  GetprofileModel getmodel;
  LoginModel logmodel;
  HomePresenter(State<HomePage> state) : super(state);

  Listitem() async {
    _api = Api<categoryModel>();
    var res = await _api.category({
      "access_type": "portal",
    });
    if (res.fail == null) {
      print('res Success');
    } else {
      print('res Fail');
    }
  }
 
 getid() async {
    SharedPreferences pref = await SharedPreferences.getInstance();
     setState(() {uid =pref.getString('Id');});
    return uid;
  }
 getprofile() async {
  
    _api = Api<GetprofileModel>(); 

    var res = await _api.getprofile({
      "id":await AccountUtil.getID()
      
      
      });


    if (res.fail == null) {
   setState(() {
        getmodel = res.success;});
        print("Hii"+getmodel.result[0].name);
            } else {
      Alert(
          style: AlertStyle(
            animationType: AnimationType.fromTop,
            isCloseButton: false,
          ),
          context: state.context,
          title: "ไม่สามารถติดต่อ\nเซิร์ฟเวอร์ได้",
          content: Icon(
            Icons.warning,
            color: Colors.orange,
            size: 80,
          ),
          buttons: [
            DialogButton(
              color: Color.fromRGBO(106, 179, 170, 1),
              onPressed: () => Navigator.pop(state.context),
              child: Text(
                "ลองอีกครั้ง",
                style: TextStyle(color: Colors.white, fontSize: 20),
              ),
            )
          ]).show();
    }
  }


}
