import 'package:flutter/material.dart';
import 'package:flutter_wallet/generated/l10n.dart';
import 'package:flutter_wallet/login/view/YSHelpView.dart';
import '../tools/YSColors.dart';
import '../tools/YSTools.dart';

class YSBase extends StatefulWidget {
  final Color? ysColor;
  final bool isTab;
  final String ysTitle;
  final Widget? ysRightWidget;
  final Widget? ysLeftWidget;
  final Widget? ysChild;
  final bool isBake;
  const YSBase({Key? key, this.ysColor, this.isTab = false, this.ysTitle = '', this.ysRightWidget, this.ysChild, this.isBake = false, this.ysLeftWidget}) : super(key: key);

  @override
  YSBaseState createState() => YSBaseState();
}

class YSBaseState extends State<YSBase> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: widget.ysColor??YSColors.containColor(context),
      body: GestureDetector(
        onTap: (){
          FocusScope.of(context).unfocus();
        },
        child: SizedBox(
          width: ysWidth(context),
          height: ysHeight(context),
          child: SingleChildScrollView(
            child: Stack(
              children: [
                Container(
                  height: ysTOP(context)+70,
                  padding: EdgeInsets.only(left: hsp(20),right: hsp(20),top: ysTOP(context)),
                  decoration: BoxDecoration(
                    gradient: LinearGradient(
                        colors: [YSColors.buttonColor(context),YSColors.buttonColor(context)]
                    )
                  ),
                  child: LayoutBuilder(
                    builder: (context,conSize){
                      return Row(
                        children: [
                          Container(
                            width: hsp(75),
                            alignment: Alignment.centerLeft,
                            child: widget.isTab==true?SizedBox(
                              width: hsp(30),
                            ):widget.ysLeftWidget??GestureDetector(
                              onTap: (){
                                Navigator.pop(context);
                              },
                              child: Row(
                                children: [
                                  Icon(Icons.chevron_left,size: zsp(30),color: YSColors.contain2Color(context),),
                                  Text(S.current.FANHUI,style: YSColors.content2Style(context),)
                                ],
                              )
                            ),
                          ),
                          Container(
                            width: conSize.maxWidth-hsp(150),
                            padding: EdgeInsets.only(left: hsp(20),right: hsp(20)),
                            alignment: Alignment.center,
                            child: widget.isBake==true?Image.asset(
                              YSColors.imageStyle(context, '资源 3'),
                              width: hsp(150),
                              height: hsp(30),
                            ):Text(widget.ysTitle.fixAutoLines(),style: YSColors.title2Style(context),maxLines: 1,),
                          ),
                          Container(
                            width: hsp(75),
                            alignment: Alignment.centerRight,
                            child: widget.ysRightWidget??Container(),
                          )
                        ],
                      );
                    },
                  ),
                ),
                Padding(
                  padding: EdgeInsets.only(top: ysTOP(context)+60),
                  child: ClipRRect(
                    borderRadius: const BorderRadius.only(topLeft: Radius.circular(10),topRight: Radius.circular(10)),
                    child: Container(
                      height: ysHeight(context)-ysTOP(context)-(widget.isTab?130:60),
                      width: ysWidth(context),
                      color: YSColors.backgroundColor(context),
                      child: SingleChildScrollView(
                          child: widget.ysChild
                      ),
                    ),
                  ),
                )
              ],
            ),
          ),
        ),
      ),
    );
  }
}

class YSBase2 extends StatefulWidget {
  final Color? ysColor;
  final bool isTab;
  final String ysTitle;
  final Widget? ysRightWidget;
  final Widget? ysChild;
  final int titleType;
  final bool isScroll;
  final int topHeight;
  const YSBase2({Key? key, this.ysColor, this.isTab = false, this.ysTitle = '', this.ysRightWidget, this.ysChild, this.titleType = 0, this.isScroll = true, this.topHeight = 300}) : super(key: key);

  @override
  YSBase2State createState() => YSBase2State();
}

class YSBase2State extends State<YSBase2> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: GestureDetector(
        onTap: (){FocusScope.of(context).unfocus();},
        child: SizedBox(
          height: ysHeight(context),
          width: ysWidth(context),
          child: SingleChildScrollView(
            child: Stack(
              children: [
                const YSHeadView(),
                // Image.asset(YSColors.imageStyle(context, '背景图'),height: hsp(widget.topHeight),width: ysWidth(context),fit: BoxFit.fill,color: Colors.black,),
                SizedBox(
                  child: Column(
                    children: [
                      Container(
                        height: ysTOP(context)+44,
                        padding: EdgeInsets.only(left: hsp(20),right: hsp(20),top: ysTOP(context)),
                        child: LayoutBuilder(
                          builder: (context,conSize){
                            return Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Container(
                                  width: hsp(75),
                                  alignment: Alignment.centerLeft,
                                  child: widget.isTab==true?SizedBox(width: hsp(30),):GestureDetector(
                                      onTap: (){
                                        Navigator.pop(context);
                                      },
                                      child: Row(
                                        children: [
                                          Icon(Icons.chevron_left,size: zsp(30),color: YSColors.containColor(context),),
                                          Text(S.current.FANHUI,style: YSColors.content2Style(context),)
                                        ],
                                      )
                                  ),
                                ),
                                widget.titleType==2?const YSChangeNetView(

                                ):Container(
                                  width: conSize.maxWidth-hsp(150),
                                  padding: EdgeInsets.only(left: hsp(20),right: hsp(20)),
                                  alignment: Alignment.center,
                                  child: widget.titleType==1?Image.asset(
                                    YSColors.imageStyle(context, '资源 3'),
                                    width: hsp(150),
                                    height: hsp(30),
                                  ):widget.titleType==2?const YSChangeNetView(

                                  ):Text(widget.ysTitle,style: YSColors.title2Style(context),maxLines: 1,),
                                ),
                                Container(
                                  width: hsp(75),
                                  alignment: Alignment.centerRight,
                                  child: widget.ysRightWidget??Container(),
                                )
                              ],
                            );
                          },
                        ),
                      ),
                      SizedBox(
                        height: ysHeight(context)-ysTOP(context)-(widget.isTab?114:44),
                        width: ysWidth(context),
                        child: widget.isScroll?SingleChildScrollView(
                            child: widget.ysChild
                        ):widget.ysChild,
                      )
                    ],
                  ),
                )
              ],
            ),
          ),
        ),
      ),
    );
  }
}
