import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_debouncer/flutter_debouncer.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:yumi/app_localizations.dart';
import 'package:yumi/ui_kit/components/sc_compontent.dart';
import 'package:yumi/ui_kit/components/text/sc_text.dart';
import 'package:yumi/ui_kit/components/sc_tts.dart';
import 'package:yumi/ui_kit/theme/socialchat_theme.dart';

import 'package:yumi/shared/tools/sc_pick_utils.dart';
import 'package:yumi/shared/data_sources/sources/repositories/sc_store_repository_imp.dart';

class RoomThemeCustomPage extends StatefulWidget {
  @override
  _RoomThemeCustomPageState createState() => _RoomThemeCustomPageState();
}

class _RoomThemeCustomPageState extends State<RoomThemeCustomPage> {
  String picPath = "";
  final Debouncer debouncer = Debouncer();

  bool uploadSucc = false;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.transparent,
      body: Column(
        children: [
          SizedBox(height: 35.w),
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              GestureDetector(
                child:
                    picPath.isNotEmpty
                        ? netImage(
                          url: picPath,
                          height: 300.w,
                          width: 200.w,
                          borderRadius: BorderRadius.all(Radius.circular(8.w)),
                        )
                        : Image.asset(
                          "sc_images/general/sc_icon_add_pic.png",
                          height: 120.w,
                        ),
                onTap: () {
                  SCPickUtils.pickImage(
                    context,
                    aspectRatio: 0.56,
                    backOriginalFile: false,
                    (bool success, String url) {
                      if (url.isNotEmpty) {
                        setState(() {
                          picPath = url;
                          uploadSucc = true;
                        });
                      }
                    },
                  );
                },
              ),
            ],
          ),
          SizedBox(height: 10.w),
          text(
            SCAppLocalizations.of(context)!.themeGoToUploadTips,
            maxLines: 6,
            fontSize: 14.sp,
            textColor: Colors.white,
          ),
          SizedBox(height: 30.w),
          GestureDetector(
            child: Container(
              height: 46.w,
              width: 250.w,
              alignment: Alignment.center,
              decoration: BoxDecoration(
                color: SocialChatTheme.primaryLight,
                borderRadius: BorderRadius.all(Radius.circular(30.w)),
              ),
              child: text(
                uploadSucc
                    ? "10000${SCAppLocalizations.of(context)!.coins}/30${SCAppLocalizations.of(context)!.day}"
                    : SCAppLocalizations.of(context)!.goToUpload,
                textColor: Colors.white,
                fontSize: 16.sp,
                fontWeight: FontWeight.bold,
              ),
            ),
            onTap: () {
              if (picPath.isNotEmpty) {
                debouncer.debounce(
                  duration: Duration(milliseconds: 350),
                  onDebounce: () {
                    SCStoreRepositoryImp().roomThemeCustomize(picPath).then((
                      value,
                    ) {
                      picPath = "";
                      setState(() {});
                      SCTts.show(
                        SCAppLocalizations.of(context)!.operationSuccessful,
                      );
                    });
                  },
                );
              }
            },
          ),
        ],
      ),
    );
  }
}
