import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';

import 'YSTools.dart';

class YSWorkUrgeAlertView extends StatefulWidget {
  final ValueSetter<bool> valueSetter;
  const YSWorkUrgeAlertView({Key? key, required this.valueSetter}) : super(key: key);

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

class YSWorkUrgeAlertViewState extends State<YSWorkUrgeAlertView> {
  @override
  Widget build(BuildContext context) {
    return Center(
      child: Container(
        width: ysWidth(context)-hsp(60),
        height: hsp(200),
        decoration: const BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.all(Radius.circular(10))
        ),
        child: LayoutBuilder(
          builder: (context,conSize){
            return Column(
              children: [
                Container(
                  padding: EdgeInsets.all(hsp(24)),
                  height: hsp(150),
                  child: Column(
                    children: [
                      Text('催办提醒',style: TextStyle(fontSize: zsp(16),color: const Color(0xFF323233),decoration: TextDecoration.none),),
                      Padding(
                        padding: EdgeInsets.only(top: hsp(8),bottom: hsp(8)),
                        child: RichText(text: TextSpan(//当前进度：等待部分负责人审批，您是否确定通知提醒相关人员进行审批？
                            text: '当前进度：',
                            style: TextStyle(fontSize: zsp(14),color: const Color(0xFF4A4A4A),decoration: TextDecoration.none,fontWeight: FontWeight.normal),
                            children: const [
                              TextSpan(
                                  text: '等待部分负责人审批，',
                                  style: TextStyle(color: Color(0xFF377DFE))
                              ),
                              TextSpan(
                                text: '您是否确定通知提醒相关人员进行审批？',
                              )
                            ]
                        )),
                      ),
                      Text('注：每天只能发送一次提醒通知',style: TextStyle(fontSize: zsp(12),color: const Color(0xFF969799),decoration: TextDecoration.none,fontWeight: FontWeight.normal),),
                    ],
                  ),
                ),
                Container(
                  height: hsp(50),
                  decoration: const BoxDecoration(
                    border: Border(top: BorderSide(color: Color(0xFFEBEDF0),width: 0.5))
                  ),
                  child: ListView.separated(
                    itemBuilder: (context,index){
                      return GestureDetector(
                        onTap: (){
                          Navigator.pop(context);
                          widget.valueSetter(index==1);
                        },
                        behavior: HitTestBehavior.opaque,
                        child: Container(
                          width: conSize.maxWidth/2-0.25,
                          alignment: Alignment.center,
                          child: Text(
                            index==0?'取消':'确定',
                            style: TextStyle(
                              fontSize: zsp(16),
                              color: index==0?const Color(0xFF323233):const Color(0xFF377DFE),
                              decoration: TextDecoration.none,
                              fontWeight: FontWeight.normal
                            ),
                          ),
                        ),
                      );
                    }, 
                    separatorBuilder: (context,index){
                      return Container(width: 0.5,color: const Color(0xFFEBEDF0),);
                    }, 
                    itemCount: 2,
                    scrollDirection: Axis.horizontal,
                  ),
                )
              ],
            );
          },
        ),
      ),
    );
  }
}

