import 'package:autosos_flutter/api/login_api.dart';
import 'package:autosos_flutter/util/sp_util.dart';
import 'package:flutter/material.dart';



class LoginPage extends StatefulWidget {
  const LoginPage({super.key});

  @override
  State<LoginPage> createState() => _LoginPageState();
}

class _LoginPageState extends State<LoginPage> {
  final TextEditingController _unameController = TextEditingController();
  final TextEditingController _pwdController = TextEditingController();
  SPUtil spUtil = SPUtil();
  @override
  Widget build(BuildContext context) {
    _unameController.text = "14725803690";
    _pwdController.text = "123456";
    return Scaffold(
      appBar: AppBar(),
      body: Column(
        children: [
          ListTile(
            leading: Image.asset(
              "images/1.5x/ic_launcher.png",
              height: 54,
              width: 54,
            ),
            title: const Text(
              "欢迎登陆啾啾救援",
              style: TextStyle(fontSize: 23, fontWeight: FontWeight.bold),
            ),
            subtitle: const Text(
              "宁波易到互联科技有限公司",
              style: TextStyle(
                fontSize: 13,
              ),
            ),
          ),
          Padding(
            padding: const EdgeInsets.all(20),
            child: Row(
              children: [
                const Text(
                  "+86",
                  style: TextStyle(fontSize: 16, color: Color(0xFF1D1D1D)),
                ),
                Padding(
                  padding: const EdgeInsets.all(15),
                  child: Container(
                    height: 20,
                    width: 1,
                    color: Colors.grey,
                  ),
                ),
                Expanded(
                    child: TextField(
                      controller: _unameController,
                      decoration: const InputDecoration(hintText: "请输入手机号"),
                    )),
              ],
            ),
          ),
          Padding(
            padding: const EdgeInsets.all(20),
            child: Row(
              children: [
                Expanded(
                    child: TextField(
                      obscureText: true,
                      controller: _pwdController,
                      decoration: const InputDecoration(hintText: "请输入密码"),
                    ))
              ],
            ),
          ),
          Padding(
              padding: const EdgeInsets.all(20),
              child: GestureDetector(
                  onTap:()=>_login(context),
                  child: Container(
                  padding: const EdgeInsets.all(12),
                  margin: const EdgeInsets.only(top: 40),
                  width: MediaQuery
                      .of(context)
                      .size
                      .width,
                  decoration: BoxDecoration(color: Colors.grey,
                      borderRadius: BorderRadius.circular(21)),
                  child: const Center(
                      child: Text(
                        "登录",
                        style: TextStyle(
                            fontSize: 18, fontWeight: FontWeight.bold),
                      ))),)
          )
        ],
      ),
    );
  }

  void _login(BuildContext context) async{
    String username = _unameController.text;
    String password = _pwdController.text;
    String cid = spUtil.get("clientId");
    LoginApi.login(context,1, username, password, "", cid, "", "");
  }
}
