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:yumi/app_localizations.dart';
import 'package:yumi/ui_kit/components/sc_debounce_widget.dart';
import 'package:yumi/shared/tools/sc_date_utils.dart';
import 'package:yumi/shared/data_sources/sources/local/data_persistence.dart';
import 'package:yumi/main.dart';

import 'package:yumi/ui_kit/components/sc_compontent.dart';
import 'package:yumi/ui_kit/components/text/sc_text.dart';
import 'package:yumi/shared/tools/sc_banner_utils.dart';
import 'package:yumi/shared/tools/sc_room_utils.dart';
import 'package:yumi/shared/business_logic/models/res/sc_index_banner_res.dart';

class IndexBannerPage extends StatefulWidget {
  SCIndexBannerRes res;

  IndexBannerPage(this.res);

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

class _IndexBannerPageState extends State<IndexBannerPage> {
  bool isSelect = false;

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      alignment: Alignment.center,
      decoration: BoxDecoration(borderRadius: BorderRadius.circular(8.w)),
      constraints: BoxConstraints(maxHeight: ScreenUtil().screenHeight * 0.7),
      width: ScreenUtil().screenWidth * 0.9,
      child: Stack(
        alignment: AlignmentDirectional.center,
        children: [
          SCDebounceWidget(
            child: netImage(
              url: widget.res.cover ?? "",
              borderRadius: BorderRadius.circular(8.w),
            ),
            onTap: () {
              print('ads:${widget.res.toJson()}');
              SmartDialog.dismiss(tag: "showBannerDialog");
              SCBannerUtils.openBanner(widget.res, navigatorKey.currentState!.context);
            },
          ),
          PositionedDirectional(
            end: 12.w,
            top: 12.w,
            child: GestureDetector(
              behavior: HitTestBehavior.opaque,
              child: Icon(Icons.close, size: 18.w, color: Colors.white),
              onTap: () {
                SCRoomUtils.closeAllDialogs();
              },
            ),
          ),

          PositionedDirectional(
            child: GestureDetector(
              behavior: HitTestBehavior.opaque,
              child: Container(
                decoration: BoxDecoration(
                  color: Colors.black38,
                  borderRadius: BorderRadius.only(
                    bottomLeft: Radius.circular(8.w),
                    bottomRight: Radius.circular(8.w),
                  ),
                ),
                width: ScreenUtil().screenWidth * 0.9,
                padding: EdgeInsets.symmetric(vertical: 5.w),
                child: Row(
                  children: [
                    SizedBox(width: 8.w),
                    Image.asset(
                      !isSelect
                          ? "sc_images/general/sc_icon_unselect.png"
                          : "sc_images/general/sc_icon_select.png",
                      width: 16.w,
                      height: 16.w,
                    ),
                    SizedBox(width: 3.w),
                    text(
                      SCAppLocalizations.of(context)!.noPromptsToday,
                      fontSize: 14.sp,
                      textColor: Colors.white,
                      fontWeight: FontWeight.w600,
                    ),
                  ],
                ),
              ),
              onTap: () {
                isSelect = !isSelect;
                setState(() {});
                DataPersistence.setBool(
                  "IndexBannerTodayShow${SCMDateUtils.formatDateTime(DateTime.now())}",
                  isSelect,
                );
              },
            ),
            start: 0.w,
            bottom: 0.w,
          ),
        ],
      ),
    );
  }
}
