/*
 * @Author       : WuWei
 * @LastEditors  : WuWei
 * @Date         : 2022-01-19 16:44:35
 * @LastEditTime : 2023-03-31 10:00:20
 * @Description  : Do not edit
 */

part of 'index.dart';

class _PageView extends StatefulWidget {
  _PageView({Key? key}) : super(key: key);
  @override
  _PageViewState createState() => _PageViewState();
}

class _PageViewState extends State<_PageView> {
  _Store get store => Provider.of(context, listen: false);

  bool _isReadPrivacy = WisStorageUtil.get(key: 'isReadPrivacy') ?? false;

  void _updateData(bool newData) {
    setState(() {
      _isReadPrivacy = newData;
    });
  }

  Future<void> onInitDialog() async {
    if (mounted && store._isReadPrivacy == false) {
      onInitShowDialog();
    }
  }

  /// 隐私政策弹窗
  Future<void> onInitShowDialog() async {
    final _isAgree = await showGeneralDialog(
        context: WNavUtil.instance!.navigatorKey.currentContext!,
        barrierDismissible: false,
        barrierLabel: '',
        transitionDuration: Duration(milliseconds: 200),
        pageBuilder: (BuildContext context, Animation<double> animation,
            Animation<double> secondaryAnimation) {
          return _CenterWebView(
            onNotAgree: () {
              Navigator.of(WNavUtil.instance!.navigatorKey.currentContext!)
                  .pop(false);
            },
            onAgree: () {
              Navigator.of(WNavUtil.instance!.navigatorKey.currentContext!)
                  .pop(true);
            },
          );
        });
    if (_isAgree == true) {
      _updateData(true);
      store.onAgree();
    } else {
      _updateData(false);
      store.onNotAgree();
    }
  }

  @override
  Widget build(BuildContext context) {
    var list = [
      'lib/assets/splash/guide1.png',
      'lib/assets/splash/guide2.png',
      'lib/assets/splash/guide3.png'
    ];
    return Scaffold(
      body: _isReadPrivacy == false
          ? WisScrollView(
              onInit: () => onInitDialog(),
              slivers: [
                SliverToBoxAdapter(
                  child: Wisdom(
                      child: Image.asset(
                    'lib/assets/splash/splash.png',
                    package: 'app_package',
                    width: MediaQuery.of(context).size.width,
                    height: MediaQuery.of(context).size.width * 2.165,
                  )),
                )
              ],
            )
          : store.isInstallApp == true
              ? Wisdom.column(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  color: Colors.white,
                  children: <Widget>[
                    Image.asset(
                      'lib/assets/splash/splash.png',
                      package: 'app_package',
                      width: MediaQuery.of(context).size.width,
                      height: MediaQuery.of(context).size.width * 2.165,
                    ).asFlexible(flex: 1),
                  ],
                )
              : Swiper(
                  itemCount: 3,
                  loop: false,
                  itemBuilder: (_, index) {
                    return Wisdom.column(
                      color: Colors.white,
                      onTap: () => {
                        if (index == 2)
                          {
                            Navigator.pushNamedAndRemoveUntil(
                              context,
                              'login',
                              (route) => false,
                            ),
                          }
                      },
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: <Widget>[
                        Image.asset(
                          list[index],
                          package: 'app_package',
                          fit: BoxFit.cover,
                          width: MediaQuery.of(context).size.width,
                          height: MediaQuery.of(context).size.width * 2.165,
                        ).asFlexible(flex: 1),
                      ],
                    );
                  }),
    );
  }
}

class _CenterWebView extends StatefulWidget {
  _CenterWebView({Key? key, this.onAgree, this.onNotAgree}) : super(key: key);
  final Function()? onAgree;
  final Function()? onNotAgree;
  @override
  __CenterWebViewState createState() => __CenterWebViewState();
}

class __CenterWebViewState extends State<_CenterWebView> {
  @override
  Widget build(BuildContext context) {
    final colorScheme = WTheme.of(context).colorScheme;
    return Center(
      child: Wisdom.column(
        padding: EdgeInsets.only(top: 30.pt, bottom: 20.pt),
        mainAxisSize: MainAxisSize.min,
        // height: 300.pt,
        width: MediaQuery.of(context).size.width * .85,
        borderRadius: BorderRadius.circular(12.pt),
        color: Colors.white,
        children: [
          Wisdom(
            padding: EdgeInsets.only(bottom: 30.pt),
            alignment: Alignment.center,
            child: WisText(
              '用户协议与隐私政策',
              size: 16.pt,
              weight: FontWeight.w600,
              color: colorScheme.mainTitle,
            ),
          ),
          ConstrainedBox(
            constraints: BoxConstraints(
              maxHeight: 230.pt,
              minHeight: 230.pt,
            ),
            child: SingleChildScrollView(
              child: Wisdom.column(
                padding: EdgeInsets.symmetric(horizontal: 15.pt),
                children: [
                  Row(
                    children: [
                      WisText('(1) 《隐私政策》中关于个人设备用户信息的收集和使用说明》。')
                          .asFlexible(flex: 1),
                    ],
                  ),
                  SizedBox(
                    height: 7.pt,
                  ),
                  Row(
                    children: [
                      WisText('(2)《隐私政策》中与第三方SDK类服务商数据共享、相关信息收集和使用说明。')
                          .asFlexible(flex: 1),
                    ],
                  ),
                  SizedBox(
                    height: 7.pt,
                  ),
                  Row(
                    children: [
                      WisText('(3)允许应用获取SN信息，通过消息推送，用于信息通知。')
                          .asFlexible(flex: 1),
                    ],
                  ),
                  SizedBox(
                    height: 7.pt,
                  ),
                  Row(
                    children: [
                      WisText('用户协议和隐私政策说明：').asFlexible(flex: 1),
                    ],
                  ),
                  SizedBox(
                    height: 20.pt,
                  ),
                  Wisdom.wrap(
                    alignment: Alignment.centerLeft,
                    children: [
                      WisText(
                        '阅读完整的',
                        color: colorScheme.grey,
                      ),
                      Wisdom(
                        onTap: () async => await launchUrl(Uri.parse(
                            'https://app.huiguanjia.cn/privacy.html')),
                        child: WisText(
                          '《绘服务个人信息保护政策》',
                          color: colorScheme.primary,
                        ),
                      ),
                      WisText(
                        '了解',
                        color: colorScheme.grey,
                      ),
                      WisText(
                        '更多详细内容',
                        color: colorScheme.grey,
                      ),
                    ],
                  )
                ],
              ),
            ),
          ),
          Wisdom.row(
            padding: EdgeInsets.only(top: 20.pt),
            children: [
              Wisdom(
                onTap: widget.onNotAgree,
                color: Color(0xffF1F1F3),
                height: 44.pt,
                borderRadius: BorderRadius.circular(20.pt),
                margin: EdgeInsets.only(
                  left: 20.pt,
                  right: 10.pt,
                ),
                alignment: Alignment.center,
                child: WisText(
                  '不同意',
                  size: 16.pt,
                  color: colorScheme.mainTitle,
                ),
              ).asFlexible(flex: 1),
              Wisdom(
                onTap: widget.onAgree,
                height: 44.pt,
                color: colorScheme.primary,
                borderRadius: BorderRadius.circular(20.pt),
                margin: EdgeInsets.only(right: 20.pt, left: 10.pt),
                alignment: Alignment.center,
                child: WisText(
                  '同意',
                  size: 16.pt,
                  color: Colors.white,
                ),
              ).asFlexible(flex: 1),
            ],
          ),
        ],
      ),
    );
  }
}
