import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:liftmanager/internal/team/model/team_info_item.dart';
import 'package:liftmanager/internal/team/team_router.dart';
import 'package:liftmanager/net/api_service.dart';
import 'package:liftmanager/res/colors.dart';
import 'package:liftmanager/res/gaps.dart';
import 'package:liftmanager/routers/fluro_navigator.dart';
import 'package:liftmanager/utils/image_utils.dart';
import 'package:liftmanager/utils/theme_utils.dart';
import 'package:liftmanager/utils/toast.dart';
import 'package:liftmanager/widgets/app_bar.dart';
import 'package:liftmanager/widgets/click_item.dart';

class TeamCardPage extends StatefulWidget {

  @override
  State<StatefulWidget> createState() {
    return TeamCardPageState();
  }
}

class TeamCardPageState extends State<TeamCardPage> {
  TeamInfoItem item = TeamInfoItem();

  @override
  void initState() {
    super.initState();
    getTeamInfo();
  }

  @override
  void dispose() {
    super.dispose();

  }

  getTeamInfo(){
    ApiService(context: context).teamDetail(onSuccess: (res){
      item = res;
      setState(() {

      });
    },onError: (code,msg){
      toasts(msg);
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: MyAppBar(
          centerTitle: "我的团队",
          actions: <Widget>[
            Offstage(
              offstage: !item.managerFlag,
              child: FlatButton(
                child: Text("认证信息"),
                textColor: Colours.dark_text,
                highlightColor: Colors.transparent,
                onPressed: () {
                  if(item.isCertificated == 0){
                    NavigatorUtils.push(context, TeamRouter.teamAuthUploadPage);
                  }else{
                    NavigatorUtils.push(context, TeamRouter.teamAuthPage);
                  }

                },
              )
            )

          ],
        ),
        body: ListView(padding: EdgeInsets.all(0.0), children: <Widget>[
          Container(
            padding: EdgeInsets.only(top: 10,bottom: 20),
            color: ThemeUtils.getTabsBg(context),
            child: Center(
              child: CircleAvatar(
                  radius: 30.0,
                  backgroundColor: Colors.transparent,
                  backgroundImage: ImageUtils.getImageProvider(
                      item.logoImg)),
            ),
          ),
          Container(
            padding: EdgeInsets.only(bottom: 20),
            color: ThemeUtils.getTabsBg(context),
            child: Center(
                child: Container(
                  padding: EdgeInsets.fromLTRB(8, 2, 8, 2),
                  decoration: BoxDecoration(
                      color: Colours.app_main,
                      borderRadius: BorderRadius.circular(12)),
                  child: Text(
                      item.isCertificated == 1
                          ? "已认证"
                          : item.isCertificated == 2 ? "审核中" : "未认证",
                      style: TextStyle(
                          fontSize: 10,
                          color: Colors.white,
                          fontWeight: FontWeight.bold)),
                )),
          ),
          Gaps.vGap12,
          ClickItem(title: "团队名", content: "${item.name}"),
          ClickItem(title: "联系人", content: "${item.corporator}"),
          ClickItem(title: "联系电话", content: "${item.telephone}"),
          Container(
            margin: EdgeInsets.only(top: 8, bottom: 8),
            child: ClickItem(
              title: "团队描述",
              content: "${item.remarks}",
            ),
          ),
//          Padding(
//            padding: const EdgeInsets.all(16),
//            child: MyButton(
//              fontSize: 14,
//              onPressed: () {
//                _joinTeamDialog();
//              },
//              text: "加入团队",
//            ),
//          )
        ]));
  }
}
