import 'package:chat/data/constants.dart';
import 'package:chat/generated/i18n.dart';
import 'package:chat/utils/CustomUI.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

import 'package:oktoast/oktoast.dart';

class VerificationPage extends StatefulWidget {
  final List applyList;
  VerificationPage({Key key, this.applyList}) : super(key: key);
  _VerificationPageState createState() => _VerificationPageState();
}

class _VerificationPageState extends State<VerificationPage> {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    Widget appBar = new AppBar(
      title: new Text(
        I18n.of(context).check_incode,
        textScaleFactor: 1.0,
      ),
      centerTitle: true,
      leading: CustomUI.buildCustomLeading(context),
    );
    return Scaffold(
      body: SafeArea(
          child: Center(
        child: Container(
          height: MediaQuery.of(context).size.height,
          width: MediaQuery.of(context).size.width,
          child: _buildBody(),
        ),
      )),
      appBar: appBar,
      resizeToAvoidBottomPadding: false,
    );
  }

  Widget _buildBody() {
    return widget.applyList.length == 0
        ? CustomUI.buildNoData(context)
        : ListView(
            children: widget.applyList == null
                ? []
                : widget.applyList.map((item) {
                    return item['Status'] == 0
                        ? Container()
                        : _buildResult(item);
                  }).toList(),
          );
  }

  Widget _buildResult(data) {
    bool isSucess = data['Status'] == 1;
    Widget tip = Container(
      margin: EdgeInsets.only(top: 25.5, bottom: 44),
      child: Text(
        isSucess
            ? I18n.of(context).successful_application1
            : I18n.of(context).application_failed1,
        textScaleFactor: 1.0,
        style: TextStyle(
            color: isSucess ? const Color(0xFF2D81FF) : const Color(0xFFFF4523),
            fontSize: 22),
      ),
    );
    Widget success = Column(
      children: <Widget>[
        Container(
          margin: EdgeInsets.only(bottom: 22),
          width: MediaQuery.of(context).size.width,
          alignment: Alignment.center,
          child: Text(
            I18n.of(context).your_incode,
            textScaleFactor: 1.0,
            style: TextStyle(
                color: Constants.BlackTextColor,
                fontSize: 17,
                fontWeight: FontWeight.w500),
          ),
        ),
        Container(
          decoration: BoxDecoration(
              border: Border(
                  bottom:
                      BorderSide(width: 1, color: const Color(0xFFFF4523)))),
          child: Text(
            data['Code'],
            textScaleFactor: 1.0,
            style: TextStyle(color: const Color(0xFFFF4523), fontSize: 33.36),
          ),
        ),
        InkWell(
            onTap: () {
              ClipboardData clipboardData =
                  new ClipboardData(text: data['Code']);
              Clipboard.setData(clipboardData);
              showToast(I18n.of(context).successful_copy);
            },
            child: Container(
              alignment: Alignment.center,
              margin: EdgeInsets.only(top: 60),
              padding: EdgeInsets.only(top: 5, left: 20, right: 20, bottom: 5),
              width: 198.05,
              height: 32.85,
              decoration: BoxDecoration(
                  color: const Color(0xFF2D81FF),
                  borderRadius: BorderRadius.all(Radius.circular(30))),
              child: Text(
                I18n.of(context).copy,
                textScaleFactor: 1.0,
                style: TextStyle(color: Colors.white),
              ),
            )),
      ],
    );

    Widget fail = Align(
      child: Padding(
        padding: EdgeInsets.only(left: 80, right: 80),
        child: Text(
          I18n.of(context).application_failed,
          textScaleFactor: 1.0,
          textAlign: TextAlign.center,
          style: TextStyle(color: const Color(0xFFB3B3B3)),
        ),
      ),
    );
    return Stack(
      children: <Widget>[
        Container(
          child: Image.asset('assets/images/yqm_bg.png'),
          margin: EdgeInsets.only(left: 41, right: 41, top: 20.5),
        ),
        Container(
            margin: EdgeInsets.only(top: 20.5),
            child: Column(
              children: <Widget>[tip, isSucess ? success : fail],
            ))
      ],
    );
  }
}
