import 'package:flutter/material.dart';
import 'package:zhiying_base_widget/pages/account_delete_page/account_delete_page_bloc.dart';
import 'package:zhiying_base_widget/pages/account_delete_page/model/account_delete_page_model.dart';
import 'package:zhiying_base_widget/utils/contants.dart';
import 'package:zhiying_comm/util/base_bloc.dart';
import 'package:zhiying_comm/util/extension/color.dart';
import 'package:zhiying_comm/util/global_config.dart';

class AccountDeletePage extends StatelessWidget {
  final Map<String, dynamic> model;

  const AccountDeletePage(this.model, {Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return BlocProvider(
        bloc: AccountDeletePageBloc(),
        child: AccountDeletePageContainer(
          model: model,
        ));
  }
}

class AccountDeletePageContainer extends StatefulWidget {
  final Map<String, dynamic> model;

  const AccountDeletePageContainer({Key key, this.model}) : super(key: key);

  @override
  _AccountDeletePageContainerState createState() => _AccountDeletePageContainerState();
}

class _AccountDeletePageContainerState extends State<AccountDeletePageContainer> {
  AccountDeletePageBloc _bloc;

  @override
  void initState() {
    _bloc = BlocProvider.of<AccountDeletePageBloc>(context);
    _bloc.loadData(widget.model[GlobalConfig.SKIP_IDENTIFIER]);
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return StreamBuilder(
        stream: _bloc.outData,
        builder: (context, asycn) {
          AccountDeletePageModel model = asycn.data;
          return Scaffold(
              appBar: AppBar(
                elevation: 0,
                leading: Navigator.canPop(context)
                    ? IconButton(
                        icon: Icon(
                          Icons.arrow_back_ios,
                          color: HexColor.fromHex(model?.appBarNameColor),
                          size: 22,
                        ),
                        onPressed: () {
                          Navigator.pop(context);
                        })
                    : Container(),
                backgroundColor: HexColor.fromHex(model?.appBarBgColor),
                centerTitle: true,
                title: Text(
                  model?.appBarName ?? "",
                  style: TextStyle(color: HexColor.fromHex(model?.appBarNameColor), fontSize: 15, fontWeight: FontWeight.w600),
                ),
              ),
              body: Column(
                children: <Widget>[
                  Expanded(
                      child: ListView(
                    shrinkWrap: true,
                    children: <Widget>[
                      Container(
                        margin: EdgeInsets.only(left: 12, right: 12, top: 8),
                        padding: EdgeInsets.all(12),
                        decoration: BoxDecoration(color: HexColor.fromHex(model?.bgColor ?? ""), borderRadius: BorderRadius.circular(8)),
                        child: Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: <Widget>[
                            Text(
                              model?.tips?.title ?? "",
                              style: TextStyle(color: HexColor.fromHex(model?.tips?.titleColor ?? ""), fontSize: 15, fontWeight: FontWeight.w600),
                            ),
                            Text(
                              model?.tips?.subtitle ?? "",
                              style: TextStyle(color: HexColor.fromHex(model?.tips?.subtitleColor ?? ""), fontSize: 14, fontWeight: FontWeight.w600),
                            ),
                            ListView.builder(
                                itemCount: model?.tips?.textList?.length ?? 0,
                                shrinkWrap: true,
                                physics: NeverScrollableScrollPhysics(),
                                itemBuilder: (context, index) {
                                  var item = model?.tips?.textList[index];
                                  return Container(
                                    margin: EdgeInsets.only(top: 4, bottom: 4),
                                    child: Row(
                                      children: <Widget>[
                                        Expanded(
                                          child: Text(
                                            item?.text ?? "",
                                            style: TextStyle(color: HexColor.fromHex(item?.color ?? ""), fontSize: 13, fontWeight: FontWeight.w600),
                                          ),
                                        )
                                      ],
                                    ),
                                  );
                                })
                          ],
                        ),
                      )
                    ],
                  )),
                  Row(
                    children: <Widget>[
                      SizedBox(
                        width: 12,
                      ),
                      Expanded(
                        child: Container(
                          height: 45,
                          child: FlatButton(
                              shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(40)),
                              color: HexColor.fromHex(model?.buttom?.left?.bgColor ?? ""),
                              onPressed: () {
                                _bloc.deleteAccount(context);
                              },
                              child: Text(
                                model?.buttom?.left?.text ?? "",
                                style: TextStyle(color: HexColor.fromHex(model?.buttom?.left?.textColor)),
                              )),
                        ),
                      ),
                      SizedBox(
                        width: 8,
                      ),
                      Expanded(
                        child: Container(
                          height: 45,
                          child: FlatButton(
                              shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(40)),
                              color: HexColor.fromHex(model?.buttom?.right?.bgColor ?? ""),
                              onPressed: () {
                                Navigator.pop(context);
                              },
                              child: Text(
                                model?.buttom?.right?.text ?? "",
                                style: TextStyle(color: HexColor.fromHex(model?.buttom?.right?.textColor)),
                              )),
                        ),
                      ),
                      SizedBox(
                        width: 12,
                      ),
                    ],
                  ),
                  SizedBox(
                    height: 16,
                  )
                ],
              ));
        });
  }
}
