import 'package:feelverapp/ui/home/home.dart';
import 'package:feelverapp/ui/login/login.dart';
import 'package:feelverapp/util/SizeConfig.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class RegisterPage extends StatefulWidget {
  @override
  _RegisterPageState createState() => _RegisterPageState();
}

class _RegisterPageState extends State<RegisterPage> with TickerProviderStateMixin {
  @override
  TabController _tabController;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();

    _tabController = TabController(length: 2, vsync: this);
//    registerBloc = RegisterBloc(this);
//    loginBloc = LoginBloc(this);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: _setupView(),
    );
  }

  _setupView() {
    return SingleChildScrollView(
      child: Column(
        children: <Widget>[
          Container(
            padding: EdgeInsets.only(
                left: SizeConfig.getPadding(60),
                right: SizeConfig.getPadding(40),
                top: SizeConfig.getPadding(60)),
            child: Image.asset(
              'assets/images/logo.png',
              width: SizeConfig.getWidth(MediaQuery.of(context).size.width),
              fit: BoxFit.fitWidth,
            ),
          ),
          SizedBox(
            height: SizeConfig.getWidth(24),
          ),
          TabBar(
            indicatorColor: Color.fromRGBO(106, 179, 170, 1),
            unselectedLabelColor: Colors.grey[400],
            labelColor: Colors.black,
            controller: _tabController,
//          onTap: (v) => registerBloc.changeMethodRegister(v),
            tabs: <Widget>[
              Tab(
                child: Text(
                  'อีเมล์',
                  style: TextStyle(
                    fontSize: SizeConfig.getFontSize(16),
                  ),
                ),
              ),
              Tab(
                child: Text(
                  'เบอร์โทร',
                  style: TextStyle(fontSize: SizeConfig.getFontSize(16)),
                ),
              ),
            ],
          ),
          SizedBox(height: SizeConfig.getWidth(30)),
          _formLogin(),
        ],
      ),
    );
  }

  Widget _formLogin() {
    return Container(
      child: Form(
        child: Column(
          children: <Widget>[
            Container(
              alignment: Alignment.topLeft,
              padding: EdgeInsets.only(left: SizeConfig.getPadding(30)),
              child: Text(
                'อีเมล์',
                style: TextStyle(
                    color: Colors.black,
                    fontSize: SizeConfig.getFontSize(20),
                    fontFamily: "SF_Pro_Text",
                    fontWeight: FontWeight.w500),
              ),
            ),
            Padding(
              padding: EdgeInsets.symmetric(
                vertical: SizeConfig.getPadding(8.0),
                horizontal: SizeConfig.getPadding(24),
              ),
              child: Card(
                shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.circular(
                    SizeConfig.getPadding(50.0),
                  ),
                ),
                child: TextFormField(
//                  controller: loginBloc.emailCtrl,
//                  validator: loginBloc.validateField,
                  decoration: InputDecoration(
                    contentPadding: EdgeInsets.symmetric(
                      vertical: SizeConfig.getPadding(20),
                      horizontal: SizeConfig.getPadding(16),
                    ),
//                    hintText:
//                    allTranslations.text(key2: 'email', key: 'login') +
//                        ' / ' +
//                        allTranslations.text(
//                            key2: 'tel_number', key: 'register'),
                    border: OutlineInputBorder(borderSide: BorderSide.none),
                  ),
                ),
              ),
            ),
            Container(
              alignment: Alignment.topLeft,
              padding: EdgeInsets.only(left: SizeConfig.getPadding(30)),
              child: Text(
                'รหัสผ่าน',
                style: TextStyle(
                    color: Colors.black,
                    fontSize: SizeConfig.getFontSize(20),
                    fontFamily: "SF_Pro_Text",
                    fontWeight: FontWeight.w500),
              ),
            ),
            Padding(
              padding: EdgeInsets.symmetric(
                  vertical: SizeConfig.getPadding(8.0),
                  horizontal: SizeConfig.getPadding(24)),
              child: Card(
                shape: RoundedRectangleBorder(
                  borderRadius:
                  BorderRadius.circular(SizeConfig.getPadding(50.0)),
                ),
                child: TextFormField(
//                  controller: loginBloc.passCtrl,
//                  validator: loginBloc.validateField,
                  decoration: InputDecoration(
                    contentPadding: EdgeInsets.symmetric(
                      vertical: SizeConfig.getPadding(20),
                      horizontal: SizeConfig.getPadding(16),
                    ),
//                    hintText:
//                    allTranslations.text(key2: 'password', key: 'login'),
                    border: OutlineInputBorder(borderSide: BorderSide.none),
                  ),
                  obscureText: true,
                ),
              ),
            ),
            Container(
              alignment: Alignment.topLeft,
              padding: EdgeInsets.only(left: SizeConfig.getPadding(30)),
              child: Text(
                'ชื่อ',
                style: TextStyle(
                    color: Colors.black,
                    fontSize: SizeConfig.getFontSize(20),
                    fontFamily: "SF_Pro_Text",
                    fontWeight: FontWeight.w500),
              ),
            ),
            Padding(
              padding: EdgeInsets.symmetric(
                vertical: SizeConfig.getPadding(8.0),
                horizontal: SizeConfig.getPadding(24),
              ),
              child: Card(
                shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.circular(
                    SizeConfig.getPadding(50.0),
                  ),
                ),
                child: TextFormField(
//                  controller: loginBloc.emailCtrl,
//                  validator: loginBloc.validateField,
                  decoration: InputDecoration(
                    contentPadding: EdgeInsets.symmetric(
                      vertical: SizeConfig.getPadding(20),
                      horizontal: SizeConfig.getPadding(16),
                    ),
//                    hintText:
//                    allTranslations.text(key2: 'email', key: 'login') +
//                        ' / ' +
//                        allTranslations.text(
//                            key2: 'tel_number', key: 'register'),
                    border: OutlineInputBorder(borderSide: BorderSide.none),
                  ),
                ),
              ),
            ),  Container(
              alignment: Alignment.topLeft,
              padding: EdgeInsets.only(left: SizeConfig.getPadding(30)),
              child: Text(
                'นามสกุล',
                style: TextStyle(
                    color: Colors.black,
                    fontSize: SizeConfig.getFontSize(20),
                    fontFamily: "SF_Pro_Text",
                    fontWeight: FontWeight.w500),
              ),
            ),
            Padding(
              padding: EdgeInsets.symmetric(
                vertical: SizeConfig.getPadding(8.0),
                horizontal: SizeConfig.getPadding(24),
              ),
              child: Card(
                shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.circular(
                    SizeConfig.getPadding(50.0),
                  ),
                ),
                child: TextFormField(
//                  controller: loginBloc.emailCtrl,
//                  validator: loginBloc.validateField,
                  decoration: InputDecoration(
                    contentPadding: EdgeInsets.symmetric(
                      vertical: SizeConfig.getPadding(20),
                      horizontal: SizeConfig.getPadding(16),
                    ),
//                    hintText:
//                    allTranslations.text(key2: 'email', key: 'login') +
//                        ' / ' +
//                        allTranslations.text(
//                            key2: 'tel_number', key: 'register'),
                    border: OutlineInputBorder(borderSide: BorderSide.none),
                  ),
                ),
              ),
            ),
            SizedBox(
              height: SizeConfig.getWidth(24),
            ),
            _submitLoginButton(),
            _policyText(),
            SizedBox(
              height: SizeConfig.getWidth(20),
            ),
            _facebookLoginButton(),
          ],
        ),
      ),
    );
  }

  _submitLoginButton() {
    return Padding(
      padding: EdgeInsets.symmetric(
          vertical: SizeConfig.getPadding(10.0),
          horizontal: SizeConfig.getPadding(32)),
      child: Container(
        height: SizeConfig.getWidth(55),
        child: CupertinoButton(
          color: Color.fromRGBO(106, 179, 170, 1),
          padding: EdgeInsets.all(0),
          borderRadius: BorderRadius.all(Radius.circular(50)),
          onPressed: () {
            Navigator.push(
              context,
              MaterialPageRoute(builder: (context) => LoginPage()),
            );
//            if (loginBloc.formKey.currentState.validate()) {
//              loginBloc.getLogin();
//            }
          },
          child: Center(
            child: Text(
              'สมัครสมาชิก',
              style: TextStyle(color: Colors.white),
            ),
          ),
        ),
      ),
    );
  }

  Widget _facebookLoginButton() {
    return Padding(
      padding: EdgeInsets.symmetric(
          vertical: SizeConfig.getPadding(16.0),
          horizontal: SizeConfig.getPadding(32)),
      child: Container(
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(SizeConfig.getPadding(50)),
          color: Color(0xff3b5998),
        ),
        height: SizeConfig.getWidth(55),
        child: CupertinoButton(
          color: Color(0xff3b5998),
          padding: EdgeInsets.all(0),
//          onPressed: loginBloc.getFacebookLogin,
          child: Center(
            child: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Padding(
                  padding: EdgeInsets.symmetric(
                      horizontal: SizeConfig.getPadding(8.0)),
                  child: ImageIcon(
                    AssetImage('assets/images/facebook-icon.png'),
                    size: 20,
                  ),
                ),
                Text(
                  'Login with Facebook',
                  style: TextStyle(fontSize: SizeConfig.getFontSize(12)),
                  textAlign: TextAlign.center,
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }

  Widget _policyText() {
    return Column(
      children: <Widget>[
        Stack(
          children: <Widget>[
            Container(
              padding: EdgeInsets.only(
                  left: SizeConfig.getPadding(30),
                  right: SizeConfig.getPadding(30),
                  top: SizeConfig.getPadding(30)),
              child: Center(
                child: Text(
                  'คุณยอมรับ ข้อกำหนดการใช้งาน และ นโยบายความเป็นส่วนตัว ของอโกด้าเมื่อดำเนินการต่อ',
                  style: TextStyle(fontSize: SizeConfig.getFontSize(12)),
                  textAlign: TextAlign.center,
                ),
              ),
            ),
            Container(
              margin: EdgeInsets.only(
                  right: SizeConfig.getPadding(34),
                  top: SizeConfig.getPadding(47)),
              alignment: Alignment.centerRight,
              child: GestureDetector(
                onTap: () {
//                  Navigator.push(
//                    context,
//                    MaterialPageRoute(builder: (context) => RegisterPage()),
//                  );
                },
                child: Text(
                  'สมัครสมาชิก',
                  style: TextStyle(
                    color: Colors.orange,
                    fontSize: SizeConfig.getFontSize(12),
                    fontFamily: "SF_Pro_Text",
                    fontWeight: FontWeight.w600,
                    decoration: TextDecoration.underline,
                  ),
                  textAlign: TextAlign.right,
                ),
              ),
            )
          ],
        ),
        Container(
          padding: EdgeInsets.all(SizeConfig.getPadding(24)),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Expanded(
                flex: 2,
                child: Container(
                  decoration: BoxDecoration(
                    border: Border(
                      bottom: BorderSide(width: 1, color: Color(0xFFE6E6E6)),
                    ),
                  ),
                ),
              ),
              Expanded(
                flex: 1,
                child: Text(
                  'หรือ',
                  style: TextStyle(fontSize: SizeConfig.getFontSize(12)),
                  textAlign: TextAlign.center,
                ),
              ),
              Expanded(
                flex: 2,
                child: Container(
                  decoration: BoxDecoration(
                    border: Border(
                      bottom: BorderSide(width: 1, color: Color(0xFFE6E6E6)),
                    ),
                  ),
                ),
              ),
            ],
          ),
        ),
        Stack(
          children: <Widget>[
            Container(
              padding: EdgeInsets.only(
                  left: SizeConfig.getPadding(60),
                  right: SizeConfig.getPadding(60)),
              child: Center(
                child: Text(
                  'สะดวกสุดๆ แค่ใช้ Facebook เข้าสู่ระบบ ก็ไม่ต้องจำรหัสผ่านอีกต่อไป คลิกปุ่มด้านล่างได้เลย',
                  style: TextStyle(fontSize: SizeConfig.getFontSize(12)),
                  textAlign: TextAlign.center,
                ),
              ),
            ),
          ],
        ),
      ],
    );
  }
}
