import 'dart:io';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:yumi/app_localizations.dart';
import 'package:yumi/ui_kit/components/sc_debounce_widget.dart';
import 'package:yumi/shared/tools/sc_loading_manager.dart';
import 'package:yumi/shared/data_sources/sources/local/user_manager.dart';
import 'package:yumi/shared/data_sources/sources/repositories/sc_user_repository_impl.dart';

import 'package:yumi/ui_kit/components/appbar/socialchat_appbar.dart';
import 'package:yumi/ui_kit/components/text/sc_text.dart';
import 'package:yumi/app/routes/sc_fluro_navigator.dart';
import 'package:yumi/modules/user/settings/settings_route.dart';

class SetAccountPage extends StatefulWidget {
  @override
  _SetAccountPageState createState() => _SetAccountPageState();
}

class _SetAccountPageState extends State<SetAccountPage> {
  @override
  Widget build(BuildContext context) {
    return Stack(
      children: [
        Image.asset(
          "sc_images/person/sc_icon_edit_userinfo_bg.png",
          width: ScreenUtil().screenWidth,
          height: ScreenUtil().screenHeight,
          fit: BoxFit.fill,
        ),
        Scaffold(
          backgroundColor: Colors.transparent,
          resizeToAvoidBottomInset: false,
          appBar: SocialChatStandardAppBar(title: SCAppLocalizations.of(context)!.setAccount, actions: []),
          body: SafeArea(top: false,child:Column(
            children: [
              Container(
                alignment: Alignment.bottomLeft,
                margin: EdgeInsets.only(left: 15.w),
                child: text(
                  SCAppLocalizations.of(context)!.account,
                  textColor: Colors.black38,
                  fontSize: 12.sp,
                ),
              ),
              Container(
                padding: EdgeInsets.symmetric(vertical: 12.w),
                margin: EdgeInsets.symmetric(vertical: 8.w, horizontal: 15.w),
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(12),
                  color: Color(0xff18F2B1).withOpacity(0.1),
                ),
                child: Column(
                  children: [
                    SCDebounceWidget(
                      onTap: () {
                        SCLoadingManager.show();
                        SCAccountRepository().accountIsBind().then((value) {
                          SCLoadingManager.hide();
                          if (value) {
                            ///修改密码
                            SCNavigatorUtils.push(
                              context,
                              SettingsRoute.resetPwd,
                              replace: false,
                            );
                          } else {
                            ///设置密码
                            SCNavigatorUtils.push(
                              context,
                              SettingsRoute.setPwd,
                              replace: false,
                            );
                          }
                        }).catchError((_){
                          SCLoadingManager.hide();
                        });
                      },
                      child: Row(
                        children: [
                          SizedBox(width: 18.w),
                          text(
                            SCAppLocalizations.of(context)!.account,
                            textColor: Colors.white,
                            fontSize: 13.sp,
                          ),
                          Spacer(),
                          text(
                            AccountStorage()
                                .getCurrentUser()
                                ?.userProfile
                                ?.account ??
                                "",
                            fontSize: 13.sp,
                            textColor: Colors.white54,
                          ),
                          SizedBox(width: 5.w),
                          Icon(
                            Icons.keyboard_arrow_right,
                            size: 15.w,
                            color: Colors.white54,
                          ),
                          SizedBox(width: 18.w),
                        ],
                      ),
                    ),
                    Divider(color: Colors.white54, thickness: 0.5),
                    Platform.isIOS
                        ? Row(
                      children: [
                        SizedBox(width: 18.w),
                        text(
                          SCAppLocalizations.of(context)!.apple,
                          textColor: Colors.white,
                          fontSize: 13.sp,
                        ),
                        Spacer(),
                        Icon(
                          Icons.keyboard_arrow_right,
                          size: 15.w,
                          color: Colors.black26,
                        ),
                        SizedBox(width: 18.w),
                      ],
                    )
                        : Container(),
                    Platform.isIOS
                        ? Divider(color: Colors.white54, thickness: 0.5)
                        : Container(),
                    SCDebounceWidget(child: Row(
                      children: [
                        SizedBox(width: 18.w),
                        text(
                          SCAppLocalizations.of(context)!.google,
                          textColor: Colors.white,
                          fontSize: 13.sp,
                        ),
                        Spacer(),
                        Icon(
                          Icons.keyboard_arrow_right,
                          size: 15.w,
                          color: Colors.white54,
                        ),
                        SizedBox(width: 18.w),
                      ],
                    ),onTap: (){

                    },) ,
                  ],
                ),
              ),
            ],
          ) ,),
        ),
      ],
    );
  }
}