class YSTipsAlertView extends StatefulWidget {
  final ValueSetter<bool> valueSetter;
  final String tipsStr;
  final String btnStr1;
  final String btnStr2;
  const YSTipsAlertView({Key? key, required this.valueSetter, this.tipsStr = '', this.btnStr1 = '否', this.btnStr2 = '是'}) : super(key: key);

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

class YSTipsAlertViewState extends State<YSTipsAlertView> {
  @override
  Widget build(BuildContext context) {
    return Center(
      child: Container(
        width: ysWidth(context)-hsp(60),
        height: hsp(150),
        decoration: const BoxDecoration(
            color: Color(0xFF3A3F49),
            borderRadius: BorderRadius.all(Radius.circular(10))
        ),
        child: LayoutBuilder(
          builder: (context,conSize){
            return Column(
              children: [
                // Container(
                //   height: hsp(50),
                //   decoration: const BoxDecoration(
                //       border: Border(bottom: BorderSide(color: Color(0xFFEBEDF0),width: 0.5))
                //   ),
                //   alignment: Alignment.center,
                //   child: Text('提醒',style: TextStyle(fontSize: zsp(16),color: Colors.black,decoration: TextDecoration.none),),
                // ),
                Container(
                  height: hsp(100),
                  alignment: Alignment.center,
                  padding: EdgeInsets.all(hsp(10)),
                  child: Text(widget.tipsStr,style: TextStyle(fontSize: zsp(16),color: Colors.white,
                      decoration: TextDecoration.none,fontWeight: FontWeight.normal),maxLines: 3,overflow: TextOverflow.ellipsis,),
                ),
                Container(
                  height: hsp(50),
                  decoration: const BoxDecoration(
                      border: Border(top: BorderSide(color: Color(0xFF1A1C1F),width: 0.5))
                  ),
                  child: ListView.separated(
                    itemBuilder: (context,index){
                      return GestureDetector(
                        onTap: (){
                          Navigator.pop(context);
                          widget.valueSetter(index==1);
                        },
                        behavior: HitTestBehavior.opaque,
                        child: Container(
                          width: conSize.maxWidth/2-0.25,
                          alignment: Alignment.center,
                          child: Text(
                            index==0?widget.btnStr1:widget.btnStr2,
                            style: TextStyle(
                                fontSize: zsp(16),
                                color: index==0?const Color(0xFFACB5C5):const Color(0xFFFBFBFB),
                                decoration: TextDecoration.none,
                                fontWeight: FontWeight.normal
                            ),
                          ),
                        ),
                      );
                    },
                    separatorBuilder: (context,index){
                      return Container(width: 0.5,color: const Color(0xFF1A1C1F),);
                    },
                    itemCount: 2,
                    scrollDirection: Axis.horizontal,
                  ),
                )
              ],
            );
          },
        ),
      ),
    );
  }
}

class YSChooseFileView extends StatefulWidget {
  final bool isPhoto;
  final ValueSetter valueSetter;
  const YSChooseFileView({Key? key, required this.valueSetter, this.isPhoto = true}) : super(key: key);

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

class YSChooseFileViewState extends State<YSChooseFileView> {
  final ImagePicker _picker = ImagePicker();
  final List _chooseArray = [];
  @override
  void initState() {
    _chooseArray.clear();
    if(widget.isPhoto){
      _chooseArray.addAll([
        {'title':'拍摄小票','type':5},
        {'title':'选择小票','type':6},
        {'title':'拍摄发票','type':7},
        {'title':'选择发票','type':8},
        {'title':'取消','type':0}
      ]);
    }else{
      _chooseArray.addAll([
        {'title':'拍摄图片','type':1},
        {'title':'选择图片','type':2},
        {'title':'拍摄视频','type':3},
        {'title':'选择视频','type':4},
        {'title':'取消','type':0}
      ]);
    }
    super.initState();
  }
  @override
  Widget build(BuildContext context) {
    return Container(
      height: hsp(20)+hsp(50*_chooseArray.length),
      decoration: const BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.only(topRight: Radius.circular(10),topLeft: Radius.circular(10))
      ),
      child: ListView.separated(
        physics: const NeverScrollableScrollPhysics(),
        itemCount: _chooseArray.length,
        padding: const EdgeInsets.all(0),
        itemBuilder: (context,index){
          Map item = _chooseArray[index];
          int type = item['type'];
          return GestureDetector(
            onTap: (){
              if(type==0){
                Navigator.pop(context);
              }else{
                if(type==1||type==5||type==6||type==7||type==8){
                  _picker.pickImage(source: type==6||type==8?ImageSource.gallery:ImageSource.camera,imageQuality: 60).then((value){
                    Map image = {'type':1,'value':value!};
                    if(type==7||type==8)image['invoice'] = true;
                    widget.valueSetter(image);
                    Navigator.pop(context);
                  });
                }else if(type==2){
                  _picker.pickMultiImage(imageQuality: 60).then((value){
                    widget.valueSetter({'type':1,'value':value});
                    Navigator.pop(context);
                  });
                }else if(type==3||type==4){
                  _picker.pickVideo(source: type==3?ImageSource.camera:ImageSource.gallery).then((value){
                    widget.valueSetter({'type':2,'value':value!});
                    Navigator.pop(context);
                  });
                }
              }
            },
            behavior: HitTestBehavior.opaque,
            child: Container(
              height: hsp(50),
              width: MediaQuery.of(context).size.width,
              padding: EdgeInsets.only(left: hsp(16),right: hsp(16)),
              alignment: Alignment.center,
              child: Text(item['title'],style: TextStyle(fontSize: zsp(16),color: Colors.black),),
            ),
          );
        },
        separatorBuilder: (context,index){
          return Divider(height: index==_chooseArray.length-2?hsp(8):hsp(1),thickness: index==_chooseArray.length-2?hsp(8):hsp(1),color: const Color(0xFFF7F7F7),);
        },
      ),
    );
  }
}
