import 'package:feelverapp/model/favorite/addfav_model.dart';
import 'package:feelverapp/model/shoplistdetail/shoplistdetail_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/shop/shop_list_detail.dart';
import 'package:feelverapp/util/SizeConfig.dart';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:url_launcher/url_launcher.dart';


class ShoplistdetailPresenter extends BasePresenter<ShopListDetail>{
  Api _api;
  final formkey = GlobalKey<FormState>();
  shoplistdetailModel model;
  AddfavModel addmodel;
  bool fav=false;
  ShoplistdetailPresenter(State<ShopListDetail> state) : super(state);
 String uid;





  Detai(String id) async{
   
    _api = Api<shoplistdetailModel>();
    var res = await _api.shoplistDetail({
      "id": id,
    });
      
    if (res.fail == null) {
        setState(() {
        model = res.success;
        print("complete");

  
      });
      print('res Success');
    } else {
      print('res Fail');
    }
  }

 getid() async {
    SharedPreferences pref = await SharedPreferences.getInstance();
    setState(() {
      uid = pref.getString('Id');
    });
    return uid;
  }
  Addfav(String id) async{
   LoadingView(state.context).show();
    _api = Api<AddfavModel>();
    var res = await _api.addfav({
      "customer_id": uid,
      "store_id":id,
      "vendor_id":id,
      "product_id":id,

    });
       LoadingView(state.context).hide();
    if (res.fail == null) {
        setState(() {
        addmodel = res.success;
        print("complete");
      fav=true;
  
      });
         showDialog(
                      context: state.context,
                      builder: (context) {
                        Future.delayed(Duration(seconds: 1), () {
                          Navigator.of(context).pop(true);
                        });
                        return AlertDialog(
                         content:ImageIcon(
                    AssetImage('assets/images/ic_fav_list.png'),
                    color:fav?Color(0xFFDD175F): Colors.grey,
                    size: SizeConfig.getFontSize(30),
                  ) ,
                          title:Center(child: Text('บันทึกสำเร็จ')),
                        );
                      });
    } else {
      print('res Fail');
    }
  }



   gotoDirection(String lat,String lng){

print("debug");
    print(lat);
        print(lng);

    launch('https://www.google.com/maps/dir/?api=1&destination=${lat},${lng}');
  }

}