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

import '../../tools/YSColors.dart';
import '../../tools/YSTools.dart';
import '../YSWalletDetail.dart';

class YSWalletManagerListItemView extends StatefulWidget {
  final bool isDetail;
  final Map item;
  const YSWalletManagerListItemView({Key? key, required this.item, this.isDetail = false}) : super(key: key);

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

class YSWalletManagerListItemViewState extends State<YSWalletManagerListItemView> {
  @override
  Widget build(BuildContext context) {
    return widget.isDetail?YSItemView(
      item: widget.item
    ):GestureDetector(
      onTap: (){
        if(widget.isDetail==true)return;
        Navigator.of(context).push(
          CupertinoPageRoute(builder: (context){
            return YSWalletDetail(wallet: widget.item,);
          })
        );
      },
      behavior: HitTestBehavior.opaque,
      child: YSItemView(item: widget.item,),
    );
  }
}

class YSItemView extends StatelessWidget {
  final Map item;
  const YSItemView({Key? key, required this.item}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      width: ysWidth(context)-hsp(30),
      height: hsp(70),
      padding: EdgeInsets.all(hsp(10)),
      decoration: BoxDecoration(
          color: YSColors.containColor(context),
          borderRadius: const BorderRadius.all(Radius.circular(10)),
          boxShadow: [
            BoxShadow(color: YSColors.shadowColor(context),blurRadius: 5)
          ]
      ),
      child: Row(
        children: [
          Stack(
            children: [
              Image.asset(YSColors.imageStyle(context, '路径 3备份 4'),height: hsp(50),width: hsp(50),),
              Container(
                width: hsp(50),
                margin: EdgeInsets.only(top: hsp(40)),
                height: hsp(10),
                // child: Row(
                //   children: [
                //     Expanded(child: Text('-29535.65%',style: TextStyle(fontSize: zsp(6),color: const Color(0xFFFA9C9C)),)),
                //     Image.asset(YSColors.imageStyle(context, '数据折线上升4备份'),height: hsp(10),width: hsp(10),)
                //   ],
                // ),
              )
            ],
          ),
          Expanded(child: Padding(
            padding: EdgeInsets.only(right: hsp(10),left: hsp(10)),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              mainAxisSize: MainAxisSize.min,
              children: [
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    RichText(text: TextSpan(
                      text: '${item['name']}',
                      style: YSColors.contentStyle(context),
                      children: [
                        WidgetSpan(child: YSTagView(wallet: item,),alignment: PlaceholderAlignment.middle)
                      ]
                    )),
                    if(item['chooseType']==1)Icon(Icons.check_circle,size: hsp(20),color: YSColors.iconColor(context),)
                  ],
                ),
                Padding(
                  padding: EdgeInsets.only(top: hsp(5)),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Row(
                        children: [
                          Container(
                            constraints: BoxConstraints(
                                maxWidth: ysWidth(context)/2
                            ),
                            child: Text(ysTextCut(item['public']),style: YSColors.subStyle(context),maxLines: 1,),
                          ),
                          GestureDetector(
                            onTap: (){
                              YSCopyPaste.copy(item['public']);
                            },
                            child: Image.asset(YSColors.imageStyle(context, '复制'),height: hsp(15),width: hsp(15),),
                          )
                        ],
                      ),
                      // Text('10.1 Layer3',style: TextStyle(fontSize: zsp(8),color: const Color(0xFF3D5AFF)),),
                    ],
                  ),
                )
              ],
            ),
          )),
        ],
      ),
    );
  }
}


