import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'package:get/get_core/src/get_main.dart';
import 'package:location/module/main/main_page.dart';
import 'package:location/resource/string.gen.dart';
import 'package:location/router/app_pages.dart';
import 'package:location/utils/common_expand.dart';

import '../resource/assets.gen.dart';
import '../resource/colors.gen.dart';
import '../utils/common_util.dart';

class AccountReplaceDialog {
  static const String _tag = 'AccountReplaceDialog';

  static void show() {
    SmartDialog.show(
        backDismiss: false,
        builder: (_) => _AccountReplaceView(),
        tag: _tag,
        clickMaskDismiss: false);
  }

  static void dismiss() {
    SmartDialog.dismiss(tag: _tag);
  }
}

class _AccountReplaceView extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      width: 274.w,
      decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(16.r),
          border: Border.all(
            color: Colors.white,
            width: 2.w,
          ),
          gradient: LinearGradient(
              begin: Alignment.topCenter,
              end: Alignment.bottomCenter,
              colors: [
                '#E4E4FF'.color,
                '#FFFFFF'.color,
              ])),
      child: Stack(
        alignment: Alignment.center,
        children: [
          Positioned(
              top: 16.w,
              right: 16.w,
              child: GestureDetector(
                onTap: onKnowClick,
                child: Assets.images.iconDialogClose2
                    .image(width: 20.w, height: 20.w),
              )),
          buildAccountReplaceContent(),
        ],
      ),
    );
  }

  Widget buildAccountReplaceContent() {
    return IntrinsicHeight(
      child: Column(
        children: [
          SizedBox(height: 33.w),
          Assets.images.iconAccountReplaceLogo.image(height: 76.w),
          SizedBox(height: 29.w),
          Text(StringName.accountReplaceTitle,
              style: TextStyle(
                  fontSize: 17.sp,
                  color: '#333333'.color,
                  fontWeight: FontWeight.bold)),
          SizedBox(height: 8.w),
          Text(StringName.accountReplaceDesc,
              style: TextStyle(fontSize: 14.sp, color: '#999999'.color)),
          SizedBox(height: 20.w),
          GestureDetector(
            onTap: onKnowClick,
            child: Container(
              width: 229.w,
              height: 43.w,
              decoration: BoxDecoration(
                color: ColorName.colorPrimary,
                borderRadius: BorderRadius.circular(100.r),
              ),
              child: Center(
                child: Text(StringName.accountReplaceBtnTxt,
                    style: TextStyle(
                        fontSize: 14.sp,
                        color: Colors.white,
                        fontWeight: FontWeight.w500)),
              ),
            ),
          ),
          SizedBox(height: 20.w),
        ],
      ),
    );
  }


  void onKnowClick() {
    //清空至首页
    backToSpecificPage(RoutePath.mainTab);
    AccountReplaceDialog.dismiss();
  }
}
